private void btnCancel_Click(object sender, EventArgs e) { switch (Status) { case DownloaderFormStatus.Waiting: StartDownload(); break; default: case DownloaderFormStatus.DownloadStarted: Close(); break; case DownloaderFormStatus.DownloadCompleted: try { btnAction.Enabled = false; ProcessStartInfo psi = new ProcessStartInfo(SavePath); psi.Verb = "runas"; psi.UseShellExecute = true; Process.Start(psi); Status = DownloaderFormStatus.InstallStarted; } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Updater", MessageBoxButtons.OK, MessageBoxIcon.Error); } Close(); break; } }
public void Install() { if (Status == DownloaderFormStatus.DownloadCompleted) { Status = DownloaderFormStatus.InstallStarted; btnAction.Enabled = false; RunInstallerWithDelay(); Close(); } }
private void fileDownloader_DownloadCompleted(object sender, EventArgs e) { ChangeStatus("Download completed."); Status = DownloaderFormStatus.DownloadCompleted; btnAction.Text = "Install"; if (AutoStartInstall) { Install(); } }
public DownloaderForm() { InitializeComponent(); fillRect = new Rectangle(0, 0, ClientSize.Width, ClientSize.Height); backgroundBrush = new LinearGradientBrush(fillRect, Color.FromArgb(80, 80, 80), Color.FromArgb(50, 50, 50), LinearGradientMode.Vertical); UpdateFormSize(); ChangeStatus("Waiting."); Status = DownloaderFormStatus.Waiting; AutoStartDownload = true; }
private UpdaterForm() { InitializeComponent(); Icon = ShareXResources.Icon; fillRect = new Rectangle(0, 0, ClientSize.Width, ClientSize.Height); UpdateFormSize(); ChangeStatus("Waiting."); Status = DownloaderFormStatus.Waiting; AutoStartDownload = true; InstallType = InstallType.Silent; AutoStartInstall = true; }
private void StartDownload() { if (!string.IsNullOrEmpty(URL) && Status == DownloaderFormStatus.Waiting) { Status = DownloaderFormStatus.DownloadStarted; btnAction.Text = "Cancel"; SavePath = Path.Combine(Path.GetTempPath(), Filename); fileStream = new FileStream(SavePath, FileMode.Create, FileAccess.Write, FileShare.Read); fileDownloader = new FileDownloader(URL, fileStream, Proxy, AcceptHeader); fileDownloader.FileSizeReceived += (v1, v2) => ChangeProgress(); fileDownloader.DownloadStarted += (v1, v2) => ChangeStatus("Download started."); fileDownloader.ProgressChanged += (v1, v2) => ChangeProgress(); fileDownloader.DownloadCompleted += fileDownloader_DownloadCompleted; fileDownloader.ExceptionThrowed += (v1, v2) => ChangeStatus(fileDownloader.LastException.Message); fileDownloader.StartDownload(); ChangeStatus("Getting file size."); } }
private void fileDownloader_DownloadCompleted(object sender, EventArgs e) { Status = DownloaderFormStatus.DownloadCompleted; ChangeStatus("Download completed."); btnAction.Text = "Install"; }