Exemple #1
0
        public static bool DownloadAndInstall(Uri downloadFrom, string fileName, bool exitToInstall)
        {
            WebClient client         = new WebClient();
            string    downloadedFile = Path.Combine(GetDownloadDirectory(), fileName);
            bool      completed      = false;
            bool      success        = false;

            downloadedFile = FindNonexistantFile(downloadedFile);

            DownloadProgressDialog downloadProgressDialog = new DownloadProgressDialog();

            client.DownloadProgressChanged += (sender, e) => { downloadProgressDialog.SetProgress(e.ProgressPercentage); };
            client.DownloadFileCompleted   += (sender, e) => {
                completed = true;
                downloadProgressDialog.DialogResult = DialogResult.OK;
            };

            client.DownloadFileAsync(downloadFrom, downloadedFile);
            var result = downloadProgressDialog.ShowDialog();

            if (result == DialogResult.OK && completed)
            {
                success = Install(downloadedFile, exitToInstall);
            }

            client.Dispose();
            downloadProgressDialog.Dispose();
            return(success);
        }
Exemple #2
0
        public static bool DownloadAndInstall(Uri downloadFrom, string fileName, bool exitToInstall)
        {
            WebClient client = new WebClient();
            string downloadedFile = Path.Combine(GetDownloadDirectory(), fileName);
            bool completed = false;
            bool success = false;

            downloadedFile = FindNonexistantFile(downloadedFile);

            DownloadProgressDialog downloadProgressDialog = new DownloadProgressDialog();
            client.DownloadProgressChanged += (sender, e) => { downloadProgressDialog.SetProgress(e.ProgressPercentage); };
            client.DownloadFileCompleted += (sender, e) => {
                completed = true;
                downloadProgressDialog.DialogResult = DialogResult.OK;
            };

            client.DownloadFileAsync(downloadFrom, downloadedFile);
            var result = downloadProgressDialog.ShowDialog();

            if (result == DialogResult.OK && completed) {
                success = Install(downloadedFile, exitToInstall);
            }

            client.Dispose();
            downloadProgressDialog.Dispose();
            return success;
        }