Browse Source

fix version check

Veloe 2 years ago
parent
commit
30ad3a3308

+ 1 - 6
VeloeLauncherUpdater/Program.cs

@@ -48,15 +48,10 @@ try
 
         if (latestLauncherVersion != null)
         {
-            string[] version = latestLauncherVersion.latest.Split('.');
             logger.Information("Latest launcher version on server: {0}", latestLauncherVersion.latest);
-            string[] versionOnServer = fileVersionInfo.FileVersion.Split('.');
             logger.Information("Launcher version: {0}", fileVersionInfo.FileVersion);
 
-            if (!(Int16.Parse(version[0]) > Int16.Parse(versionOnServer[0]) ||
-                Int16.Parse(version[1]) > Int16.Parse(versionOnServer[1]) ||
-                Int16.Parse(version[2]) > Int16.Parse(versionOnServer[2]) ||
-                Int16.Parse(version[3]) > Int16.Parse(versionOnServer[3])))
+            if (!(new Version(latestLauncherVersion.latest) > new Version(fileVersionInfo.FileVersion)))
             {
                 logger.Information("No update required.");
                 return;

+ 2 - 0
VeloeLauncherUpdater/VeloeLauncherUpdater.csproj

@@ -6,6 +6,8 @@
     <ImplicitUsings>enable</ImplicitUsings>
     <Nullable>enable</Nullable>
     <DebugType>embedded</DebugType>
+    <AssemblyVersion>1.0.1.0</AssemblyVersion>
+    <FileVersion>1.0.1.0</FileVersion>
   </PropertyGroup>
 
   <ItemGroup>

+ 7 - 17
VeloeMinecraftLauncher/ViewModels/MainWindowViewModel.cs

@@ -77,18 +77,13 @@ namespace VeloeMinecraftLauncher.ViewModels
                     {
                         logger.Information("Launcher version on server: {0}", latestLauncherInfo.latest);
                         logger.Information("Launcher version: {0}", Assembly.GetExecutingAssembly().GetName().Version);
-                        string[] version = latestLauncherInfo.latest.Split('.');
 
-                        var vat = Assembly.GetExecutingAssembly().GetName().Version;
-
-                        if (Int16.Parse(version[0]) > Assembly.GetExecutingAssembly().GetName().Version.Major ||
-                            Int16.Parse(version[1]) > Assembly.GetExecutingAssembly().GetName().Version.Minor ||
-                            Int16.Parse(version[2]) > Assembly.GetExecutingAssembly().GetName().Version.Build ||
-                            Int16.Parse(version[3]) > Assembly.GetExecutingAssembly().GetName().Version.Revision)
+                        if (new Version(latestLauncherInfo.latest) > Assembly.GetExecutingAssembly().GetName().Version)
                         {
                             logger.Debug("Update available!");
                             IsUpdateAvailable = true;
                         }
+
                     }
                 }
                 catch (Exception ex)
@@ -694,19 +689,14 @@ namespace VeloeMinecraftLauncher.ViewModels
                         return;
                     }
 
-                        if (latestLauncherVersion != null)
+                    if (latestLauncherVersion != null)
                     {
-                        string[] version = latestLauncherVersion.updater.Split('.');
                         logger.Information("Latest updater version on server: {0}", latestLauncherVersion.updater);
-                        string[] versionOnServer = fileVersionInfo.FileVersion.Split('.');
                         logger.Information("Updater version: {0}", fileVersionInfo.FileVersion);
 
-                        if (!(Int16.Parse(version[0]) > Int16.Parse(versionOnServer[0]) ||
-                            Int16.Parse(version[1]) > Int16.Parse(versionOnServer[1]) ||
-                            Int16.Parse(version[2]) > Int16.Parse(versionOnServer[2]) ||
-                            Int16.Parse(version[3]) > Int16.Parse(versionOnServer[3])))
+                        if (!(new Version(latestLauncherVersion.updater) > new Version(fileVersionInfo.FileVersion)))
                         {
-                            logger.Information("No update required.");
+                            logger.Information($"No update for \"{fileName}\" required.");
                             return;
                         }
                     }
@@ -727,14 +717,14 @@ namespace VeloeMinecraftLauncher.ViewModels
                     if (url == String.Empty)
                         return;
 
-                    webClient.DownloadFile(new System.Uri(url), "updater.zip"); ;
+                    webClient.DownloadFile(new System.Uri(url), "updater.zip");
                 }
                 catch (Exception ex)
                 {
                     logger.Error("Error occured on getting updater.zip from the server.");
                     throw;
                 }
-
+                webClient.Dispose();
                 logger.Information("Unpacking updater.zip");
                 ZipFile.ExtractToDirectory($"updater.zip", Directory.GetCurrentDirectory(), true);