예제 #1
0
파일: Updater.cs 프로젝트: zjuyou/wnmp
        /// <summary>
        /// Downloads Update
        /// </summary>
        public void Update(Action UpdateDownloaded, Action UpdateCanceled)
        {
            updateDownloaded = UpdateDownloaded;
            updateCanceled = UpdateCanceled;

            updateProgress = new UpdateProgress();
            updateProgress.FormClosed += updateProgress_FormClosed;

            updateProgress.StartPosition = FormStartPosition.CenterParent;
            updateProgress.Show();

            webClient = new WebClient();
            webClient.DownloadProgressChanged += webClient_DownloadProgressChanged;
            webClient.DownloadFileCompleted += webClient_DownloadFileCompleted;

            webClient.DownloadFileAsync(UpdateDownloadURL, SaveName);
        }
예제 #2
0
파일: Updater.cs 프로젝트: snakems/wnmp
        /// <summary>
        /// Downloads the update for Wnmp
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="path"></param>
        private static void DownloadWnmpUpdate(Uri uri, string path)
        {
            var frm = new UpdateProgress();
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.Show();
            Program.formInstance.Enabled = false;

            webClient = new WebClient();

            frm.FormClosed += (s, e) => {
                Program.formInstance.Enabled = true;
                webClient.CancelAsync();
            };

            webClient.DownloadProgressChanged += (s, e) => {
                frm.progressBar1.Value = e.ProgressPercentage;
                frm.label2.Text = e.ProgressPercentage.ToString() + "%";
            };

            webClient.DownloadFileCompleted += (s, e) => {
                if (!e.Cancelled) {
                    webClient.Dispose();
                    frm.Close();
                    Process.Start(UpdateExe);
                    KillProcesses();
                    DoBackUp();
                    Application.Exit();
                    Process.GetCurrentProcess().Kill();
                } else
                    webClient.Dispose();
            };

            webClient.DownloadFileAsync(uri, path);

            webClient.Dispose();
        }