diff --git a/source/CT_Config.py b/source/CT_Config.py index b87376e..de3ce29 100644 --- a/source/CT_Config.py +++ b/source/CT_Config.py @@ -41,7 +41,6 @@ class CT_Config: """ add a cup to the config :param cup: a Cup object to add as an ordered cup - :return: ? """ self.ordered_cups.append(cup) for track in cup.tracks: @@ -52,7 +51,6 @@ class CT_Config: """ add a single track to the config :param track: a Track object to add as an unordered tracks - :return: ? """ self.unordered_tracks.append(track) self.all_version.add(track.since_version) @@ -63,7 +61,6 @@ class CT_Config: create a ctfile configuration in a directory :param highlight_version: highlight a specific version in light blue :param directory: create CTFILE.txt and RCTFILE.txt in this directory - :return: None """ with open(directory + "CTFILE.txt", "w", encoding="utf-8") as ctfile, \ open(directory + "RCTFILE.txt", "w", encoding="utf-8") as rctfile: diff --git a/source/Game.py b/source/Game.py index a1afe0e..07bfa0d 100644 --- a/source/Game.py +++ b/source/Game.py @@ -75,12 +75,12 @@ class Game: """ if format in ["ISO", "WBFS", "CISO"]: path_game_format: str = os.path.realpath(self.path + "/../MKWFaraphel." + format.lower()) - wszst.wit_copy(self.path, path_game_format, format) + wszst.wit.copy(self.path, path_game_format, format) shutil.rmtree(self.path) self.path = path_game_format self.gui.progress(statut=self.gui.translate("Changing game's ID"), add=1) - wszst.edit(self.path, region_ID=self.region_ID, name=f"Mario Kart Wii Faraphel {self.ctconfig.version}") + wszst.wit.edit(self.path, region_ID=self.region_ID, name=f"Mario Kart Wii Faraphel {self.ctconfig.version}") def extract(self) -> None: """ @@ -97,7 +97,7 @@ class Game: if not (os.path.exists(path_dir)): break directory_name, i = f"MKWiiFaraphel ({i})", i + 1 - wszst.wit_extract(self.path, path_dir) + wszst.wit.extract(self.path, path_dir) self.path = path_dir if os.path.exists(self.path + "/DATA"): self.path += "/DATA" @@ -166,7 +166,7 @@ class Game: if extension == "szs": if not (os.path.realpath(path) in extracted_file): - wszst.szs_extract(path, get_nodir(path)) + wszst.szs.extract(path, get_nodir(path)) extracted_file.append(os.path.realpath(path)) szs_extract_path = path + ".d" @@ -194,12 +194,12 @@ class Game: for file in extracted_file: self.gui.progress(statut=self.gui.translate("Recompilating", "\n", get_nodir(file)), add=1) - wszst.create(file) + wszst.szs.create(file) if os.path.exists(file + ".d"): shutil.rmtree(file + ".d") self.gui.progress(statut=self.gui.translate("Patch main.dol"), add=1) - wszst.str_patch(self.path) + wszst.wstrt.patch(self.path) self.gui.progress(statut=self.gui.translate("Patch lecode.bin"), add=1) @@ -209,7 +209,7 @@ class Game: shutil.copyfile("./file/lpar-default.txt", self.path + "/tmp/lpar-default.txt") shutil.copyfile(f"./file/lecode-{self.region}.bin", self.path + f"/tmp/lecode-{self.region}.bin") - wszst.lec_patch( + wszst.lec.patch( self.path, lecode_file=f"./tmp/lecode-{self.region}.bin", dest_lecode_file=f"./files/rel/lecode-{self.region}.bin", @@ -235,7 +235,7 @@ class Game: """ if os.path.exists(auto_add_dir): shutil.rmtree(auto_add_dir) if not os.path.exists(self.path + "/tmp/"): os.makedirs(self.path + "/tmp/") - wszst.autoadd(self.path, get_nodir(self.path) + "/tmp/auto-add/") + wszst.szs.autoadd(self.path, get_nodir(self.path) + "/tmp/auto-add/") shutil.move(self.path + "/tmp/auto-add/", auto_add_dir) shutil.rmtree(self.path + "/tmp/") @@ -265,10 +265,10 @@ class Game: bmglang = gamefile[-len("E.txt"):-len(".txt")] # Langue du fichier self.gui.progress(statut=self.gui.translate("Patching text", " ", bmglang), add=1) - wszst.szs_extract(gamefile, get_nodir(gamefile)) + wszst.szs.extract(gamefile, get_nodir(gamefile)) - bmgmenu = wszst.bmg_cat(gamefile, ".d/message/Menu.bmg") # Menu.bmg - bmgtracks = wszst.bmg_cat(gamefile, ".d/message/Common.bmg") # Common.bmg + bmgmenu = wszst.bmg.cat(gamefile, ".d/message/Menu.bmg") # Menu.bmg + bmgtracks = wszst.bmg.cat(gamefile, ".d/message/Common.bmg") # Common.bmg trackheader = "#--- standard track names" trackend = "2328" @@ -306,9 +306,9 @@ class Game: if not os.path.exists("./file/tmp/"): os.makedirs("./file/tmp/") shutil.copyfile(gamefile + ".d/message/Common.bmg", "./file/tmp/Common.bmg") - bmgcommon = wszst.ctc_patch_bmg(ctfile="./file/CTFILE.txt", + bmgcommon = wszst.ctc.patch_bmg(ctfile="./file/CTFILE.txt", bmgs=["./file/tmp/Common.bmg", "./file/ExtraCommon.txt"]) - rbmgcommon = wszst.ctc_patch_bmg(ctfile="./file/RCTFILE.txt", + rbmgcommon = wszst.ctc.patch_bmg(ctfile="./file/RCTFILE.txt", bmgs=["./file/tmp/Common.bmg", "./file/ExtraCommon.txt"]) shutil.rmtree(gamefile + ".d") @@ -320,7 +320,7 @@ class Game: for text, colored_text in replacement_list.items(): bmgtext = bmgtext.replace(text, colored_text) with open(file, "w", encoding="utf-8") as f: f.write(bmgtext) - wszst.bmg_encode(file) + wszst.bmg.encode(file) os.remove(file) finalise(f"./file/Menu_{bmglang}.txt", bmgmenu, menu_replacement) @@ -372,7 +372,7 @@ class Game: for i, file in enumerate(fc["img"]): self.gui.progress(statut=self.gui.translate("Converting images") + f"\n({i + 1}/{len(fc['img'])}) {file}", add=1) - wszst.img_encode("./file/" + file, fc["img"][file]) + wszst.img.encode("./file/" + file, fc["img"][file]) def patch_img_desc(self, img_desc_path: str = "./file/img_desc", dest_dir: str = "./file") -> None: """ diff --git a/source/Gui.py b/source/Gui.py index ba55911..c546981 100644 --- a/source/Gui.py +++ b/source/Gui.py @@ -14,7 +14,10 @@ with open("./translation.json", encoding="utf-8") as f: def restart(): - subprocess.Popen([sys.executable] + sys.argv, creationflags=CREATE_NO_WINDOW, cwd=os.getcwd()) + """ + restart the application + """ + subprocess.Popen([sys.executable] + sys.argv, creationflags=subprocess.CREATE_NO_WINDOW, cwd=os.getcwd()) exit() diff --git a/source/Track.py b/source/Track.py index 02f35df..27ee7e3 100644 --- a/source/Track.py +++ b/source/Track.py @@ -61,15 +61,14 @@ class Track: check if track wu8's sha1 is correct :return: 0 if yes, -1 if no """ - ws = wszst.sha1(self.file_wu8) - if wszst.sha1(self.file_wu8) == self.sha1: return 0 + if wszst.szs.sha1(self.file_wu8) == self.sha1: return 0 else: return -1 def convert_wu8_to_szs(self) -> None: """ convert track to szs """ - wszst.normalize(src_file=self.file_wu8) + wszst.szs.normalize(src_file=self.file_wu8) def download_wu8(self, github_content_root: str) -> int: """ diff --git a/source/definition.py b/source/definition.py index b50fa1a..592b524 100644 --- a/source/definition.py +++ b/source/definition.py @@ -1,6 +1,5 @@ from threading import Thread -CREATE_NO_WINDOW = 0x08000000 GITHUB_REPOSITORY = "Faraphel/MKWF-Install" GITHUB_MASTER_BRANCH = f"https://raw.githubusercontent.com/{GITHUB_REPOSITORY}/master/" GITHUB_DEV_BRANCH = f"https://raw.githubusercontent.com/{GITHUB_REPOSITORY}/dev/" diff --git a/source/wszst.py b/source/wszst.py deleted file mode 100644 index 4d9b35a..0000000 --- a/source/wszst.py +++ /dev/null @@ -1,174 +0,0 @@ -from .definition import * -import subprocess - - -def sha1(file, autoadd_path: str = "./file/auto-add/") -> str: - """ - :param autoadd_path: directory where is autoadd directory - :param file: track file to check sha1 - :return: track's sha1 - """ - return subprocess.run(["./tools/szs/wszst", "SHA1", file, "--autoadd-path", autoadd_path], - check=True, creationflags=CREATE_NO_WINDOW, - stdout=subprocess.PIPE).stdout.decode().split(" ")[0] - - -def normalize(src_file: str, dest_dir: str = "./file/Track/", dest_name: str = "%N.szs", - output_format: str = "szs", autoadd_path: str = "./file/auto-add/") -> None: - """ - convert a track into an another format - :param src_file: source file - :param dest_dir: destination directory - :param dest_name: destination filename (%N mean same name as src_file) - :param output_format: format of the destination track - :param autoadd_path: path of the auto-add directory - """ - subprocess.run(["./tools/szs/wszst", "NORMALIZE", src_file, "--DEST", - dest_dir+dest_name, "--"+output_format, "--overwrite", "--autoadd-path", - autoadd_path], creationflags=CREATE_NO_WINDOW, stderr=subprocess.PIPE) - - -def wit_extract(file: str, dest_dir: str) -> None: - """ - extract the game into a directory - :param file: game's file to extract (can be WBFS, ISO, CISO) - :param dest_dir: where to extract the game - """ - subprocess.run(["./tools/wit/wit", "EXTRACT", get_nodir(file), "--DEST", dest_dir], - creationflags=CREATE_NO_WINDOW, cwd=get_dir(file)) - - -def create(file: str) -> None: - """ - convert a directory into a szs file - :param file: create a .szs file from the directory {file}.d - """ - subprocess.run(["./tools/szs/wszst", "CREATE", get_nodir(file) + ".d", "-d", get_nodir(file), - "--overwrite"], creationflags=CREATE_NO_WINDOW, cwd=get_dir(file), - check=True, stdout=subprocess.PIPE) - - -def str_patch(path: str) -> None: - """ - Patch the main.dol file - :param path: path to the game - """ - subprocess.run(["./tools/szs/wstrt", "patch", get_nodir(path) + "/sys/main.dol", "--clean-dol", - "--add-lecode"], creationflags=CREATE_NO_WINDOW, cwd=get_dir(path), - check=True, stdout=subprocess.PIPE) - - -def lec_patch(path: str, - lecode_file: str = f"./tmp/lecode-PAL.bin", - dest_lecode_file: str = f"./files/rel/lecode-PAL.bin", - game_track_path: str = "./files/Race/Course/", - move_track_path: str = "./files/Race/Course/", - ctfile_path: str = "./tmp/CTFILE.txt", - lpar_path: str = "./tmp/lpar-default.txt") -> None: - """ - Patch the file with a lecode file (this is the adding track part) - :param path: path to the game file - :param lecode_file: path to the lecode file - :param dest_lecode_file: destination of the lecode file - :param game_track_path: subpath to the track directory - :param move_track_path: where are stored the track to move - :param ctfile_path: where is the ctfile (track and cup definition) - :param lpar_path: where is the lpar_path (game modification like speed, speedometer, ...) - """ - subprocess.run( - ["./tools/szs/wlect", "patch", lecode_file, "-od", - dest_lecode_file, "--track-dir", game_track_path, - "--move-tracks", move_track_path, "--le-define", ctfile_path, "--lpar", - lpar_path, "--overwrite"], creationflags=CREATE_NO_WINDOW, cwd=path, check=True, stdout=subprocess.PIPE) - - -def edit(file: str, region_ID: str = "P", name: str = "Mario Kart Wii") -> None: - """ - Edit game property like region or name - :param file: game's file - :param region_ID: new region_ID - :param name: new name - """ - subprocess.run(["./tools/wit/wit", "EDIT", get_nodir(file), "--id", - f"RMC{region_ID}60", "--name", name, "--modify", "ALL"], - creationflags=CREATE_NO_WINDOW, cwd=get_dir(file), - check=True, stdout=subprocess.PIPE) - - -def autoadd(file: str, dest_dir: str) -> None: - """ - Create an auto_add directory from a game file - :param file: the game's path - :param dest_dir: directory where to store autoadd file - """ - subprocess.run(["./tools/szs/wszst", "AUTOADD", get_nodir(file) + "/files/Race/Course/", "--DEST", dest_dir], - creationflags=CREATE_NO_WINDOW, cwd=get_dir(file), - check=True, stdout=subprocess.PIPE) - - -def bmg_encode(file: str) -> None: - """ - Encode a txt file into a bmg file - :param file: txt file to convert - """ - subprocess.run(["./tools/szs/wbmgt", "ENCODE", get_nodir(file), "--overwrite"], - creationflags=CREATE_NO_WINDOW, cwd=get_dir(file)) - - -def bmg_cat(path: str, subfile: str = ".d/message/Common.bmg") -> str: - """ - read a bmg file - :param path: path to a szs file - :param subfile: path to a subdirectory - :return: bmg definition - """ - return subprocess.run(["./tools/szs/wbmgt", "CAT", get_nodir(path) + subfile], - creationflags=CREATE_NO_WINDOW, cwd=get_dir(path), - check=True, stdout=subprocess.PIPE).stdout.decode() - - -def wit_copy(src_path, dst_path, format: str = "ISO") -> None: - """ - Copy the game into an another format - :param src_path: original game path - :param dst_path: new game path - :param format: format for the new game - """ - subprocess.run(["./tools/wit/wit", "COPY", get_nodir(src_path), "--DEST", - get_nodir(dst_path), f"--{format.lower()}", "--overwrite"], - creationflags=CREATE_NO_WINDOW, cwd=get_dir(dst_path), - check=True, stdout=subprocess.PIPE) - - -def ctc_patch_bmg(bmgs: list, ctfile: str = "./file/CTFILE.txt"): - """ - Patch a bmg file with a ctfile with OVERWRITE option - :param bmgs: all bmg files - :param ctfile: the ctfile path - :return: combined bmg - """ - bmg_cmd = [] - for bmg in bmgs: bmg_cmd.extend(["--patch-bmg", f"OVERWRITE={bmg}"]) - return subprocess.run( - ["tools/szs/wctct", "bmg", "--le-code", "--long", ctfile, *bmg_cmd], - creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE).stdout.decode() - - -def img_encode(src_file: str, format: str) -> None: - """ - Encode an .png image into a new format - :param src_file: .png image - :param format: new image format - """ - subprocess.run(["./tools/szs/wimgt", "ENCODE", src_file, "-x", format, "--overwrite"], - creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE) - - -def szs_extract(file: str, dest_dir: str) -> None: - """ - Extract an szs in a directory - :param file: .szs file - :param dest_dir: directory where to extract the file - """ - subprocess.run(["./tools/szs/wszst", "EXTRACT", get_nodir(file), "--DEST", dest_dir+".d"], - creationflags=CREATE_NO_WINDOW, cwd=get_dir(file)) \ No newline at end of file diff --git a/source/wszst/__init__.py b/source/wszst/__init__.py new file mode 100644 index 0000000..974f247 --- /dev/null +++ b/source/wszst/__init__.py @@ -0,0 +1,5 @@ +from ..definition import * +from subprocess import CREATE_NO_WINDOW +import subprocess + +__all__ = ["bmg", "ctc", "img", "lec", "wstrt", "szs", "wit", "subprocess", "CREATE_NO_WINDOW"] diff --git a/source/wszst/bmg.py b/source/wszst/bmg.py new file mode 100644 index 0000000..4f291ef --- /dev/null +++ b/source/wszst/bmg.py @@ -0,0 +1,22 @@ +from . import * + + +def encode(file: str) -> None: + """ + Encode a txt file into a bmg file + :param file: txt file to convert + """ + subprocess.run(["./tools/szs/wbmgt", "ENCODE", file, "--overwrite"], + creationflags=CREATE_NO_WINDOW) + + +def cat(path: str, subfile: str = ".d/message/Common.bmg") -> str: + """ + read a bmg file + :param path: path to a szs file + :param subfile: path to a subdirectory + :return: bmg definition + """ + return subprocess.run(["./tools/szs/wbmgt", "CAT", path + subfile], + creationflags=CREATE_NO_WINDOW, + check=True, stdout=subprocess.PIPE).stdout.decode() \ No newline at end of file diff --git a/source/wszst/ctc.py b/source/wszst/ctc.py new file mode 100644 index 0000000..401c5ff --- /dev/null +++ b/source/wszst/ctc.py @@ -0,0 +1,15 @@ +from . import * + + +def ctc_patch_bmg(bmgs: list, ctfile: str = "./file/CTFILE.txt"): + """ + Patch a bmg file with a ctfile with OVERWRITE option + :param bmgs: all bmg files + :param ctfile: the ctfile path + :return: combined bmg + """ + bmg_cmd = [] + for bmg in bmgs: bmg_cmd.extend(["--patch-bmg", f"OVERWRITE={bmg}"]) + return subprocess.run( + ["tools/szs/wctct", "bmg", "--le-code", "--long", ctfile, *bmg_cmd], + creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE).stdout.decode() \ No newline at end of file diff --git a/source/wszst/img.py b/source/wszst/img.py new file mode 100644 index 0000000..a81551f --- /dev/null +++ b/source/wszst/img.py @@ -0,0 +1,11 @@ +from . import * + + +def encode(src_file: str, format: str) -> None: + """ + Encode an .png image into a new format + :param src_file: .png image + :param format: new image format + """ + subprocess.run(["./tools/szs/wimgt", "ENCODE", src_file, "-x", format, "--overwrite"], + creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE) diff --git a/source/wszst/lec.py b/source/wszst/lec.py new file mode 100644 index 0000000..1b094a6 --- /dev/null +++ b/source/wszst/lec.py @@ -0,0 +1,24 @@ +from . import * + + +def patch(path: str, + lecode_file: str = f"./tmp/lecode-PAL.bin", + dest_lecode_file: str = f"./files/rel/lecode-PAL.bin", + game_track_path: str = "./files/Race/Course/", + move_track_path: str = "./files/Race/Course/", + ctfile_path: str = "./tmp/CTFILE.txt", + lpar_path: str = "./tmp/lpar-default.txt") -> None: + """ + Patch the file with a lecode file (this is the adding track part) + :param path: path to the game file + :param lecode_file: path to the lecode file + :param dest_lecode_file: destination of the lecode file + :param game_track_path: subpath to the track directory + :param move_track_path: where are stored the track to move + :param ctfile_path: where is the ctfile (track and cup definition) + :param lpar_path: where is the lpar_path (game modification like speed, speedometer, ...) + """ + subprocess.run( + ["./tools/szs/wlect", "patch", lecode_file, "-od", dest_lecode_file, "--track-dir", game_track_path, + "--move-tracks", move_track_path, "--le-define", ctfile_path, "--lpar", lpar_path, "--overwrite"], + creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE) \ No newline at end of file diff --git a/source/wszst/szs.py b/source/wszst/szs.py new file mode 100644 index 0000000..e209aa2 --- /dev/null +++ b/source/wszst/szs.py @@ -0,0 +1,56 @@ +from . import * + + +def szs_extract(file: str, dest_dir: str) -> None: + """ + Extract an szs in a directory + :param file: .szs file + :param dest_dir: directory where to extract the file + """ + subprocess.run(["./tools/szs/wszst", "EXTRACT", file, "--DEST", dest_dir + ".d"], + creationflags=CREATE_NO_WINDOW) + + +def sha1(file, autoadd_path: str = "./file/auto-add/") -> str: + """ + :param autoadd_path: directory where is autoadd directory + :param file: track file to check sha1 + :return: track's sha1 + """ + return subprocess.run(["./tools/szs/wszst", "SHA1", file, "--autoadd-path", autoadd_path], + check=True, creationflags=CREATE_NO_WINDOW, + stdout=subprocess.PIPE).stdout.decode().split(" ")[0] + + +def normalize(src_file: str, dest_dir: str = "./file/Track/", dest_name: str = "%N.szs", + output_format: str = "szs", autoadd_path: str = "./file/auto-add/") -> None: + """ + convert a track into an another format + :param src_file: source file + :param dest_dir: destination directory + :param dest_name: destination filename (%N mean same name as src_file) + :param output_format: format of the destination track + :param autoadd_path: path of the auto-add directory + """ + subprocess.run(["./tools/szs/wszst", "NORMALIZE", src_file, "--DEST", dest_dir + dest_name, "--" + output_format, + "--overwrite", "--autoadd-path", autoadd_path], + creationflags=CREATE_NO_WINDOW, stderr=subprocess.PIPE) + + +def create(file: str) -> None: + """ + convert a directory into a szs file + :param file: create a .szs file from the directory {file}.d + """ + subprocess.run(["./tools/szs/wszst", "CREATE", file + ".d", "-d", file, "--overwrite"], + creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE) + + +def autoadd(file: str, dest_dir: str) -> None: + """ + Create an auto_add directory from a game file + :param file: the game's path + :param dest_dir: directory where to store autoadd file + """ + subprocess.run(["./tools/szs/wszst", "AUTOADD", file + "/files/Race/Course/", "--DEST", dest_dir], + creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE) \ No newline at end of file diff --git a/source/wszst/wit.py b/source/wszst/wit.py new file mode 100644 index 0000000..da9a2f0 --- /dev/null +++ b/source/wszst/wit.py @@ -0,0 +1,34 @@ +from . import * + + +def extract(file: str, dest_dir: str) -> None: + """ + extract the game into a directory + :param file: game's file to extract (can be WBFS, ISO, CISO) + :param dest_dir: where to extract the game + """ + subprocess.run(["./tools/wit/wit", "EXTRACT", file, "--DEST", dest_dir], + creationflags=CREATE_NO_WINDOW) + + +def edit(file: str, region_ID: str = "P", name: str = "Mario Kart Wii") -> None: + """ + Edit game property like region or name + :param file: game's file + :param region_ID: new region_ID + :param name: new name + """ + subprocess.run( + ["./tools/wit/wit", "EDIT", file, "--id", f"RMC{region_ID}60", "--name", name, "--modify", "ALL"], + creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE) + + +def copy(src_path, dst_path, format: str = "ISO") -> None: + """ + Copy the game into an another format + :param src_path: original game path + :param dst_path: new game path + :param format: format for the new game + """ + subprocess.run(["./tools/wit/wit", "COPY", src_path, "--DEST", dst_path, f"--{format.lower()}", "--overwrite"], + creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE) diff --git a/source/wszst/wstrt.py b/source/wszst/wstrt.py new file mode 100644 index 0000000..a2ef645 --- /dev/null +++ b/source/wszst/wstrt.py @@ -0,0 +1,10 @@ +from . import * + + +def patch(path: str) -> None: + """ + Patch the main.dol file + :param path: path to the game + """ + subprocess.run(["./tools/szs/wstrt", "patch", path + "/sys/main.dol", "--clean-dol", "--add-lecode"], + creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE) \ No newline at end of file