Skip to content

Commit e2a2262

Browse files
committed
Improve KDK & Metallib download
1 parent 8ba19fc commit e2a2262

File tree

14 files changed

+139
-64
lines changed

14 files changed

+139
-64
lines changed

oclp_r/constants.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
import getpass
1313
class Constants:
1414
def __init__(self) -> None:
15+
#API Link
16+
self.kdk_api_link: str = ""
17+
self.metallib_api_link: str = ""
18+
1519
# Patcher Versioning
1620
self.patcher_version: str = "3.0.0" # OCLP-R
1721
self.patcher_support_pkg_version: str = "1.10.1-pre" # PatcherSupportPkg
@@ -29,7 +33,7 @@ def __init__(self) -> None:
2933
self.user_download_file: str = f"/Users/{getpass.getuser()}/Downloads"
3034
# OpenCore Versioning
3135
# https://github.com/acidanthera/OpenCorePkg
32-
self.opencore_version: str = "1.0.5"
36+
self.opencore_version: str = "1.0.6"
3337

3438
# Kext Versioning
3539
## Acidanthera
@@ -264,7 +268,15 @@ def __init__(self) -> None:
264268
self.github_mirror: str = ""
265269
# Open Intel Wireless
266270
self.intel_wireless_tahoe: bool = False
271+
self.api_link()
267272

