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

@@ -992,9 +992,22 @@ class wx_python_gui:
self.subheader.Centre(wx.HORIZONTAL)
i = -20
for app in avalible_installers:
print(f"macOS {avalible_installers[app]['Version']} ({avalible_installers[app]['Build']} - {utilities.human_fmt(avalible_installers[app]['Size'])} - {avalible_installers[app]['Source']})")
self.install_selection = wx.Button(self.frame, label=f"macOS {avalible_installers[app]['Version']} ({avalible_installers[app]['Build']} - {utilities.human_fmt(avalible_installers[app]['Size'])})", size=(250, 30))
if avalible_installers:
for app in avalible_installers:
print(f"macOS {avalible_installers[app]['Version']} ({avalible_installers[app]['Build']} - {utilities.human_fmt(avalible_installers[app]['Size'])} - {avalible_installers[app]['Source']})")
self.install_selection = wx.Button(self.frame, label=f"macOS {avalible_installers[app]['Version']} ({avalible_installers[app]['Build']} - {utilities.human_fmt(avalible_installers[app]['Size'])})", size=(250, 30))
i = i + 25
self.install_selection.SetPosition(
# Set Position right above bottom of frame
wx.Point(
self.subheader.GetPosition().x,
self.subheader.GetPosition().y + self.subheader.GetSize().height + i
)
)
self.install_selection.Bind(wx.EVT_BUTTON, lambda event, temp=app: self.download_macos_click(f"macOS {avalible_installers[temp]['Version']} ({avalible_installers[temp]['Build']})", avalible_installers[temp]['Link']))
self.install_selection.Centre(wx.HORIZONTAL)
else:
self.install_selection = wx.StaticText(self.frame, label="No installers available")
i = i + 25
self.install_selection.SetPosition(
# Set Position right above bottom of frame
@@ -1003,7 +1016,7 @@ class wx_python_gui:
self.subheader.GetPosition().y + self.subheader.GetSize().height + i
)
)
self.install_selection.Bind(wx.EVT_BUTTON, lambda event, temp=app: self.download_macos_click(f"macOS {avalible_installers[temp]['Version']} ({avalible_installers[temp]['Build']})", avalible_installers[temp]['Link']))
self.install_selection.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
self.install_selection.Centre(wx.HORIZONTAL)
# Return to Main Menu
@@ -1058,25 +1071,28 @@ class wx_python_gui:
self.frame.SetSize(-1, self.return_to_main_menu.GetPosition().y + self.return_to_main_menu.GetSize().height + 40)
# Download macOS install data
installer.download_install_assistant(self.constants.payload_path, installer_link)
if installer.download_install_assistant(self.constants.payload_path, installer_link):
# Fix stdout
sys.stdout = self.stock_stdout
self.download_label.SetLabel(f"Finished Downloading {installer_name}")
self.download_label.Centre(wx.HORIZONTAL)
# Fix stdout
sys.stdout = self.stock_stdout
self.download_label.SetLabel(f"Finished Downloading {installer_name}")
self.download_label.Centre(wx.HORIZONTAL)
# Update Label:
sys.stdout=menu_redirect.RedirectLabelAll(self.download_label)
installer.install_macOS_installer(self.constants.payload_path)
sys.stdout = self.stock_stdout
# Update Label:
self.download_label.SetLabel(f"Finished Installing {installer_name}")
self.download_label.Centre(wx.HORIZONTAL)
# Update Label:
sys.stdout=menu_redirect.RedirectLabelAll(self.download_label)
installer.install_macOS_installer(self.constants.payload_path)
sys.stdout = self.stock_stdout
# Update Label:
self.download_label.SetLabel(f"Finished Installing {installer_name}")
self.download_label.Centre(wx.HORIZONTAL)
# Set Return to Main Menu into flash_installer_menu
self.return_to_main_menu.SetLabel("Flash Installer")
self.return_to_main_menu.Bind(wx.EVT_BUTTON, self.flash_installer_menu)
self.return_to_main_menu.Centre(wx.HORIZONTAL)
# Set Return to Main Menu into flash_installer_menu
self.return_to_main_menu.SetLabel("Flash Installer")
self.return_to_main_menu.Bind(wx.EVT_BUTTON, self.flash_installer_menu)
self.return_to_main_menu.Centre(wx.HORIZONTAL)
else:
sys.stdout = self.stock_stdout
self.download_label.SetLabel(f"Failed to download {installer_name}")
self.download_label.Centre(wx.HORIZONTAL)
def flash_installer_menu(self, event=None):
self.frame.DestroyChildren()

View File

@@ -23,6 +23,9 @@ class RedirectLabel(object):
self.out.SetLabel(string)
self.out.Centre(wx.HORIZONTAL)
wx.GetApp().Yield()
def flush(self):
pass
class RedirectLabelAll(object):
def __init__(self,aWxTextCtrl):

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