1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-02 11:34:08 +02:00

Make update download form double buffered & tweak cancelling

This commit is contained in:
chylex 2017-03-29 14:30:51 +02:00
parent 48ed0e01d1
commit d7cdaf2870
2 changed files with 21 additions and 12 deletions

View File

@ -82,6 +82,7 @@ private void InitializeComponent() {
this.Controls.Add(this.labelDescription);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.progressDownload);
this.DoubleBuffered = true;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;

View File

@ -28,18 +28,17 @@ public enum Status{
public FormUpdateDownload(UpdateInfo info){
InitializeComponent();
this.webClient = new WebClient{ Proxy = null };
this.webClient.Headers[HttpRequestHeader.UserAgent] = BrowserUtils.HeaderUserAgent;
Text = "Updating "+Program.BrandName;
labelDescription.Text = "Downloading version "+info.VersionTag+"...";
this.updateInfo = info;
this.UpdateStatus = Status.Waiting;
webClient.DownloadProgressChanged += webClient_DownloadProgressChanged;
webClient.DownloadFileCompleted += webClient_DownloadFileCompleted;
Text = "Updating "+Program.BrandName;
labelDescription.Text = "Downloading version "+info.VersionTag+"...";
this.webClient = new WebClient{ Proxy = null };
this.webClient.Headers[HttpRequestHeader.UserAgent] = BrowserUtils.HeaderUserAgent;
this.webClient.DownloadProgressChanged += webClient_DownloadProgressChanged;
this.webClient.DownloadFileCompleted += webClient_DownloadFileCompleted;
Disposed += (sender, args) => this.webClient.Dispose();
}
@ -48,15 +47,24 @@ private void FormUpdateDownload_Shown(object sender, EventArgs e){
}
private void btnCancel_Click(object sender, EventArgs e){
webClient.CancelAsync();
btnCancel.Enabled = false;
if (webClient.IsBusy){
webClient.CancelAsync();
btnCancel.Enabled = false;
}
else{
UpdateStatus = Status.Cancelled;
Close();
}
}
private void FormUpdateDownload_FormClosing(object sender, FormClosingEventArgs e){
if (UpdateStatus == Status.Waiting){
e.Cancel = true;
webClient.CancelAsync();
UpdateStatus = e.CloseReason == CloseReason.UserClosing ? Status.Cancelled : Status.Manual; // manual will exit the app
if (webClient.IsBusy){
webClient.CancelAsync();
e.Cancel = true;
}
}
}