This commit is contained in:
Timerix 2024-12-29 01:26:41 +05:00
parent e24ee815bc
commit d141ec23dc
6 changed files with 26 additions and 13 deletions

View File

@ -104,7 +104,7 @@ public class GameVersion
[ [
new AssetsDownloadTaskFactory(_descriptor), new AssetsDownloadTaskFactory(_descriptor),
new LibrariesDownloadTaskFactory(_descriptor, _libraries), new LibrariesDownloadTaskFactory(_descriptor, _libraries),
new VersionFileDownloadTaskFactory(_descriptor), new VersionJarDownloadTaskFactory(_descriptor),
]; ];
if (LauncherApp.Config.download_java) if (LauncherApp.Config.download_java)
{ {
@ -176,7 +176,7 @@ public class GameVersion
Dictionary<string, string> placeholder_values = new() { Dictionary<string, string> placeholder_values = new() {
{ "resolution_width", "1600" }, { "resolution_width", "1600" },
{ "resolution_height", "900" }, { "resolution_height", "900" },
{ "xms", "2048" }, { "xms", LauncherApp.Config.max_memory.ToString() },
{ "xmx", LauncherApp.Config.max_memory.ToString() }, { "xmx", LauncherApp.Config.max_memory.ToString() },
{ "auth_player_name", LauncherApp.Config.player_name }, { "auth_player_name", LauncherApp.Config.player_name },
{ "auth_access_token", uuid }, { "auth_access_token", uuid },
@ -196,6 +196,8 @@ public class GameVersion
{ "game_assets", GetAssetsDir().ToString() }, { "game_assets", GetAssetsDir().ToString() },
{ "game_directory", WorkingDirectory.ToString() }, { "game_directory", WorkingDirectory.ToString() },
{ "natives_directory", GetNativeLibrariesDir(_descriptor.id).ToString() }, { "natives_directory", GetNativeLibrariesDir(_descriptor.id).ToString() },
{ "library_directory", GetLibrariesDir().ToString() },
{ "classpath_separator", ";"},
{ "path", GetLog4jConfigFilePath().ToString() }, { "path", GetLog4jConfigFilePath().ToString() },
{ "version_name", _descriptor.id }, { "version_name", _descriptor.id },
{ "version_type", _descriptor.type }, { "version_type", _descriptor.type },

View File

@ -30,7 +30,7 @@ public class GameArguments : ArgumentsWithPlaceholders
{ {
foreach (var arg in av.value) foreach (var arg in av.value)
{ {
if(!_raw_args.Contains(arg)) // if(!_raw_args.Contains(arg))
_raw_args.Add(arg); _raw_args.Add(arg);
} }
} }

View File

@ -21,7 +21,6 @@ public class JavaArguments : ArgumentsWithPlaceholders
"-Dminecraft.client.jar=${client_jar}", "-Dminecraft.client.jar=${client_jar}",
"-Dminecraft.launcher.brand=${launcher_name}", "-Dminecraft.launcher.brand=${launcher_name}",
"-Dminecraft.launcher.version=${launcher_version}", "-Dminecraft.launcher.version=${launcher_version}",
"-cp", "${classpath}"
]; ];
private static readonly string[] _enabled_features = private static readonly string[] _enabled_features =
@ -39,11 +38,17 @@ public class JavaArguments : ArgumentsWithPlaceholders
{ {
foreach (var arg in av.value) foreach (var arg in av.value)
{ {
if(!_raw_args.Contains(arg)) // if(!_raw_args.Contains(arg))
_raw_args.Add(arg); _raw_args.Add(arg);
} }
} }
} }
} }
if (!_raw_args.Contains("-cp"))
{
_raw_args.Add("-cp");
_raw_args.Add("${classpath}");
}
} }
} }

View File

