Add error handling for failed downloads

This commit is contained in:
Mykola Grymalyuk
2021-12-25 19:24:52 -07:00
parent 6d917fbc29
commit a2500e50c2
5 changed files with 84 additions and 60 deletions

View File

@@ -1165,11 +1165,14 @@ B. Exit
self.download_macOS()
def download_install_assistant(self, link):
installer.download_install_assistant(self.constants.payload_path, link)
installer.install_macOS_installer(self.constants.payload_path)
input("Press any key to continue...")
# To avoid selecting the wrong installer by mistake, let user select the correct one
self.find_local_installer()
if installer.download_install_assistant(self.constants.payload_path, link):
installer.install_macOS_installer(self.constants.payload_path)
input("Press any key to continue...")
# To avoid selecting the wrong installer by mistake, let user select the correct one
self.find_local_installer()
else:
print("Failed to start download")
input("Press any key to continue...")
def download_macOS_installer(self):

View File

@@ -54,7 +54,9 @@ def create_installer(installer_path, volume_name):
def download_install_assistant(download_path, ia_link):
# Downloads InstallAssistant.pkg
utilities.download_file(ia_link, (Path(download_path) / Path("InstallAssistant.pkg")))
if utilities.download_file(ia_link, (Path(download_path) / Path("InstallAssistant.pkg"))):
return True
return False
def install_macOS_installer(download_path):
args = [
@@ -85,41 +87,41 @@ def list_downloadable_macOS_installers(download_path, catalog):
link = "https://swscan.apple.com/content/catalogs/others/index-12customerseed-12-10.16-10.15-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog.gz"
# Download and unzip the catalog
utilities.download_file(link, (Path(download_path) / Path("seed.sucatalog.gz")))
subprocess.run(["gunzip", "-d", "-f", Path(download_path) / Path("seed.sucatalog.gz")])
catalog_plist = plistlib.load((Path(download_path) / Path("seed.sucatalog")).open("rb"))
if utilities.download_file(link, (Path(download_path) / Path("seed.sucatalog.gz"))):
subprocess.run(["gunzip", "-d", "-f", Path(download_path) / Path("seed.sucatalog.gz")])
catalog_plist = plistlib.load((Path(download_path) / Path("seed.sucatalog")).open("rb"))
for item in catalog_plist["Products"]:
try:
# Check if entry has SharedSupport and BuildManifest
# Ensures only Big Sur and newer Installers are listed
catalog_plist["Products"][item]["ExtendedMetaInfo"]["InstallAssistantPackageIdentifiers"]["SharedSupport"]
catalog_plist["Products"][item]["ExtendedMetaInfo"]["InstallAssistantPackageIdentifiers"]["BuildManifest"]
for item in catalog_plist["Products"]:
try:
# Check if entry has SharedSupport and BuildManifest
# Ensures only Big Sur and newer Installers are listed
catalog_plist["Products"][item]["ExtendedMetaInfo"]["InstallAssistantPackageIdentifiers"]["SharedSupport"]
catalog_plist["Products"][item]["ExtendedMetaInfo"]["InstallAssistantPackageIdentifiers"]["BuildManifest"]
for bm_package in catalog_plist["Products"][item]["Packages"]:
if "BuildManifest.plist" in bm_package["URL"]:
utilities.download_file(bm_package["URL"], (Path(download_path) / Path("BuildManifest.plist")))
build_plist = plistlib.load((Path(download_path) / Path("BuildManifest.plist")).open("rb"))
version = build_plist["ProductVersion"]
build = build_plist["ProductBuildVersion"]
for ia_package in catalog_plist["Products"][item]["Packages"]:
if "InstallAssistant.pkg" in ia_package["URL"]:
download_link = ia_package["URL"]
size = ia_package["Size"]
integrity = ia_package["IntegrityDataURL"]
for bm_package in catalog_plist["Products"][item]["Packages"]:
if "BuildManifest.plist" in bm_package["URL"]:
utilities.download_file(bm_package["URL"], (Path(download_path) / Path("BuildManifest.plist")))
build_plist = plistlib.load((Path(download_path) / Path("BuildManifest.plist")).open("rb"))
version = build_plist["ProductVersion"]
build = build_plist["ProductBuildVersion"]
for ia_package in catalog_plist["Products"][item]["Packages"]:
if "InstallAssistant.pkg" in ia_package["URL"]:
download_link = ia_package["URL"]
size = ia_package["Size"]
integrity = ia_package["IntegrityDataURL"]
avalible_apps.update({
item: {
"Version": version,
"Build": build,
"Link": download_link,
"Size": size,
"integrity": integrity,
"Source": "Apple Inc.",
}
})
except KeyError:
pass
avalible_apps.update({
item: {
"Version": version,
"Build": build,
"Link": download_link,
"Size": size,
"integrity": integrity,
"Source": "Apple Inc.",
}
})
except KeyError:
pass
return avalible_apps
def format_drive(disk_id):

View File

@@ -373,7 +373,7 @@ def download_file(link, location, is_gui=None):
print(f"https://github.com/dortania/OpenCore-Legacy-Patcher/releases/download/{constants.Constants().patcher_version}/OpenCore-Patcher-TUI-Offline.app.zip")
else:
print(link)
sys.exit()
return None
def elevated(*args, **kwargs) -> subprocess.CompletedProcess:
# When runnign through our GUI, we run as root, however we do not get uid 0