From 5e4b124b2ac91d86d74f6a657f54a5a9c4211761 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Wed, 6 Nov 2024 10:18:17 -0700 Subject: [PATCH] defaults.py: Implement additional error handling for 2.1.0 bug --- CHANGELOG.md | 9 ++++++++ opencore_legacy_patcher/constants.py | 2 +- opencore_legacy_patcher/support/defaults.py | 9 ++++++++ .../support/global_settings.py | 19 +++++++++++++++ opencore_legacy_patcher/wx_gui/gui_build.py | 23 ++++++++++++++++++- 5 files changed, 60 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b22c6f044..6bfbab4265 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # OpenCore Legacy Patcher changelog +## 2.1.2 +- Add additional error handling for when building OpenCore errors out + - Prevents broken EFI from being installed to disk +- Add additional error handling for broken settings file from OCLP 2.1.0 + - If typing for settings is wrong, app will skip setting it, delete from settings file and use default + - Delete `/Users/Shared/.com.dortania.opencore-legacy-patcher.plist` and restart app to avoid this issue +- Add additional warning about OCLP 2.1.0 bug where certain settings saved incorrectly + - Delete `/Users/Shared/.com.dortania.opencore-legacy-patcher.plist` and restart app if `TypeError: unsupported type: ` error occurs + ## 2.1.1 - Resolve boolean GUI settings saving incorrectly as Python's None type diff --git a/opencore_legacy_patcher/constants.py b/opencore_legacy_patcher/constants.py index 8ab2f57036..a4e2151f0a 100644 --- a/opencore_legacy_patcher/constants.py +++ b/opencore_legacy_patcher/constants.py @@ -13,7 +13,7 @@ class Constants: def __init__(self) -> None: # Patcher Versioning - self.patcher_version: str = "2.1.1" # OpenCore-Legacy-Patcher + self.patcher_version: str = "2.1.2" # OpenCore-Legacy-Patcher self.patcher_support_pkg_version: str = "1.8.4" # PatcherSupportPkg self.copyright_date: str = "Copyright © 2020-2024 Dortania" self.patcher_name: str = "OpenCore Legacy Patcher" diff --git a/opencore_legacy_patcher/support/defaults.py b/opencore_legacy_patcher/support/defaults.py index ea2256f2d6..d922af5c1c 100644 --- a/opencore_legacy_patcher/support/defaults.py +++ b/opencore_legacy_patcher/support/defaults.py @@ -435,5 +435,14 @@ def _load_gui_defaults(self) -> None: plist[key] = None if hasattr(self.constants, constants_key): + # Check if type is different + original_type = type(getattr(self.constants, constants_key)) + new_type = type(plist[key]) + if original_type != new_type: + logging.error(f"Global settings type mismatch for {constants_key}: {original_type} vs {new_type}") + logging.error(f"Removing {key} from global settings") + global_settings.GlobalEnviromentSettings().delete_property(key) + continue + logging.info(f"Setting {constants_key} to {plist[key]}") setattr(self.constants, constants_key, plist[key]) \ No newline at end of file diff --git a/opencore_legacy_patcher/support/global_settings.py b/opencore_legacy_patcher/support/global_settings.py index ddffb95365..5404d7c14a 100644 --- a/opencore_legacy_patcher/support/global_settings.py +++ b/opencore_legacy_patcher/support/global_settings.py @@ -44,6 +44,25 @@ def read_property(self, property_name: str) -> str: return None + def delete_property(self, property_name: str) -> None: + """ + Deletes a property from the global settings file + """ + if Path(self.global_settings_plist).exists(): + try: + plist = plistlib.load(Path(self.global_settings_plist).open("rb")) + except Exception as e: + logging.error("Error: Unable to read global settings file") + logging.error(e) + return + if property_name in plist: + del plist[property_name] + try: + plistlib.dump(plist, Path(self.global_settings_plist).open("wb")) + except PermissionError: + logging.info("Failed to write to global settings") + + def write_property(self, property_name: str, property_value) -> None: """ Writes a property to the global settings file diff --git a/opencore_legacy_patcher/wx_gui/gui_build.py b/opencore_legacy_patcher/wx_gui/gui_build.py index 6ffc1cd9fb..f673a2b809 100644 --- a/opencore_legacy_patcher/wx_gui/gui_build.py +++ b/opencore_legacy_patcher/wx_gui/gui_build.py @@ -28,6 +28,8 @@ def __init__(self, parent: wx.Frame, title: str, global_constants: constants.Con super(BuildFrame, self).__init__(parent, title=title, size=(350, 200), style=wx.DEFAULT_FRAME_STYLE & ~(wx.RESIZE_BORDER | wx.MAXIMIZE_BOX)) gui_support.GenerateMenubar(self, global_constants).generate() + self.build_successful: bool = False + self.install_button: wx.Button = None self.text_box: wx.TextCtrl = None self.frame_modal: wx.Dialog = None @@ -107,6 +109,18 @@ def _invoke_build(self) -> None: wx.Yield() self.return_button.Enable() + + # Check if config.plist was built + if self.build_successful is False: + dialog = wx.MessageDialog( + parent=self, + message="An error occurred while building OpenCore", + caption="Error building OpenCore", + style=wx.OK | wx.ICON_ERROR + ) + dialog.ShowModal() + return + dialog = wx.MessageDialog( parent=self, message=f"Would you like to install OpenCore now?", @@ -126,9 +140,16 @@ def _build(self) -> None: logger.addHandler(gui_support.ThreadHandler(self.text_box)) try: build.BuildOpenCore(self.constants.custom_model or self.constants.computer.real_model, self.constants) - except: + self.build_successful = True + except Exception as e: logging.error("An internal error occurred while building:\n") logging.error(traceback.format_exc()) + + # Handle bug from 2.1.0 where None type was stored in config.plist from global settings + if "TypeError: unsupported type: " in traceback.format_exc(): + logging.error("If you continue to see this error, delete the following file and restart the application:") + logging.error("Path: /Users/Shared/.com.dortania.opencore-legacy-patcher.plist") + logger.removeHandler(logger.handlers[2])