From 01eee888dcb918cb2e7247ef9634d99016ef9253 Mon Sep 17 00:00:00 2001 From: Hawx Date: Wed, 5 Apr 2017 19:51:01 +0800 Subject: [PATCH] Async conventions --- SCPatchDownloader/MainWindow.cs | 21 ++++++++++++++++----- SCPatchDownloader/SCPatchDownloader.csproj | 8 +++++--- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/SCPatchDownloader/MainWindow.cs b/SCPatchDownloader/MainWindow.cs index b29331e..6aa016d 100644 --- a/SCPatchDownloader/MainWindow.cs +++ b/SCPatchDownloader/MainWindow.cs @@ -58,7 +58,7 @@ public MainWindow() } //loading application - private void MainWindow_Load(object sender, EventArgs e) + private async void MainWindow_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Settings.Default.PrvDir)) textBoxDownloadDirectory.Text = Settings.Default.PrvDir; @@ -68,7 +68,7 @@ private void MainWindow_Load(object sender, EventArgs e) toolTip_Native.SetToolTip(checkBoxNativeFile, "Sorts files into public/test directories instead of using build number. Allows for easy copy/pasting or direct download into program files. Existing files will not be overwritten"); - DownloadPatchList(); + await DownloadPatchList(); } //on Browse Directory click @@ -80,7 +80,7 @@ private void BrowseDirectoryButtonClick(object sender, EventArgs e) } //download button - private void DownloadStartButtonClick(object sender, EventArgs e) + private async void DownloadStartButtonClick(object sender, EventArgs e) { buttonCancel.Enabled = true; buttonDownloadStart.Enabled = false; @@ -89,7 +89,7 @@ private void DownloadStartButtonClick(object sender, EventArgs e) textBoxDownloadDirectory.Enabled = false; buttonBrowseDirectory.Enabled = false; checkBoxNativeFile.Enabled = false; - DownloadGameFiles(); + await DownloadGameFiles(); } @@ -146,6 +146,17 @@ private async Task DownloadGameFiles() MessageBox.Show("Unable to write to disk. Do you have enough space? Full Exception: " + x, "IOException", MessageBoxButtons.OK, MessageBoxIcon.Error); } + catch (WebException x) + { + //Handle the cancel event + if (x.Message == "The request was aborted: The request was canceled.") + { + return; + } + MessageBox.Show($"Download failure, unable to continue. \nFull exception: {x.Message}", "WebException", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + else MessageBox.Show("Please provide a valid download location", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); @@ -170,8 +181,8 @@ private void Client_InstallFileCompleted(object sender, AsyncCompletedEventArgs { if (e.Cancelled) { - if (fulldir != null) File.Delete(fulldir); client.Dispose(); + if (fulldir != null) File.Delete(fulldir); labelMegaBytes.Text = "N/A MB/s"; ResetAllBoxes(this); } diff --git a/SCPatchDownloader/SCPatchDownloader.csproj b/SCPatchDownloader/SCPatchDownloader.csproj index d28fb6f..d6b44d9 100644 --- a/SCPatchDownloader/SCPatchDownloader.csproj +++ b/SCPatchDownloader/SCPatchDownloader.csproj @@ -13,6 +13,8 @@ true false + + publish\ true Disk @@ -27,8 +29,6 @@ 1.0.0.%2a false true - - x64 @@ -138,7 +138,9 @@ - + + Designer + PreserveNewest