Pārlūkot izejas kodu

Merge branch 'master' into development

flabbet 2 gadi atpakaļ
vecāks
revīzija
79266513b3

+ 1 - 1
src/Installer/installer-setup-x64-light.iss

@@ -10,7 +10,7 @@
 
 // custom setup info
 #define MyAppName "PixiEditor"
-#define MyAppVersion GetFileVersion("..\Builds\PixiEditor-x64-light\PixiEditor\PixiEditor.exe")     ;Not perfect solution, it's enviroment dependend
+#define MyAppVersion GetFileVersion("..\..\Builds\PixiEditor-x64-light\PixiEditor\PixiEditor.exe")     ;Not perfect solution, it's enviroment dependend
 #define MyAppPublisher "PixiEditor"
 #define MyAppURL "https://github.com/PixiEditor/PixiEditor"
 #define MyAppExeName "PixiEditor.exe"

+ 1 - 1
src/Installer/installer-setup-x86-light.iss

@@ -10,7 +10,7 @@
 
 // custom setup info
 #define MyAppName "PixiEditor"
-#define MyAppVersion GetFileVersion("..\Builds\PixiEditor-x86-light\PixiEditor\PixiEditor.exe")     ;Not perfect solution, it's enviroment dependend
+#define MyAppVersion GetFileVersion("..\..\Builds\PixiEditor-x86-light\PixiEditor\PixiEditor.exe")     ;Not perfect solution, it's enviroment dependend
 #define MyAppPublisher "PixiEditor"
 #define MyAppURL "https://github.com/PixiEditor/PixiEditor"
 #define MyAppExeName "PixiEditor.exe"

+ 29 - 1
src/PixiEditor.UpdateModule/UpdateChecker.cs

@@ -45,6 +45,33 @@ public class UpdateChecker
     {
         return NormalizeVersionString(originalVer) != NormalizeVersionString(newVer);
     }
+    
+    /// <summary>
+    ///     Checks if originalVer is smaller than newVer
+    /// </summary>
+    /// <param name="originalVer">Version on the left side of the equation</param>
+    /// <param name="newVer">Version to compare to</param>
+    /// <returns>True if originalVer is smaller than newVer.</returns>
+    public static bool VersionSmaller(string originalVer, string newVer)
+    {
+        string normalizedOriginal = NormalizeVersionString(originalVer);
+        string normalizedNew = NormalizeVersionString(newVer);
+
+        if (normalizedOriginal == normalizedNew) return false;
+
+        bool parsed = TryParseToFloatVersion(normalizedOriginal, out float orgFloat);
+        if (!parsed) throw new Exception($"Couldn't parse version {originalVer} to float.");
+
+        parsed = TryParseToFloatVersion(normalizedNew, out float newFloat);
+        if (!parsed) throw new Exception($"Couldn't parse version {newVer} to float.");
+
+        return orgFloat < newFloat;
+    }
+
+    private static bool TryParseToFloatVersion(string normalizedString, out float ver)
+    {
+        return float.TryParse(normalizedString.Replace(".", string.Empty).Insert(1, "."), NumberStyles.Any, CultureInfo.InvariantCulture, out ver);
+    }
 
     public async Task<bool> CheckUpdateAvailable()
     {
@@ -65,7 +92,8 @@ public class UpdateChecker
     public async Task<bool> IsUpdateCompatible()
     {
         string[] incompatibleVersions = await GetUpdateIncompatibleVersionsAsync(LatestReleaseInfo.TagName);
-        return IsUpdateCompatible(incompatibleVersions);
+        bool isDowngrading = VersionSmaller(LatestReleaseInfo.TagName, CurrentVersionTag);
+        return IsUpdateCompatible(incompatibleVersions) && !isDowngrading; // Incompatible.json doesn't support backwards compatibility, thus downgrading always means update is not compatble
     }
 
     public async Task<string[]> GetUpdateIncompatibleVersionsAsync(string tag)

+ 2 - 2
src/PixiEditor/Properties/AssemblyInfo.cs

@@ -50,5 +50,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("0.1.9.3")]
-[assembly: AssemblyFileVersion("0.1.9.3")]
+[assembly: AssemblyVersion("0.1.9.4")]
+[assembly: AssemblyFileVersion("0.1.9.4")]

+ 8 - 2
src/PixiEditor/ViewModels/SubViewModels/Main/UpdateViewModel.cs

@@ -43,7 +43,7 @@ internal class UpdateViewModel : SubViewModel<ViewModelMain>
             RaisePropertyChanged(nameof(UpdateReadyToInstall));
             if (value)
             {
-                VersionText = $"to install update (current {VersionHelpers.GetCurrentAssemblyVersionString()})"; // Button shows "Restart" before this text
+                VersionText = $"to install update ({UpdateChecker.LatestReleaseInfo.TagName})"; // Button shows "Restart" before this text
             }
         }
     }
@@ -105,7 +105,13 @@ internal class UpdateViewModel : SubViewModel<ViewModelMain>
                     $"update-{UpdateChecker.LatestReleaseInfo.TagName}.exe");
 
                 bool updateExeExists = File.Exists(exePath);
-                
+
+                if (updateExeExists && !UpdateChecker.VersionDifferent(UpdateChecker.LatestReleaseInfo.TagName, UpdateChecker.CurrentVersionTag))
+                {
+                    File.Delete(exePath);
+                    updateExeExists = false;
+                }
+
                 string updaterPath = Path.Join(dir, "PixiEditor.UpdateInstaller.exe");
 
                 if (updateFileExists || updateExeExists)