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
+37 -21
View File
@@ -992,9 +992,22 @@ class wx_python_gui:
self.subheader.Centre(wx.HORIZONTAL) self.subheader.Centre(wx.HORIZONTAL)
i = -20 i = -20
for app in avalible_installers: if avalible_installers:
print(f"macOS {avalible_installers[app]['Version']} ({avalible_installers[app]['Build']} - {utilities.human_fmt(avalible_installers[app]['Size'])} - {avalible_installers[app]['Source']})") for app in avalible_installers:
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)) 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 i = i + 25
self.install_selection.SetPosition( self.install_selection.SetPosition(
# Set Position right above bottom of frame # 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.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) self.install_selection.Centre(wx.HORIZONTAL)
# Return to Main Menu # 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) self.frame.SetSize(-1, self.return_to_main_menu.GetPosition().y + self.return_to_main_menu.GetSize().height + 40)
# Download macOS install data # 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 # Update Label:
sys.stdout = self.stock_stdout sys.stdout=menu_redirect.RedirectLabelAll(self.download_label)
self.download_label.SetLabel(f"Finished Downloading {installer_name}") installer.install_macOS_installer(self.constants.payload_path)
self.download_label.Centre(wx.HORIZONTAL) sys.stdout = self.stock_stdout
# Update Label:
self.download_label.SetLabel(f"Finished Installing {installer_name}")
self.download_label.Centre(wx.HORIZONTAL)
# Update Label: # Set Return to Main Menu into flash_installer_menu
sys.stdout=menu_redirect.RedirectLabelAll(self.download_label) self.return_to_main_menu.SetLabel("Flash Installer")
installer.install_macOS_installer(self.constants.payload_path) self.return_to_main_menu.Bind(wx.EVT_BUTTON, self.flash_installer_menu)
sys.stdout = self.stock_stdout self.return_to_main_menu.Centre(wx.HORIZONTAL)
# Update Label: else:
self.download_label.SetLabel(f"Finished Installing {installer_name}") sys.stdout = self.stock_stdout
self.download_label.Centre(wx.HORIZONTAL) self.download_label.SetLabel(f"Failed to download {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)
def flash_installer_menu(self, event=None): def flash_installer_menu(self, event=None):
self.frame.DestroyChildren() self.frame.DestroyChildren()
+3
View File
@@ -23,6 +23,9 @@ class RedirectLabel(object):
self.out.SetLabel(string) self.out.SetLabel(string)
self.out.Centre(wx.HORIZONTAL) self.out.Centre(wx.HORIZONTAL)
wx.GetApp().Yield() wx.GetApp().Yield()
def flush(self):
pass
class RedirectLabelAll(object): class RedirectLabelAll(object):
def __init__(self,aWxTextCtrl): def __init__(self,aWxTextCtrl):
+8 -5
View File
@@ -1165,11 +1165,14 @@ B. Exit
self.download_macOS() self.download_macOS()
def download_install_assistant(self, link): def download_install_assistant(self, link):
installer.download_install_assistant(self.constants.payload_path, link) if installer.download_install_assistant(self.constants.payload_path, link):
installer.install_macOS_installer(self.constants.payload_path) installer.install_macOS_installer(self.constants.payload_path)
input("Press any key to continue...") input("Press any key to continue...")
# To avoid selecting the wrong installer by mistake, let user select the correct one # To avoid selecting the wrong installer by mistake, let user select the correct one
self.find_local_installer() self.find_local_installer()
else:
print("Failed to start download")
input("Press any key to continue...")
def download_macOS_installer(self): def download_macOS_installer(self):
+35 -33
View File
@@ -54,7 +54,9 @@ def create_installer(installer_path, volume_name):
def download_install_assistant(download_path, ia_link): def download_install_assistant(download_path, ia_link):
# Downloads InstallAssistant.pkg # 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): def install_macOS_installer(download_path):
args = [ 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" 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 # Download and unzip the catalog
utilities.download_file(link, (Path(download_path) / Path("seed.sucatalog.gz"))) if utilities.download_file(link, (Path(download_path) / Path("seed.sucatalog.gz"))):
subprocess.run(["gunzip", "-d", "-f", 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")) catalog_plist = plistlib.load((Path(download_path) / Path("seed.sucatalog")).open("rb"))
for item in catalog_plist["Products"]: for item in catalog_plist["Products"]:
try: try:
# Check if entry has SharedSupport and BuildManifest # Check if entry has SharedSupport and BuildManifest
# Ensures only Big Sur and newer Installers are listed # Ensures only Big Sur and newer Installers are listed
catalog_plist["Products"][item]["ExtendedMetaInfo"]["InstallAssistantPackageIdentifiers"]["SharedSupport"] catalog_plist["Products"][item]["ExtendedMetaInfo"]["InstallAssistantPackageIdentifiers"]["SharedSupport"]
catalog_plist["Products"][item]["ExtendedMetaInfo"]["InstallAssistantPackageIdentifiers"]["BuildManifest"] catalog_plist["Products"][item]["ExtendedMetaInfo"]["InstallAssistantPackageIdentifiers"]["BuildManifest"]
for bm_package in catalog_plist["Products"][item]["Packages"]: for bm_package in catalog_plist["Products"][item]["Packages"]:
if "BuildManifest.plist" in bm_package["URL"]: if "BuildManifest.plist" in bm_package["URL"]:
utilities.download_file(bm_package["URL"], (Path(download_path) / Path("BuildManifest.plist"))) utilities.download_file(bm_package["URL"], (Path(download_path) / Path("BuildManifest.plist")))
build_plist = plistlib.load((Path(download_path) / Path("BuildManifest.plist")).open("rb")) build_plist = plistlib.load((Path(download_path) / Path("BuildManifest.plist")).open("rb"))
version = build_plist["ProductVersion"] version = build_plist["ProductVersion"]
build = build_plist["ProductBuildVersion"] build = build_plist["ProductBuildVersion"]
for ia_package in catalog_plist["Products"][item]["Packages"]: for ia_package in catalog_plist["Products"][item]["Packages"]:
if "InstallAssistant.pkg" in ia_package["URL"]: if "InstallAssistant.pkg" in ia_package["URL"]:
download_link = ia_package["URL"] download_link = ia_package["URL"]
size = ia_package["Size"] size = ia_package["Size"]
integrity = ia_package["IntegrityDataURL"] integrity = ia_package["IntegrityDataURL"]
avalible_apps.update({ avalible_apps.update({
item: { item: {
"Version": version, "Version": version,
"Build": build, "Build": build,
"Link": download_link, "Link": download_link,
"Size": size, "Size": size,
"integrity": integrity, "integrity": integrity,
"Source": "Apple Inc.", "Source": "Apple Inc.",
} }
}) })
except KeyError: except KeyError:
pass pass
return avalible_apps return avalible_apps
def format_drive(disk_id): def format_drive(disk_id):
+1 -1
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") print(f"https://github.com/dortania/OpenCore-Legacy-Patcher/releases/download/{constants.Constants().patcher_version}/OpenCore-Patcher-TUI-Offline.app.zip")
else: else:
print(link) print(link)
sys.exit() return None
def elevated(*args, **kwargs) -> subprocess.CompletedProcess: def elevated(*args, **kwargs) -> subprocess.CompletedProcess:
# When runnign through our GUI, we run as root, however we do not get uid 0 # When runnign through our GUI, we run as root, however we do not get uid 0