defaults.py: Implement additional error handling for 2.1.0 bug

This commit is contained in:
Mykola Grymalyuk
2024-11-06 10:18:17 -07:00
parent 2a578734b9
commit 5e4b124b2a
5 changed files with 60 additions and 2 deletions

View File

@@ -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: <class 'NoneType'>` error occurs
## 2.1.1
- Resolve boolean GUI settings saving incorrectly as Python's None type

View File

@@ -13,7 +13,7 @@ from .detections import device_probe
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"

View File

@@ -435,5 +435,14 @@ class GenerateDefaults:
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])

View File

@@ -44,6 +44,25 @@ class GlobalEnviromentSettings:
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

View File

@@ -28,6 +28,8 @@ class BuildFrame(wx.Frame):
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 @@ class BuildFrame(wx.Frame):
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 @@ class BuildFrame(wx.Frame):
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: <class 'NoneType'>" 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])