Browse Source

downloader class refactoring, added fabric libs download, fixed username for old versions, fixed fablic start for 1.5.2 (for BTW mod), net version and packets updated

Veloe 1 year ago
parent
commit
71735ccfae

+ 1 - 1
VeloeLauncherUpdater/VeloeLauncherUpdater.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
 	  <OutputType>WinExe</OutputType>
-    <TargetFramework>net6.0</TargetFramework>
+    <TargetFramework>net8.0</TargetFramework>
     <ImplicitUsings>enable</ImplicitUsings>
     <Nullable>enable</Nullable>
     <DebugType>embedded</DebugType>

+ 1 - 0
VeloeMinecraftLauncher/Models/Entity/Version/Version.cs

@@ -99,6 +99,7 @@ public class Library
 {
     public Downloads Downloads { get; set; }
     public string Name { get; set; }
+    public string Url { get; set; }
     public List<Rule> Rules { get; set; }
     //public Extract Extract { get; set; }
     public Natives Natives { get; set; }

File diff suppressed because it is too large
+ 524 - 518
VeloeMinecraftLauncher/Utils/Downloader.cs


+ 59 - 0
VeloeMinecraftLauncher/Utils/DownloaderParameters.cs

@@ -0,0 +1,59 @@
+using System;
+using VeloeMinecraftLauncher.Models.Entity;
+
+namespace VeloeMinecraftLauncher.Utils
+{
+    public class DownloaderParameters
+    {
+        public Actions Action { get; set; } = new Actions();
+
+        public Parameters Parameter { get; set; } = new Parameters();
+
+        public DataModels Data { get; set; } = new DataModels();
+
+        public class Actions
+        {
+
+            /// <summary>
+            /// Action for set downloading file status outside (on ui)
+            /// </summary>
+            public Action<string> DownloadingFileName { get; set; } = value => { };
+            /// <summary>
+            /// Action for set overall downloading status outside (on ui)
+            /// </summary>
+            public Action<string> TasksStatus { get; set; } = value => { };
+            /// <summary>
+            /// Action for set lock ui command
+            /// </summary>
+            public Action<bool> IsControlsEnabled { get; set; } = value => {};
+            /// <summary>
+            /// Action for set progress bar value outside (on ui)
+            /// </summary>
+            public Action<long> SetProgress { get; set; } = value => { };
+        }
+
+        public class Parameters
+        {
+            public bool DownloadJava { get; set; } = false;
+            public bool InstallForge { get; set; } = false;
+            public bool InstallOptifine { get; set; } = false;
+            public bool InstallForgeOptifine { get; set; } = false;
+            public bool InstallFabric { get; set; } = false;
+        }
+
+        public class DataModels
+        {
+            /// <summary>
+            /// Selected version model from versions manifest json file
+            /// </summary>
+            public Entity.VersionManifest.Version? SelectedVersion { get; set; } = null;
+
+            public Entity.Version.Version? VersionJson { get; set; } = null;
+
+            /// <summary>
+            /// Selected modpack from modpacks list json file
+            /// </summary>
+            public Modpack? SelectedModpack { get; set; } = null;
+        }
+    }
+}

+ 28 - 9
VeloeMinecraftLauncher/Utils/StartCommandBuilder.cs

@@ -6,7 +6,6 @@ using System.Linq;
 using System.Security.Cryptography;
 using System.Text;
 using System.Text.Json;
-using VeloeMinecraftLauncher.Entity.Version;
 
 namespace VeloeMinecraftLauncher.Utils;
 
@@ -149,7 +148,11 @@ internal static class StartCommandBuilder
                     if (argument is null ||
                         argument is not JsonElement jsonArgument ||
                         jsonArgument.ValueKind != JsonValueKind.String ||
-                        jsonArgument.Deserialize(typeof(string)) is not string value) continue;
+                        jsonArgument.Deserialize(typeof(string)) is not string value ||
+                        value.Contains("-Djava.library.path") || //this for fabric for 1.5.2
+                        value.Contains("-cp") ||                // this args already added to args
+                        value.Equals("${classpath}")) continue;
+              
 
                     //for new forge versions (1.18, 1.19)
                     if (value.Contains("${version_name}"))
@@ -284,6 +287,16 @@ internal static class StartCommandBuilder
             }
         }
 
+        //for old versions username fix
+
+        if (!args.Contains("--username"))
+            returnString.Append(" " + username);
+
+        if (!args.Contains("--uuid")) // or maybe uuid
+            returnString.Append(" " + NameUUIDFromBytes(Encoding.UTF8.GetBytes($"OfflinePlayer:{username}")).ToString());
+
+        // add ${auth_session} for old versions
+
         for (int i = 0; i < args.Count; i++)
         {
             switch (args[i])
@@ -346,6 +359,19 @@ internal static class StartCommandBuilder
     }
 
     public static string GetLibPathFromName(string name)
