Skip to content
This repository has been archived by the owner on Jan 9, 2020. It is now read-only.

Commit

Permalink
Async conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
Hawxy committed Apr 5, 2017
1 parent dae0700 commit 01eee88
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
21 changes: 16 additions & 5 deletions SCPatchDownloader/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -89,7 +89,7 @@ private void DownloadStartButtonClick(object sender, EventArgs e)
textBoxDownloadDirectory.Enabled = false;
buttonBrowseDirectory.Enabled = false;
checkBoxNativeFile.Enabled = false;
DownloadGameFiles();
await DownloadGameFiles();
}


Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
8 changes: 5 additions & 3 deletions SCPatchDownloader/SCPatchDownloader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
<IsWebBootstrapper>false</IsWebBootstrapper>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
Expand All @@ -27,8 +29,6 @@
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget>
Expand Down Expand Up @@ -138,7 +138,9 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="FodyWeavers.xml" />
<Content Include="FodyWeavers.xml">
<SubType>Designer</SubType>
</Content>
<Content Include="INSTRUCTIONS.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down

0 comments on commit 01eee88

Please sign in to comment.