diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c4d397f6..bfae26b46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # OpenCore Legacy Patcher changelog ## 1.1.0 +- Add error handling for corrupted patcher settings ## 1.0.0 - Resolve BCM2046 and BCM2070 support on macOS 13.3 and newer diff --git a/resources/global_settings.py b/resources/global_settings.py index 41ec38f0c..91d979b63 100644 --- a/resources/global_settings.py +++ b/resources/global_settings.py @@ -31,7 +31,12 @@ class GlobalEnviromentSettings: """ if Path(self.global_settings_plist).exists(): - plist = plistlib.load(Path(self.global_settings_plist).open("rb")) + 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 None if property_name in plist: return plist[property_name] return None @@ -43,7 +48,12 @@ class GlobalEnviromentSettings: """ if Path(self.global_settings_plist).exists(): - plist = plistlib.load(Path(self.global_settings_plist).open("rb")) + 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 plist[property_name] = property_value try: plistlib.dump(plist, Path(self.global_settings_plist).open("wb")) @@ -69,9 +79,14 @@ class GlobalEnviromentSettings: defaults_path = Path(defaults_path).expanduser() if Path(defaults_path).exists(): - defaults_plist = plistlib.load(Path(defaults_path).open("rb")) # merge defaults with global settings - global_settings_plist = plistlib.load(Path(self.global_settings_plist).open("rb")) + try: + defaults_plist = plistlib.load(Path(defaults_path).open("rb")) + global_settings_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 global_settings_plist.update(defaults_plist) try: plistlib.dump(global_settings_plist, Path(self.global_settings_plist).open("wb"))