@ -37,7 +37,13 @@ public class AssetsDownloadTaskFactory : INetworkTaskFactory
} }
private async Task<bool> CheckFilesAsync(bool checkHashes) private async Task<bool> CheckFilesAsync(bool checkHashes)
{ {
if(!File.Exists(_indexFilePath)) string assetIndexHash = "";
if(checkHashes)
{
await using var fs = File.OpenRead(_indexFilePath);
assetIndexHash = _hasher.ComputeHash(fs).HashToString();
}
if(!File.Exists(_indexFilePath) || (checkHashes && assetIndexHash != _descriptor.assetIndex.sha1))
{ {
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"started downloading asset index to '{_indexFilePath}'"); LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"started downloading asset index to '{_indexFilePath}'");
await DownloadFile(_descriptor.assetIndex.url, _indexFilePath); await DownloadFile(_descriptor.assetIndex.url, _indexFilePath);

View File

@ -7,13 +7,13 @@ using static Mlaumcherb.Client.Avalonia.сеть.NetworkHelper;
namespace Mlaumcherb.Client.Avalonia.сеть.TaskFactories; namespace Mlaumcherb.Client.Avalonia.сеть.TaskFactories;
public class VersionFileDownloadTaskFactory : INetworkTaskFactory public class VersionJarDownloadTaskFactory : INetworkTaskFactory
{ {
private GameVersionDescriptor _descriptor; private GameVersionDescriptor _descriptor;
private IOPath _filePath; private IOPath _filePath;
private SHA1 _hasher; private SHA1 _hasher;
public VersionFileDownloadTaskFactory(GameVersionDescriptor descriptor) public VersionJarDownloadTaskFactory(GameVersionDescriptor descriptor)
{ {
_descriptor = descriptor; _descriptor = descriptor;
_filePath = PathHelper.GetVersionJarFilePath(_descriptor.id); _filePath = PathHelper.GetVersionJarFilePath(_descriptor.id);
@ -25,7 +25,7 @@ public class VersionFileDownloadTaskFactory : INetworkTaskFactory
NetworkTask? networkTask = null; NetworkTask? networkTask = null;
if (!CheckFiles(checkHashes)) if (!CheckFiles(checkHashes))
networkTask = new NetworkTask( networkTask = new NetworkTask(
$"version file '{_descriptor.id}'", $"version jar '{_descriptor.id}'",
GetTotalSize(), GetTotalSize(),
Download Download
); );
@ -58,10 +58,10 @@ public class VersionFileDownloadTaskFactory : INetworkTaskFactory
private async Task Download(NetworkProgressReporter pr, CancellationToken ct) private async Task Download(NetworkProgressReporter pr, CancellationToken ct)
{ {
if (_descriptor.downloads is null) if (_descriptor.downloads is null)
throw new Exception($"can't download version file '{_descriptor.id}' because it has no download url"); throw new Exception($"can't download version jar '{_descriptor.id}' because it has no download url");
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"started downloading version file '{_descriptor.id}'"); LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"started downloading version jar '{_descriptor.id}'");
await DownloadFile(_descriptor.downloads.client.url, _filePath, ct, pr.AddBytesCount); await DownloadFile(_descriptor.downloads.client.url, _filePath, ct, pr.AddBytesCount);
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"finished downloading version file '{_descriptor.id}'"); LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"finished downloading version jar '{_descriptor.id}'");
} }
} }

View File

@ -11,7 +11,7 @@ public static class PathHelper
Path.Concat(GetRootFullPath(), "assets"); Path.Concat(GetRootFullPath(), "assets");
public static IOPath GetAssetIndexFilePath(string id) => public static IOPath GetAssetIndexFilePath(string id) =>
Path.Concat(GetAssetsDir(), $"assets/indexes/{id}.json"); Path.Concat(GetAssetsDir(), $"indexes/{id}.json"); // this path is hardcoded in the game
public static IOPath GetVersionDescriptorPath(string id) => public static IOPath GetVersionDescriptorPath(string id) =>
Path.Concat(GetVersionDir(id), id + ".json"); Path.Concat(GetVersionDir(id), id + ".json");