+    {
+        string libPath = GetLibRelativePathFromName(name);
+
+#if DEBUG
+        if (File.Exists(Settings.minecraftForlderPath + "libraries/" + libPath))
+            Debug.WriteLine($"Lib exists: {Settings.minecraftForlderPath + "libraries/" + libPath}");
+        else
+            Debug.WriteLine($"Lib not exists: {Settings.minecraftForlderPath + "libraries/" + libPath}");
+#endif
+        return libPath;
+    }
+
+    public static string GetLibRelativePathFromName(string name)
     {
         Debug.WriteLine($"GameLibPathFromName: {name}");
         var dirs = name.Split(':');
@@ -357,13 +383,6 @@ internal static class StartCommandBuilder
         }
 
         libPath += dirs[^2] + "-" + dirs[^1] + ".jar";
-
-#if DEBUG
-        if (File.Exists(Settings.minecraftForlderPath + "libraries/" + libPath))
-            Debug.WriteLine($"Lib exists: {Settings.minecraftForlderPath + "libraries/" + libPath}");
-        else
-            Debug.WriteLine($"Lib not exists: {Settings.minecraftForlderPath + "libraries/" + libPath}");
-#endif
         return libPath;
     }
 

+ 15 - 15
VeloeMinecraftLauncher/VeloeMinecraftLauncher.csproj

@@ -1,7 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
 	<PropertyGroup>
 		<OutputType>WinExe</OutputType>
-		<TargetFramework>net7.0</TargetFramework>
+		<TargetFramework>net8.0</TargetFramework>
 		<TieredCompilationQuickJit>false</TieredCompilationQuickJit>
 		<Nullable>enable</Nullable>
 		<TrimMode>partial</TrimMode>
@@ -9,8 +9,8 @@
 		<DebugType>embedded</DebugType>
 		<StartupObject>VeloeMinecraftLauncher.Program</StartupObject>
 		<PlatformTarget>x64</PlatformTarget>
-		<AssemblyVersion>1.4.0.101</AssemblyVersion>
-		<FileVersion>1.4.0.101</FileVersion>
+		<AssemblyVersion>1.5.0.11</AssemblyVersion>
+		<FileVersion>1.5.0.11</FileVersion>
 		<Configurations>Debug;Release</Configurations>
 	</PropertyGroup>
 	<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -32,20 +32,20 @@
 		<TrimmableAssembly Include="Avalonia.Themes.Default" />
 	</ItemGroup>
 	<ItemGroup>
-		<PackageReference Include="Avalonia" Version="11.0.4" />
-		<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.4" />
-		<PackageReference Include="Avalonia.Desktop" Version="11.0.4" />
+		<PackageReference Include="Avalonia" Version="11.0.10" />
+		<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.10" />
+		<PackageReference Include="Avalonia.Desktop" Version="11.0.10" />
 		<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
-		<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.4" />
-		<PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.4" />
-		<PackageReference Include="Avalonia.ReactiveUI" Version="11.0.4" />
-		<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.4" />
-		<PackageReference Include="Avalonia.Xaml.Interactivity" Version="11.0.2" />
-		<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
-		<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.10" />
-		<PackageReference Include="ReactiveUI.Blazor" Version="19.4.1" />
+		<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.10" />
+		<PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.10" />
+		<PackageReference Include="Avalonia.ReactiveUI" Version="11.0.10" />
+		<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.10" />
+		<PackageReference Include="Avalonia.Xaml.Interactivity" Version="11.0.10.6" />
+		<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
+		<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.4" />
+		<PackageReference Include="ReactiveUI.Blazor" Version="19.6.1" />
 		<PackageReference Include="ReactiveUI.Validation" Version="3.1.7" />
-		<PackageReference Include="Serilog" Version="3.0.1" />
+		<PackageReference Include="Serilog" Version="3.1.1" />
 		<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
 		<PackageReference Include="SerilogTraceListener" Version="3.2.0" />
 		<PackageReference Include="System.Net.Http" Version="4.3.4" />

+ 21 - 2
VeloeMinecraftLauncher/ViewModels/MainWindowViewModel.cs

