Bladeren bron

Fixed update process

Kenric Nugteren 5 maanden geleden
bovenliggende
commit
2ef49a766e

+ 10 - 6
prs.desktop/Forms/Issues/IssuesGrid.cs

@@ -12,6 +12,7 @@ using System.Threading.Tasks;
 using System.Windows.Controls;
 using System.Windows.Media;
 using InABox.Wpf;
+using System.Windows;
 
 namespace PRSDesktop.Forms.Issues;
 
@@ -92,8 +93,6 @@ public class IssuesGrid : DynamicGrid<Kanban>, ISpecificGrid
     {
         return new UIComponent(this);
     }
-    
-
 
     protected override void Init()
     {
@@ -110,16 +109,21 @@ public class IssuesGrid : DynamicGrid<Kanban>, ISpecificGrid
         return false;
     }
 
-    
-
     private bool CheckForUpdates(Button button, CoreRow[] rows)
     {
-        if (!SupportUtils.CheckForUpdates())
+        if (SupportUtils.CheckForUpdates())
+        {
+            Application.Current.Shutdown();
+        }
+        else
         {
             if (MessageWindow.ShowYesNo(
                     "You appear to be using the latest version already!\n\nRun the installer anyway?", "Update"))
             {
-                SupportUtils.DownloadAndRunInstaller();
+                if (SupportUtils.DownloadAndRunInstaller())
+                {
+                    Application.Current.Shutdown();
+                }
             }
         }
         return false;

+ 15 - 3
prs.desktop/MainWindow.xaml.cs

@@ -275,7 +275,12 @@ public partial class MainWindow : IPanelHostControl
         Title = $"{(String.Equals(App.Profile?.ToUpper(), "DEFAULT") ? "PRS Desktop" : App.Profile)} (Release {CoreUtils.GetVersion()})";
         
         Logger.Send(LogType.Information, "", "Checking for updates");
-        SupportUtils.CheckForUpdates();
+        if (SupportUtils.CheckForUpdates())
+        {
+            Logger.Send(LogType.Information, "", "Update found, closing application.");
+            Close();
+            return;
+        }
 
         Exception? startupException = null;
         ValidationStatus? loginStatus = null;
@@ -2975,12 +2980,19 @@ public partial class MainWindow : IPanelHostControl
     
     private void CheckForUpdates_OnClick(object sender, RoutedEventArgs e)
     {
-        if (!SupportUtils.CheckForUpdates())
+        if (SupportUtils.CheckForUpdates())
+        {
+            Close();
+        }
+        else
         {
             if (MessageWindow.ShowYesNo(
                     "You appear to be using the latest version already!\n\nRun the installer anyway?", "Update"))
             {
-                SupportUtils.DownloadAndRunInstaller();
+                if (SupportUtils.DownloadAndRunInstaller())
+                {
+                    Close();
+                }
             }
         }
     }

+ 4 - 3
prs.desktop/Utils/SupportUtils.cs

@@ -106,14 +106,15 @@ public static class SupportUtils
             GetUpdateLocation, GetLatestVersion, GetReleaseNotes, GetInstaller, null, App.AutoUpdateSettings.Elevated, "PRSDesktopSetup.exe");
     }
 
-    public static void DownloadAndRunInstaller()
+    public static bool DownloadAndRunInstaller()
     {
+        bool? result = null;
         InABox.WPF.Progress.ShowModal("Retrieving Update", progress =>
         {
-            Update.DownloadAndRunInstaller(GetInstaller, null, App.AutoUpdateSettings.Elevated, GetUpdateLocation(),
+            result = Update.DownloadAndRunInstaller(GetInstaller, null, App.AutoUpdateSettings.Elevated, GetUpdateLocation(),
                 "PRSDesktopSetup.exe", progress);
         });
-
+        return result == null || result == true;
     }
 
 }

+ 5 - 0
prs.licensing/GUI/Console.xaml.cs

@@ -108,6 +108,11 @@ public partial class Console : Window, INotifyPropertyChanged
         Title = Title = $"PRS Licensing (Release {CoreUtils.GetVersion()})";
         var isUpdateAvailable = Update.CheckForUpdates(
             GetUpdateLocation, GetLatestVersion, GetReleaseNotes, null, null, false, "");
+        if (isUpdateAvailable)
+        {
+            Close();
+            return;
+        }
         
         RefreshStatus();
         Progress.ShowModal("Registering Classes", progress =>

+ 6 - 3
prs.shared/Update.cs

@@ -120,13 +120,16 @@ namespace PRS.Shared
                 if (getInstaller == null)
                     return true;
                 
-                var bOK = false;
+                bool? bOK = null;
                 Progress.ShowModal("Retrieving Update", progress =>
                 {
                     bOK = DownloadAndRunInstaller(getInstaller, beforeUpdate, elevated, location, tempName, progress);
                 });
-                if (bOK)
+                if (bOK is null || bOK == true)
+                {
+                    // In this case, the Progress window was closed by the installer, and so we must close our current window.
                     return true;
+                }
 
                 MessageBox.Show("Unable to retrieve installer!");
                 return false;
@@ -134,7 +137,7 @@ namespace PRS.Shared
             return false;
         }
 
-        public static bool DownloadAndRunInstaller(Func<string, byte[]?>? getInstaller, Action? beforeUpdate, bool elevated, string location,
+        public static bool DownloadAndRunInstaller(Func<string, byte[]?> getInstaller, Action? beforeUpdate, bool elevated, string location,
             string tempName, IProgress<string> progress)
         {
             bool bOK = false;