Skip to content

Commit

Permalink
defaults.py: Implement additional error handling for 2.1.0 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
khronokernel committed Nov 6, 2024
1 parent 2a57873 commit 5e4b124
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion opencore_legacy_patcher/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions opencore_legacy_patcher/support/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
19 changes: 19 additions & 0 deletions opencore_legacy_patcher/support/global_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion opencore_legacy_patcher/wx_gui/gui_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?",
Expand All @@ -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: <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])


Expand Down

0 comments on commit 5e4b124

Please sign in to comment.