Last active
December 4, 2024 08:49
-
-
Save Gesugao-san/4a3ecb9229699315e8deec67889e5337 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
User = 'ChangeMe' | |
WalkthroughNumber = 1 | |
WordMetaMain = r'.\world_meta.xml' | |
WorldFileNamePrefab = '.%s.%s' % (User, WalkthroughNumber) | |
import os | |
import xml.etree.ElementTree as ET | |
import glob | |
xmlFilesRaw = [ | |
f.rstrip(').xml') for f in glob.glob( | |
'world_meta(*).xml', | |
root_dir=r'.\Backup' | |
) | |
] | |
WorldIndexes = [int(f.lstrip('world_meta(')) for f in xmlFilesRaw] | |
#WorldIndexes.sort() | |
print('WorldIndexes:', WorldIndexes) | |
print() | |
global st_atime | |
global st_mtime | |
#global st_birthtime | |
global st_ctime | |
st_atime = 0 | |
st_mtime = 0 | |
#st_birthtime = 0 | |
st_ctime = 0 | |
def save_utime(path_to_file): | |
global st_atime | |
global st_mtime | |
#global st_birthtime | |
global st_ctime | |
stinfo = os.stat(path_to_file) | |
st_atime = stinfo.st_atime | |
st_mtime = stinfo.st_mtime | |
#st_birthtime = stinfo.st_birthtime | |
st_ctime = stinfo.st_ctime | |
#print (stinfo) | |
def get_tree(path_to_file): | |
global WFNNew | |
global tree | |
tree = ET.parse(path_to_file) | |
return tree | |
def fix_name(tree): | |
root = tree.getroot() | |
GameVersion = root.find('GameVersion').text.split('.')[2] | |
#print('GameVersion:', GameVersion) | |
WorldFileName = root.find('WorldFileName') | |
#print('WorldFileNameOld:', WorldFileName.text) | |
WFNNew = '%s%s' % (GameVersion, WorldFileNamePrefab) | |
#print('WorldFileNameNew:', WFNNew) | |
#print() | |
if (WorldFileName.text != WFNNew): | |
WorldFileName.text = WFNNew | |
#for elem in root.iter(): print(elem.tag, elem.attrib, elem.text) | |
def write_xml(path_to_file): | |
global st_atime | |
global st_mtime | |
#global st_birthtime | |
global st_ctime | |
tree = get_tree(path_to_file) | |
fix_name(tree) | |
tree.write(path_to_file) | |
# os.utime(<path>, (<access date epoch>, <modification date epoch>)) | |
os.utime(path_to_file, (st_atime, st_mtime)) | |
def fix_difficulty(path_to_file): | |
tree = get_tree(path_to_file) | |
difficulty = tree.find('./DifficultySetting') | |
if (difficulty.attrib['Id'] != 'Normal'): | |
difficulty.set('Id', 'Normal') | |
global st_atime | |
global st_mtime | |
#global st_birthtime | |
global st_ctime | |
tree.write(path_to_file) | |
# os.utime(<path>, (<access date epoch>, <modification date epoch>)) | |
os.utime(path_to_file, (st_atime, st_mtime)) | |
def fix_main(path_to_file): | |
save_utime(path_to_file) | |
get_tree(path_to_file) | |
write_xml(path_to_file) | |
def fix_backups(): | |
for i in WorldIndexes: | |
#print(i, os.stat('.\\Backup\\screenshot(%s).png' % i).st_ctime) | |
screenshot = '.\\Backup\\screenshot(%s).png' % i | |
screenshot2 = '.\\Backup\\screenshot(%s)_AutoSave.png' % i | |
meta = '.\\Backup\\world_meta(%s).xml' % i | |
data = '.\\Backup\\world(%s).xml' % i | |
autosave = '.\\Backup\\world(%s)_AutoSave.xml' % i | |
if os.path.isfile(screenshot): | |
save_utime(screenshot) | |
if os.path.isfile(screenshot2): | |
save_utime(screenshot2) | |
if os.path.isfile(meta): | |
get_tree(meta) | |
write_xml(meta) | |
if os.path.isfile(data): | |
fix_difficulty(data) | |
if os.path.isfile(autosave): | |
fix_difficulty(autosave) | |
def main(): | |
fix_main(WordMetaMain) | |
fix_backups() | |
#os._exit(0) | |
#pass | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment