improved some aspect of the pack extraction tools (error check, automatically select the mod after installing)

This commit is contained in:
Faraphel 2022-02-10 08:35:35 +01:00
parent 2e5c7ec773
commit 821ae77a22
4 changed files with 17 additions and 2 deletions

View file

@ -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"
)

View file

@ -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)

View file

@ -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(