from Scripts.datasets import os_data
from Scripts.datasets import pci_data
from Scripts.custom_dialogs import show_confirmation, show_info, show_options_dialog
from Scripts import utils
class HardwareCustomizer:
def __init__(self, utils_instance=None):
self.utils = utils_instance if utils_instance else utils.Utils()
def show_macos_compatibility(self, device_compatibility):
if not device_compatibility:
return "Unchecked"
if not device_compatibility[0]:
return "Unsupported"
max_compatibility = self.utils.parse_darwin_version(device_compatibility[0])[0]
min_compatibility = self.utils.parse_darwin_version(device_compatibility[-1])[0]
max_version = self.utils.parse_darwin_version(os_data.get_latest_darwin_version())[0]
min_version = self.utils.parse_darwin_version(os_data.get_lowest_darwin_version())[0]
if max_compatibility == min_version:
return "Maximum support up to {}".format(
os_data.get_macos_name_by_darwin(device_compatibility[-1])
)
if min_version < min_compatibility or max_compatibility < max_version:
return "{} to {}".format(
os_data.get_macos_name_by_darwin(device_compatibility[-1]),
os_data.get_macos_name_by_darwin(device_compatibility[0])
)
return "Up to {}".format(
os_data.get_macos_name_by_darwin(device_compatibility[0])
)
def hardware_customization(self, hardware_report, macos_version):
self.hardware_report = hardware_report
self.macos_version = macos_version
self.customized_hardware = {}
self.disabled_devices = {}
self.selected_devices = {}
needs_oclp = False
self.utils.log_message("[HARDWARE CUSTOMIZATION] Starting hardware customization", level="INFO")
for device_type, devices in self.hardware_report.items():
if not device_type in ("BIOS", "GPU", "Sound", "Biometric", "Network", "Storage Controllers", "Bluetooth", "SD Controller"):
self.customized_hardware[device_type] = devices
continue
self.customized_hardware[device_type] = {}
if device_type == "BIOS":
self.customized_hardware[device_type] = devices.copy()
if devices.get("Firmware Type") != "UEFI":
content = (
"Would you like to build the EFI for UEFI?
"
"If yes, please make sure to update your BIOS and enable UEFI Boot Mode in your BIOS settings.
"
"You can still proceed with Legacy if you prefer."
)
if show_confirmation("BIOS Firmware Type is not UEFI", content):
self.utils.log_message("[HARDWARE CUSTOMIZATION] BIOS Firmware Type is not UEFI, building EFI for UEFI", level="INFO")
self.customized_hardware[device_type]["Firmware Type"] = "UEFI"
else:
self.utils.log_message("[HARDWARE CUSTOMIZATION] BIOS Firmware Type is not UEFI, building EFI for Legacy", level="INFO")
self.customized_hardware[device_type]["Firmware Type"] = "Legacy"
continue
for device_name in devices:
device_props = devices[device_name].copy()
if device_props.get("OCLP Compatibility") and self.utils.parse_darwin_version(device_props.get("OCLP Compatibility")[0]) >= self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version(device_props.get("OCLP Compatibility")[-1]):
self.customized_hardware[device_type][device_name] = device_props
needs_oclp = True
continue
device_compatibility = device_props.get("Compatibility", (os_data.get_latest_darwin_version(), os_data.get_lowest_darwin_version()))
try:
if self.utils.parse_darwin_version(device_compatibility[0]) >= self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version(device_compatibility[-1]):
self.customized_hardware[device_type][device_name] = device_props
except:
self.disabled_devices["{}: {}{}".format(device_props["Device Type"] if not "Unknown" in device_props.get("Device Type", "Unknown") else device_type, device_name, "" if not device_props.get("Audio Endpoints") else " ({})".format(", ".join(device_props.get("Audio Endpoints"))))] = device_props
if self.customized_hardware[device_type].get(device_name) and self.customized_hardware[device_type][device_name].get("OCLP Compatibility"):
del self.customized_hardware[device_type][device_name]["OCLP Compatibility"]
if not self.customized_hardware[device_type]:
del self.customized_hardware[device_type]
else:
if device_type in ("GPU", "Network", "Bluetooth"):
self._handle_device_selection(device_type if device_type != "Network" else "WiFi")
if self.selected_devices:
content = "The following devices have been selected for your configuration:
"
content += "
| Category | " content += "Device Name | " content += "Device ID | " content += "
| {} | ".format(device_type) content += "{} | ".format(device_name) content += "{} | ".format(device_id) content += "
Note: Unselected devices in these categories have been disabled.
" show_info("Hardware Configuration Summary", content) return self.customized_hardware, self.disabled_devices, needs_oclp def _get_device_combinations(self, device_indices): devices = sorted(list(device_indices)) n = len(devices) all_combinations = [] if n == 0: return [] for i in range(1, 1 << n): current_combination = [] for j in range(n): if (i >> j) & 1: current_combination.append(devices[j]) if 1 <= len(current_combination) <= n: all_combinations.append(current_combination) all_combinations.sort(key=lambda combo: (len(combo), combo)) return all_combinations def _handle_device_selection(self, device_type): devices = self._get_compatible_devices(device_type) device_groups = None title = "Multiple {} Devices Detected".format(device_type) content = [] if len(devices) > 1: if device_type == "WiFi" or device_type == "Bluetooth": content.append("macOS works best with only one {} device enabled.