From fccde7214b1f906cfb8ec120ff3fb9c64ddd5994 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Fri, 30 Aug 2024 14:45:24 -0600 Subject: [PATCH] GUI Installer: Support chainloading --- .../support/metallib_handler.py | 3 ++ .../wx_gui/gui_macos_installer_flash.py | 48 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/opencore_legacy_patcher/support/metallib_handler.py b/opencore_legacy_patcher/support/metallib_handler.py index a8e2d14cc..1a1f91eb0 100644 --- a/opencore_legacy_patcher/support/metallib_handler.py +++ b/opencore_legacy_patcher/support/metallib_handler.py @@ -205,6 +205,9 @@ class MetalLibraryObject: Check if a metallib is already installed """ + if self.ignore_installed: + return None + if not Path(METALLIB_INSTALL_PATH).exists(): return None diff --git a/opencore_legacy_patcher/wx_gui/gui_macos_installer_flash.py b/opencore_legacy_patcher/wx_gui/gui_macos_installer_flash.py index b3fe856fc..e25923c05 100644 --- a/opencore_legacy_patcher/wx_gui/gui_macos_installer_flash.py +++ b/opencore_legacy_patcher/wx_gui/gui_macos_installer_flash.py @@ -27,6 +27,7 @@ from ..support import ( utilities, network_handler, kdk_handler, + metallib_handler, subprocess_wrapper ) @@ -463,6 +464,8 @@ class macOSInstallerFlashFrame(wx.Frame): subprocess.run(["/bin/mkdir", "-p", f"{path}/Library/Packages/"]) subprocess.run(generate_copy_arguments(self.constants.installer_pkg_path, f"{path}/Library/Packages/")) + # Chainload KDK and Metallib + self._chainload_metallib(os_version["ProductBuildVersion"], os_version["ProductVersion"], Path(path + "/Library/Packages/")) self._kdk_chainload(os_version["ProductBuildVersion"], os_version["ProductVersion"], Path(path + "/Library/Packages/")) @@ -543,6 +546,51 @@ class macOSInstallerFlashFrame(wx.Frame): logging.info("Removing KDK Disk Image") kdk_dmg_path.unlink() + + def _chainload_metallib(self, build: str, version: str, download_dir: str): + """ + Download the correct Metallib to be chainloaded in the macOS installer + """ + + metallib_pkg_path = Path(download_dir) / "MetallibSupportPkg.pkg" + + if metallib_pkg_path.exists(): + metallib_pkg_path.unlink() + + logging.info("Initiating Metallib download") + logging.info(f"- Build: {build}") + logging.info(f"- Version: {version}") + logging.info(f"- Working Directory: {download_dir}") + + metallib_obj = metallib_handler.MetalLibraryObject(self.constants, build, version, ignore_installed=True) + if metallib_obj.success is False: + logging.info("Failed to retrieve Metallib") + logging.info(metallib_obj.error_msg) + return + + metallib_download_obj = metallib_obj.retrieve_download(override_path=metallib_pkg_path) + if metallib_download_obj is None: + logging.info("Failed to retrieve Metallib") + logging.info(metallib_obj.error_msg) + + # Check remaining disk space before downloading + space = utilities.get_free_space(download_dir) + size = 100 * 1024 * 1024 + if space < size: + logging.info("Not enough disk space to download and install Metallib") + return + + metallib_download_obj.download(spawn_thread=False) + if metallib_download_obj.download_complete is False: + logging.info("Failed to download Metallib") + logging.info(metallib_download_obj.error_msg) + return + + if not metallib_pkg_path.exists(): + logging.info(f"Metallib missing: {metallib_pkg_path}") + return + + def _validate_installer_pkg(self, disk: str) -> bool: logging.info("Validating installer pkg") error_message = ""