From f41488307f5dd6cd0bbbecb90a9cf5489098081e Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Mon, 18 Jan 2021 15:22:47 -0800 Subject: [PATCH] Further improvements for update handling. IO-408 --- BodyshopUploader/Properties/AssemblyInfo.cs | 2 +- .../Properties/Resources.Designer.cs | 2 +- BodyshopUploader/Properties/Resources.resx | 2 +- BodyshopUploader/Releases/RELEASES | 7 ++++ BodyshopUploader/Utils/SquirrelAwareHelper.cs | 14 ++++++-- BodyshopUploader/Utils/UpdateHandler.cs | 32 ++++++++++++++++--- .../ViewModels/MainViewModel.commands.cs | 4 +-- BodyshopUploader/ViewModels/MainViewModel.cs | 19 ++--------- BodyshopUploader/Views/Main.xaml | 5 +-- 9 files changed, 56 insertions(+), 31 deletions(-) create mode 100644 BodyshopUploader/Releases/RELEASES diff --git a/BodyshopUploader/Properties/AssemblyInfo.cs b/BodyshopUploader/Properties/AssemblyInfo.cs index f60b4b7..e90f239 100644 --- a/BodyshopUploader/Properties/AssemblyInfo.cs +++ b/BodyshopUploader/Properties/AssemblyInfo.cs @@ -51,7 +51,7 @@ 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.0.0")] +[assembly: AssemblyVersion("1.0.4.0")] [assembly: AssemblyFileVersion("1.0.0.0")] //Setting Squirrel Aware Version. [assembly: AssemblyMetadata("SquirrelAwareVersion", "1")] \ No newline at end of file diff --git a/BodyshopUploader/Properties/Resources.Designer.cs b/BodyshopUploader/Properties/Resources.Designer.cs index 89def06..d259576 100644 --- a/BodyshopUploader/Properties/Resources.Designer.cs +++ b/BodyshopUploader/Properties/Resources.Designer.cs @@ -160,7 +160,7 @@ namespace BodyshopPartner.Properties { } /// - /// Looks up a localized string similar to Browse for QB File. + /// Looks up a localized string similar to Browse for QuickBooks File. /// public static string Label_BrowseForQb { get { diff --git a/BodyshopUploader/Properties/Resources.resx b/BodyshopUploader/Properties/Resources.resx index 819ee27..c9f99f9 100644 --- a/BodyshopUploader/Properties/Resources.resx +++ b/BodyshopUploader/Properties/Resources.resx @@ -151,7 +151,7 @@ Auto-start Monitors - Browse for QB File + Browse for QuickBooks File File Path diff --git a/BodyshopUploader/Releases/RELEASES b/BodyshopUploader/Releases/RELEASES new file mode 100644 index 0000000..662aeee --- /dev/null +++ b/BodyshopUploader/Releases/RELEASES @@ -0,0 +1,7 @@ +CC5A9E1708874E6ACB29A5622DFD9C5772230727 ImEXOnlinePartner-1.0.0-full.nupkg 4937580 +7C5340F2B41ECAAA84BEE8ACD790135A64485D29 ImEXOnlinePartner-1.0.1-delta.nupkg 36746 +DCD839653F086BCA57F1D32A5235FFD63656E828 ImEXOnlinePartner-1.0.1-full.nupkg 4936984 +AF4689DFA19C7EAC5E1F03DFCF298A05B550198B ImEXOnlinePartner-1.0.2-delta.nupkg 30212 +F2D64AFC971565D6A6AB3C69D39918BA651D2BB3 ImEXOnlinePartner-1.0.2-full.nupkg 4938834 +B28BABEA8C23215EE92CD691B8F69CEEC40D04C8 ImEXOnlinePartner-1.0.3-delta.nupkg 30700 +CA43E2BC60A8A67126609C5682AA3D39D68D2400 ImEXOnlinePartner-1.0.3-full.nupkg 4935967 \ No newline at end of file diff --git a/BodyshopUploader/Utils/SquirrelAwareHelper.cs b/BodyshopUploader/Utils/SquirrelAwareHelper.cs index b72dcde..9390586 100644 --- a/BodyshopUploader/Utils/SquirrelAwareHelper.cs +++ b/BodyshopUploader/Utils/SquirrelAwareHelper.cs @@ -63,12 +63,20 @@ namespace BodyshopPartner.Utils { logger.Fatal("Unable to set exception for http port", Ex.ToString()); } - + Utils.UpdateHandler.ToggleStartWithWindows(true); mgr.CreateShortcutForThisExe(); }, - onAppUpdate: v => mgr.CreateShortcutForThisExe(), + onAppUpdate: v => { + mgr.CreateShortcutForThisExe(); + Utils.UpdateHandler.ToggleStartWithWindows(Properties.Settings.Default.StartWithWindows); + }, onAppUninstall: v => mgr.RemoveShortcutForThisExe(), - onFirstRun: () => { logger.Info("We've run for the first time."); }); + onFirstRun: () => + { + logger.Info("We've run for the first time."); + + Utils.UpdateHandler.ToggleStartWithWindows(true); + }); } } } diff --git a/BodyshopUploader/Utils/UpdateHandler.cs b/BodyshopUploader/Utils/UpdateHandler.cs index b556284..54a7902 100644 --- a/BodyshopUploader/Utils/UpdateHandler.cs +++ b/BodyshopUploader/Utils/UpdateHandler.cs @@ -1,4 +1,5 @@ -using Squirrel; +using Microsoft.Win32; +using Squirrel; using System; using System.Collections.Generic; using System.Configuration; @@ -13,6 +14,25 @@ namespace BodyshopPartner.Utils { public static class UpdateHandler { + + public static void ToggleStartWithWindows(bool shouldStart) + { + + RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); + if (shouldStart) + { + // Add the value in the registry so that the application runs at startup + rkApp.SetValue(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, System.Reflection.Assembly.GetEntryAssembly().Location); + } + else + { + // Remove the value from the registry so that the application doesn't start + rkApp.DeleteValue(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, false); + } + + } + + private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); public const string UpdatePath = @"http://partner.imex.online/"; @@ -22,6 +42,7 @@ namespace BodyshopPartner.Utils try { logger.Debug("Checking if updates are available."); + using (var updateManager = new UpdateManager(UpdatePath)) { var updateInfo = await updateManager.CheckForUpdate(); @@ -44,7 +65,9 @@ namespace BodyshopPartner.Utils } - public static async Task ApplyUpdates(int DownloadProgress, int InstallProgress) + public delegate void DownloadProgress(int value); + public delegate void InstallProgress(int value); + public static async Task ApplyUpdates(DownloadProgress DownloadProgress, InstallProgress InstallProgress) { try { @@ -65,13 +88,14 @@ namespace BodyshopPartner.Utils await updateManager.DownloadReleases(releases, _ => { logger.Debug("Download Release Progress " + _.ToString()); - DownloadProgress = _; + DownloadProgress(_); }); await updateManager.ApplyReleases(updateInfo, _ => { logger.Debug("Install Progress " + _.ToString()); - InstallProgress = _; + InstallProgress(_); }); + UpdateManager.RestartApp(System.Reflection.Assembly.GetEntryAssembly().Location); } catch (Exception Ex) { diff --git a/BodyshopUploader/ViewModels/MainViewModel.commands.cs b/BodyshopUploader/ViewModels/MainViewModel.commands.cs index 9464a33..84d8254 100644 --- a/BodyshopUploader/ViewModels/MainViewModel.commands.cs +++ b/BodyshopUploader/ViewModels/MainViewModel.commands.cs @@ -148,7 +148,7 @@ namespace BodyshopPartner.ViewModels async p => { await InstallUpdates(); - UpdateAvailable = false; + }); } return _installUpdatesCommand; @@ -203,7 +203,7 @@ namespace BodyshopPartner.ViewModels p => true, p => { - ToggleStartWithWindows((bool)(p)); + Utils.UpdateHandler.ToggleStartWithWindows((bool)(p)); }); } return _startWithWindowsCommand; diff --git a/BodyshopUploader/ViewModels/MainViewModel.cs b/BodyshopUploader/ViewModels/MainViewModel.cs index 686c7b1..06068b3 100644 --- a/BodyshopUploader/ViewModels/MainViewModel.cs +++ b/BodyshopUploader/ViewModels/MainViewModel.cs @@ -97,12 +97,13 @@ namespace BodyshopPartner.ViewModels } } + private async Task InstallUpdates() { logger.Debug("Updates are available! Installing."); try { - await Utils.UpdateHandler.ApplyUpdates(UpdateProgress, UpdateProgress); + await Utils.UpdateHandler.ApplyUpdates((val) => UpdateProgress = val, (val) => UpdateProgress = val); } catch (Exception Ex) @@ -198,22 +199,6 @@ namespace BodyshopPartner.ViewModels App.Current.Shutdown(); } - public void ToggleStartWithWindows(bool shouldStart) - { - - RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); - if (shouldStart) - { - // Add the value in the registry so that the application runs at startup - rkApp.SetValue(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, System.Reflection.Assembly.GetEntryAssembly().Location); - } - else - { - // Remove the value from the registry so that the application doesn't start - rkApp.DeleteValue(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, false); - } - - } public async Task LoadBodyshopData() { diff --git a/BodyshopUploader/Views/Main.xaml b/BodyshopUploader/Views/Main.xaml index 22a0a9a..f913dc5 100644 --- a/BodyshopUploader/Views/Main.xaml +++ b/BodyshopUploader/Views/Main.xaml @@ -149,12 +149,13 @@ Margin="8" Content="{x:Static p:Resources.Label_BrowseForQb}" /> -