273+
def api_link(self):
274+
if self.github_proxy_link!="SimpleHac":
275+
self.kdk_api_link="https://dortania.github.io/KdkSupportPkg/manifest.json"
276+
self.metallib_api_link="https://dortania.github.io/MetallibSupportPkg/manifest.json"
277+
if self.github_proxy_link=="SimpleHac":
278+
self.kdk_api_link="https://next.oclpapi.simplehac.cn/KdkSupportPkg/manifest.json"
279+
self.metallib_api_link="https://next.oclpapi.simplehac.cn/MetallibSupportPkg/manifest.json"
268280
@property
269281
def special_build(self):
270282
"""
@@ -800,30 +812,58 @@ def icon_path_ssd(self):
800812
def icon_path_macos_generic(self):
801813
return self.icns_resource_path / Path("Generic.icns")
802814

815+
@property
816+
def package_icns_path_generic(self):
817+
return self.icns_resource_path / Path("Package.icns")
818+
803819
@property
804820
def icon_path_macos_big_sur(self):
805821
return self.icns_resource_path / Path("BigSur.icns")
806822

823+
@property
824+
def package_icns_path_big_sur(self):
825+
return self.icns_resource_path / Path("Package11.icns")
826+
807827
@property
808828
def icon_path_macos_monterey(self):
809829
return self.icns_resource_path / Path("Monterey.icns")
810830

831+
@property
832+
def package_icns_path_monterey(self):
833+
return self.icns_resource_path / Path("Package12.icns")
834+
811835
@property
812836
def icon_path_macos_ventura(self):
813837
return self.icns_resource_path / Path("Ventura.icns")
814838

839+
@property
840+
def package_icns_path_ventura(self):
841+
return self.icns_resource_path / Path("Package13.icns")
842+
815843
@property
816844
def icon_path_macos_sonoma(self):
817845
return self.icns_resource_path / Path("Sonoma.icns")
818846

847+
@property
848+
def package_icns_path_sonoma(self):
849+
return self.icns_resource_path / Path("Package14.icns")
850+
819851
@property
820852
def icon_path_macos_sequoia(self):
821853
return self.icns_resource_path / Path("Sequoia.icns")
822854

855+
@property
856+
def package_icns_path_sequoia(self):
857+
return self.icns_resource_path / Path("Package15.icns")
858+
823859
@property
824860
def icon_path_macos_tahoe(self):
825861
return self.icns_resource_path / Path("Tahoe.icns")
826862

863+
@property
864+
def package_icns_path_tahoe(self):
865+
return self.icns_resource_path / Path("Package26.icns")
866+
827867
@property
828868
def gui_path(self):
829869
return self.payload_path / Path("Icon/Resources.zip")
@@ -861,6 +901,18 @@ def icons_path(self):
861901
str(self.icon_path_macos_tahoe),
862902
]
863903

904+
@property
905+
def package_icns_paths(self):
906+
return [
907+
str(self.package_icns_path_generic),
908+
str(self.package_icns_path_big_sur),
909+
str(self.package_icns_path_monterey),
910+
str(self.package_icns_path_ventura),
911+
str(self.package_icns_path_sonoma),
912+
str(self.package_icns_path_sequoia),
913+
str(self.package_icns_path_tahoe),
914+
]
915+
864916
sbm_values = [
865917
"j137ap", # iMacPro1,1
866918
"j680ap", # MacBookPro15,1

oclp_r/support/kdk_handler.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
network_handler,
2222
subprocess_wrapper
2323
)
24-
24+
from ..constants import Constants
2525
KDK_INSTALL_PATH: str = "/Library/Developer/KDKs"
2626
KDK_INFO_PLIST: str = "KDKInfo.plist"
27-
KDK_API_LINK_ORG: str = "https://dortania.github.io/KdkSupportPkg/manifest.json"
28-
KDK_API_LINK_PROXY:str = "https://next.oclpapi.simplehac.cn/KdkSupportPkg/manifest.json"
27+
28+
29+
2930
KDK_ASSET_LIST: list = None
3031

3132
class KernelDebugKitObject:
@@ -59,7 +60,7 @@ def __init__(self, global_constants: constants.Constants,
5960
) -> None:
6061

6162
self.constants: constants.Constants = global_constants
62-
63+
self.KDK_API_LINK_ORG: str = self.constants.kdk_api_link
6364
self.host_build: str = host_build # ex. 20A5384c
6465
self.host_version: str = host_version # ex. 11.0.1
6566

@@ -108,10 +109,7 @@ def _get_remote_kdks(self) -> list:
108109
return KDK_ASSET_LIST
109110

110111
try:
111-
if self.constants.github_proxy_link!="SimpleHac":
112-
KDK_API_LINK=KDK_API_LINK_ORG
113-
else:
114-
KDK_API_LINK=KDK_API_LINK_PROXY
112+
KDK_API_LINK=self.KDK_API_LINK_ORG
115113
results = network_handler.NetworkUtilities().get(
116114
KDK_API_LINK,
117115
headers={
@@ -270,6 +268,11 @@ def _get_latest_kdk(self, host_build: str = None, host_version: str = None) -> N
270268
self.success = True
271269

272270
def convert_size(self, size_str):
271+
if isinstance(size_str, float):
272+
return float(size_str)
273+
if isinstance(size_str, int):
274+
return float(size_str)
275+
273276
units = {'KB': 1024, 'MB': 1024**2, 'GB': 1024**3, 'TB': 1024**4}
274277
for unit, factor in units.items():
275278
if unit in size_str:

oclp_r/support/metallib_handler.py

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818

1919
METALLIB_INSTALL_PATH: str = "/Library/Application Support/Hackdoc/MetallibSupportPkg"
20-
METALLIB_API_LINK_ORG: str = "https://dortania.github.io/MetallibSupportPkg/manifest.json"
21-
METALLIB_API_LINK_PROXY:str ="https://next.oclpapi.simplehac.cn/MetallibSupportPkg/manifest.json"
20+
21+
2222
METALLIB_ASSET_LIST: list = None
2323

2424

@@ -30,7 +30,7 @@ def __init__(self, global_constants: constants.Constants,
3030
) -> None:
3131

3232
self.constants: constants.Constants = global_constants
33-
33+
self.METALLIB_API_LINK_ORG: str = self.constants.metallib_api_link
3434
self.host_build: str = host_build # ex. 20A5384c
3535
self.host_version: str = host_version # ex. 11.0.1
3636

@@ -70,10 +70,7 @@ def _get_remote_metallibs(self) -> dict:
7070
return METALLIB_ASSET_LIST
7171

7272
try:
73-
if self.constants.github_proxy_link=="SimpleHac":
74-
METALLIB_API_LINK=METALLIB_API_LINK_PROXY
75-
else:
76-
METALLIB_API_LINK=METALLIB_API_LINK_ORG
73+
METALLIB_API_LINK=self.METALLIB_API_LINK_ORG
7774
results = network_handler.NetworkUtilities().get(
7875
METALLIB_API_LINK,
7976
headers={
@@ -93,6 +90,17 @@ def _get_remote_metallibs(self) -> dict:
9390

9491
return METALLIB_ASSET_LIST
9592

93+
def _get_file_size(self, url: str) -> int:
94+
try:
95+
response = requests.head(url, verify=False, allow_redirects=True, timeout=10)
96+
if response.status_code == 200:
97+
content_length = response.headers.get('content-length')
98+
if content_length:
99+
return int(content_length)
100+
except Exception as e:
101+
logging.warning(f"Cannot get file size {url}: {e}")
102+
103+
return 0
96104

97105
def _get_latest_metallib(self) -> None:
98106
"""
@@ -158,6 +166,7 @@ def _get_latest_metallib(self) -> None:
158166
self.metallib_url = metallib["url"]
159167
self.metallib_url_build = metallib["build"]
160168
self.metallib_url_version = metallib["version"]
169+
self.metallib_file_size = self._get_file_size(self.metallib_url)
161170
self.metallib_url_is_exactly_match = True
162171
break
163172

