From 821ae77a2242022ef457516313502281bb4e19de Mon Sep 17 00:00:00 2001 From: Faraphel Date: Thu, 10 Feb 2022 08:35:35 +0100 Subject: [PATCH] improved some aspect of the pack extraction tools (error check, automatically select the mod after installing) --- source/Error.py | 12 ++++++++++-- source/Gui/CheatManager.py | 0 source/Gui/Main.py | 1 + source/Gui/SelectPack.py | 6 ++++++ 4 files changed, 17 insertions(+), 2 deletions(-) delete mode 100644 source/Gui/CheatManager.py diff --git a/source/Error.py b/source/Error.py index 2627fc0..1e83f5c 100644 --- a/source/Error.py +++ b/source/Error.py @@ -38,6 +38,11 @@ class MissingTrackWU8(Exception): super().__init__("The original wu8 track file is missing !") +class CorruptedPack(Exception): + def __init__(self): + super().__init__("This pack seem corrupted !") + + class ErrorLogger: def __init__(self, common): self.common = common @@ -47,12 +52,15 @@ class ErrorLogger: When an error occur, will show it in a messagebox and write it in error.log """ error = traceback.format_exc() + file_list = os.listdir('./file/') if os.path.exists("./file/") else None + ctconfig_list = os.listdir(self.common.ct_config.pack_path) if os.path.exists(self.common.ct_config.pack_path) else None + with open("./error.log", "a") as f: f.write( f"---\n" f"For game version : {self.common.ct_config.version}\n" - f"./file/ directory : {os.listdir('./file/')}\n" - f"ctconfig directory : {os.listdir(self.common.ct_config.pack_path)}\n" + f"./file/ directory : {file_list}\n" + f"ctconfig directory : {ctconfig_list}\n" f"GAME/files/ information : {self.common.game.path, self.common.game.region}\n" f"{error}\n" ) diff --git a/source/Gui/CheatManager.py b/source/Gui/CheatManager.py deleted file mode 100644 index e69de29..0000000 diff --git a/source/Gui/Main.py b/source/Gui/Main.py index eb05526..2c9222a 100644 --- a/source/Gui/Main.py +++ b/source/Gui/Main.py @@ -275,6 +275,7 @@ class Main: def get_available_packs() -> list: available_packs = [] + os.makedirs("./Pack/", exist_ok=True) for pack_ctconfig in glob.glob("./Pack/*/ct_config.json"): dirname = os.path.basename(os.path.dirname(pack_ctconfig)) available_packs.append(dirname) diff --git a/source/Gui/SelectPack.py b/source/Gui/SelectPack.py index 3b6a7c1..14f1d0f 100644 --- a/source/Gui/SelectPack.py +++ b/source/Gui/SelectPack.py @@ -5,6 +5,8 @@ from tkinter import messagebox import zipfile import os +from source.Error import CorruptedPack + class SelectPack: def __init__(self, common): @@ -43,8 +45,11 @@ class SelectPack: packname = ".".join(packname) with zipfile.ZipFile(path) as zip_pack: + if "ct_config.json" not in zip_pack.namelist(): + raise CorruptedPack() zip_pack.extractall(f"./Pack/{packname}/") + self.common.gui_main.stringvar_ctconfig.set(packname) self.common.gui_main.reload_ctconfig() messagebox.showinfo( @@ -55,6 +60,7 @@ class SelectPack: except Exception as e: self.progressbar_extract.grid_forget() + self.common.log_error() raise e self.button_extract_modpack = Button(