Remove more unneeded code

This commit is contained in:
Mykola Grymalyuk
2022-05-02 22:09:22 -06:00
parent b4bfd827ce
commit 8489823f8b
10 changed files with 210 additions and 194 deletions

View File

@@ -1,6 +1,19 @@
# Dictionary defining patch sets used during Root Volume patching (sys_patch.py)
# Copyright (C) 2022, Mykola Grymalyuk
# Schema for sys_patch_dict.py:
# Supports 3 types of higher level keys:
# - Install: Install to root volume - Dictionary of strings with value of source
# - Install Non-Root: Install to data partition - Dictionary of strings with value of source
# - Remove: Files to remove - Array of strings
# - Processes: Additional processes to run - Array of strings
# File Storage is based off the origin, ie. '10.13.6/System/Library/Extensions/IOSurface.kext'
# Stubbed binaries are OS specific, this use the 'os' variable to denounce which folder to use
from data import os_data
def SystemPatchDictionary(os):
def SystemPatchDictionary(os_major):
sys_patch_dict = {
"Graphics": {
"Non-Metal Common": {
@@ -10,13 +23,13 @@ def SystemPatchDictionary(os):
},
"/System/Library/Frameworks": {
"OpenGL.framework": "10.14.3",
"CoreDisplay.framework": f"10.14.4-{os}",
"IOSurface.framework": f"10.15.7-{os}",
"QuartzCore.framework": f"10.15.7-{os}",
"CoreDisplay.framework": f"10.14.4-{os_major}",
"IOSurface.framework": f"10.15.7-{os_major}",
"QuartzCore.framework": f"10.15.7-{os_major}",
},
"/System/Library/PrivateFrameworks": {
"GPUSupport.framework": "10.14.3",
"SkyLight.framework": f"10.14.6-{os}",
"SkyLight.framework": f"10.14.6-{os_major}",
},
},
"Remove": {
@@ -49,8 +62,8 @@ def SystemPatchDictionary(os):
},
"Install Non-Root": {
"/Library/Application Support/SkyLightPlugins": {
**({ "DropboxHack.dylib": "SkyLightPlugins" } if os >= os_data.os_data.monterey else {}),
**({ "DropboxHack.txt": "SkyLightPlugins" } if os >= os_data.os_data.monterey else {}),
**({ "DropboxHack.dylib": "SkyLightPlugins" } if os_major >= os_data.os_data.monterey else {}),
**({ "DropboxHack.txt": "SkyLightPlugins" } if os_major >= os_data.os_data.monterey else {}),
},
},
},
@@ -85,7 +98,7 @@ def SystemPatchDictionary(os):
"GeForceTeslaVADriver.bundle": "10.13.6",
"NVDANV50HalTesla.kext": "10.13.6",
"NVDAResmanTesla.kext": "10.13.6",
**({ "NVDAStartup.kext": "12.0 Beta 6" } if os >= os_data.os_data.monterey else {})
**({ "NVDAStartup.kext": "12.0 Beta 6" } if os_major >= os_data.os_data.monterey else {})
},
},
},
@@ -104,6 +117,29 @@ def SystemPatchDictionary(os):
},
},
},
"Nvidia Web Drivers": {
"Install": {
"/System/Library/Extensions": {
"NVDAStartupWeb.kext": "10.13.6",
"GeForceTeslaWeb.kext": "10.13.6",
"GeForceWeb.kext": "10.13.6",
"NVDAGF100HalWeb.kext": "10.13.6",
"NVDAGK100HalWeb.kext": "10.13.6",
"NVDAGM100HalWeb.kext": "10.13.6",
"NVDAGP100HalWeb.kext": "10.13.6",
"NVDANV50HalTeslaWeb.kext": "10.13.6",
"NVDAResmanTeslaWeb.kext": "10.13.6",
"NVDAResmanWeb.kext": "10.13.6",
"GeForceVADriverWeb.bundle": "10.13.6",
"GeForceAIRPluginWeb.bundle": "10.13.6",
"GeForceGLDriverWeb.bundle": "10.13.6",
"GeForceMTLDriverWeb.bundle": "10.13.6",
"GeForceTeslaGAWeb.bundle": "10.13.6",
"GeForceTeslaGLDriverWeb.bundle": "10.13.6",
"GeForceTeslaVADriverWeb.bundle": "10.13.6",
},
},
},
"AMD TeraScale 1": {
"Install": {
"/System/Library/Extensions": {
@@ -152,11 +188,11 @@ def SystemPatchDictionary(os):
},
"/System/Library/Frameworks": {
"OpenCL.framework": "10.13.6",
"IOSurface.framework": f"10.14.6-{os}",
"IOSurface.framework": f"10.14.6-{os_major}",
},
"/System/Library/PrivateFrameworks": {
"GPUSupport.framework": "10.13.6",
"IOAccelerator.framework": f"10.13.6-{os}",
"IOAccelerator.framework": f"10.13.6-{os_major}",
},
},
"Remove": {
@@ -250,8 +286,8 @@ def SystemPatchDictionary(os):
},
"Install Non-Root": {
"/Library/Application Support/SkyLightPlugins": {
**({ "CoreWLAN.dylib": "SkyLightPlugins" } if os >= os_data.os_data.monterey else {}),
**({ "CoreWLAN.txt": "SkyLightPlugins" } if os >= os_data.os_data.monterey else {}),
**({ "CoreWLAN.dylib": "SkyLightPlugins" } if os_major >= os_data.os_data.monterey else {}),
**({ "CoreWLAN.txt": "SkyLightPlugins" } if os_major >= os_data.os_data.monterey else {}),
},
},
},

