Remove TUI modules

This commit is contained in:
Mykola Grymalyuk
2023-02-09 16:26:47 -07:00
parent 48471ce4d3
commit d305515c28
9 changed files with 59 additions and 1686 deletions

View File

@@ -3,4 +3,4 @@
from resources import main
if __name__ == '__main__':
main.OpenCoreLegacyPatcher(True)
main.OpenCoreLegacyPatcher()

View File

@@ -1,6 +0,0 @@
#!/usr/bin/env python3
# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk
from resources import main
if __name__ == '__main__':
main.OpenCoreLegacyPatcher()

View File

@@ -1,44 +0,0 @@
# -*- mode: python ; coding: utf-8 -*-
import sys, os
sys.path.append(os.path.abspath(os.getcwd()))
from resources import constants
block_cipher = None
a = Analysis(['OpenCore-Patcher.command'],
pathex=['resources', 'data'],
binaries=[],
datas=[('payloads', 'payloads')],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=['wxPython', 'wxpython'],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='OpenCore-Patcher',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True )
app = BUNDLE(exe,
name='OpenCore-Patcher.app',
icon="payloads/OC-Patcher-TUI.icns",
bundle_identifier="com.dortania.opencore-legacy-patcher-tui",
info_plist={
"CFBundleShortVersionString": constants.Constants().patcher_version,
"CFBundleExecutable": "MacOS/Launcher",
"NSHumanReadableCopyright": constants.Constants().copyright_date,
})

View File

@@ -1,11 +0,0 @@
# Mirrors of Apple's InstallAssistant.pkg
# Currently only listing important Installers no longer on Apple's servers
Install_macOS_Big_Sur_11_2_3 = {
"Version": "11.2.3",
"Build": "20D91",
"Link": "https://archive.org/download/install-assistant-20D91/InstallAssistant.pkg",
"Size": 12211077798,
"Source": "Archive.org",
"integrity": None,
}

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,7 @@ import shutil
import os
import logging
from pathlib import Path
from resources import utilities, constants, tui_helpers
from resources import utilities, constants
from data import os_data
class tui_disk_installation:
@@ -75,65 +75,6 @@ class tui_disk_installation:
return supported_partitions
def copy_efi(self):
utilities.cls()
utilities.header(["Installing OpenCore to Drive"])
if not self.constants.opencore_release_folder.exists():
tui_helpers.TUIOnlyLogging.info(
["Installing OpenCore to Drive"],
"Press [Enter] to go back.\n",
[
"""OpenCore folder missing!
Please build OpenCore first!"""
],
).start()
return
logging.info("\nDisk picker is loading...")
all_disks = self.list_disks()
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."],
return_number_instead_of_direct_call=True,
loop=True,
)
for disk in all_disks:
menu.add_menu_option(f"{disk}: {all_disks[disk]['name']} ({all_disks[disk]['size']})", key=disk[4:])
response = menu.start()
if response == -1:
return
disk_identifier = "disk" + response
selected_disk = all_disks[disk_identifier]
menu = tui_helpers.TUIMenu(
["Select Partition"],
"Please select the partition you would like to install OpenCore to: ",
return_number_instead_of_direct_call=True,
loop=True,
in_between=["Missing partitions? Ensure they are formatted as an EFI or FAT32.", "", "* denotes likely candidate."],
)
for partition in selected_disk["partitions"]:
if selected_disk["partitions"][partition]["fs"] not in ("msdos", "EFI"):
continue
text = f"{partition}: {selected_disk['partitions'][partition]['name']} ({utilities.human_fmt(selected_disk['partitions'][partition]['size'])})"
if selected_disk["partitions"][partition]["type"] == "EFI" or (
selected_disk["partitions"][partition]["type"] == "Microsoft Basic Data" and selected_disk["partitions"][partition]["size"] < 1024 * 1024 * 512
): # 512 megabytes:
text += " *"
menu.add_menu_option(text, key=partition[len(disk_identifier) + 1 :])
response = menu.start()
if response == -1:
return
self.install_opencore(f"{disk_identifier}s{response}")
def install_opencore(self, full_disk_identifier):
def determine_sd_card(media_name):
# Array filled with common SD Card names
@@ -169,18 +110,13 @@ Please build OpenCore first!"""
# cancelled prompt
return
else:
if self.constants.gui_mode is False:
tui_helpers.TUIOnlyLogging.info(
["Copying OpenCore"], "Press [Enter] to go back.\n", ["An error occurred!"] + result.stderr.decode().split("\n") + [""]
).start()
else:
logging.info("An error occurred!")
logging.info(result.stderr.decode())
logging.info("An error occurred!")
logging.info(result.stderr.decode())
# Check if we're in Safe Mode, and if so, tell user FAT32 is unsupported
if utilities.check_boot_mode() == "safe_boot":
logging.info("\nSafe Mode detected. FAT32 is unsupported by macOS in this mode.")
logging.info("Please disable Safe Mode and try again.")
# Check if we're in Safe Mode, and if so, tell user FAT32 is unsupported
if utilities.check_boot_mode() == "safe_boot":
logging.info("\nSafe Mode detected. FAT32 is unsupported by macOS in this mode.")
logging.info("Please disable Safe Mode and try again.")
return
partition_info = plistlib.loads(subprocess.run(f"diskutil info -plist {full_disk_identifier}".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode())
parent_disk = partition_info["ParentWholeDisk"]
@@ -252,10 +188,7 @@ Please build OpenCore first!"""
logging.info("\nPress [Enter] to continue.\n")
input()
else:
if self.constants.gui_mode is False:
tui_helpers.TUIOnlyLogging.info(["Copying OpenCore"], "Press [Enter] to go back.\n", ["EFI failed to mount!"]).start()
else:
logging.info("EFI failed to mount!")
logging.info("EFI failed to mount!")
return False
return True