@@ -176,6 +185,7 @@ def _get_latest_metallib(self) -> None:
176185
self.metallib_closest_match_url = metallib["url"]
177186
self.metallib_closest_match_url_build = metallib["build"]
178187
self.metallib_closest_match_url_version = metallib["version"]
188+
self.metallib_closest_match_file_size = self._get_file_size(self.metallib_closest_match_url)
179189
self.metallib_url_is_exactly_match = False
180190
break
181191

@@ -190,6 +200,8 @@ def _get_latest_metallib(self) -> None:
190200
self.metallib_url = self.metallib_closest_match_url
191201
self.metallib_url_build = self.metallib_closest_match_url_build
192202
self.metallib_url_version = self.metallib_closest_match_url_version
203+
self.metallib_file_size = self.metallib_closest_match_file_size
204+
193205
else:
194206
logging.info(f"Direct match found for {self.host_build} ({self.host_version})")
195207

@@ -206,10 +218,23 @@ def _get_latest_metallib(self) -> None:
206218
logging.info(f"- metallib Build: {self.metallib_url_build}")
207219
logging.info(f"- metallib Version: {self.metallib_url_version}")
208220
logging.info(f"- metallib URL: {self.metallib_url}")
221+
logging.info(f"- metallib size: {self._format_file_size(self.metallib_file_size)}")
209222

210223
self.success = True
211224

