Ver Fonte

added launcher update from linux, fix breaking change in .net 8

Veloe há 1 ano atrás
pai
commit
39b872f29a

+ 1 - 0
.gitignore

@@ -366,3 +366,4 @@ FodyWeavers.xsd
 /launcher_profiles.json
 /settings.json
 /VeloeMinecraftLauncher/Properties/launchSettings.json
+/VeloeLauncherUpdater/Properties/launchSettings.json

+ 24 - 15
VeloeLauncherUpdater/Program.cs

@@ -3,14 +3,22 @@ using Serilog;
 using Serilog.Events;
 using System.Diagnostics;
 using System.IO.Compression;
+using System.Reflection;
 using System.Text.Json;
 using VeloeLauncherUpdater;
 
+if (args.Length > 0 && args[0] == "--version")
+{
+    Console.WriteLine(Assembly.GetExecutingAssembly().GetName().Version);
+    return;
+}
+
+if (args.Length > 0) return;
+
 var logger = new LoggerConfiguration()
     .MinimumLevel.Debug()
     .WriteTo.File("update.log", LogEventLevel.Debug)// restricted... is Optional
     .CreateLogger();
-
 try
 {
     string fileName = "VeloeMinecraftLauncher";
@@ -18,14 +26,9 @@ try
 
     if (OperatingSystem.IsWindows())
         fileName += ".exe";
-    if (File.Exists(fileName))
-    {
-        if (OperatingSystem.IsLinux())
-        {
-            logger.Information("Manual updates only.");
-            return;
-        }
 
+    if (OperatingSystem.IsWindows() && File.Exists(fileName))
+    {
         FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(fileName);
         LatestLauncherVersion? latestLauncherVersion;
 
@@ -57,19 +60,25 @@ try
         }
     }
     
+    if(OperatingSystem.IsLinux())
+    {
+        logger.Warning("Force update mode only.");
+    }
+
     try
     {
         logger.Information("Downloading latest.zip");
         string url = String.Empty;
 
-        if (OperatingSystem.IsWindows())
-            url = "https://files.veloe.link/launcher/update/latest.zip";
-
-        if (OperatingSystem.IsLinux())
-            url = "https://files.veloe.link/launcher/update/latest_linux-x64.zip";
+        url = OperatingSystem.IsWindows() ? 
+                OperatingSystem.IsWindowsVersionAtLeast(10, 0, 14393) ? 
+                    "https://files.veloe.link/launcher/update/latest.zip" : 
+                    "https://files.veloe.link/launcher/update/latest_net7.0.zip" : 
+                OperatingSystem.IsLinux() ?
+                    "https://files.veloe.link/launcher/update/latest_linux-x64.zip" :
+                    string.Empty;
 
-        if (url == String.Empty)
-            return;
+        if (url == String.Empty) return;
 
         using HttpResponseMessage response = await httpClient.GetAsync(new System.Uri(url), HttpCompletionOption.ResponseHeadersRead);
         response.EnsureSuccessStatusCode();

+ 3 - 3
VeloeLauncherUpdater/VeloeLauncherUpdater.csproj

@@ -2,12 +2,12 @@
 
   <PropertyGroup>
 	  <OutputType>WinExe</OutputType>
-    <TargetFramework>net8.0</TargetFramework>
+    <TargetFramework>net7.0</TargetFramework>
     <ImplicitUsings>enable</ImplicitUsings>
     <Nullable>enable</Nullable>
     <DebugType>embedded</DebugType>
-    <AssemblyVersion>1.0.1.3</AssemblyVersion>
-    <FileVersion>1.0.1.3</FileVersion>
+    <AssemblyVersion>1.0.2.0</AssemblyVersion>
+    <FileVersion>1.0.2.0</FileVersion>
   </PropertyGroup>
 
   <ItemGroup>

+ 2 - 2
VeloeMinecraftLauncher/VeloeMinecraftLauncher.csproj

@@ -10,8 +10,8 @@
 		<DebugType>embedded</DebugType>
 		<StartupObject>VeloeMinecraftLauncher.Program</StartupObject>
 		<PlatformTarget>x64</PlatformTarget>
-		<AssemblyVersion>1.5.0.29</AssemblyVersion>
-		<FileVersion>1.5.0.29</FileVersion>
+		<AssemblyVersion>1.5.0.48</AssemblyVersion>
+		<FileVersion>1.5.0.48</FileVersion>
 		<Configurations>Debug;Release</Configurations>
 	</PropertyGroup>
 	<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

+ 24 - 13
VeloeMinecraftLauncher/ViewModels/MainWindowViewModel.cs

@@ -502,7 +502,6 @@ public class MainWindowViewModel : ViewModelBase
                     UseShellExecute = false,
                     RedirectStandardOutput = true,
                     RedirectStandardError = true,
-                    WindowStyle = ProcessWindowStyle.Hidden,
                     CreateNoWindow = true,
                     FileName = Path.GetFullPath(Path.Combine(Settings.minecraftForlderPath, javaPath)),
                     StandardErrorEncoding = Encoding.UTF8,
@@ -763,28 +762,40 @@ public class MainWindowViewModel : ViewModelBase
                 fileName += ".exe";
             if (File.Exists(fileName))
             {
-                FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(fileName);
                 var latestLauncherVersion = await Downloader.DownloadAndDeserializeJsonData<LatestLauncherVersion>("https://files.veloe.link/launcher/update/versions.json");
-
-                if (OperatingSystem.IsLinux())
+                
+                if (OperatingSystem.IsWindows())
                 {
-                    _logger.Information("Manual updates only.");
-                    return;
-                }
+                    FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(fileName);
+                    if (latestLauncherVersion?.Updater is not null && fileVersionInfo?.FileVersion is not null)
+                    {
+                        _logger.Information("Latest updater version on server: {0}", latestLauncherVersion.Updater);
+                        _logger.Information("Updater version: {0}", fileVersionInfo.FileVersion);
 
-                if (latestLauncherVersion?.Updater is not null && fileVersionInfo?.FileVersion is not null)
+                        if (!(new Version(latestLauncherVersion.Updater) > new Version(fileVersionInfo.FileVersion)))
+                        {
+                            _logger.Information($"No update for \"{fileName}\" required.");
+                            return;
+                        }
+                    }
+                    else
+                        _logger.Warning("Version verification for {0} failed: latestLauncherVersion or fileVersionInfo does not contain version info or null!", fileName);
+                }
+                
+                if (OperatingSystem.IsLinux())
                 {
-                    _logger.Information("Latest updater version on server: {0}", latestLauncherVersion.Updater);
-                    _logger.Information("Updater version: {0}", fileVersionInfo.FileVersion);
+                    using var updaterProcess = Process.Start(new ProcessStartInfo() { FileName = fileName, Arguments = " --version", RedirectStandardOutput = true });
+                    updaterProcess.WaitForExit();
 
-                    if (!(new Version(latestLauncherVersion.Updater) > new Version(fileVersionInfo.FileVersion)))
+                    var versionStr = System.Text.RegularExpressions.Regex.Match(updaterProcess.StandardOutput.ReadToEnd(), "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+").Value;
+                    if (!string.IsNullOrWhiteSpace(versionStr) && 
+                        latestLauncherVersion?.Updater is not null && 
+                        !(new Version(latestLauncherVersion.Updater) > new Version(versionStr)))
                     {
                         _logger.Information($"No update for \"{fileName}\" required.");
                         return;
                     }
                 }
-                else
-                    _logger.Warning("Version verification for {0} failed: latestLauncherVersion or fileVersionInfo does not contain version info or null!", fileName);
             }
                            
             try