Browse Source

Added retry install consent prompt

flabbet 4 years ago
parent
commit
6943bc3870

+ 3 - 3
PixiEditor.UpdateModule/UpdateChecker.cs

@@ -25,9 +25,9 @@ namespace PixiEditor.UpdateModule
         /// <summary>
         ///     Compares version strings and returns true if newVer > originalVer.
         /// </summary>
-        /// <param name="originalVer">Version to compare</param>
-        /// <param name="newVer">Version to compare with</param>
-        /// <returns>True if semantic version is higher</returns>
+        /// <param name="originalVer">Version to compare.</param>
+        /// <param name="newVer">Version to compare with.</param>
+        /// <returns>True if semantic version is higher.</returns>
         public static bool VersionBigger(string originalVer, string newVer)
         {
             if (!ParseVersionString(originalVer, out float ver1))

+ 3 - 1
PixiEditor/ViewModels/SubViewModels/Main/UpdateViewModel.cs

@@ -57,7 +57,9 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
                 bool updateCompatible = await UpdateChecker.IsUpdateCompatible();
                 bool updateFileDoesNotExists = !File.Exists(
                     Path.Join(UpdateDownloader.DownloadLocation, $"update-{UpdateChecker.LatestReleaseInfo.TagName}.zip"));
-                if (updateAvailable && updateFileDoesNotExists)
+                bool updateExeDoesNotExists = !File.Exists(
+                    Path.Join(UpdateDownloader.DownloadLocation, $"update-{UpdateChecker.LatestReleaseInfo.TagName}.exe"));
+                if (updateAvailable && updateFileDoesNotExists && updateExeDoesNotExists)
                 {
                     VersionText = "Downloading update...";
                     if (updateCompatible)

+ 26 - 2
PixiEditor/Views/MainWindow.xaml.cs

@@ -6,6 +6,7 @@ using System.Reflection;
 using System.Windows;
 using System.Windows.Input;
 using PixiEditor.Helpers;
+using PixiEditor.Models.Dialogs;
 using PixiEditor.Models.Processes;
 using PixiEditor.UpdateModule;
 using PixiEditor.ViewModels;
@@ -107,15 +108,38 @@ namespace PixiEditor
         {
             bool alreadyUpdated = AssemblyHelper.GetCurrentAssemblyVersion() ==
                     updateExeFile.Split('-')[1].Split(".exe")[0];
+            string triedInstallFilePath = Path.Join(
+                UpdateDownloader.DownloadLocation,
+                Path.GetFileNameWithoutExtension(updateExeFile) + "restartedToUpdate.txt");
+
             if (!alreadyUpdated)
             {
-                Process.Start(updateExeFile);
-                Close();
+                if (!File.Exists(triedInstallFilePath))
+                {
+                    RestartToUpdate(updateExeFile);
+                    File.Create(triedInstallFilePath);
+                }
+                else
+                {
+                   var result = ConfirmationDialog.Show("Update is ready to install. Do you want to install it now?");
+
+                   if (result == Models.Enums.ConfirmationType.Yes)
+                   {
+                        RestartToUpdate(updateExeFile);
+                   }
+                }
             }
             else
             {
                 File.Delete(updateExeFile);
+                File.Delete(triedInstallFilePath);
             }
         }
+
+        private void RestartToUpdate(string updateExeFile)
+        {
+            Process.Start(updateExeFile);
+            Close();
+        }
     }
 }