From 627e652212e9f2969587f4618658eb4778e00c9e Mon Sep 17 00:00:00 2001 From: Emboarger <90681641+Emboarger@users.noreply.github.com> Date: Sat, 3 Feb 2024 00:21:29 +0000 Subject: [PATCH 1/3] Added rudimentary save backup upon loading Save backup automatically created in the official save backup folder -> {save_dir}/backup/world/{date-time} --- PalEdit.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/PalEdit.py b/PalEdit.py index 26b0ede..3245037 100644 --- a/PalEdit.py +++ b/PalEdit.py @@ -1,4 +1,4 @@ -import os, webbrowser, json, time, uuid, math +import os, webbrowser, json, time, uuid, math, shutil, datetime # pyperclip # docs: https://pypi.org/project/pyperclip/#description @@ -414,6 +414,24 @@ def loadfile(): if file: filename = file + + now = datetime.datetime.now() + current_date = ".".join((str(now.date().year), + "{:02d}".format(now.date().month), + "{:02d}".format(now.date().day))) + current_time = ".".join(("{:02d}".format(now.time().hour), + "{:02d}".format(now.time().minute), + "{:02d}".format(now.time().second))) + current_datetime = "-".join((current_date, current_time)) + backup_path = file.replace("Level.sav", os.path.join("backup", "world", current_datetime)) + if not os.path.exists(backup_path): + os.makedirs(backup_path) + os.makedirs(os.path.join(backup_path, "Players")) + shutil.copy(filename, os.path.join(backup_path, "Level.sav")) + shutil.copy(filename.replace("Level.sav", "LevelMeta.sav"), os.path.join(backup_path, "LevelMeta.sav")) + for player_file in os.scandir(filename.replace("Level.sav", "Players")): + shutil.copy(player_file.path, os.path.join(backup_path, "players", player_file.name)) + root.title(f"PalEdit v{version} - {file}") skilllabel.config(text="Decompiling save, please be patient...") doconvertjson(file, (not debug)) @@ -518,7 +536,7 @@ def load(file): changetext(-1) jump() - messagebox.showinfo("Done", "Done loading!") + messagebox.showinfo("Done", "Done loading!\n(Backup save created)") def jump(): root.attributes('-topmost', 1) From 7622445a1c859bb2515c5cf5a55e256f0f59f418 Mon Sep 17 00:00:00 2001 From: Emboarger <90681641+Emboarger@users.noreply.github.com> Date: Sat, 17 Feb 2024 20:49:54 +0000 Subject: [PATCH 2/3] Update PalEdit.py --- PalEdit.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/PalEdit.py b/PalEdit.py index 1e6e511..e03d3ab 100644 --- a/PalEdit.py +++ b/PalEdit.py @@ -1,4 +1,4 @@ -import os, webbrowser, json, time, uuid, math +import os, webbrowser, json, time, uuid, math, shutil, datetime # pyperclip # docs: https://pypi.org/project/pyperclip/#description @@ -450,9 +450,30 @@ def loadfile(self): file = askopenfilename(initialdir=os.path.expanduser('~') + "\\AppData\\Local\\Pal\\Saved\\SaveGames", filetypes=[("Level.sav", "Level.sav")]) print(f"Opening file {file}") + print('Backing up save') if file: self.filename = file + + now = datetime.datetime.now() + current_date = ".".join((str(now.date().year), + "{:02d}".format(now.date().month), + "{:02d}".format(now.date().day))) + current_time = ".".join(("{:02d}".format(now.time().hour), + "{:02d}".format(now.time().minute), + "{:02d}".format(now.time().second))) + current_datetime = "-".join((current_date, current_time)) + backup_path = file.replace("Level.sav", os.path.join("backup", "world", current_datetime)) + if not os.path.exists(backup_path): + os.makedirs(backup_path) + os.makedirs(os.path.join(backup_path, "Players")) + os.makedirs(backup_path.replace('world', 'local')) + shutil.copy(self.filename, os.path.join(backup_path, "Level.sav")) + shutil.copy(self.filename.replace("Level.sav", "LevelMeta.sav"), os.path.join(backup_path, "LevelMeta.sav")) + shutil.copy(self.filename.replace("Level.sav", "LocalData.sav"), os.path.join(backup_path.replace('world', 'local'), 'LocalData.sav')) + for player_file in os.scandir(self.filename.replace("Level.sav", "Players")): + shutil.copy(player_file.path, os.path.join(backup_path, "players", player_file.name)) + self.gui.title(f"PalEdit v{PalEditConfig.version} - {file}") self.skilllabel.config(text=self.i18n['msg_decompressing']) with open(file, "rb") as f: From 92ef090a4ba868fca80a477bd59462dd0e1e7775 Mon Sep 17 00:00:00 2001 From: Emboarger <90681641+Emboarger@users.noreply.github.com> Date: Mon, 19 Feb 2024 21:41:10 +0000 Subject: [PATCH 3/3] Update PalEdit.py --- PalEdit.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/PalEdit.py b/PalEdit.py index 74a7f95..ec3a87d 100644 --- a/PalEdit.py +++ b/PalEdit.py @@ -1,4 +1,4 @@ -import os, webbrowser, json, time, uuid, math +import os, webbrowser, json, time, uuid, math, shutil # pyperclip # docs: https://pypi.org/project/pyperclip/#description @@ -565,9 +565,31 @@ def loadfile(self): file = askopenfilename(initialdir=os.path.expanduser('~') + "\\AppData\\Local\\Pal\\Saved\\SaveGames", filetypes=[("Level.sav", "Level.sav")]) self.logger.WriteLog(f"Opening file {file}") + self.logger.WriteLog(f"Backing up save") if file: self.filename = file + + now = datetime.now() + current_date = ".".join((str(now.date().year), + "{:02d}".format(now.date().month), + "{:02d}".format(now.date().day))) + current_time = ".".join(("{:02d}".format(now.time().hour), + "{:02d}".format(now.time().minute), + "{:02d}".format(now.time().second))) + current_datetime = "-".join((current_date, current_time)) + backup_path = file.replace("Level.sav", os.path.join("backup", "world", current_datetime)) + if not os.path.exists(backup_path): + os.makedirs(backup_path) + os.makedirs(os.path.join(backup_path, "Players")) + if not os.path.exists(backup_path.replace('world', 'local')): + os.makedirs(backup_path.replace('world', 'local')) + shutil.copy(self.filename, os.path.join(backup_path, "Level.sav")) + shutil.copy(self.filename.replace("Level.sav", "LevelMeta.sav"), os.path.join(backup_path, "LevelMeta.sav")) + shutil.copy(self.filename.replace("Level.sav", "LocalData.sav"), os.path.join(backup_path.replace('world', 'local'), 'LocalData.sav')) + for player_file in os.scandir(self.filename.replace("Level.sav", "Players")): + shutil.copy(player_file.path, os.path.join(backup_path, "players", player_file.name)) + self.gui.title(f"PalEdit v{PalEditConfig.version} - {file}") self.skilllabel.config(text=self.i18n['msg_decompressing']) with open(file, "rb") as f: