diff --git a/source/Game.py b/source/Game.py index fcf8e7c..fdb6f7c 100644 --- a/source/Game.py +++ b/source/Game.py @@ -1,14 +1,44 @@ -from .definition import region_ID +from . import wszst +from .definition import * +import glob +import os class Game: - def __init__(self, path: str, region: str = "PAL"): + def __init__(self, path: str, region: str = "PAL", game_ID: str = "RMCP01"): self.path = path self.region_ID = region_ID[region] self.region = region + self.game_ID = game_ID def extract_game(self): - pass + extension = get_extension(self.path) + if extension.upper() == "DOL": + self.path = os.path.realpath(self.path + "/../../") # main.dol is in PATH/sys/, so go back 2 dir upper + + elif extension.upper() in ["ISO", "WBFS", "CSIO"]: + # Fiding a directory name that doesn't already exist + directory_name, i = "MKWiiFaraphel", 1 + while True: + self.path = os.path.realpath(self.path + f"/../{directory_name}") + if not (os.path.exists(self.path)): break + directory_name, i = f"MKWiiFaraphel ({i})", i + 1 + + wszst.extract(self.path, self.path) + if os.path.exists(self.path + "/DATA"): self.path += "/DATA" + + else: + raise Exception("This format is not supported !") + + if glob.glob(self.path + "/files/rel/lecode-???.bin"): # if a LECODE file is already here + raise Warning("ROM Already patched") # warning already patched + + with open(self.path + "/setup.txt") as f: setup = f.read() + setup = setup[setup.find("!part-id = ") + len("!part-id = "):] + self.game_ID = setup[:setup.find("\n")] + + self.region_ID = self.game_ID[3] + self.region = region_ID[self.region_ID] if self.region_ID in region_ID else self.region def install_mod(self): pass diff --git a/source/wszst.py b/source/wszst.py index 3e4a025..248b794 100644 --- a/source/wszst.py +++ b/source/wszst.py @@ -28,3 +28,7 @@ def normalize(src_file: str, dest_dir: str = "./file/Track/", dest_name: str = " autoadd_path], creationflags=CREATE_NO_WINDOW, stderr=subprocess.PIPE) return 0 + +def extract(file: str, dest_dir: str): + subprocess.call(["./tools/wit/wit", "EXTRACT", get_nodir(file), "--DEST", dest_dir], + creationflags=CREATE_NO_WINDOW, cwd=get_dir(file)) \ No newline at end of file