private void cancel_Click(object sender, EventArgs e) { if (Downloading) { try { if (DownloadThread != null && DownloadThread.IsAlive) { DownloadThread.Abort( ); } } catch (ThreadAbortException) { this.LogWarn("Abortting 'Download' Thread."); } } if (RunningThread != null && RunningThread.IsAlive) { try { RunningThread.Abort( ); } catch (ThreadAbortException) { this.LogWarn("Abortting 'Running' Thread."); } } this.DialogResult = DialogResult.Cancel; }
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (DownloadThread.IsAlive) { DownloadThread.Abort(); } if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); }
private void perform_Click(object sender, EventArgs e) { try { SetControlEnabled(this.perform, false); SetControlVisible(this.progress, true); SetControlVisible(stepImage, true); if (DownloadThread != null && DownloadThread.IsAlive) { try { DownloadThread.Abort( ); } catch (ThreadAbortException taex) { this.LogWarn("Aborted download thread."); } } DownloadThread = new Thread(new ThreadStart(delegate { FileInfo tfile = new FileInfo(ZipFile); if (tfile.Exists) { tfile.Delete( ); } if (!tfile.Directory.Exists) { tfile.Directory.Create( ); } this.LogInfo("Checking USB Driver Version..."); bool isCupcake = AndroidUsbDriverHelper.IsCupcakeDriver; this.LogInfo("Downloading {0} SDK Tools", isCupcake ? "1.5" : "1.6"); HttpWebRequest req = HttpWebRequest.Create(new Uri(isCupcake ? Properties.Resources.AndroidCupcakeSdkDownloadUrl : Properties.Resources.AndroidDonutSdkDownloadUrl)) as HttpWebRequest; if (Settings.Instance.Proxy.Enabled) { req.Proxy = Settings.Instance.Proxy.CreateProxy( ); } HttpWebResponse resp = req.GetResponse( ) as HttpWebResponse; using (Stream reader = resp.GetResponseStream( )) { Downloading = true; int bytesRead = 0; byte[] buffer = new byte[2048]; long totalBytes = resp.ContentLength; long totalBytesRead = 0; using (FileStream fs = new FileStream(ZipFile, FileMode.Create, FileAccess.Write, FileShare.Read)) { while ((bytesRead = reader.Read(buffer, 0, buffer.Length)) > 0) { fs.Write(buffer, 0, bytesRead); totalBytesRead += bytesRead; int percentage = ( int )((( double )totalBytesRead / ( double )totalBytes) * 100f); if (this.InvokeRequired) { this.Invoke(new UpdateProgressBarValueDelegate(this.UpdateProgressBarValue), 0, 100, percentage); this.Invoke(new UpdateLabelDelegate(this.UpdateStatusLabel), string.Format(new DroidExplorer.Core.IO.FileSizeFormatProvider( ), "Downloading Android Tools: {0:fs} of {1:fs} - {2}%", totalBytesRead, totalBytes, percentage)); } else { UpdateProgressBarValue(0, 100, percentage); UpdateStatusLabel(string.Format(new DroidExplorer.Core.IO.FileSizeFormatProvider( ), "Downloading Android Tools: {0:fs} of {1:fs} - {2}%", totalBytesRead, totalBytes, percentage)); } } if (this.InvokeRequired) { this.Invoke(new UpdateProgressBarValueDelegate(this.UpdateProgressBarValue), 0, 100, 0); this.Invoke(new UpdateLabelDelegate(this.UpdateStatusLabel), "Download Complete"); } else { UpdateProgressBarValue(0, 100, 0); UpdateStatusLabel("Download Complete"); } Downloading = false; } } if (RunningThread != null && RunningThread.IsAlive) { try { RunningThread.Abort( ); } catch { } } RunningThread = new Thread(new ThreadStart(delegate { Step2( ); })); RunningThread.Start( ); })); DownloadThread.Start( ); } catch (Exception ex) { this.LogError(ex.Message, ex); SetError(ex); FinializeSetup( ); } }