From 6fd428769a19f10732dfd02b53b68b1d37291284 Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Sun, 18 Mar 2018 19:04:47 +0000 Subject: [PATCH] Deal with threading and download errors --- Core/Net/NetAsyncModulesDownloader.cs | 4 ++ Core/Net/NetModuleCache.cs | 8 +-- GUI/MainWait.cs | 85 ++++++++++++++++++--------- 3 files changed, 64 insertions(+), 33 deletions(-) diff --git a/Core/Net/NetAsyncModulesDownloader.cs b/Core/Net/NetAsyncModulesDownloader.cs index d1b15e67b7..835f206dee 100644 --- a/Core/Net/NetAsyncModulesDownloader.cs +++ b/Core/Net/NetAsyncModulesDownloader.cs @@ -94,6 +94,10 @@ private void ModuleDownloadsComplete(NetModuleCache cache, Uri[] urls, string[] { cache.Store(modules[i], filenames[i], modules[i].StandardName()); } + catch (InvalidModuleFileKraken kraken) + { + User.RaiseError(kraken.ToString()); + } catch (FileNotFoundException e) { log.WarnFormat("cache.Store(): FileNotFoundException: {0}", e.Message); diff --git a/Core/Net/NetModuleCache.cs b/Core/Net/NetModuleCache.cs index 12c3cc3752..f24da81bdc 100644 --- a/Core/Net/NetModuleCache.cs +++ b/Core/Net/NetModuleCache.cs @@ -117,13 +117,13 @@ public string Store(CkanModule module, string path, string description = null, b // Check file size if (fi.Length != module.download_size) throw new InvalidModuleFileKraken(module, path, - $"{path} has length {fi.Length}, should be {module.download_size}"); + $"{module}: {path} has length {fi.Length}, should be {module.download_size}"); // Check valid CRC string invalidReason; if (!NetFileCache.ZipValid(path, out invalidReason)) throw new InvalidModuleFileKraken(module, path, - $"{path} is not a valid ZIP file: {invalidReason}"); + $"{module}: {path} is not a valid ZIP file: {invalidReason}"); // Some older metadata doesn't have hashes if (module.download_hash != null) @@ -132,13 +132,13 @@ public string Store(CkanModule module, string path, string description = null, b string sha1 = GetFileHashSha1(path); if (sha1 != module.download_hash.sha1) throw new InvalidModuleFileKraken(module, path, - $"{path} has SHA1 {sha1}, should be {module.download_hash.sha1}"); + $"{module}: {path} has SHA1 {sha1}, should be {module.download_hash.sha1}"); // Check SHA256 match string sha256 = GetFileHashSha256(path); if (sha256 != module.download_hash.sha256) throw new InvalidModuleFileKraken(module, path, - $"{path} has SHA256 {sha256}, should be {module.download_hash.sha256}"); + $"{module}: {path} has SHA256 {sha256}, should be {module.download_hash.sha256}"); } // If no exceptions, then everything is fine diff --git a/GUI/MainWait.cs b/GUI/MainWait.cs index e37a0e26f9..7cf3914312 100644 --- a/GUI/MainWait.cs +++ b/GUI/MainWait.cs @@ -13,37 +13,52 @@ public partial class Main public void ShowWaitDialog(bool cancelable = true) { - tabController.ShowTab("WaitTabPage", 2); - - CancelCurrentActionButton.Enabled = cancelable; - - DialogProgressBar.Value = 0; - DialogProgressBar.Minimum = 0; - DialogProgressBar.Maximum = 100; - DialogProgressBar.Style = ProgressBarStyle.Marquee; - MessageTextBox.Text = "Please wait"; - StatusProgress.Value = 0; - StatusProgress.Style = ProgressBarStyle.Marquee; - StatusProgress.Visible = true; + Util.Invoke(DialogProgressBar, () => + { + tabController.ShowTab("WaitTabPage", 2); + + CancelCurrentActionButton.Enabled = cancelable; + + DialogProgressBar.Value = 0; + DialogProgressBar.Minimum = 0; + DialogProgressBar.Maximum = 100; + DialogProgressBar.Style = ProgressBarStyle.Marquee; + MessageTextBox.Text = "Please wait"; + }); + Util.Invoke(statusStrip1, () => + { + StatusProgress.Value = 0; + StatusProgress.Style = ProgressBarStyle.Marquee; + StatusProgress.Visible = true; + }); } public void HideWaitDialog(bool success) { - MessageTextBox.Text = "All done!"; - DialogProgressBar.Value = 100; - DialogProgressBar.Style = ProgressBarStyle.Continuous; - StatusProgress.Value = 100; - StatusProgress.Style = ProgressBarStyle.Continuous; - RecreateDialogs(); - - tabController.SetActiveTab("ManageModsTabPage"); - - CancelCurrentActionButton.Enabled = false; - DialogProgressBar.Value = 0; - DialogProgressBar.Style = ProgressBarStyle.Continuous; - StatusProgress.Value = 0; - StatusProgress.Style = ProgressBarStyle.Continuous; - StatusProgress.Visible = false; + Util.Invoke(statusStrip1, () => + { + StatusProgress.Value = 100; + StatusProgress.Style = ProgressBarStyle.Continuous; + }); + Util.Invoke(DialogProgressBar, () => + { + MessageTextBox.Text = "All done!"; + DialogProgressBar.Value = 100; + DialogProgressBar.Style = ProgressBarStyle.Continuous; + RecreateDialogs(); + + tabController.SetActiveTab("ManageModsTabPage"); + + CancelCurrentActionButton.Enabled = false; + DialogProgressBar.Value = 0; + DialogProgressBar.Style = ProgressBarStyle.Continuous; + }); + Util.Invoke(statusStrip1, () => + { + StatusProgress.Value = 0; + StatusProgress.Style = ProgressBarStyle.Continuous; + StatusProgress.Visible = false; + }); } public void SetProgress(int progress) @@ -61,6 +76,9 @@ public void SetProgress(int progress) { DialogProgressBar.Value = progress; DialogProgressBar.Style = ProgressBarStyle.Continuous; + }); + Util.Invoke(statusStrip1, () => + { StatusProgress.Value = progress; StatusProgress.Style = ProgressBarStyle.Continuous; }); @@ -71,6 +89,9 @@ public void ResetProgress() Util.Invoke(DialogProgressBar, () => { DialogProgressBar.Style = ProgressBarStyle.Marquee; + }); + Util.Invoke(statusStrip1, () => + { StatusProgress.Style = ProgressBarStyle.Marquee; }); } @@ -92,7 +113,10 @@ public void AddLogMessage(string message) private void RetryCurrentActionButton_Click(object sender, EventArgs e) { - tabController.ShowTab("ChangesetTabPage", 1); + Util.Invoke(DialogProgressBar, () => + { + tabController.ShowTab("ChangesetTabPage", 1); + }); } private void CancelCurrentActionButton_Click(object sender, EventArgs e) @@ -101,7 +125,10 @@ private void CancelCurrentActionButton_Click(object sender, EventArgs e) { cancelCallback(); } - CancelCurrentActionButton.Enabled = false; + Util.Invoke(DialogProgressBar, () => + { + CancelCurrentActionButton.Enabled = false; + }); HideWaitDialog(true); }