From c71d7d7663f3ec2ed0f4cf9851aad96e6518bc1c Mon Sep 17 00:00:00 2001 From: Mc-muffin <8714476+Mc-muffin@users.noreply.github.com> Date: Thu, 27 Jul 2023 22:00:32 -0500 Subject: [PATCH] Update ToolsTOR.py --- pythonlib/games/ToolsTOR.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pythonlib/games/ToolsTOR.py b/pythonlib/games/ToolsTOR.py index 0681eb1..f6a4f8f 100644 --- a/pythonlib/games/ToolsTOR.py +++ b/pythonlib/games/ToolsTOR.py @@ -536,10 +536,7 @@ class ToolsTOR(ToolsTales): def extract_main_archive(self) -> None: dat_bin_path = self.paths["extracted_files"] / "DAT" - if dat_bin_path.exists(): - print("Cleaning extract folder...") - shutil.rmtree(dat_bin_path) - dat_bin_path.mkdir(exist_ok=True) + self.clean_folder(dat_bin_path) print("Extracting DAT.BIN files...") with open( self.dat_bin_original, "rb") as f: @@ -779,7 +776,7 @@ class ToolsTOR(ToolsTales): iso.open(str(umd_iso)) extract_to = self.paths["original_files"] - shutil.rmtree(extract_to) + self.clean_folder(extract_to) files = [] for dirname, _, filelist in iso.walk(iso_path="/"): @@ -795,4 +792,15 @@ class ToolsTOR(ToolsTales): output.write(data) pbar.update(len(data)) - iso.close() \ No newline at end of file + iso.close() + + + def clean_folder(self, path: Path) -> None: + target_files = list(path.iterdir()) + if len(target_files) != 0: + print("Cleaning folder...") + for file in target_files: + if file.is_dir(): + shutil.rmtree(file) + elif file.name.lower() != ".gitignore": + file.unlink(missing_ok=False) \ No newline at end of file