diff --git a/source/gui/install.py b/source/gui/install.py index 760f0ac..8c31f8a 100644 --- a/source/gui/install.py +++ b/source/gui/install.py @@ -259,7 +259,7 @@ class SourceGame(ttk.LabelFrame): """ path = Path(tkinter.filedialog.askopenfilename( title=_("SELECT_SOURCE_GAME"), - filetypes=[(_("WII GAMES"), "*.iso *.wbfs *.dol")], + filetypes=[(_("WII GAMES"), "*.iso *.ciso *.wbfs *.dol")], )) # if the user didn't select any file, return None if not path.exists(): diff --git a/source/mkw/ExtractedGame.py b/source/mkw/ExtractedGame.py index 6783ffe..7a60faa 100644 --- a/source/mkw/ExtractedGame.py +++ b/source/mkw/ExtractedGame.py @@ -5,7 +5,7 @@ from typing import Generator, IO from source.mkw.ModConfig import ModConfig from source.mkw.Patch.Patch import Patch -from source.wt import szs, lec +from source.wt import szs, lec, wit from source.wt.wstrt import StrPath @@ -155,3 +155,27 @@ class ExtractedGame: for patch_directory in part_directory.glob("_PATCH/"): yield from Patch(patch_directory, mod_config, self._special_file).install(self) + def convert_to(self, output_type: wit.Extension) -> Generator[dict, None, None]: + """ + Convert the extracted game to another format + :param output_type: path to the destination of the game + :output_type: format of the destination game + """ + yield {"description": f"Converting game to {output_type}", "determinate": False} + if output_type == wit.Extension.FST: return + + destination_file = self.path.with_suffix(self.path.suffix + output_type.value) + dest_name: str = destination_file.name + + i: int = 0 + while destination_file.exists(): + i += 1 + destination_file = destination_file.with_name(dest_name + f" ({i})") + + wit.copy( + source_directory=self.path, + destination_file=destination_file, + ) + + yield {"description": "Deleting the extracted game...", "determinate": False} + shutil.rmtree(self.path) diff --git a/source/mkw/Game.py b/source/mkw/Game.py index 65ddec8..ed0ead2 100644 --- a/source/mkw/Game.py +++ b/source/mkw/Game.py @@ -139,3 +139,5 @@ class Game: cache_ogtracks_directory, ) + # convert the extracted game into a file + yield from extracted_game.convert_to(output_type) diff --git a/source/wt/wit.py b/source/wt/wit.py index 7079b7b..73e42c2 100644 --- a/source/wt/wit.py +++ b/source/wt/wit.py @@ -13,13 +13,25 @@ _tools_run_dict = get_tools_run_dict_function(tools_path) _tools_run_popen = get_tools_run_popen_function(tools_path) +def copy(source_directory: Path | str, destination_file: Path | str): + """ + Copy a game directory to a game file with a specific format. + :param source_directory: path to the extracted game + :param destination_file: path to the destination game + :return: the destination game path + """ + _tools_run("COPY", source_directory, "--DEST", destination_file) + return Path(destination_file) + + class Extension(enum.Enum): """ Enum for game extension """ WBFS = ".wbfs" - ISO = ".iso" FST = ".dol" + CISO = ".ciso" + ISO = ".iso" @classmethod def _missing_(cls, value: str) -> "Extension | None":