mirror of
https://github.com/dortania/OpenCore-Legacy-Patcher.git
synced 2026-06-21 06:30:52 +10:00
global_settings.py: Implement settings system
This commit is contained in:
+8
-8
@@ -16,7 +16,7 @@ from pathlib import Path
|
|||||||
import binascii
|
import binascii
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
from resources import constants, defaults, build, install, installer, sys_patch_download, utilities, sys_patch_detect, sys_patch, run, generate_smbios, updates, integrity_verification
|
from resources import constants, defaults, build, install, installer, sys_patch_download, utilities, sys_patch_detect, sys_patch, run, generate_smbios, updates, integrity_verification, global_settings
|
||||||
from data import model_array, os_data, smbios_data, sip_data
|
from data import model_array, os_data, smbios_data, sip_data
|
||||||
from gui import menu_redirect, gui_help
|
from gui import menu_redirect, gui_help
|
||||||
|
|
||||||
@@ -180,8 +180,8 @@ class wx_python_gui:
|
|||||||
threading.Thread(target=self.check_for_updates).start()
|
threading.Thread(target=self.check_for_updates).start()
|
||||||
|
|
||||||
def check_for_updates(self, event=None):
|
def check_for_updates(self, event=None):
|
||||||
ignore_updates = subprocess.run(["defaults", "read", "com.dortania.opencore-legacy-patcher", "IgnoreAppUpdates"], capture_output=True).stdout.decode("utf-8").strip()
|
ignore_updates = global_settings.global_settings().read_property("IgnoreAppUpdates")
|
||||||
if ignore_updates not in ["1", "True", "TRUE"]:
|
if ignore_updates is not True:
|
||||||
self.constants.ignore_updates = False
|
self.constants.ignore_updates = False
|
||||||
dict = updates.check_binary_updates(self.constants).check_binary_updates()
|
dict = updates.check_binary_updates(self.constants).check_binary_updates()
|
||||||
if dict:
|
if dict:
|
||||||
@@ -202,7 +202,7 @@ class wx_python_gui:
|
|||||||
elif responce == wx.ID_NO:
|
elif responce == wx.ID_NO:
|
||||||
print("- Setting IgnoreAppUpdates to True")
|
print("- Setting IgnoreAppUpdates to True")
|
||||||
self.constants.ignore_updates = True
|
self.constants.ignore_updates = True
|
||||||
subprocess.run(["defaults", "write", "com.dortania.opencore-legacy-patcher", "IgnoreAppUpdates", "-bool", "TRUE"])
|
global_settings.global_settings().write_property("IgnoreAppUpdates", True)
|
||||||
else:
|
else:
|
||||||
self.constants.ignore_updates = True
|
self.constants.ignore_updates = True
|
||||||
print("- Ignoring App Updates due to defaults")
|
print("- Ignoring App Updates due to defaults")
|
||||||
@@ -2369,9 +2369,9 @@ class wx_python_gui:
|
|||||||
def set_ignore_app_updates_click(self, event):
|
def set_ignore_app_updates_click(self, event):
|
||||||
self.constants.ignore_updates = self.set_ignore_app_updates_checkbox.GetValue()
|
self.constants.ignore_updates = self.set_ignore_app_updates_checkbox.GetValue()
|
||||||
if self.constants.ignore_updates is True:
|
if self.constants.ignore_updates is True:
|
||||||
subprocess.run(["defaults", "write", "com.dortania.opencore-legacy-patcher", "IgnoreAppUpdates", "-bool", "TRUE"])
|
global_settings.write_property("IgnoreAppUpdates", True)
|
||||||
else:
|
else:
|
||||||
subprocess.run(["defaults", "write", "com.dortania.opencore-legacy-patcher", "IgnoreAppUpdates", "-bool", "FALSE"])
|
global_settings.write_property("IgnoreAppUpdates", False)
|
||||||
|
|
||||||
def firewire_click(self, event=None):
|
def firewire_click(self, event=None):
|
||||||
if self.firewire_boot_checkbox.GetValue():
|
if self.firewire_boot_checkbox.GetValue():
|
||||||
@@ -2432,11 +2432,11 @@ class wx_python_gui:
|
|||||||
def ts2_accel_click(self, event=None):
|
def ts2_accel_click(self, event=None):
|
||||||
if self.set_terascale_accel_checkbox.GetValue():
|
if self.set_terascale_accel_checkbox.GetValue():
|
||||||
print("TS2 Acceleration Enabled")
|
print("TS2 Acceleration Enabled")
|
||||||
subprocess.run(["defaults", "write", "com.dortania.opencore-legacy-patcher", "MacBookPro_TeraScale_2_Accel", "-bool", "TRUE"])
|
global_settings.global_settings().write_property("MacBookPro_TeraScale_2_Accel", True)
|
||||||
self.constants.allow_ts2_accel = True
|
self.constants.allow_ts2_accel = True
|
||||||
else:
|
else:
|
||||||
print("TS2 Acceleration Disabled")
|
print("TS2 Acceleration Disabled")
|
||||||
subprocess.run(["defaults", "write", "com.dortania.opencore-legacy-patcher", "MacBookPro_TeraScale_2_Accel", "-bool", "FALSE"])
|
global_settings.global_settings().write_property("MacBookPro_TeraScale_2_Accel", False)
|
||||||
self.constants.allow_ts2_accel = False
|
self.constants.allow_ts2_accel = False
|
||||||
|
|
||||||
def windows_gmux_click(self, event=None):
|
def windows_gmux_click(self, event=None):
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from resources import constants, install, utilities, defaults, sys_patch, installer, tui_helpers
|
from resources import constants, install, utilities, defaults, sys_patch, installer, tui_helpers, global_settings
|
||||||
from data import cpu_data, smbios_data, model_array, os_data, mirror_data
|
from data import cpu_data, smbios_data, model_array, os_data, mirror_data
|
||||||
|
|
||||||
|
|
||||||
@@ -589,10 +589,10 @@ handle acceleration tasks.
|
|||||||
|
|
||||||
change_menu = input("Allow TeraScale 2 Acceleration?(y/n/q): ")
|
change_menu = input("Allow TeraScale 2 Acceleration?(y/n/q): ")
|
||||||
if change_menu in {"y", "Y", "yes", "Yes"}:
|
if change_menu in {"y", "Y", "yes", "Yes"}:
|
||||||
subprocess.run(["defaults", "write", "com.dortania.opencore-legacy-patcher", "MacBookPro_TeraScale_2_Accel", "-bool", "TRUE"])
|
global_settings.global_settings().write_property("MacBookPro_TeraScale_2_Accel", True)
|
||||||
self.constants.allow_ts2_accel = True
|
self.constants.allow_ts2_accel = True
|
||||||
elif change_menu in {"n", "N", "no", "No"}:
|
elif change_menu in {"n", "N", "no", "No"}:
|
||||||
subprocess.run(["defaults", "write", "com.dortania.opencore-legacy-patcher", "MacBookPro_TeraScale_2_Accel", "-bool", "FALSE"])
|
global_settings.global_settings().write_property("MacBookPro_TeraScale_2_Accel", False)
|
||||||
self.constants.allow_ts2_accel = False
|
self.constants.allow_ts2_accel = False
|
||||||
elif change_menu in {"q", "Q", "Quit", "quit"}:
|
elif change_menu in {"q", "Q", "Quit", "quit"}:
|
||||||
print("Returning to previous menu")
|
print("Returning to previous menu")
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Generate Default Data
|
# Generate Default Data
|
||||||
from resources import utilities, device_probe, generate_smbios
|
from resources import utilities, device_probe, generate_smbios, global_settings
|
||||||
from data import model_array, smbios_data, cpu_data
|
from data import model_array, smbios_data, cpu_data
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
@@ -119,11 +119,11 @@ class generate_defaults:
|
|||||||
if model in ["MacBookPro8,2", "MacBookPro8,3"]:
|
if model in ["MacBookPro8,2", "MacBookPro8,3"]:
|
||||||
# Users disabling TS2 most likely have a faulty dGPU
|
# Users disabling TS2 most likely have a faulty dGPU
|
||||||
# users can override this in settings
|
# users can override this in settings
|
||||||
ts2_status = subprocess.run(["defaults", "read", "com.dortania.opencore-legacy-patcher", "MacBookPro_TeraScale_2_Accel"], stdout=subprocess.PIPE).stdout.decode("utf-8").strip()
|
ts2_status = global_settings.global_settings().read_property("MacBookPro_TeraScale_2_Accel")
|
||||||
if ts2_status in ["1", "true"]:
|
if ts2_status is True:
|
||||||
settings.allow_ts2_accel = True
|
settings.allow_ts2_accel = True
|
||||||
else:
|
else:
|
||||||
subprocess.run(["defaults", "write", "com.dortania.opencore-legacy-patcher", "MacBookPro_TeraScale_2_Accel", "-bool", "FALSE"])
|
global_settings.global_settings().write_property("MacBookPro_TeraScale_2_Accel", False)
|
||||||
settings.allow_ts2_accel = False
|
settings.allow_ts2_accel = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
# Alternative to Apple's 'defaults' tool
|
||||||
|
# Store data in '/Users/Shared'
|
||||||
|
# This is to ensure compatibility when running wihout a user
|
||||||
|
# ie. during automated patching
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
import plistlib
|
||||||
|
|
||||||
|
class global_settings:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.file_name = ".com.dortania.opencore-legacy-patcher.plist"
|
||||||
|
self.global_settings_folder = "/Users/Shared"
|
||||||
|
self.global_settings_plist = f"{self.global_settings_folder}/{self.file_name}"
|
||||||
|
self.generate_settings_file()
|
||||||
|
|
||||||
|
def generate_settings_file(self):
|
||||||
|
if Path(self.global_settings_plist).exists():
|
||||||
|
return
|
||||||
|
plistlib.dump({"Developed by Dortania": True,}, Path(self.global_settings_plist).open("wb"))
|
||||||
|
|
||||||
|
def read_property(self, property_name):
|
||||||
|
plist = plistlib.load(Path(self.global_settings_plist).open("rb"))
|
||||||
|
if property_name in plist:
|
||||||
|
return plist[property_name]
|
||||||
|
return None
|
||||||
|
|
||||||
|
def write_property(self, property_name, property_value):
|
||||||
|
plist = plistlib.load(Path(self.global_settings_plist).open("rb"))
|
||||||
|
plist[property_name] = property_value
|
||||||
|
plistlib.dump(plist, Path(self.global_settings_plist).open("wb"))
|
||||||
|
|
||||||
|
|
||||||
|
def convert_defaults_to_global_settings(self):
|
||||||
|
defaults_path = "~/Library/Preferences/com.dortania.opencore-legacy-patcher.plist"
|
||||||
|
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"))
|
||||||
|
global_settings_plist.update(defaults_plist)
|
||||||
|
plistlib.dump(global_settings_plist, Path(self.global_settings_plist).open("wb"))
|
||||||
|
|
||||||
|
# delete defaults plist
|
||||||
|
Path(defaults_path).unlink()
|
||||||
+2
-1
@@ -8,7 +8,7 @@ from pathlib import Path
|
|||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
from resources import build, cli_menu, constants, utilities, device_probe, os_probe, defaults, arguments, install, tui_helpers, reroute_payloads
|
from resources import build, cli_menu, constants, utilities, device_probe, os_probe, defaults, arguments, install, tui_helpers, reroute_payloads, global_settings
|
||||||
from data import model_array
|
from data import model_array
|
||||||
|
|
||||||
class OpenCoreLegacyPatcher:
|
class OpenCoreLegacyPatcher:
|
||||||
@@ -46,6 +46,7 @@ class OpenCoreLegacyPatcher:
|
|||||||
self.constants.unpack_thread.start()
|
self.constants.unpack_thread.start()
|
||||||
|
|
||||||
defaults.generate_defaults.probe(self.computer.real_model, True, self.constants)
|
defaults.generate_defaults.probe(self.computer.real_model, True, self.constants)
|
||||||
|
global_settings.global_settings().convert_defaults_to_global_settings()
|
||||||
|
|
||||||
if utilities.check_cli_args() is not None:
|
if utilities.check_cli_args() is not None:
|
||||||
print("- Detected arguments, switching to CLI mode")
|
print("- Detected arguments, switching to CLI mode")
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ from pathlib import Path
|
|||||||
import plistlib
|
import plistlib
|
||||||
import subprocess
|
import subprocess
|
||||||
import webbrowser
|
import webbrowser
|
||||||
from resources import sys_patch_detect, utilities, sys_patch_detect, updates
|
from resources import sys_patch_detect, utilities, sys_patch_detect, updates, global_settings
|
||||||
from gui import gui_main
|
from gui import gui_main
|
||||||
|
|
||||||
class AutomaticSysPatch:
|
class AutomaticSysPatch:
|
||||||
@@ -112,8 +112,8 @@ class AutomaticSysPatch:
|
|||||||
|
|
||||||
print("- Determining if macOS drive matches boot drive")
|
print("- Determining if macOS drive matches boot drive")
|
||||||
|
|
||||||
should_notify = subprocess.run(["defaults", "read", "com.dortania.opencore-legacy-patcher", "AutoPatch_Notify_Mismatched_Disks"], stdout=subprocess.PIPE).stdout.decode("utf-8").strip()
|
should_notify = global_settings.global_settings().read_property("AutoPatch_Notify_Mismatched_Disks")
|
||||||
if should_notify in ["0", "false"]:
|
if should_notify is False:
|
||||||
print("- Skipping due to user preference")
|
print("- Skipping due to user preference")
|
||||||
else:
|
else:
|
||||||
if settings.booted_oc_disk:
|
if settings.booted_oc_disk:
|
||||||
|
|||||||
Reference in New Issue
Block a user