From 49ee43f6ed938495ccbbb8be4647175259a0279b Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Thu, 5 May 2022 11:35:03 -0600 Subject: [PATCH] sys_patch.py: Add patch set info to root --- CHANGELOG.md | 3 +++ gui/gui_main.py | 2 +- resources/main.py | 3 ++- resources/sys_patch.py | 25 +++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b65fc970..419e9cecc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ - Add Macmini8,1 FeatureUnlock support - Drops CPU check, supports all machines - Refactor Root Patching System +- Add `OpenCore-Legacy-Patcher.plist` for applied patch info + - Located under `/System/Library/CoreServices` + - Lists patch sets applied including files installed and removed ## 0.4.4 - Lower SIP requirement for Root Patching diff --git a/gui/gui_main.py b/gui/gui_main.py index d273d58f5..9f2b37304 100644 --- a/gui/gui_main.py +++ b/gui/gui_main.py @@ -804,7 +804,7 @@ class wx_python_gui: i = i + self.patch_label.GetSize().height + 3 else: # Prompt user with no patches found - self.patch_label = wx.StaticText(self.frame, label="No patches found") + self.patch_label = wx.StaticText(self.frame, label="No patches needed") self.patch_label.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)) self.patch_label.SetPosition( wx.Point( diff --git a/resources/main.py b/resources/main.py index 0e717151c..a15bbcc85 100644 --- a/resources/main.py +++ b/resources/main.py @@ -44,7 +44,8 @@ class OpenCoreLegacyPatcher: if utilities.check_cli_args() is not None: print("- Detected arguments, switching to CLI mode") self.constants.gui_mode = True # Assumes no user interaction is required - if "--auto_patch" not in sys.argv: + ignore_args = ["--auto_patch", "--gui_patch", "--gui_unpatch"] + if not any(x in sys.argv for x in ignore_args): self.constants.current_path = Path.cwd() if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"): print("- Rerouting payloads location") diff --git a/resources/sys_patch.py b/resources/sys_patch.py index 6258e0fb0..19441a118 100644 --- a/resources/sys_patch.py +++ b/resources/sys_patch.py @@ -25,6 +25,9 @@ import shutil import subprocess from pathlib import Path +from datetime import datetime +import plistlib +import os from resources import constants, generate_smbios, utilities, sys_patch_download, sys_patch_detect, sys_patch_auto from data import os_data @@ -167,6 +170,27 @@ class PatchSysVolume: print("- Creating SkylightPlugins folder") utilities.process_status(utilities.elevated(["mkdir", "-p", f"{self.mount_application_support}/SkyLightPlugins/"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)) + def write_patchset(self, patchset): + source_path = f"{self.constants.payload_path}" + destination_path = f"{self.mount_location}/System/Library/CoreServices" + file_name = "OpenCore-Legacy-Patcher.plist" + source_path_file = f"{source_path}/{file_name}" + destination_path_file = f"{destination_path}/{file_name}" + + data = { + "OpenCore Legacy Patcher": f"v{self.constants.patcher_version}", + "PatcherSupportPkg": f"v{self.constants.patcher_support_pkg_version}", + "Time Patched": f"{datetime.now().strftime('%B %d, %Y @ %H:%M:%S')}", + } + print("- Writing patchset information to Root Volume") + data.update(patchset) + if Path(source_path_file).exists(): + os.remove(source_path_file) + # Need to write to a safe location + plistlib.dump(data, Path(source_path_file).open("wb"), sort_keys=False) + if Path(destination_path_file).exists(): + utilities.process_status(utilities.elevated(["rm", destination_path_file], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)) + utilities.process_status(utilities.elevated(["cp", source_path_file, destination_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)) def patch_root_vol(self): print(f"- Running patches for {self.model}") @@ -214,6 +238,7 @@ class PatchSysVolume: utilities.process_status(utilities.elevated(process_array, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)) else: utilities.process_status(subprocess.run(process_array, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)) + self.write_patchset(required_patches) def preflight_checks(self, required_patches, source_files_path): print("- Running Preflight Checks before patching")