From cf8d1bb20e87bcdce759b0e0ffaf22fa527fb53d Mon Sep 17 00:00:00 2001 From: Faraphel Date: Mon, 23 Aug 2021 23:52:30 +0200 Subject: [PATCH 1/3] "do everything button" now use a single thread instead of 3 threads for the 3 parts, allowing the program to stop if an error is raised --- source/Game.py | 8 ++++++-- source/Gui.py | 15 ++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/source/Game.py b/source/Game.py index dd347ec..7088c43 100644 --- a/source/Game.py +++ b/source/Game.py @@ -148,7 +148,9 @@ class Game: self.region = region_id_to_name[self.region_ID] if self.region_ID in region_id_to_name else self.region @in_thread - def install_mod(self): + def install_mod(self): self.nothread_install_mod() + + def nothread_install_mod(self): """ Patch the game to install the mod """ @@ -348,7 +350,9 @@ class Game: finalise(f"./file/Common_R{bmglang}.txt", rbmgcommon) @in_thread - def patch_file(self): + def patch_file(self): self.nothread_patch_file() + + def nothread_patch_file(self): """ Prepare all files to install the mod (track, bmg text, descriptive image, ...) """ diff --git a/source/Gui.py b/source/Gui.py index 89e6067..72a52b4 100644 --- a/source/Gui.py +++ b/source/Gui.py @@ -108,7 +108,9 @@ class Gui: self.frame_game_path_action.columnconfigure(1, weight=1) @in_thread - def use_path(): + def use_path(): nothread_use_path() + + def nothread_use_path(): self.frame_action.grid_forget() try: self.game.set_path(entry_game_path.get()) @@ -132,14 +134,9 @@ class Gui: @in_thread def do_everything(): - use_path().join() - self.game.patch_file().join() - self.game.install_mod().join() - - if messagebox.askyesno(self.translate("Experimental functionality"), - self.translate("This will extract the selected ROM, prepare files and install mod. " - "Do you wish to continue ?")): - do_everything() + nothread_use_path() + self.game.nothread_patch_file() + self.game.nothread_install_mod() self.button_do_everything = Button(self.frame_game_path_action, text=self.translate("Do everything"), relief=RIDGE, command=do_everything) self.button_do_everything.grid(row=1, column=2, sticky="NEWS") From 4758e6ae888a2036f73c9327dcb49163726d7297 Mon Sep 17 00:00:00 2001 From: Faraphel Date: Tue, 24 Aug 2021 19:58:29 +0200 Subject: [PATCH 2/3] added return when exception is raise in nothread_use_path so that "do everything" process stop when an error is occuring --- source/Gui.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/Gui.py b/source/Gui.py index 72a52b4..af15249 100644 --- a/source/Gui.py +++ b/source/Gui.py @@ -119,12 +119,16 @@ class Gui: self.frame_action.grid(row=3, column=1, sticky="NEWS") except RomAlreadyPatched: messagebox.showerror(self.translate("Error"), self.translate("This game is already modded")) + raise RomAlreadyPatched except InvalidGamePath: messagebox.showerror(self.translate("Error"), self.translate("The file path in invalid")) + raise InvalidGamePath except InvalidFormat: messagebox.showerror(self.translate("Error"), self.translate("This game's format is invalid")) + raise InvalidFormat except: self.log_error() + raise Exception finally: self.progress(show=False) From bb59d1dc18b38bbddfb53710d4d4d3f9e0e8be22 Mon Sep 17 00:00:00 2001 From: Faraphel Date: Thu, 26 Aug 2021 11:34:25 +0200 Subject: [PATCH 3/3] removed a old useless condition stopping the patch_file process if patch_tracks failed (not return 0), which can't happen since patch_track could only return 0 --- source/Game.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/source/Game.py b/source/Game.py index 7088c43..75b9580 100644 --- a/source/Game.py +++ b/source/Game.py @@ -58,9 +58,9 @@ class NoGui: def get(self): return self.value - def progress(self, *args, **kwargs): print(args, kwargs) - def translate(self, *args, **kwargs): return "" - def log_error(self, *args, **kwargs): print(args, kwargs) + def progress(*args, **kwargs): print(args, kwargs) + def translate(*args, **kwargs): return "" + def log_error(*args, **kwargs): print(args, kwargs) is_dev_version = False button_install_mod = NoButton() @@ -377,7 +377,7 @@ class Game: for file in glob.glob(self.path + "/files/Scene/UI/MenuSingle_?.szs"): self.patch_bmg(file) # MenuSingle could be any other file, Common and Menu are all the same in all other files. self.patch_autoadd() - if self.patch_tracks() != 0: return + self.patch_tracks() self.gui.button_install_mod.grid(row=2, column=1, columnspan=2, sticky="NEWS") self.gui.button_install_mod.config( @@ -423,11 +423,9 @@ class Game: new_4_3.paste(img_lang_4_3, (0, 0), img_lang_4_3) new_4_3.save(dest_dir + f"/strapA_608x456{get_filename(get_nodir(file_lang))}.png") - - def patch_tracks(self) -> int: + def patch_tracks(self) -> None: """ Download track's wu8 file and convert them to szs - :return: 0 if no error occured """ max_process = self.gui.intvar_process_track.get() thread_list = {} @@ -500,5 +498,3 @@ class Game: clean_process() while clean_process() != 1: pass # End the process if all process ended - - return 0