Skip to content

Commit

Permalink
Merge #2374 Deal with threading and download errors
Browse files Browse the repository at this point in the history
  • Loading branch information
politas committed Mar 19, 2018
2 parents 1eea827 + 6fd4287 commit 5479760
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ All notable changes to this project will be documented in this file.
- [GUI] Improve response to checkbox changes (#2354 by: HebaruSan; reviewed: politas)
- [Core] Allow downloader to be used multiple times (#2365 by: HebaruSan; reviewed: politas)
- [GUI] Clean up URL Handler registration (#2366 by: HebaruSan; reviewed: politas)
- [Multiple] Deal with threading and download errors (#2374 by: HebaruSan; reviewed: politas)

### Internal

Expand Down
4 changes: 4 additions & 0 deletions Core/Net/NetAsyncModulesDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions Core/Net/NetModuleCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
85 changes: 56 additions & 29 deletions GUI/MainWait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
});
Expand All @@ -71,6 +89,9 @@ public void ResetProgress()
Util.Invoke(DialogProgressBar, () =>
{
DialogProgressBar.Style = ProgressBarStyle.Marquee;
});
Util.Invoke(statusStrip1, () =>
{
StatusProgress.Style = ProgressBarStyle.Marquee;
});
}
Expand All @@ -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)
Expand All @@ -101,7 +125,10 @@ private void CancelCurrentActionButton_Click(object sender, EventArgs e)
{
cancelCallback();
}
CancelCurrentActionButton.Enabled = false;
Util.Invoke(DialogProgressBar, () =>
{
CancelCurrentActionButton.Enabled = false;
});
HideWaitDialog(true);
}

Expand Down

0 comments on commit 5479760

Please sign in to comment.