diff --git a/Scripts/acpi_guru.py b/Scripts/acpi_guru.py index fb54c63..47851ee 100644 --- a/Scripts/acpi_guru.py +++ b/Scripts/acpi_guru.py @@ -338,12 +338,10 @@ class ACPIGuru: return None def check_acpi_directory(self, acpi_directory): - if acpi_directory: - if not os.path.isdir(acpi_directory): - self.utils.mkdirs(acpi_directory) - return acpi_directory - else: - return acpi_directory + self.utils.create_folder(acpi_directory, remove_content=True) + + if os.path.exists(acpi_directory): + return acpi_directory return None def write_ssdt(self, ssdt_name, ssdt_content, compile=True): diff --git a/Scripts/efi_builder.py b/Scripts/efi_builder.py index 39fb9ac..05448fc 100644 --- a/Scripts/efi_builder.py +++ b/Scripts/efi_builder.py @@ -379,7 +379,7 @@ class builder: def build_efi(self, hardware, macos_version): efi_directory = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "Results") - self.utils.mkdirs(efi_directory) + self.utils.create_folder(efi_directory, remove_content=True) if not os.path.exists(self.kext.ock_files_dir): raise Exception("Directory '{}' does not exist.".format(self.kext.ock_files_dir)) diff --git a/Scripts/gathering_files.py b/Scripts/gathering_files.py index b76d60d..a3f2d50 100644 --- a/Scripts/gathering_files.py +++ b/Scripts/gathering_files.py @@ -278,7 +278,7 @@ class gatheringFiles: ock_data = self.get_bootloader_kexts_data() - self.utils.mkdirs(self.temporary_dir) + self.utils.create_folder(self.temporary_dir) for product_data in ock_data: @@ -287,7 +287,7 @@ class gatheringFiles: continue asset_dir = os.path.join(self.ock_files_dir, product_data.get("product_name")) - self.utils.mkdirs(asset_dir) + self.utils.create_folder(asset_dir, remove_content=True) zip_path = os.path.join(self.temporary_dir, product_data.get("product_name")) + ".zip" self.fetcher.download_and_save_file(product_data.get("url"), zip_path) diff --git a/Scripts/utils.py b/Scripts/utils.py index 9451c55..8fb33ca 100644 --- a/Scripts/utils.py +++ b/Scripts/utils.py @@ -85,14 +85,14 @@ class Utils: def sort_dict_by_key(self, input_dict, sort_key): return dict(sorted(input_dict.items(), key=lambda item: item[1].get(sort_key, ""))) - def mkdirs(self, *directories): - for directory in directories: - if not os.path.exists(os.path.dirname(directory)): - os.makedirs(os.path.dirname(directory)) - if os.path.exists(directory): - shutil.rmtree(directory) - os.mkdir(directory) - + def create_folder(self, path, remove_content=False): + if os.path.exists(path): + if remove_content: + shutil.rmtree(path) + os.makedirs(path) + else: + os.makedirs(path) + def hex_to_bytes(self, string): try: # Remove non-hex characters (e.g., hyphens) diff --git a/updater.py b/updater.py index 0dbafb4..0cba37d 100644 --- a/updater.py +++ b/updater.py @@ -34,7 +34,7 @@ class Updater: return latest_commit.get("sha") or "0506fb67111d5c5230bf59b826c318ea4251dfc4" def download_update(self): - self.utils.mkdirs(self.temporary_dir) + self.utils.create_folder(self.temporary_dir) file_path = os.path.join(self.temporary_dir, os.path.basename(self.download_repo_url)) self.fetcher.download_and_save_file(self.download_repo_url, file_path) self.utils.extract_zip_file(file_path)