diff --git a/SuperGrate/Classes/Download.cs b/SuperGrate/Classes/Download.cs index 0de98f4..6d8f936 100644 --- a/SuperGrate/Classes/Download.cs +++ b/SuperGrate/Classes/Download.cs @@ -1,5 +1,6 @@ using System; using System.Net; +using System.ComponentModel; using System.Threading.Tasks; namespace SuperGrate @@ -9,7 +10,7 @@ class Download private WebClient Client = new WebClient(); private string URL; private string DESTINATION; - private bool Downloaded = false; + private AsyncCompletedEventArgs Done = null; public Download(string Url, string Destination) { URL = Url; @@ -17,19 +18,28 @@ public Download(string Url, string Destination) Client.DownloadProgressChanged += Client_DownloadProgressChanged; Client.DownloadFileCompleted += Client_DownloadFileCompleted; } - private void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) + private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { - Downloaded = true; + Done = e; } private void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { Logger.UpdateProgress(e.ProgressPercentage); } - public Task Start() + public Task Start() { Client.DownloadFileAsync(new Uri(URL), DESTINATION); return Task.Run(async () => { - while (!Downloaded) { await Task.Delay(100); } + while (Done == null) { await Task.Delay(100); } + if(Done.Error == null) + { + return true; + } + else + { + Logger.Exception(Done.Error, "Error downloading: " + URL + "."); + return false; + } }); } } diff --git a/SuperGrate/Classes/USMT.cs b/SuperGrate/Classes/USMT.cs index 3679a0e..c865c68 100644 --- a/SuperGrate/Classes/USMT.cs +++ b/SuperGrate/Classes/USMT.cs @@ -251,6 +251,7 @@ private static Task DownloadUSMTFromWeb() return Task.Run(async () => { try { + bool success = true; Logger.Information("Downloading USMT (" + DetectedArch + ") from the web..."); if (!Directory.Exists(USMTPath)) { @@ -259,15 +260,17 @@ private static Task DownloadUSMTFromWeb() string dlPath = Path.Combine(USMTPath, "USMT.zip"); if (DetectedArch == "64-bit") { - await new Download("https://github.com/belowaverage-org/SuperGrate/raw/master/USMT/x64.zip", dlPath).Start(); + success = await new Download("https://github.com/belowaverage-org/SuperGrate/raw/master/USMT/x64.zip", dlPath).Start(); + if (!success) throw new Exception("Download failure."); } else if (DetectedArch == "32-bit") { - await new Download("https://github.com/belowaverage-org/SuperGrate/raw/master/USMT/x86.zip", dlPath).Start(); + success = await new Download("https://github.com/belowaverage-org/SuperGrate/raw/master/USMT/x86.zip", dlPath).Start(); + if (!success) throw new Exception("Download failure."); } else { - return false; + throw new Exception("Could not determine target architecture."); } Logger.Information("Decompressing USMT..."); ZipFile.ExtractToDirectory(dlPath, USMTPath); @@ -277,6 +280,8 @@ private static Task DownloadUSMTFromWeb() } catch(Exception e) { + Logger.Warning("Removing USMT folder due to failure..."); + Directory.Delete(USMTPath, true); Logger.Exception(e, "Failed to automatically download USMT from the web. Please download USMT and update the SuperGrate.xml accordingly."); return false; }