mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-08-18 13:31:41 +02:00
Make update download form double buffered & tweak cancelling
This commit is contained in:
1
Updates/FormUpdateDownload.Designer.cs
generated
1
Updates/FormUpdateDownload.Designer.cs
generated
@@ -82,6 +82,7 @@
|
|||||||
this.Controls.Add(this.labelDescription);
|
this.Controls.Add(this.labelDescription);
|
||||||
this.Controls.Add(this.btnCancel);
|
this.Controls.Add(this.btnCancel);
|
||||||
this.Controls.Add(this.progressDownload);
|
this.Controls.Add(this.progressDownload);
|
||||||
|
this.DoubleBuffered = true;
|
||||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
||||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||||
this.MaximizeBox = false;
|
this.MaximizeBox = false;
|
||||||
|
@@ -28,18 +28,17 @@ namespace TweetDck.Updates{
|
|||||||
public FormUpdateDownload(UpdateInfo info){
|
public FormUpdateDownload(UpdateInfo info){
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
this.webClient = new WebClient{ Proxy = null };
|
Text = "Updating "+Program.BrandName;
|
||||||
this.webClient.Headers[HttpRequestHeader.UserAgent] = BrowserUtils.HeaderUserAgent;
|
labelDescription.Text = "Downloading version "+info.VersionTag+"...";
|
||||||
|
|
||||||
this.updateInfo = info;
|
this.updateInfo = info;
|
||||||
this.UpdateStatus = Status.Waiting;
|
this.UpdateStatus = Status.Waiting;
|
||||||
|
|
||||||
webClient.DownloadProgressChanged += webClient_DownloadProgressChanged;
|
this.webClient = new WebClient{ Proxy = null };
|
||||||
webClient.DownloadFileCompleted += webClient_DownloadFileCompleted;
|
this.webClient.Headers[HttpRequestHeader.UserAgent] = BrowserUtils.HeaderUserAgent;
|
||||||
|
this.webClient.DownloadProgressChanged += webClient_DownloadProgressChanged;
|
||||||
Text = "Updating "+Program.BrandName;
|
this.webClient.DownloadFileCompleted += webClient_DownloadFileCompleted;
|
||||||
labelDescription.Text = "Downloading version "+info.VersionTag+"...";
|
|
||||||
|
|
||||||
Disposed += (sender, args) => this.webClient.Dispose();
|
Disposed += (sender, args) => this.webClient.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,15 +47,24 @@ namespace TweetDck.Updates{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void btnCancel_Click(object sender, EventArgs e){
|
private void btnCancel_Click(object sender, EventArgs e){
|
||||||
webClient.CancelAsync();
|
if (webClient.IsBusy){
|
||||||
btnCancel.Enabled = false;
|
webClient.CancelAsync();
|
||||||
|
btnCancel.Enabled = false;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
UpdateStatus = Status.Cancelled;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FormUpdateDownload_FormClosing(object sender, FormClosingEventArgs e){
|
private void FormUpdateDownload_FormClosing(object sender, FormClosingEventArgs e){
|
||||||
if (UpdateStatus == Status.Waiting){
|
if (UpdateStatus == Status.Waiting){
|
||||||
e.Cancel = true;
|
|
||||||
webClient.CancelAsync();
|
|
||||||
UpdateStatus = e.CloseReason == CloseReason.UserClosing ? Status.Cancelled : Status.Manual; // manual will exit the app
|
UpdateStatus = e.CloseReason == CloseReason.UserClosing ? Status.Cancelled : Status.Manual; // manual will exit the app
|
||||||
|
|
||||||
|
if (webClient.IsBusy){
|
||||||
|
webClient.CancelAsync();
|
||||||
|
e.Cancel = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user