212-
225+
def _format_file_size(self, size_bytes: int) -> str:
226+
"""
227+
Format file size for display
228+
"""
229+
if size_bytes == 0:
230+
return "/"
231+
size_names = ["B", "KB", "MB", "GB"]
232+
i = 0
233+
size = float(size_bytes)
234+
while size >= 1024 and i < len(size_names) - 1:
235+
size /= 1024.0
236+
i += 1
237+
return f"{size:.2f} {size_names[i]}"
213238
def _local_metallib_installed(self, match: str = None, check_version: bool = False) -> str:
214239
"""
215240
Check if a metallib is already installed
@@ -258,7 +283,7 @@ def retrieve_download(self, override_path: str = "") -> network_handler.Download
258283
self.success = True
259284

260285
metallib_download_path = self.constants.metallib_download_path if override_path == "" else Path(override_path)
261-
return network_handler.DownloadObject(self.metallib_url, metallib_download_path)
286+
return network_handler.DownloadObject(self.metallib_url, metallib_download_path, self.metallib_file_size)
262287

263288

264289
def install_metallib(self, metallib: str = None) -> None:

oclp_r/wx_gui/gui_kdk_dl.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@
1717
utilities,
1818
network_handler,
1919
)
20-
KDK_API_LINK_ORIGIN:str = "https://dortania.github.io/KdkSupportPkg/manifest.json"
21-
KDK_API_LINK_PROXY:str = "https://next.oclpapi.simplehac.cn/KdkSupportPkg/manifest.json"
2220
class KDKDownloadFrame(wx.Frame):
2321
def __init__(self, parent: wx.Frame, title: str, global_constants: constants.Constants,screen_location: tuple = None):
2422
logging.info("Initializing KDK Download Frame")
2523
self.constants: constants.Constants = global_constants
2624
self.title: str = title
2725
self.parent: wx.Frame = parent
28-
icon_path = str(self.constants.icns_resource_path / "Package.icns")
29-
self.icons = [self._icon_to_bitmap(icon_path), self._icon_to_bitmap(icon_path, (64, 64))]
26+
27+
self.icons = [[self._icon_to_bitmap(icon_path), self._icon_to_bitmap(icon_path, (64, 64))] for icon_path in self.constants.package_icns_paths]
3028
self.repl=False
3129
self.path_validate=None
3230
self.retry_download:bool=False
@@ -42,8 +40,20 @@ def __init__(self, parent: wx.Frame, title: str, global_constants: constants.Con
4240
self.catalog_seed: sucatalog.SeedType = sucatalog.SeedType.DeveloperSeed
4341
self.frame_modal = wx.Dialog(parent, title=title, size=(330, 200))
4442
self.on_download()
43+
4544
def _icon_to_bitmap(self, icon: str, size: tuple = (32, 32)) -> wx.Bitmap:
4645
return wx.Bitmap(wx.Bitmap(icon, wx.BITMAP_TYPE_ICON).ConvertToImage().Rescale(size[0], size[1], wx.IMAGE_QUALITY_HIGH))
46+
47+
def _macos_version_to_icon(self, version: int) -> int:
48+
"""
49+
Convert macOS version to icon(Package)
50+
"""
51+
try:
52+
self.constants.package_icns_paths[version-19]
53+
return version - 19
54+
except IndexError:
55+
return 0
56+
4757
def _generate_catalog_frame(self) -> None:
4858
super(KDKDownloadFrame, self).__init__(None, title=self.title, size=(300, 200), style=wx.DEFAULT_FRAME_STYLE & ~(wx.RESIZE_BORDER | wx.MAXIMIZE_BOX))
4959
gui_support.GenerateMenubar(self, self.constants).generate()
@@ -59,10 +69,7 @@ def _generate_catalog_frame(self) -> None:
5969
self.Show()
6070
def _fetch_installers():
6171
try:
62-
if self.constants.github_proxy_link=="SimpleHac":
63-
KDK_API_LINK:str=KDK_API_LINK_PROXY
64-
else:
65-
KDK_API_LINK: str = KDK_API_LINK_ORIGIN
72+
KDK_API_LINK=self.constants.kdk_api_link
6673
response = requests.get(KDK_API_LINK,verify=False)
6774
self.kdk_data = response.json()
6875
self.kdk_data_latest = []
@@ -127,12 +134,14 @@ def _fetch_installers():
127134
self.on_return_to_main_menu()
128135
else:
129136
self._display_available_installers()
137+
130138
def convert_size(self,size_bytes):
131139
for unit in ['B', 'KB', 'MB', 'GB']:
132140
if size_bytes < 1024.0:
133141
return f"{size_bytes:.2f} {unit}"
134142
size_bytes /= 1024.0
135143
return f"{size_bytes:.2f} TB"
144+
136145
def detect_os_build(self, rsr: bool = False) -> str:
137146
import plistlib
138147
file_path = "/System/Library/CoreServices/SystemVersion.plist"
@@ -142,13 +151,14 @@ def detect_os_build(self, rsr: bool = False) -> str:
142151
return plistlib.load(open(file_path, "rb"))["ProductBuildVersion"]
143152
except Exception as e:
144153
raise RuntimeError(f"Failed to detect OS build: {e}")
154+
145155
def _display_available_installers(self, event: wx.Event = None, show_full: bool = False) -> None:
146156
if show_full:
147157
self.show_fully=True
148158
else:
149159
self.show_fully=False
150160
self.os_build_tahoe=self.detect_os_build(False)
151-
bundles = [wx.BitmapBundle.FromBitmaps(self.icons)]
161+
bundles = [wx.BitmapBundle.FromBitmaps(icon) for icon in self.icons]
152162
self.frame_modal.Destroy()
153163
self.frame_modal = wx.Dialog(self, title="Choose KDK Version", size=(500, 580))
154164
title_label = wx.StaticText(self.frame_modal, label="Choose KDKs", pos=(-1,-1))
@@ -178,7 +188,7 @@ def _display_available_installers(self, event: wx.Event = None, show_full: bool
178188
logging.info(f"- {item['name']} (macOS {item['version']} - {item['build']}):\n - Size: {self.convert_size(item['fileSize'])}\n - Link: {item['url']}\n")
179189
version = re.search(r'^\d+', item['version'])
180190
index = self.list.InsertItem(self.list.GetItemCount(), f"macOS {xnu_name[version.group()]}")
181-
self.list.SetItemImage(index, 0)
191+
self.list.SetItemImage(index, self._macos_version_to_icon(int(item['build'][:2])))
182192
self.list.SetItem(index, 1, f"{item['version']}")
183193
self.list.SetItem(index, 2, f"{item['build']}")
184194
self.list.SetItem(index, 3, f"{self.convert_size(item['fileSize'])}")
@@ -280,7 +290,7 @@ def is_dir_writable(dirpath):
280290
global_constants=self.constants,
281291
download_obj=download_obj,
282292
item_name=f"KDK {selected_installer['version']} {selected_installer['build']}",
283-
download_icon=str(self.constants.icns_resource_path / "Package.icns")
293+
download_icon=self.constants.package_icns_paths[self._macos_version_to_icon(int(selected_installer['build'][:2]))]
284294
)
285295
if download_obj.download_complete is False:
286296
import os

oclp_r/wx_gui/gui_macos_installer_download.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,11 @@ def _macos_version_to_icon(self, version: int) -> int:
7373
Convert macOS version to icon
7474
"""
7575
try:
76-
self.constants.icons_path[version - 19]
76+
self.constants.icons_path[version-19]
7777
return version - 19
7878
except IndexError:
7979
return 0
80-
81-
80+
8281
def _generate_elements(self, frame: wx.Frame = None) -> None:
8382
"""
8483
Format:

0 commit comments

Comments
 (0)