From 54979f9a696ec02b57c173d69e9feb2bfb90f249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20B=C3=B6rchers?= Date: Fri, 23 Mar 2018 14:07:24 +0100 Subject: [PATCH] Moved ChangelogHelper and MarkdownSharp.cs to Katteker Lib, polish up the Gui. --- Example/MainWindow.xaml | 2 +- Example/Properties/AssemblyInfo.cs | 4 +- Katteker.Gui/Katteker.Gui.csproj | 2 - Katteker.Gui/Properties/Resources.Designer.cs | 18 +++++ Katteker.Gui/Properties/Resources.resx | 6 ++ Katteker.Gui/UpdateWindow.Designer.cs | 13 ++-- Katteker.Gui/UpdateWindow.cs | 69 ++++++++++------- Katteker.Gui/UpdateWindow.resx | 77 ------------------- Katteker.Gui/Wrapper.cs | 49 ++++++------ {Katteker.Gui => Katteker}/ChangelogHelper.cs | 6 +- Katteker/Katteker.csproj | 2 + {Katteker.Gui => Katteker}/MarkdownSharp.cs | 0 Katteker/Properties/AssemblyInfo.cs | 4 +- Katteker/UpdateManager.cs | 49 ++++++------ 14 files changed, 128 insertions(+), 173 deletions(-) rename {Katteker.Gui => Katteker}/ChangelogHelper.cs (93%) rename {Katteker.Gui => Katteker}/MarkdownSharp.cs (100%) diff --git a/Example/MainWindow.xaml b/Example/MainWindow.xaml index d721f83..0d191ab 100644 --- a/Example/MainWindow.xaml +++ b/Example/MainWindow.xaml @@ -8,7 +8,7 @@ Title="MainWindow" Width="800" Height="450" - Background="BlueViolet" + Background="Chartreuse" ContentRendered="MainWindow_OnContentRendered" mc:Ignorable="d"> diff --git a/Example/Properties/AssemblyInfo.cs b/Example/Properties/AssemblyInfo.cs index 1c3e88a..8dc1820 100644 --- a/Example/Properties/AssemblyInfo.cs +++ b/Example/Properties/AssemblyInfo.cs @@ -49,5 +49,5 @@ using System.Windows; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.42")] -[assembly: AssemblyFileVersion("1.0.42")] +[assembly: AssemblyVersion("1.0.48")] +[assembly: AssemblyFileVersion("1.0.48")] diff --git a/Katteker.Gui/Katteker.Gui.csproj b/Katteker.Gui/Katteker.Gui.csproj index ced1c89..a4c1fe1 100644 --- a/Katteker.Gui/Katteker.Gui.csproj +++ b/Katteker.Gui/Katteker.Gui.csproj @@ -42,8 +42,6 @@ - - diff --git a/Katteker.Gui/Properties/Resources.Designer.cs b/Katteker.Gui/Properties/Resources.Designer.cs index 22775ea..b58a096 100644 --- a/Katteker.Gui/Properties/Resources.Designer.cs +++ b/Katteker.Gui/Properties/Resources.Designer.cs @@ -60,6 +60,15 @@ namespace Katteker.Gui.Properties { } } + /// + /// Looks up a localized string similar to Could not update your application.. + /// + internal static string CouldNotUpdateYourApplication { + get { + return ResourceManager.GetString("CouldNotUpdateYourApplication", resourceCulture); + } + } + /// /// Looks up a localized string similar to Installed new Version! Would you like to restart the Application?. /// @@ -123,6 +132,15 @@ namespace Katteker.Gui.Properties { } } + /// + /// Looks up a localized string similar to Updater. + /// + internal static string Updater { + get { + return ResourceManager.GetString("Updater", resourceCulture); + } + } + /// /// Looks up a localized string similar to You can update to Version: . /// diff --git a/Katteker.Gui/Properties/Resources.resx b/Katteker.Gui/Properties/Resources.resx index 5451a9a..b260d49 100644 --- a/Katteker.Gui/Properties/Resources.resx +++ b/Katteker.Gui/Properties/Resources.resx @@ -144,4 +144,10 @@ Ask your local distributor. + + Updater + + + Could not update your application. + \ No newline at end of file diff --git a/Katteker.Gui/UpdateWindow.Designer.cs b/Katteker.Gui/UpdateWindow.Designer.cs index 3325b58..3e34ea2 100644 --- a/Katteker.Gui/UpdateWindow.Designer.cs +++ b/Katteker.Gui/UpdateWindow.Designer.cs @@ -21,7 +21,6 @@ namespace Katteker.Gui [STAThread] private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UpdateWindow)); this.mainSplitContainer = new System.Windows.Forms.SplitContainer(); this.titleLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); this.closeWindowBtn = new System.Windows.Forms.Button(); @@ -85,6 +84,7 @@ namespace Katteker.Gui this.titleLayoutPanel.Controls.Add(this.minimizeBtn, 2, 0); this.titleLayoutPanel.Controls.Add(this.label1, 0, 0); this.titleLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; + this.titleLayoutPanel.ForeColor = System.Drawing.SystemColors.Control; this.titleLayoutPanel.Location = new System.Drawing.Point(0, 0); this.titleLayoutPanel.Name = "titleLayoutPanel"; this.titleLayoutPanel.RowCount = 1; @@ -101,7 +101,6 @@ namespace Katteker.Gui this.closeWindowBtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Red; this.closeWindowBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.closeWindowBtn.Font = new System.Drawing.Font("Segoe UI Symbol", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.closeWindowBtn.ForeColor = System.Drawing.SystemColors.ControlLightLight; this.closeWindowBtn.Location = new System.Drawing.Point(658, 0); this.closeWindowBtn.Margin = new System.Windows.Forms.Padding(0); this.closeWindowBtn.Name = "closeWindowBtn"; @@ -118,7 +117,6 @@ namespace Katteker.Gui this.maximizeBtn.FlatAppearance.BorderSize = 0; this.maximizeBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.maximizeBtn.Font = new System.Drawing.Font("Segoe UI Symbol", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.maximizeBtn.ForeColor = System.Drawing.SystemColors.ControlLightLight; this.maximizeBtn.Location = new System.Drawing.Point(618, 0); this.maximizeBtn.Margin = new System.Windows.Forms.Padding(0); this.maximizeBtn.Name = "maximizeBtn"; @@ -133,12 +131,11 @@ namespace Katteker.Gui // this.titlebar.Dock = System.Windows.Forms.DockStyle.Fill; this.titlebar.Font = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.titlebar.ForeColor = System.Drawing.SystemColors.ControlLightLight; this.titlebar.Location = new System.Drawing.Point(123, 0); this.titlebar.Name = "titlebar"; this.titlebar.Size = new System.Drawing.Size(452, 30); this.titlebar.TabIndex = 0; - this.titlebar.Text = "titleBar"; + this.titlebar.Text = "Updater"; this.titlebar.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.titlebar.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Titlebar_MouseDown); // @@ -148,7 +145,6 @@ namespace Katteker.Gui this.minimizeBtn.FlatAppearance.BorderSize = 0; this.minimizeBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.minimizeBtn.Font = new System.Drawing.Font("Segoe UI Symbol", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.minimizeBtn.ForeColor = System.Drawing.SystemColors.ControlLightLight; this.minimizeBtn.Location = new System.Drawing.Point(578, 0); this.minimizeBtn.Margin = new System.Windows.Forms.Padding(0); this.minimizeBtn.Name = "minimizeBtn"; @@ -163,7 +159,6 @@ namespace Katteker.Gui // this.label1.Dock = System.Windows.Forms.DockStyle.Fill; this.label1.Font = new System.Drawing.Font("Segoe UI Symbol", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label1.ForeColor = System.Drawing.SystemColors.Window; this.label1.Location = new System.Drawing.Point(3, 0); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(114, 30); @@ -276,11 +271,13 @@ namespace Katteker.Gui this.DoubleBuffered = true; this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; - this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "UpdateWindow"; + this.ShowIcon = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Activated += new System.EventHandler(this.UpdateWindow_Activated); + this.Deactivate += new System.EventHandler(this.UpdateWindow_Deactivate); this.Load += new System.EventHandler(this.UpdateWindow_Load); this.mainSplitContainer.Panel1.ResumeLayout(false); this.mainSplitContainer.Panel2.ResumeLayout(false); diff --git a/Katteker.Gui/UpdateWindow.cs b/Katteker.Gui/UpdateWindow.cs index 2763d87..491bcd3 100644 --- a/Katteker.Gui/UpdateWindow.cs +++ b/Katteker.Gui/UpdateWindow.cs @@ -8,14 +8,18 @@ namespace Katteker.Gui { public sealed partial class UpdateWindow : Form { + private readonly UpdateManager _updateManager; + private readonly ReleaseEntry _entry; private const int HTCAPTION = 0x2; private const int WM_NCLBUTTONDOWN = 0xA1; /// /// The Update Window /// - public UpdateWindow() + public UpdateWindow(UpdateManager updateManager, ReleaseEntry entry) { + _updateManager = updateManager; + _entry = entry; Font = SystemFonts.MessageBoxFont; Application.EnableVisualStyles(); if (Environment.OSVersion.Version.Major >= 6) @@ -23,19 +27,9 @@ namespace Katteker.Gui InitializeComponent(); } - private string Changelog => UpdateManager.ChangelogFilename; - - /// - /// Last release entry. - /// - public ReleaseEntry ReleaseEntry { get; set; } + private string Changelog => _updateManager.ChangelogFilename; - /// - /// Update manager - /// - public UpdateManager UpdateManager { get; set; } - - private string PublishPath => UpdateManager.UrlOrPath; + private string PublishPath => _updateManager.UrlOrPath; /// /// @@ -76,22 +70,40 @@ namespace Katteker.Gui private void Titlebar_MouseDown(object sender, MouseEventArgs e) { + if (e.Button == MouseButtons.Left && e.Clicks >= 2) + { + MaximizeBtn_Click(sender, e); + return; + } if (e.Button != MouseButtons.Left) return; ReleaseCapture(); SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0); } + + private void UpdateWindow_Activated(object sender, EventArgs e) + { + titleLayoutPanel.BackColor = SystemColors.ControlDarkDark; + titleLayoutPanel.ForeColor = SystemColors.Control; + } + + private void UpdateWindow_Deactivate(object sender, EventArgs e) + { + titleLayoutPanel.BackColor = SystemColors.Control; + titleLayoutPanel.ForeColor = SystemColors.ControlText; + } + private async void UpdateWindow_Load(object sender, EventArgs e) { var changelog = await ChangelogHelper.LoadChangelogAsync(Changelog, PublishPath).ConfigureAwait(false); Invoke(new Action(() => changelogBrowser.DocumentText = changelog)); - if (ReleaseEntry == null) + if (_entry == null) { Invoke(new Action(() => { WriteTitle(Resources.No_update_available); })); } else { - var latest = ReleaseEntry.Version; + var latest = _entry.Version; Invoke(new Action(() => { WriteTitle(Resources.You_can_update_to_Version + latest); @@ -107,13 +119,25 @@ namespace Katteker.Gui try { var progress = new Progress(x => Invoke(new Action(() => { progressBar1.Value = x; }))); - await UpdateManager.UpdateAppAsync(progress).ConfigureAwait(false); + await _updateManager.UpdateAppAsync(progress).ConfigureAwait(false); WriteTitle(Resources.You_re_up_to_date); + var messResult = MessageBox.Show( + Resources.Installed_new_Version, + Resources.New_Version, + MessageBoxButtons.YesNo, + MessageBoxIcon.Question); + if (messResult == DialogResult.Yes) + { + DialogResult = DialogResult.OK; + Close(); + } } catch (Exception ex) { - WriteTitle(ex.Message); + MessageBox.Show(Resources.CouldNotUpdateYourApplication + Environment.NewLine + ex.Message, Gui.Properties.Resources.Updater, MessageBoxButtons.OK, MessageBoxIcon.Error); + WriteTitle(Resources.Updater); + } finally { @@ -121,19 +145,10 @@ namespace Katteker.Gui { progressBar1.Visible = false; updBtn.Visible = false; - var messResult = MessageBox.Show( - Resources.Installed_new_Version, - Resources.New_Version, - MessageBoxButtons.YesNo, - MessageBoxIcon.Question); - if (messResult == DialogResult.Yes) - { - DialogResult = DialogResult.OK; - Close(); - } })); } } + private void WriteTitle(string text) { Invoke(new Action(() => diff --git a/Katteker.Gui/UpdateWindow.resx b/Katteker.Gui/UpdateWindow.resx index e69aef3..1af7de1 100644 --- a/Katteker.Gui/UpdateWindow.resx +++ b/Katteker.Gui/UpdateWindow.resx @@ -117,81 +117,4 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.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Xv/9r////Z////2f///6DG - w/+22d7/2v///8X4/f9ehZvPubuYAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACYnpg7apO398// - ///T////p8bM/y8sX/8/MH3/NTBx/zAmXP9bZHv/psbK/8z4+f/Y////jau2/3B7ov98gqf/hZWd/7/m - 4f/a////xe30/8L7/f/a////eqfG/3WEk4EAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGR3 - lbWw5/L/0v///9P///+Jp67/Lydl/zgubP8xOFv/kKmx/9T++//N////1v///6S8wf97d6r/trD//7Wv - //+gm+H/X3GM/7DY3v/N/Pn/1////4691/9Nboa3xMKtBgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALTF - mw2Ln5NQfqPD/9P////N+f//2f///3WKlP8rImH/Nz5m/6zN0P/a////yfv//8z7///N9uj/cn6d/7Wx - +v+srPj/n5ve/3t3ov9JWoD/W4i0/2aax/9chrf/UnKM1K64lRoAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAmpuYUnOEmKuv3+n/z/7//8z8/P/a////b3iN/yYpS/+iw87/1////8z8/P/O/P3/2P///5i9 - 0P9SXoT/doOz/19rkf9IS2D/Z2ls/5GWnP91gpr/ZJDE/0hytf+KlYiDAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAABje5eGbY6k2cX9/v/P/f//yfj7/5/Awv8+SVL/bH2B/+D////J+f//0f///8Pz - +v9smLD/Pl59/2Jmdv9ecZT/ZX6f/6Ouuf////////////r49P+RoKv/UXiw/159lJwAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAGF9nYltlq3cx////9D7///L+f3/v+Pm/6nDyP94nJn/vevn/9f/ - //+75+7/Tnmi/1Jpiv/V2df/9vr4/9Pc4/+CiY3/5ubn/8XHx/+YnJ///////+no4/9aeJz/P2abtgAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAmJyVU3yTl6u97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ZjdH/VH22/3uU - l38AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAg6KaP3KG - jb2MnJd0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAA/wB///8Af///gH///4Af//+AA///AAD//gAAf/4AAD/8AAAf+AAAD/AA - AA/wAAAP4AAAH+AAAB+AAAA/gAAAf4AAAH+AAAB/gAAAP4AAAD/AAAAH8AAAA/gAAAH/gAAB/4ABgf/A - A///wA///8H////A////wP///8H////j//8= - - \ No newline at end of file diff --git a/Katteker.Gui/Wrapper.cs b/Katteker.Gui/Wrapper.cs index 1b7df27..43fe7c5 100644 --- a/Katteker.Gui/Wrapper.cs +++ b/Katteker.Gui/Wrapper.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using Katteker.Gui.Properties; @@ -10,6 +11,8 @@ namespace Katteker.Gui /// public static class Wrapper { + private static UpdateManager _manager; + /// /// Checks for Updates. /// @@ -23,38 +26,36 @@ namespace Katteker.Gui /// Task public static async Task CheckForUpdateAsync(bool isStartup) { - using (var window = new UpdateWindow()) + if (_manager == null && !UpdateManager.TryCreate(out _manager)) { - var dialogResult = DialogResult.Cancel; - if (!UpdateManager.TryCreate(out var manager)) + if (!isStartup) { - if (!isStartup) - { - MessageBox.Show(Resources.SquirrelWrapper_CheckForUpdate, - Resources.SquirrelWrapper_CheckForUpdate_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - return; + MessageBox.Show(Resources.SquirrelWrapper_CheckForUpdate, + Resources.SquirrelWrapper_CheckForUpdate_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } - var releases = (await manager.CheckForUpdateAsync().ConfigureAwait(true)).ToArray(); - window.UpdateManager = manager; - window.ReleaseEntry = releases.LastOrDefault(); - if (isStartup) - { - if (releases?.Any() == true) - { - dialogResult = window.ShowDialog(); - } - } - else - { - dialogResult = window.ShowDialog(); - } + return; + } + var releases = (await _manager.CheckForUpdateAsync().ConfigureAwait(false)).ToArray(); + if (releases.Any() || !isStartup) + { + var thread = new Thread(ThreadProcess); + thread.SetApartmentState(ApartmentState.STA); + thread.Start(releases.LastOrDefault()); + thread.Join(); + } + } + private static void ThreadProcess(object argument) + { + var entry = (ReleaseEntry) argument; + using (var window = new UpdateWindow(_manager, entry)) + { + var dialogResult = window.ShowDialog(); if (dialogResult == DialogResult.OK) { - manager.RestartApp(); + _manager.RestartApp(); } } } diff --git a/Katteker.Gui/ChangelogHelper.cs b/Katteker/ChangelogHelper.cs similarity index 93% rename from Katteker.Gui/ChangelogHelper.cs rename to Katteker/ChangelogHelper.cs index e16f090..545a192 100644 --- a/Katteker.Gui/ChangelogHelper.cs +++ b/Katteker/ChangelogHelper.cs @@ -3,9 +3,9 @@ using System.IO; using System.Net; using System.Threading.Tasks; -namespace Katteker.Gui +namespace Katteker { - internal static class ChangelogHelper + public static class ChangelogHelper { private static string GenerateChangelogAsHtml(string text, string extension) { @@ -27,7 +27,7 @@ namespace Katteker.Gui return result; } - internal static async Task LoadChangelogAsync(string filename, string path) + public static async Task LoadChangelogAsync(string filename, string path) { if (!string.IsNullOrEmpty(filename) || !string.IsNullOrEmpty(path)) { diff --git a/Katteker/Katteker.csproj b/Katteker/Katteker.csproj index 19fa3ab..69a3f38 100644 --- a/Katteker/Katteker.csproj +++ b/Katteker/Katteker.csproj @@ -38,8 +38,10 @@ + + diff --git a/Katteker.Gui/MarkdownSharp.cs b/Katteker/MarkdownSharp.cs similarity index 100% rename from Katteker.Gui/MarkdownSharp.cs rename to Katteker/MarkdownSharp.cs diff --git a/Katteker/Properties/AssemblyInfo.cs b/Katteker/Properties/AssemblyInfo.cs index d98e725..dd23e8e 100644 --- a/Katteker/Properties/AssemblyInfo.cs +++ b/Katteker/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, // indem Sie "*" wie unten gezeigt eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0")] -[assembly: AssemblyFileVersion("1.0.0")] +[assembly: AssemblyVersion("1.0.2")] +[assembly: AssemblyFileVersion("1.0.2")] diff --git a/Katteker/UpdateManager.cs b/Katteker/UpdateManager.cs index 2a4f9eb..acdf67c 100644 --- a/Katteker/UpdateManager.cs +++ b/Katteker/UpdateManager.cs @@ -80,6 +80,7 @@ namespace Katteker return false; } } + public async Task> CheckForUpdateAsync() { _releases = Utility.IsWebUrl(_urlOrPath) ? await DownloadIndexAsync(_urlOrPath).ConfigureAwait(false) : GetFromFilesystem(_urlOrPath); @@ -124,7 +125,7 @@ namespace Katteker var url = urlOrPath.TrimEnd('/'); url += "/" + Constants.RELEASE; var content = await new WebClient().DownloadStringTaskAsync(url).ConfigureAwait(false); - var lines = content.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); + var lines = content.Split(new[] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries); return new Releases(lines); } @@ -136,6 +137,7 @@ namespace Katteker if (!File.Exists(configPath)) throw new FileNotFoundException("Configuration file not found.", configPath); return KattekerConfig.ReadFromFile(configPath); } + private static bool VerifyFileChecksum(string targetFile, string lastEntrySha1) { var hash = Utility.ComputeFileHash(targetFile); @@ -175,35 +177,28 @@ namespace Katteker private async Task UpdateAppImplAsync(ReleaseEntry lastEntry, IProgress progress) { - try + + var targetFile = Path.Combine(_packageDir, lastEntry.Filename); + //download file. + await PutFileInPackageFolderAsync(lastEntry.Filename).ConfigureAwait(false); + progress?.Report(60); + + if (!VerifyFileChecksum(targetFile, lastEntry.SHA1)) throw new FileLoadException(); + progress?.Report(70); + + await KillAppStubAsync().ConfigureAwait(false); + progress?.Report(80); + + using (var updater = new Process()) { - var targetFile = Path.Combine(_packageDir, lastEntry.Filename); - //download file. - await PutFileInPackageFolderAsync(lastEntry.Filename).ConfigureAwait(false); - progress?.Report(60); - - if (!VerifyFileChecksum(targetFile, lastEntry.SHA1)) throw new FileLoadException(); - progress?.Report(70); - - await KillAppStubAsync().ConfigureAwait(false); - progress?.Report(80); - - using (var updater = new Process()) - { - updater.StartInfo = new ProcessStartInfo(targetFile, "/S"); - updater.Start(); - updater.WaitForExit(); - } - progress?.Report(100); - - return true; - } - catch (Exception e) - { - Console.WriteLine(e); + updater.StartInfo = new ProcessStartInfo(targetFile, "/S"); + updater.Start(); + updater.WaitForExit(); } - return false; + progress?.Report(100); + + return true; } } }