separated install_mod function into multiple subfunction to be may more easier to understand

This commit is contained in:
raphael60650 2021-10-31 22:36:42 +01:00
parent d65ef8c08f
commit f7186b6abc

View file

@ -155,17 +155,17 @@ class Game:
def install_mod(self): def install_mod(self):
self.nothread_install_mod() self.nothread_install_mod()
def nothread_install_mod(self): def count_patch_subfile_operation(self) -> int:
""" """
Patch the game to install the mod count all the step patching subfile will take (for the progress bar)
:return: number of step estimated
""" """
try:
with open("./fs.json") as f: with open("./fs.json") as f:
fs = json.load(f) fs = json.load(f)
# This part is used to estimate the max_step # This part is used to estimate the max_step
extracted_file = [] extracted_file = []
max_step, step = 1, 0 max_step = 1
def count_rf(path): def count_rf(path):
nonlocal max_step nonlocal max_step
@ -185,19 +185,18 @@ class Game:
count_rf(path=f) count_rf(path=f)
elif type(fs[fp][nf]) == list: elif type(fs[fp][nf]) == list:
for ffp in fs[fp][nf]: count_rf(path=f) for ffp in fs[fp][nf]: count_rf(path=f)
###
return max_step
def install_patch_subfile(self) -> None:
"""
patch subfile as indicated in the fs.json file (for file structure)
"""
with open("./fs.json") as f:
fs = json.load(f)
extracted_file = [] extracted_file = []
max_step += 5 # PATCH main.dol and PATCH lecode.bin, converting, changing ID, copying MyStuff Folder self.gui.progress(show=True, indeter=False, statut=self.gui.translate("Modifying subfile..."), add=1)
self.gui.progress(show=True, indeter=False, statut=self.gui.translate("Copying MyStuff"), max=max_step,
step=0)
mystuff_folder = self.gui.stringvar_mystuff_folder.get()
if mystuff_folder and mystuff_folder != "None":
shutil.copytree(mystuff_folder, self.path + "/files/", dirs_exist_ok=True)
self.gui.progress(show=True, indeter=False, statut=self.gui.translate("Installing mod"),
add=1)
def replace_file(path, file, subpath="/") -> None: def replace_file(path, file, subpath="/") -> None:
""" """
@ -243,13 +242,30 @@ class Game:
if os.path.exists(file + ".d"): if os.path.exists(file + ".d"):
shutil.rmtree(file + ".d") shutil.rmtree(file + ".d")
def install_copy_mystuff(self) -> None:
"""
copy MyStuff directory into the game before patching the game
"""
self.gui.progress(show=True, indeter=False, statut=self.gui.translate("Copying MyStuff..."), add=1)
mystuff_folder = self.gui.stringvar_mystuff_folder.get()
if mystuff_folder and mystuff_folder != "None":
shutil.copytree(mystuff_folder, self.path + "/files/", dirs_exist_ok=True)
def install_patch_maindol(self) -> None:
"""
patch the main.dol file to allow the addition of LECODE.bin file
"""
self.gui.progress(statut=self.gui.translate("Patch main.dol"), add=1) self.gui.progress(statut=self.gui.translate("Patch main.dol"), add=1)
wstrt.patch(path=self.path) wstrt.patch(path=self.path)
def install_patch_lecode(self) -> None:
"""
configure and add the LECODE.bin file to the mod
"""
self.gui.progress(statut=self.gui.translate("Patch lecode.bin"), add=1) self.gui.progress(statut=self.gui.translate("Patch lecode.bin"), add=1)
shutil.copytree("./file/Track/", self.path + "/files/Race/Course/", dirs_exist_ok=True) shutil.copytree("./file/Track/", self.path + "/files/Race/Course/", dirs_exist_ok=True)
lpar_path = "./file/lpar-debug.txt" if self.gui.boolvar_use_debug_mode.get() else "./file/lpar-default.txt" lpar_path = "./file/lpar-debug.txt" if self.gui.boolvar_use_debug_mode.get() else "./file/lpar-default.txt"
lec.patch( lec.patch(
@ -261,10 +277,29 @@ class Game:
lpar_path=lpar_path, lpar_path=lpar_path,
) )
def install_convert_rom(self) -> None:
"""
convert the rom to the selected game format
"""
output_format = self.gui.stringvar_game_format.get() output_format = self.gui.stringvar_game_format.get()
self.gui.progress(statut=self.gui.translate("Converting to", " ", output_format), add=1) self.gui.progress(statut=self.gui.translate("Converting to", " ", output_format), add=1)
self.convert_to(output_format) self.convert_to(output_format)
def nothread_install_mod(self) -> None:
"""
Patch the game to install the mod
"""
try:
max_step = 5 + self.count_patch_subfile_operation()
# PATCH main.dol and PATCH lecode.bin, converting, changing ID, copying MyStuff Folder
self.gui.progress(statut=self.gui.translate("Installing mod..."), max=max_step, step=0)
self.install_copy_mystuff()
self.install_patch_subfile()
self.install_patch_maindol()
self.install_patch_lecode()
self.install_convert_rom()
messagebox.showinfo(self.gui.translate("End"), self.gui.translate("The mod has been installed !")) messagebox.showinfo(self.gui.translate("End"), self.gui.translate("The mod has been installed !"))
except: except: