diff --git a/OpCore-Simplify.py b/OpCore-Simplify.py index badada1..c2ba253 100644 --- a/OpCore-Simplify.py +++ b/OpCore-Simplify.py @@ -17,8 +17,6 @@ class OCPE: self.c = compatibility_checker.CompatibilityChecker() self.b = efi_builder.builder() self.u = utils.Utils() - self.hardware = None - self.compatibility = None self.result_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "Results") def gathering_files(self): @@ -30,7 +28,7 @@ class OCPE: self.o.get_bootloader_kexts_data() self.o.gathering_bootloader_kexts() - def select_aida64_report(self): + def select_hardware_report(self): while True: self.u.head("Select your AIDA64 report") print("") @@ -48,21 +46,20 @@ class OCPE: path = self.u.normalize_path(user_input) if not path: continue - self.hardware = self.a.dump(path) - return + return path, self.a.dump(path) - def hardware_report(self): + def show_hardware_report(self, hardware_report): self.u.head("Review the hardware information") contents = [] - for index, device_type in enumerate(self.hardware, start=1): + for index, device_type in enumerate(hardware_report, start=1): contents.append("{}. {}{}".format(index, device_type, "" if device_type == "Intel MEI" else ":")) if device_type == "SD Controller": - contents.append("{}* {}".format(" "*4, self.hardware.get(device_type).get("Device Description"))) + contents.append("{}* {}".format(" "*4, hardware_report.get(device_type).get("Device Description"))) elif device_type == "Intel MEI": pass else: - for device_name, device_props in self.hardware.get(device_type).items(): + for device_name, device_props in hardware_report.get(device_type).items(): contents.append("{}* {}{}".format(" "*4, device_name, ": {}".format(device_props) if isinstance(device_props, str) else "")) content = "\n".join(contents) + "\n" self.u.adjust_window_size(content) @@ -70,45 +67,39 @@ class OCPE: self.u.request_input() return - def compatibility_check(self): - self.hardware = self.c.check_compatibility(self.hardware) - self.compatibility = self.hardware.get("Compatibility") - supported_macOS_version = self.compatibility.get("macOS Version") + def compatibility_check(self, hardware_report): + supported_macos_version, unsupported_devices = self.c.check_compatibility(hardware_report) self.u.head("Compatibility Checker") print("") - if not supported_macOS_version: + if not supported_macos_version: self.u.request_input("Your hardware is not compatible with macOS!") self.u.exit_program() print("* Supported macOS Version:") - print("{}Max Version: {}".format(" "*4, os_data.get_macos_name_by_darwin(supported_macOS_version.get("Max Version")))) - print("{}Min Version: {}".format(" "*4, os_data.get_macos_name_by_darwin(supported_macOS_version.get("Min Version")))) - if self.compatibility.get("Unsupported Devices"): + print("{}Max Version: {}".format(" "*4, os_data.get_macos_name_by_darwin(supported_macos_version[-1]))) + print("{}Min Version: {}".format(" "*4, os_data.get_macos_name_by_darwin(supported_macos_version[0]))) + if unsupported_devices: print("* Unsupported devices:") - for index, device_name in enumerate(self.compatibility.get("Unsupported Devices"), start=1): - device_props = self.compatibility.get("Unsupported Devices").get(device_name) + for index, device_name in enumerate(unsupported_devices, start=1): + device_props = unsupported_devices.get(device_name) print("{}{}. {}{}".format(" "*4, index, device_name, "" if not device_props.get("Audio Endpoints") else " ({})".format(", ".join(device_props.get("Audio Endpoints"))))) print("") self.u.request_input() - return + return supported_macos_version, unsupported_devices - def select_macos_version(self): - supported_macOS_version = self.compatibility.get("macOS Version") - min_version = supported_macOS_version.get("Min Version") - max_version = supported_macOS_version.get("Max Version") - + def select_macos_version(self, supported_macos_version): version_pattern = re.compile(r'^(\d+)(?:\.(\d+)(?:\.(\d+))?)?$') while True: self.u.head("Select macOS Version") print("") - for index, macos_version_name in enumerate(os_data.get_macos_names(min_version, max_version), start=int(min_version[:2])): + for index, macos_version_name in enumerate(os_data.get_macos_names(supported_macos_version[0], supported_macos_version[-1]), start=int(supported_macos_version[0][:2])): print("{}. {}".format(index, macos_version_name)) print("") print("Please enter the macOS version you want to select:") print("- To select a major version, enter the number (e.g., 19).") print("- To specify a full version, use the Darwin version format (e.g., 22.4.6).") - print("- The version must be in the range from {} to {}.".format(min_version, max_version)) + print("- The version must be in the range from {} to {}.".format(supported_macos_version[0], supported_macos_version[-1])) print("") print("Q. Quit") print("") @@ -120,11 +111,10 @@ class OCPE: if match: target_version = "{}.{}.{}".format(match.group(1), match.group(2) if match.group(2) else 99, match.group(3) if match.group(3) else 99) - if self.u.parse_darwin_version(min_version) <= self.u.parse_darwin_version(target_version) <= self.u.parse_darwin_version(max_version): - self.macos_version = target_version - return + if self.u.parse_darwin_version(supported_macos_version[0]) <= self.u.parse_darwin_version(target_version) <= self.u.parse_darwin_version(supported_macos_version[-1]): + return target_version - def show_result(self): + def show_result(self, hardware_report): def generate_tree_content(dir_path, prefix=''): contents = sorted(os.listdir(dir_path)) pointers = ['├── '] * (len(contents) - 1) + ['└── '] @@ -156,7 +146,7 @@ class OCPE: return content efi_dir = os.path.join(self.result_dir, "EFI") - content = "\nYour OpenCore EFI for {} has been built at:".format(self.hardware.get("Motherboard").get("Motherboard Name")) + content = "\nYour OpenCore EFI for {} has been built at:".format(hardware_report.get("Motherboard").get("Motherboard Name")) content += "\n\t{}\n".format(self.result_dir) content += "\nEFI\n{}\n".format(generate_tree_content(efi_dir)) self.u.adjust_window_size(content) @@ -173,15 +163,43 @@ class OCPE: return def main(self): - self.select_aida64_report() - self.hardware_report() - self.compatibility_check() - self.select_macos_version() - self.gathering_files() - self.b.build_efi(self.hardware, self.macos_version) - self.show_result() - reminder_message = "\n\nIMPORTANT REMINDER: Please make sure you add the USBMap.kext to /EFI/OC/Kexts before using this\nOpenCore EFI.\n\n" - self.u.exit_program(o.u.message(reminder_message, "reminder")) + hardware_report_path = None + macos_version = None + + while True: + self.u.head() + print("") + print("Hardware Report: {}".format("No report selected" if not hardware_report_path else hardware_report_path)) + print("macOS Version: {}{}".format("Unknown" if not macos_version else os_data.get_macos_name_by_darwin(macos_version), "" if not macos_version else " ({})".format(macos_version))) + print("") + print("1. Select Hardware Report") + print("2. Select macOS Version") + print("3. Build OpenCore EFI") + print("") + print("Q. Quit") + print("") + option = self.u.request_input("Select an option: ") + if option.lower() == "q": + self.u.exit_program() + if option == "1": + hardware_report_path, hardware_report = self.select_hardware_report() + self.show_hardware_report(hardware_report) + supported_macos_version, unsupported_devices = self.compatibility_check(hardware_report) + macos_version = supported_macos_version[-1] + if int(macos_version[:2]) == os_data.macos_versions[-1].darwin_version and os_data.macos_versions[-1].release_status == "beta": + macos_version = str(int(macos_version[:2]) - 1) + macos_version[2:] + elif option == "2": + try: + macos_version = self.select_macos_version(supported_macos_version) + except: + self.u.request_input("\nPlease select a hardware report to proceed") + elif option == "3": + try: + self.gathering_files() + self.b.build_efi(hardware_report, unsupported_devices, macos_version) + self.show_result(hardware_report) + except: + self.u.request_input("\nPlease select a hardware report to proceed") if __name__ == '__main__': o = OCPE() diff --git a/Scripts/compatibility_checker.py b/Scripts/compatibility_checker.py index 51d6b40..43756d8 100644 --- a/Scripts/compatibility_checker.py +++ b/Scripts/compatibility_checker.py @@ -205,12 +205,4 @@ class CompatibilityChecker: hardware["Storage Controllers"] = self.check_storage_compatibility(hardware.get("Storage Controllers")) self.check_sd_controller_compatibility(hardware) - hardware["Compatibility"] = { - "macOS Version": { - "Max Version": ".".join(str(item) for item in self.max_supported_macos_version), - "Min Version": ".".join(str(item) for item in self.min_supported_macos_version) - } if self.max_supported_macos_version != (-1, -1, -1) else None, - "Unsupported Devices": self.unsupported_devices - } - - return hardware + return () if self.max_supported_macos_version[0] == -1 else (".".join(str(item) for item in self.min_supported_macos_version), ".".join(str(item) for item in self.max_supported_macos_version)), self.unsupported_devices \ No newline at end of file diff --git a/Scripts/efi_builder.py b/Scripts/efi_builder.py index 9e00ab5..db25d94 100644 --- a/Scripts/efi_builder.py +++ b/Scripts/efi_builder.py @@ -376,7 +376,7 @@ class builder: print("") self.utils.request_input() - def build_efi(self, hardware, macos_version): + def build_efi(self, hardware, unsupported_devices, macos_version): efi_directory = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "Results") self.utils.create_folder(efi_directory, remove_content=True) @@ -410,7 +410,7 @@ class builder: hardware_shorc["Input"] = hardware.get("Input") hardware_shorc["Storage Controllers"] = hardware.get("Storage Controllers") hardware_shorc["Intel MEI"] = hardware.get("Intel MEI") - hardware_shorc["Unsupported Devices"] = hardware.get("Compatibility").get("Unsupported Devices") + hardware_shorc["Unsupported Devices"] = unsupported_devices forbidden_chars = r'[<>:"/\\|?*]' hardware_shorc["Motherboard Name"] = re.sub(forbidden_chars, '_', hardware_shorc["Motherboard Name"])