View File

@@ -899,7 +899,7 @@ class wx_python_gui:
# Download resources
sys.stdout=menu_redirect.RedirectLabel(self.developer_note)
download_result, os_ver, link = sys_patch_download.grab_patcher_support_pkg(self.constants).download_files()
download_result, link = sys_patch_download.grab_patcher_support_pkg(self.constants).download_files()
sys.stdout=sys.__stdout__
if download_result is None:

View File

@@ -3,7 +3,7 @@
import sys
import subprocess
from resources import constants, install, utilities, defaults, sys_patch, installer
from resources import constants, install, utilities, defaults, sys_patch, installer, tui_helpers
from data import cpu_data, smbios_data, model_array, os_data, mirror_data
@@ -1014,7 +1014,7 @@ AssetCache.
self.set_cc_support()
def credits(self):
utilities.TUIOnlyPrint(
tui_helpers.TUIOnlyPrint(
["Credits"],
"Press [Enter] to go back.\n",
[
@@ -1085,7 +1085,7 @@ system_profiler SPHardwareDataType | grep 'Model Identifier'
response = None
while not (response and response == -1):
title = ["Adjust Advanced Patcher Settings, for developers ONLY"]
menu = utilities.TUIMenu(title, "Please select an option: ", auto_number=True, top_level=True)
menu = tui_helpers.TUIMenu(title, "Please select an option: ", auto_number=True, top_level=True)
options = [
[f"Set Metal GPU Status:\t\tCurrently {self.constants.imac_vendor}", MenuOptions(self.constants.custom_model or self.constants.computer.real_model, self.constants).change_metal],
[f"Set DRM Preferences:\t\tCurrently {self.constants.drm_support}", MenuOptions(self.constants.custom_model or self.constants.computer.real_model, self.constants).drm_setting],
@@ -1105,7 +1105,7 @@ system_profiler SPHardwareDataType | grep 'Model Identifier'
response = None
while not (response and response == -1):
title = ["Adjust Patcher Settings"]
menu = utilities.TUIMenu(title, "Please select an option: ", auto_number=True, top_level=True)
menu = tui_helpers.TUIMenu(title, "Please select an option: ", auto_number=True, top_level=True)
options = [
["Debug Settings", self.patcher_setting_debug],
["Security Settings", self.patcher_settings_security],
@@ -1129,7 +1129,7 @@ system_profiler SPHardwareDataType | grep 'Model Identifier'
response = None
while not (response and response == -1):
title = ["Adjust Debug Settings"]
menu = utilities.TUIMenu(title, "Please select an option: ", auto_number=True, top_level=True)
menu = tui_helpers.TUIMenu(title, "Please select an option: ", auto_number=True, top_level=True)
options = [
[f"Enable Verbose Mode:\tCurrently {self.constants.verbose_debug}", MenuOptions(self.constants.custom_model or self.constants.computer.real_model, self.constants).change_verbose],
[f"Enable OpenCore DEBUG:\tCurrently {self.constants.opencore_debug}", MenuOptions(self.constants.custom_model or self.constants.computer.real_model, self.constants).change_oc],
@@ -1149,7 +1149,7 @@ system_profiler SPHardwareDataType | grep 'Model Identifier'
response = None
while not (response and response == -1):
title = ["Adjust Security Settings"]
menu = utilities.TUIMenu(title, "Please select an option: ", auto_number=True, top_level=True)
menu = tui_helpers.TUIMenu(title, "Please select an option: ", auto_number=True, top_level=True)
options = [
# [
# f"Set Apple Mobile File Integrity (AMFI):\tCurrently {self.constants.amfi_status}",
@@ -1175,7 +1175,7 @@ system_profiler SPHardwareDataType | grep 'Model Identifier'
response = None
while not (response and response == -1):
title = ["Adjust SMBIOS Settings"]
menu = utilities.TUIMenu(title, "Please select an option: ", auto_number=True, top_level=True)
menu = tui_helpers.TUIMenu(title, "Please select an option: ", auto_number=True, top_level=True)
options = [
[f"Set SMBIOS Spoof Level:\tCurrently {self.constants.serial_settings}", MenuOptions(self.constants.custom_model or self.constants.computer.real_model, self.constants).change_serial],
[f"Set SMBIOS Spoof Model:\tCurrently {self.constants.override_smbios}", MenuOptions(self.constants.custom_model or self.constants.computer.real_model, self.constants).set_smbios],
@@ -1192,7 +1192,7 @@ system_profiler SPHardwareDataType | grep 'Model Identifier'
response = None
while not (response and response == -1):
title = ["Adjust Bootable Volume Settings"]
menu = utilities.TUIMenu(title, "Please select an option: ", auto_number=True, top_level=True)
menu = tui_helpers.TUIMenu(title, "Please select an option: ", auto_number=True, top_level=True)
options = [
[f"Set FireWire Boot:\t\tCurrently {self.constants.firewire_boot}", MenuOptions(self.constants.custom_model or self.constants.computer.real_model, self.constants).allow_firewire],
[f"Set XHCI Boot:\t\tCurrently {self.constants.xhci_boot}", MenuOptions(self.constants.custom_model or self.constants.computer.real_model, self.constants).allow_xhci],
@@ -1209,7 +1209,7 @@ system_profiler SPHardwareDataType | grep 'Model Identifier'
response = None
while not (response and response == -1):
title = ["Adjust Miscellaneous Settings"]
menu = utilities.TUIMenu(title, "Please select an option: ", auto_number=True, top_level=True)
menu = tui_helpers.TUIMenu(title, "Please select an option: ", auto_number=True, top_level=True)
options = [
[f"Set ShowPicker Mode:\tCurrently {self.constants.showpicker}", MenuOptions(self.constants.custom_model or self.constants.computer.real_model, self.constants).change_showpicker],
[f"Set Wake on WLAN:\t\tCurrently {self.constants.enable_wake_on_wlan}", MenuOptions(self.constants.custom_model or self.constants.computer.real_model, self.constants).allow_wowl],
@@ -1246,7 +1246,7 @@ system_profiler SPHardwareDataType | grep 'Model Identifier'
response = None
while not (response and response == -1):
title = ["Adjust Advanced Patcher Settings, for developers ONLY"]
menu = utilities.TUIMenu(title, "Please select an option: ", auto_number=True, top_level=True)
menu = tui_helpers.TUIMenu(title, "Please select an option: ", auto_number=True, top_level=True)
options = [
[f"Set Metal GPU Status:\t\tCurrently {self.constants.imac_vendor}", MenuOptions(self.constants.custom_model or self.constants.computer.real_model, self.constants).change_metal],
[f"Set DRM Preferences:\t\tCurrently {self.constants.drm_support}", MenuOptions(self.constants.custom_model or self.constants.computer.real_model, self.constants).drm_setting],
@@ -1301,7 +1301,7 @@ B. Exit
while not (response and response == -1):
options = []
title = ["Select the macOS Installer you wish to download"]
menu = utilities.TUIMenu(title, "Please select an option: ", auto_number=True, top_level=True)
menu = tui_helpers.TUIMenu(title, "Please select an option: ", auto_number=True, top_level=True)
available_installers = installer.list_downloadable_macOS_installers(self.constants.payload_path, "DeveloperSeed")
if available_installers:
# Add mirror of 11.2.3 for users who want it
@@ -1321,7 +1321,7 @@ B. Exit
while not (response and response == -1):
options = []
title = ["Select the macOS Installer you wish to use"]
menu = utilities.TUIMenu(title, "Please select an option: ", auto_number=True, top_level=True)
menu = tui_helpers.TUIMenu(title, "Please select an option: ", auto_number=True, top_level=True)
available_installers = installer.list_local_macOS_installers()
if available_installers:
for app in available_installers:

View File

@@ -7,7 +7,7 @@ import subprocess
import shutil
import os
from pathlib import Path
from resources import utilities, constants
from resources import utilities, constants, tui_helpers
from data import os_data
class tui_disk_installation:
@@ -79,7 +79,7 @@ class tui_disk_installation:
utilities.header(["Installing OpenCore to Drive"])
if not self.constants.opencore_release_folder.exists():
utilities.TUIOnlyPrint(
tui_helpers.TUIOnlyPrint(
["Installing OpenCore to Drive"],
"Press [Enter] to go back.\n",
[
@@ -92,7 +92,7 @@ Please build OpenCore first!"""
print("\nDisk picker is loading...")
all_disks = self.list_disks()
menu = utilities.TUIMenu(
menu = tui_helpers.TUIMenu(
["Select Disk"],
"Please select the disk you would like to install OpenCore to: ",
in_between=["Missing disks? Ensure they have an EFI or FAT32 partition."],
@@ -110,7 +110,7 @@ Please build OpenCore first!"""
disk_identifier = "disk" + response
selected_disk = all_disks[disk_identifier]
menu = utilities.TUIMenu(
menu = tui_helpers.TUIMenu(
["Select Partition"],
"Please select the partition you would like to install OpenCore to: ",
return_number_instead_of_direct_call=True,
@@ -169,7 +169,7 @@ Please build OpenCore first!"""
return
else:
if self.constants.gui_mode is False:
utilities.TUIOnlyPrint(
tui_helpers.TUIOnlyPrint(
["Copying OpenCore"], "Press [Enter] to go back.\n", ["An error occurred!"] + result.stderr.decode().split("\n") + [""]
).start()
else:
@@ -252,7 +252,7 @@ Please build OpenCore first!"""
input()
else:
if self.constants.gui_mode is False:
utilities.TUIOnlyPrint(["Copying OpenCore"], "Press [Enter] to go back.\n", ["EFI failed to mount!"]).start()
tui_helpers.TUIOnlyPrint(["Copying OpenCore"], "Press [Enter] to go back.\n", ["EFI failed to mount!"]).start()
else:
print("EFI failed to mount!")

View File

@@ -3,7 +3,7 @@ from pathlib import Path
import plistlib
import subprocess
import requests
from resources import utilities
from resources import utilities, tui_helpers
def list_local_macOS_installers():
# Finds all applicable macOS installers
@@ -264,7 +264,7 @@ def select_disk_to_format():
except KeyError:
# Avoid crashing with CDs installed
continue
menu = utilities.TUIMenu(
menu = tui_helpers.TUIMenu(
["Select Disk to write the macOS Installer onto"],
"Please select the disk you would like to install OpenCore to: ",
in_between=["Missing drives? Verify they are 14GB+ and external (ie. USB)", "", "Ensure all data is backed up on selected drive, entire drive will be erased!"],

View File

@@ -6,7 +6,7 @@ import subprocess
import sys
from pathlib import Path
from resources import build, cli_menu, constants, utilities, device_probe, os_probe, defaults, arguments, install
from resources import build, cli_menu, constants, utilities, device_probe, os_probe, defaults, arguments, install, tui_helpers
from data import model_array
class OpenCoreLegacyPatcher:
@@ -79,7 +79,7 @@ class OpenCoreLegacyPatcher:
else:
in_between = ["This model is supported"]
menu = utilities.TUIMenu(title, "Please select an option: ", in_between=in_between, auto_number=True, top_level=True)
menu = tui_helpers.TUIMenu(title, "Please select an option: ", in_between=in_between, auto_number=True, top_level=True)
options = (
[["Build OpenCore", build.BuildOpenCore(self.constants.custom_model or self.constants.computer.real_model, self.constants).build_opencore]]

View File

@@ -5,10 +5,8 @@
# - Temporary Work-around: sudo bless --mount /System/Volumes/Update/mnt1 --bootefi --last-sealed-snapshot
# - Work-around battery throttling on laptops with no battery (IOPlatformPluginFamily.kext/Contents/PlugIns/ACPI_SMC_PlatformPlugin.kext/Contents/Resources/)
import os
import shutil
import subprocess
import zipfile
from pathlib import Path
from resources import constants, generate_smbios, utilities, sys_patch_download, sys_patch_detect
@@ -268,6 +266,7 @@ class PatchSysVolume:
print(" - Adding Nvidia Tesla Graphics Patchset")
required_patches.update({"Non-Metal Common": all_hardware_patchset["Graphics"]["Non-Metal Common"]})
required_patches.update({"Nvidia Tesla": all_hardware_patchset["Graphics"]["Nvidia Tesla"]})
required_patches.update({"Nvidia Web Drivers": all_hardware_patchset["Graphics"]["Nvidia Web Drivers"]})
if self.kepler_gpu is True:
print(" - Adding Nvidia Kepler Graphics Patchset")
required_patches.update({"Metal Common": all_hardware_patchset["Graphics"]["Metal Common"]})
@@ -304,34 +303,7 @@ class PatchSysVolume:
def execute_patchset(self, required_patches):
source_files_path = str(self.constants.payload_local_binaries_root_path)
print("- Running Preflight Checks before patching")
# Make sure old SkyLight plugins aren't being used
self.clean_skylight_plugins()
# Make sure SNB kexts are compatible with the host
if "Intel Sandy Bridge" in required_patches:
if self.computer.reported_board_id not in self.constants.sandy_board_id_stock:
print(f"- Found unspported Board ID {self.computer.reported_board_id}, performing AppleIntelSNBGraphicsFB bin patching")
board_to_patch = generate_smbios.determine_best_board_id_for_sandy(self.computer.reported_board_id, self.computer.gpus)
print(f"- Replacing {board_to_patch} with {self.computer.reported_board_id}")
board_to_patch_hex = bytes.fromhex(board_to_patch.encode('utf-8').hex())
reported_board_hex = bytes.fromhex(self.computer.reported_board_id.encode('utf-8').hex())
if len(board_to_patch_hex) != len(reported_board_hex):
print(f"- Error: Board ID {self.computer.reported_board_id} is not the same length as {board_to_patch}")
raise Exception("Host's Board ID is not the same length as the kext's Board ID, cannot patch!!!")
else:
path = source_files_path + "10.13.6/System/Library/Extensions/AppleIntelSNBGraphicsFB.kext/Contents/MacOS/AppleIntelSNBGraphicsFB"
if Path(path).exists:
with open(path, 'rb') as f:
data = f.read()
data = data.replace(board_to_patch_hex, reported_board_hex)
with open(path, 'wb') as f:
f.write(data)
else:
raise Exception("Failed to find AppleIntelSNBGraphicsFB.kext, cannot patch!!!")
print("- Finished Preflight, starting patching")
self.preflight_checks(required_patches, source_files_path)
for patch in required_patches:
print("- Installing Patchset: " + patch)
if "Remove" in required_patches[patch]:
@@ -367,6 +339,55 @@ class PatchSysVolume:
else:
utilities.process_status(subprocess.run(process_array, stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
def preflight_checks(self, required_patches, source_files_path):
print("- Running Preflight Checks before patching")
# Make sure old SkyLight plugins aren't being used
self.clean_skylight_plugins()
# Make sure SNB kexts are compatible with the host
if "Intel Sandy Bridge" in required_patches:
if self.computer.reported_board_id not in self.constants.sandy_board_id_stock:
print(f"- Found unspported Board ID {self.computer.reported_board_id}, performing AppleIntelSNBGraphicsFB bin patching")
board_to_patch = generate_smbios.determine_best_board_id_for_sandy(self.computer.reported_board_id, self.computer.gpus)
print(f"- Replacing {board_to_patch} with {self.computer.reported_board_id}")
board_to_patch_hex = bytes.fromhex(board_to_patch.encode('utf-8').hex())
reported_board_hex = bytes.fromhex(self.computer.reported_board_id.encode('utf-8').hex())
if len(board_to_patch_hex) != len(reported_board_hex):
print(f"- Error: Board ID {self.computer.reported_board_id} is not the same length as {board_to_patch}")
raise Exception("Host's Board ID is not the same length as the kext's Board ID, cannot patch!!!")
else:
path = source_files_path + "10.13.6/System/Library/Extensions/AppleIntelSNBGraphicsFB.kext/Contents/MacOS/AppleIntelSNBGraphicsFB"
if Path(path).exists:
with open(path, 'rb') as f:
data = f.read()
data = data.replace(board_to_patch_hex, reported_board_hex)
with open(path, 'wb') as f:
f.write(data)
else:
raise Exception("Failed to find AppleIntelSNBGraphicsFB.kext, cannot patch!!!")
# Check all the files are present
for patch in required_patches:
if "Install" in required_patches[patch]:
for install_patch_directory in required_patches[patch]["Install"]:
for install_file in required_patches[patch]["Install"][install_patch_directory]:
source_file = source_files_path + "/" + required_patches[patch]['Install'][install_patch_directory][install_file] + install_patch_directory + "/" + install_file
if not Path(source_file).exists:
raise Exception(f"Failed to find {source_file}")
if "Install Non-Root" in required_patches[patch]:
for install_patch_directory in required_patches[patch]["Install Non-Root"]:
print(f"- Handling Non-Root Installs in: {install_patch_directory}")
for install_file in required_patches[patch]["Install Non-Root"][install_patch_directory]:
source_file = source_files_path + "/" + required_patches[patch]['Install Non-Root'][install_patch_directory][install_file] + install_patch_directory + "/" + install_file
if not Path(source_file).exists:
raise Exception(f"Failed to find {source_file}")
print("- Finished Preflight, starting patching")
def install_new_file(self, source_folder, destination_folder, file_name):
# .frameworks are merged
# .kexts and .apps are deleted and replaced
@@ -423,22 +444,18 @@ class PatchSysVolume:
def download_files(self):
if self.constants.gui_mode is False or "Library/InstallerSandboxes/" in str(self.constants.payload_path):
download_result, os_ver, link = sys_patch_download.grab_patcher_support_pkg(self.constants).download_files()
download_result, link = sys_patch_download.grab_patcher_support_pkg(self.constants).download_files()
else:
download_result = True
os_ver, link = sys_patch_download.grab_patcher_support_pkg(self.constants).generate_pkg_link()
link = sys_patch_download.grab_patcher_support_pkg(self.constants).generate_pkg_link()
if download_result and self.constants.payload_local_binaries_root_path_zip.exists():
print("- Unzipping binaries...")
try:
utilities.process_status(subprocess.run(["ditto", "-V", "-x", "-k", "--sequesterRsrc", "--rsrc", self.constants.payload_local_binaries_root_path_zip, self.constants.payload_path]))
print("- Renaming folder")
print("- Binaries downloaded to:")
print(self.constants.payload_path)
return self.constants.payload_local_binaries_root_path
except zipfile.BadZipFile:
print("- Couldn't unzip")
return None
utilities.process_status(subprocess.run(["ditto", "-V", "-x", "-k", "--sequesterRsrc", "--rsrc", self.constants.payload_local_binaries_root_path_zip, self.constants.payload_path]))
print("- Renaming folder")
print("- Binaries downloaded to:")
print(self.constants.payload_path)
return self.constants.payload_local_binaries_root_path
else:
if self.constants.gui_mode is True:
print("- Download failed, please verify the below link work:")

View File

@@ -12,21 +12,11 @@ class grab_patcher_support_pkg:
self.constants = constants
def generate_pkg_link(self):
if self.constants.detected_os == os_data.os_data.monterey:
os_ver = "12-Monterey"
elif self.constants.detected_os == os_data.os_data.big_sur:
os_ver = "11-Big-Sur"
elif self.constants.detected_os == os_data.os_data.catalina:
os_ver = "10.15-Catalina"
elif self.constants.detected_os == os_data.os_data.mojave:
os_ver = "10.14-Mojave"
else:
raise Exception(f"Unsupported OS: {self.constants.detected_os}")
link = f"{self.constants.url_patcher_support_pkg}{self.constants.patcher_support_pkg_version}/Universal-Binaries.zip"
return os_ver, link
return link
def download_files(self):
os_ver, link = self.generate_pkg_link()
link = self.generate_pkg_link()
if Path(self.constants.payload_local_binaries_root_path).exists():
print("- Removing old Apple Binaries folder")
# Delete folder
@@ -41,4 +31,4 @@ class grab_patcher_support_pkg:
print(f"- No local version found, downloading...")
download_result = utilities.download_file(link, self.constants.payload_local_binaries_root_path_zip)
return download_result, os_ver, link
return download_result, link

78
resources/tui_helpers.py Normal file
View File

@@ -0,0 +1,78 @@
# Copyright (C) 2020-2022, Dhinak G, Mykola Grymaluk
from resources import utilities
class TUIMenu:
def __init__(self, title, prompt, options=None, return_number_instead_of_direct_call=False, add_quit=True, auto_number=False, in_between=None, top_level=False, loop=False):
self.title = title
self.prompt = prompt
self.in_between = in_between or []
self.options = options or []
self.return_number_instead_of_direct_call = return_number_instead_of_direct_call
self.auto_number = auto_number
self.add_quit = add_quit
self.top_level = top_level
self.loop = loop
self.added_quit = False
def add_menu_option(self, name, description="", function=None, key=""):
self.options.append([key, name, description, function])
def start(self):
return_option = ["Q", "Quit"] if self.top_level else ["B", "Back"]
if self.add_quit and not self.added_quit:
self.add_menu_option(return_option[1], function=None, key=return_option[0])
self.added_quit = True
while True:
utilities.cls()
utilities.header(self.title)
print()
for i in self.in_between:
print(i)
if self.in_between:
print()
for index, option in enumerate(self.options):
if self.auto_number and not (index == (len(self.options) - 1) and self.add_quit):
option[0] = str((index + 1))
print(option[0] + ". " + option[1])
for i in option[2]:
print("\t" + i)
print()
selected = input(self.prompt)
keys = [option[0].upper() for option in self.options]
if not selected or selected.upper() not in keys:
if self.loop:
continue
else:
return
if self.add_quit and selected.upper() == return_option[0]:
return -1
elif self.return_number_instead_of_direct_call:
return self.options[keys.index(selected.upper())][0]
else:
self.options[keys.index(selected.upper())][3]() if self.options[keys.index(selected.upper())][3] else None
if not self.loop:
return
class TUIOnlyPrint:
def __init__(self, title, prompt, in_between=None):
self.title = title
self.prompt = prompt
self.in_between = in_between or []
def start(self):
utilities.cls()
utilities.header(self.title)
print()
for i in self.in_between:
print(i)
if self.in_between:
print()
return input(self.prompt)

View File

@@ -567,108 +567,3 @@ def check_cli_args():
return None
else:
return args
# def menu(title, prompt, menu_options, add_quit=True, auto_number=False, in_between=[], top_level=False):
# return_option = ["Q", "Quit", None] if top_level else ["B", "Back", None]
# if add_quit: menu_options.append(return_option)
# cls()
# header(title)
# print()
# for i in in_between: print(i)
# if in_between: print()
# for index, option in enumerate(menu_options):
# if auto_number and not (index == (len(menu_options) - 1) and add_quit):
# option[0] = str((index + 1))
# print(option[0] + ". " + option[1])
# print()
# selected = input(prompt)
# keys = [option[0].upper() for option in menu_options]
# if not selected or selected.upper() not in keys:
# return
# if selected.upper() == return_option[0]:
# return -1
# else:
# menu_options[keys.index(selected.upper())][2]() if menu_options[keys.index(selected.upper())][2] else None
class TUIMenu:
def __init__(self, title, prompt, options=None, return_number_instead_of_direct_call=False, add_quit=True, auto_number=False, in_between=None, top_level=False, loop=False):
self.title = title
self.prompt = prompt
self.in_between = in_between or []
self.options = options or []
self.return_number_instead_of_direct_call = return_number_instead_of_direct_call
self.auto_number = auto_number
self.add_quit = add_quit
self.top_level = top_level
self.loop = loop
self.added_quit = False
def add_menu_option(self, name, description="", function=None, key=""):
self.options.append([key, name, description, function])
def start(self):
return_option = ["Q", "Quit"] if self.top_level else ["B", "Back"]
if self.add_quit and not self.added_quit:
self.add_menu_option(return_option[1], function=None, key=return_option[0])
self.added_quit = True
while True:
cls()
header(self.title)
print()
for i in self.in_between:
print(i)
if self.in_between:
print()
for index, option in enumerate(self.options):
if self.auto_number and not (index == (len(self.options) - 1) and self.add_quit):
option[0] = str((index + 1))
print(option[0] + ". " + option[1])
for i in option[2]:
print("\t" + i)
print()
selected = input(self.prompt)
keys = [option[0].upper() for option in self.options]
if not selected or selected.upper() not in keys:
if self.loop:
continue
else:
return
if self.add_quit and selected.upper() == return_option[0]:
return -1
elif self.return_number_instead_of_direct_call:
return self.options[keys.index(selected.upper())][0]
else:
self.options[keys.index(selected.upper())][3]() if self.options[keys.index(selected.upper())][3] else None
if not self.loop:
return
class TUIOnlyPrint:
def __init__(self, title, prompt, in_between=None):
self.title = title
self.prompt = prompt
self.in_between = in_between or []
def start(self):
cls()
header(self.title)
print()
for i in self.in_between:
print(i)
if self.in_between:
print()
return input(self.prompt)