/// <summary> /// Updates the progress bar and stage message /// </summary> private void UpdateProgressBar(ProgressReporter progressReport) { //int progress = updater.GetProgress(); if (!string.IsNullOrEmpty(progressReport.StatusMessage)) { Brush foregroundBrush; switch (progressReport.MessageState) { case ProgressReporter.State.Success: foregroundBrush = new SolidColorBrush(Colors.LightGreen); break; case ProgressReporter.State.Error: foregroundBrush = new SolidColorBrush(Colors.LightSalmon); break; default: foregroundBrush = new SolidColorBrush(Colors.Ivory); break; } StackPanelLog.Children.Add(new TextBlock() { Text = progressReport.StatusMessage, Foreground = foregroundBrush }); ScrollViewer.ScrollToBottom(); } if (progressReport.Progress >= 0) { progressBar.Value = progressReport.Progress; } }
/// <summary> /// Downloads a file to the given destination from the given URL /// </summary> /// /// <param name="url">The URL to download from</param> /// <param name="outName">File to output contents to</param> /// /// <returns>Success or Fail</returns> private async Task <bool> DownloadFile(string url, string outName, IProgress <ProgressReporter> progress) { using (var client = new WebClient()) { client.Headers.Add("User-Agent", "Anything"); var reporter = new ProgressReporter(GetProgress()); if (url == null) { await Fetch(progress); Parse(progress); url = downloadURL; if (url == null) { progress.Report(new ProgressReporter("url for downloading is null due to error while parsing.")); return(false); } } progress.Report(new ProgressReporter($"downloading {url} to {outName}")); Debug.WriteLine("URL: " + url); Debug.WriteLine("Out File: " + outName); await client.DownloadFileTaskAsync(url, outName); } return(File.Exists(outName)); }
/// <summary> /// Updates the progress bar and stage message /// </summary> private void UpdateProgressBar(ProgressReporter progressReport) { //int progress = updater.GetProgress(); if (!string.IsNullOrEmpty(progressReport.statusMessage)) { updateStatus.Text += "\n" + progressReport.statusMessage; scrollViewer.ScrollToBottom(); } if (progressReport.progress >= 0) { progressBar.Value = progressReport.progress; } }
/// <summary> /// Checks if an update is available /// </summary> /// /// <returns>true if update available</returns> private async Task <bool> CheckForUpdates(IProgress <ProgressReporter> progress) { var reporter = new ProgressReporter(-1); if (!await updater.Fetch(progress)) { reporter.StatusMessage = "Fetch failed, retrying…"; progress.Report(reporter); if (!await updater.Fetch(progress)) { return(false); } } if (!updater.Parse(progress)) { reporter.StatusMessage = updater.LastError(); progress.Report(reporter); return(false); } return(updater.Check(applicationPath, progress)); }
/// <summary> /// Performs the update /// </summary> private async Task <bool> DoUpdate(IProgress <ProgressReporter> progress) { var reporter = new ProgressReporter(0, "Starting the update"); progress.Report(reporter); reporter.Progress = -1; if (!await updater.Download(progress)) { if (!await updater.Fetch(progress) || !updater.Parse(progress)) { reporter.StatusMessage = updater.LastError(); progress.Report(reporter); return(false); } reporter.StatusMessage = "Download of update failed, retrying…"; progress.Report(reporter); if (!await updater.Download(progress)) { return(false); } } CloseASB(); if (!updater.Extract(applicationPath, UseLocalAppDataForDataFiles, progress)) { reporter.StatusMessage = "Extracting update files failed, retrying…"; progress.Report(reporter); if (!updater.Extract(applicationPath, UseLocalAppDataForDataFiles, progress)) { return(false); } } return(true); }