-
Notifications
You must be signed in to change notification settings - Fork 0
/
gsm_xml_processor.py
32 lines (30 loc) · 1.18 KB
/
gsm_xml_processor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# gsm_xml_processor.py
import xml.etree.ElementTree as ET
from py7zr import SevenZipFile
from zipfile import ZipFile
import logging
#Detect "GSM_INFO.xml" file in GameSave Manager zip file
def locate_gsm_info_in_zip(zip_ref):
try:
if isinstance(zip_ref, SevenZipFile):
for fname, bio in zip_ref.readall().items():
if fname == 'GSM_INFO.xml':
return bio.read()
return None
elif isinstance(zip_ref, ZipFile):
for fname in zip_ref.namelist():
if fname == 'GSM_INFO.xml':
return zip_ref.read(fname)
return None
except Exception as e:
logging.error(f"Error locating GSM_INFO.xml in zip: {e}")
return None
def validate_xml_string(gsm_gsba_file_path: str, xml_string: str, print_xml: bool = False):
try:
root = ET.fromstring(xml_string)
if print_xml:
logging.info(xml_string.decode('ascii'))
return (root.tag == 'GameSaveManager_EntryData')
except ET.ParseError as e:
logging.error(f"Error parsing XML data in file: {gsm_gsba_file_path}. {str(e)}")
return False