@@ -403,16 +403,35 @@ public class MainWindowViewModel : ViewModelBase
                     {
                         TaskStatus result;
 
+                        var parameters = new DownloaderParameters();
+                        parameters.Action.DownloadingFileName = value => StartButtonOutput = value;
+                        parameters.Action.IsControlsEnabled = value => IsNoGameRunning = value;
+
                         if (string.IsNullOrEmpty(versionJson.InheritsFrom))
-                            result = await Downloader.StartDownload(value => StartButtonOutput = value, value => { } ,value => IsNoGameRunning = value, value => { }, versionJson, _tokenSource.Token);
+                        {
+                            parameters.Data.VersionJson = versionJson;
+                            await new Downloader(parameters).DownloadClient(_tokenSource.Token);
+                            result = TaskStatus.RanToCompletion;
+                        }
                         else
                         {
+                            var downloader = new Downloader(parameters);
+                            if (versionJson.Libraries.Any(x => x.Name is not null && x.Name.Contains("fabric")))
+                            {
+                                parameters.Data.VersionJson = versionJson;
+                                await downloader.DownloadFabricLibraries(_tokenSource.Token);
+                            }
+
                             using StreamReader inheritsFromReader = new(Settings.minecraftForlderPath + "versions/" + versionJson.InheritsFrom + "/" + versionJson.InheritsFrom + ".json");
                             string jsonInheritsFrom = inheritsFromReader.ReadToEnd();
                             var inheritsFromJson = JsonSerializer.Deserialize<Entity.Version.Version>(jsonInheritsFrom, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
 
                             if (inheritsFromJson is not null)
-                                result = await Downloader.StartDownload(value => StartButtonOutput = value, value => { }, value => IsNoGameRunning = value, value => { }, inheritsFromJson, _tokenSource.Token);
+                            {
+                                parameters.Data.VersionJson = inheritsFromJson;
+                                await downloader.DownloadClient(_tokenSource.Token);
+                                result = TaskStatus.RanToCompletion;
+                            }
                             else
                                 result = TaskStatus.Faulted;
                         }

+ 23 - 31
VeloeMinecraftLauncher/ViewModels/VersionsDownloaderViewModel.cs

@@ -401,48 +401,40 @@ public class VersionsDownloaderViewModel : ViewModelBase, IDisposable
             if (FilteredVersion is null)
                 return TaskStatus.Faulted;
 
+            var parameters = new DownloaderParameters();
+            parameters.Action.DownloadingFileName = value => DownloadingFileName = value;
+            parameters.Action.TasksStatus = value => TasksStatusLine = value;
+            parameters.Action.IsControlsEnabled = value => IsDownloaderTabControlsEnabled = value;
+            parameters.Action.SetProgress = value => Progress = value;
+
+            parameters.Parameter.DownloadJava = DownloadJava;
+
             if (FilteredVersion.Type == "modpack")
             {
                 _selectedModpack = _modpackVersions.Where(m => m.Name == FilteredVersion.Id).FirstOrDefault();
                 if (_selectedModpack is null)
                     return TaskStatus.Faulted;
 
-                if (FilteredVersions.Where(x => x.Id == _selectedModpack.Version).FirstOrDefault() is null)
+
+                var selectedVersion = FilteredVersions.Where(x => x.Id == _selectedModpack.Version).FirstOrDefault();
+                if (selectedVersion is null)
                     return TaskStatus.Faulted;
 
-                await Task.Run(async () => await Downloader.StartDownloadModpack(
-                    value => DownloadingFileName = value,
-                    value => TasksStatusLine = value,
-                    value => IsDownloaderTabControlsEnabled = value,
-                    value => Progress = value,
-                    FilteredVersions,
-                    _selectedModpack,
-                    _tokenSource.Token,
-                    DownloadJava,
-                    InstallFabric = _selectedModpack.Fabric,
-                    InstallForge = _selectedModpack.Forge,
-                    InstallOptifine = _selectedModpack.Optifine,
-                    InstallForgeOptifine = _selectedModpack.ForgeOptifine));
+                parameters.Data.SelectedVersion = selectedVersion;
+                parameters.Data.SelectedModpack = _selectedModpack;
+
+                await new Downloader(parameters).DownloadClient(_tokenSource.Token);
             }
             else
             {
-                _logger.Debug("Downloading {0}.json", FilteredVersion.Id);
-                DownloadingFileName = $"{FilteredVersion.Id}.json";
-                var versionJson = await Downloader.DownloadAndDeserializeJsonData<Entity.Version.Version>(FilteredVersion.Url, Settings.minecraftForlderPath + "versions/" + FilteredVersion.Id + "/", FilteredVersion.Id + ".json");
-
-                if (versionJson is not null)
-                    await Downloader.StartDownload(
-                      value => DownloadingFileName = value,
-                      value => TasksStatusLine = value,
-                      value => IsDownloaderTabControlsEnabled = value,
-                      value => Progress = value,
-                      versionJson,
-                      _tokenSource.Token,
-                      DownloadJava,
-                      InstallForge,
-                      InstallOptifine,
-                      InstallForgeOptifine,
-                      InstallFabric);
+                parameters.Data.SelectedVersion = FilteredVersion;
+
+                parameters.Parameter.InstallForge = InstallForge;
+                parameters.Parameter.InstallOptifine = InstallOptifine;
+                parameters.Parameter.InstallForgeOptifine = InstallForgeOptifine;
+                parameters.Parameter.InstallFabric = InstallFabric;
+
+                await new Downloader(parameters).DownloadClient(_tokenSource.Token);
             }
 
             SearchGameFolderForVersions();

Some files were not shown because too many files changed in this diff