View File

@@ -4,7 +4,7 @@ import plistlib
import subprocess
import tempfile
import logging
from resources import utilities, tui_helpers, network_handler
from resources import utilities, network_handler
def list_local_macOS_installers():
# Finds all applicable macOS installers
@@ -325,52 +325,6 @@ def format_drive(disk_id):
input("\nPress Enter to exit")
return False
def select_disk_to_format():
utilities.cls()
utilities.header(["Installing OpenCore to Drive"])
logging.info("\nDisk picker is loading...")
all_disks = {}
# TODO: AllDisksAndPartitions is not supported in Snow Leopard and older
try:
# High Sierra and newer
disks = plistlib.loads(subprocess.run("diskutil list -plist physical".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode())
except ValueError:
# Sierra and older
disks = plistlib.loads(subprocess.run("diskutil list -plist".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode())
for disk in disks["AllDisksAndPartitions"]:
disk_info = plistlib.loads(subprocess.run(f"diskutil info -plist {disk['DeviceIdentifier']}".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode())
try:
all_disks[disk["DeviceIdentifier"]] = {"identifier": disk_info["DeviceNode"], "name": disk_info["MediaName"], "size": disk_info["TotalSize"], "removable": disk_info["Internal"], "partitions": {}}
except KeyError:
# Avoid crashing with CDs installed
continue
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!"],
return_number_instead_of_direct_call=True,
loop=True,
)
for disk in all_disks:
# Strip disks that are under 14GB (15,032,385,536 bytes)
# createinstallmedia isn't great at detecting if a disk has enough space
if not any(all_disks[disk]['size'] > 15032385536 for partition in all_disks[disk]):
continue
# Strip internal disks as well (avoid user formatting their SSD/HDD)
# Ensure user doesn't format their boot drive
if not any(all_disks[disk]['removable'] is False for partition in all_disks[disk]):
continue
menu.add_menu_option(f"{disk}: {all_disks[disk]['name']} ({utilities.human_fmt(all_disks[disk]['size'])})", key=disk[4:])
response = menu.start()
if response == -1:
return None
return response
def list_disk_to_format():

View File

@@ -4,21 +4,16 @@ import sys
import time
import logging
import threading
import subprocess
from pathlib import Path
from data import model_array
from resources.build import build
from resources.gui import gui_main
from resources import (
cli_menu,
constants,
utilities,
device_probe,
os_probe,
defaults,
arguments,
install,
tui_helpers,
reroute_payloads,
commit_info,
logging_handler
@@ -26,36 +21,50 @@ from resources import (
class OpenCoreLegacyPatcher:
def __init__(self, launch_gui=False):
self.constants = constants.Constants()
self.constants.wxpython_variant = launch_gui
"""
Initial entry point for starting OpenCore Legacy Patcher
"""
def __init__(self):
logging_handler.InitializeLoggingSupport()
self.constants: constants = constants.Constants()
self.constants.wxpython_variant: bool = True
logging.info(f"- Loading OpenCore Legacy Patcher v{self.constants.patcher_version}...")
self.generate_base_data()
self._generate_base_data()
if utilities.check_cli_args() is None:
if launch_gui is True:
utilities.disable_cls()
from resources.gui import gui_main
gui_main.wx_python_gui(self.constants).main_menu(None)
else:
self.main_menu()
gui_main.wx_python_gui(self.constants).main_menu(None)
def generate_base_data(self):
def _generate_base_data(self):
"""
Generate base data required for the patcher to run
"""
# Generate OS data
os_data = os_probe.OSProbe()
self.constants.detected_os = os_data.detect_kernel_major()
self.constants.detected_os_minor = os_data.detect_kernel_minor()
self.constants.detected_os_build = os_data.detect_os_build()
self.constants.detected_os_version = os_data.detect_os_version()
# Generate computer data
self.constants.computer = device_probe.Computer.probe()
self.constants.recovery_status = utilities.check_recovery()
self.computer = self.constants.computer
self.constants.booted_oc_disk = utilities.find_disk_off_uuid(utilities.clean_device_path(self.computer.opencore_path))
if self.constants.computer.firmware_vendor:
if self.constants.computer.firmware_vendor != "Apple":
self.constants.host_is_hackintosh = True
# Generate environment data
self.constants.recovery_status = utilities.check_recovery()
utilities.disable_cls()
# Generate binary data
launcher_script = None
launcher_binary = sys.executable
if "python" in launcher_binary:
@@ -65,83 +74,40 @@ class OpenCoreLegacyPatcher:
launcher_script = launcher_script.replace("/resources/main.py", "/OpenCore-Patcher-GUI.command")
self.constants.launcher_binary = launcher_binary
self.constants.launcher_script = launcher_script
# Initialize working directory
self.constants.unpack_thread = threading.Thread(target=reroute_payloads.reroute_payloads(self.constants).setup_tmp_disk_image)
self.constants.unpack_thread.start()
self.constants.commit_info = commit_info.commit_info(self.constants.launcher_binary).generate_commit_info()
# Now that we have commit info, update nightly link
# Generate commit info
self.constants.commit_info = commit_info.commit_info(self.constants.launcher_binary).generate_commit_info()
if self.constants.commit_info[0] not in ["Running from source", "Built from source"]:
# Now that we have commit info, update nightly link
branch = self.constants.commit_info[0]
branch = branch.replace("refs/heads/", "")
self.constants.installer_pkg_url_nightly = self.constants.installer_pkg_url_nightly.replace("main", branch)
# Generate defaults
defaults.generate_defaults(self.computer.real_model, True, self.constants)
if utilities.check_cli_args() is not None:
logging.info("- Detected arguments, switching to CLI mode")
self.constants.gui_mode = True # Assumes no user interaction is required
ignore_args = ["--auto_patch", "--gui_patch", "--gui_unpatch"]
if not any(x in sys.argv for x in ignore_args):
self.constants.current_path = Path.cwd()
self.constants.cli_mode = True
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
logging.info("- Rerouting payloads location")
self.constants.payload_path = sys._MEIPASS / Path("payloads")
ignore_args = ignore_args.pop(0)
if not any(x in sys.argv for x in ignore_args):
while self.constants.unpack_thread.is_alive():
time.sleep(0.1)
arguments.arguments().parse_arguments(self.constants)
else:
if utilities.check_cli_args() is None:
logging.info(f"- No arguments present, loading {'GUI' if self.constants.wxpython_variant is True else 'TUI'} mode")
return
logging.info("- Detected arguments, switching to CLI mode")
self.constants.gui_mode = True # Assumes no user interaction is required
def main_menu(self):
response = None
while not (response and response == -1):
title = [
f"OpenCore Legacy Patcher v{self.constants.patcher_version}",
f"Selected Model: {self.constants.custom_model or self.computer.real_model}",
]
ignore_args = ["--auto_patch", "--gui_patch", "--gui_unpatch"]
if not any(x in sys.argv for x in ignore_args):
self.constants.current_path = Path.cwd()
self.constants.cli_mode = True
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
logging.info("- Rerouting payloads location")
self.constants.payload_path = sys._MEIPASS / Path("payloads")
ignore_args = ignore_args.pop(0)
if (self.constants.custom_model or self.computer.real_model) not in model_array.SupportedSMBIOS and self.constants.allow_oc_everywhere is False:
in_between = [
"Your model is not supported by this patcher for running unsupported OSes!",
"",
'If you plan to create the USB for another machine, please select the \n"Change Model" option in the menu.',
"",
'If you want to run OCLP on a native Mac, please toggle \n"Allow OpenCore on native Models" in settings',
]
elif not self.constants.custom_model and self.computer.real_model == "iMac7,1" and "SSE4.1" not in self.computer.cpu.flags:
in_between = [
"Your model requires a CPU upgrade to a CPU supporting SSE4.1+ to be supported by this patcher!",
"",
f'If you plan to create the USB for another {self.computer.real_model} with SSE4.1+, please select the "Change Model" option in the menu.',
]
elif self.constants.custom_model == "iMac7,1":
in_between = ["This model is supported", "However please ensure the CPU has been upgraded to support SSE4.1+"]
else:
in_between = ["This model is supported"]
if not any(x in sys.argv for x in ignore_args):
while self.constants.unpack_thread.is_alive():
time.sleep(0.1)
menu = tui_helpers.TUIMenu(title, "Please select an option: ", in_between=in_between, auto_number=True, top_level=True)
options = (
[["Build OpenCore", build.build_opencore(self.constants.custom_model or self.constants.computer.real_model, self.constants).build_opencore]]
if ((self.constants.custom_model or self.computer.real_model) in model_array.SupportedSMBIOS) or self.constants.allow_oc_everywhere is True
else []
) + [
["Install OpenCore to USB/internal drive", install.tui_disk_installation(self.constants).copy_efi],
["Post-Install Volume Patch", cli_menu.MenuOptions(self.constants.custom_model or self.computer.real_model, self.constants).PatchVolume],
["Change Model", cli_menu.MenuOptions(self.constants.custom_model or self.computer.real_model, self.constants).change_model],
["Patcher Settings", cli_menu.MenuOptions(self.constants.custom_model or self.computer.real_model, self.constants).patcher_settings],
["Installer Creation", cli_menu.MenuOptions(self.constants.custom_model or self.computer.real_model, self.constants).download_macOS],
["Credits", cli_menu.MenuOptions(self.constants.custom_model or self.computer.real_model, self.constants).credits],
]
for option in options:
menu.add_menu_option(option[0], function=option[1])
response = menu.start()
if getattr(sys, "frozen", False) and self.constants.recovery_status is False:
subprocess.run("""osascript -e 'tell application "Terminal" to close first window' & exit""", shell=True)
arguments.arguments(self.constants)

View File

@@ -1,78 +0,0 @@
# Copyright (C) 2020-2022, Dhinak G, Mykola Grymalyuk
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)