From ae7e5096fc3aca2ea8661458bb83b333f954189c Mon Sep 17 00:00:00 2001 From: Timerix Date: Fri, 18 Oct 2024 18:13:22 +0500 Subject: [PATCH] JavaVersionCatalog --- Млаумчерб.Клиент/Игра.cs | 4 +-- Млаумчерб.Клиент/Млаумчерб.Клиент.csproj | 1 + Млаумчерб.Клиент/классы/GameArguments.cs | 2 +- .../классы/{VersionCatalog.cs => GameVersionCatalog.cs} | 2 +- .../{VersionDescriptor.cs => GameVersionDescriptor.cs} | 2 +- Млаумчерб.Клиент/классы/JavaArguments.cs | 2 +- Млаумчерб.Клиент/классы/JavaVersionCatalog.cs | 30 +++++++++++++++++++ Млаумчерб.Клиент/классы/Libraries.cs | 2 +- .../сеть/NetworkTaskFactories/AssetsDownloadTaskFactory.cs | 6 ++-- .../сеть/NetworkTaskFactories/JavaDownloadTaskFactory.cs | 18 ++++++++--- .../NetworkTaskFactories/LibrariesDownloadTaskFactory.cs | 4 +-- .../NetworkTaskFactories/VersionFileDownloadTaskFactory.cs | 4 +-- Млаумчерб.Клиент/сеть/Сеть.cs | 2 +- 13 files changed, 60 insertions(+), 19 deletions(-) rename Млаумчерб.Клиент/классы/{VersionCatalog.cs => GameVersionCatalog.cs} (93%) rename Млаумчерб.Клиент/классы/{VersionDescriptor.cs => GameVersionDescriptor.cs} (96%) create mode 100644 Млаумчерб.Клиент/классы/JavaVersionCatalog.cs diff --git a/Млаумчерб.Клиент/Игра.cs b/Млаумчерб.Клиент/Игра.cs index 0ec8c9f..f11357a 100644 --- a/Млаумчерб.Клиент/Игра.cs +++ b/Млаумчерб.Клиент/Игра.cs @@ -16,7 +16,7 @@ public class GameVersion private IOPath JavaExecutableFilePath; - private VersionDescriptor descriptor; + private GameVersionDescriptor descriptor; private JavaArguments javaArgs; private GameArguments gameArgs; private Libraries libraries; @@ -54,7 +54,7 @@ public class GameVersion { _props = props; string descriptorText = File.ReadAllText(props.LocalDescriptorPath); - descriptor = JsonConvert.DeserializeObject(descriptorText) + descriptor = JsonConvert.DeserializeObject(descriptorText) ?? throw new Exception($"can't parse descriptor file '{props.LocalDescriptorPath}'"); javaArgs = new JavaArguments(descriptor); gameArgs = new GameArguments(descriptor); diff --git a/Млаумчерб.Клиент/Млаумчерб.Клиент.csproj b/Млаумчерб.Клиент/Млаумчерб.Клиент.csproj index 6e5af0b..581ae2d 100644 --- a/Млаумчерб.Клиент/Млаумчерб.Клиент.csproj +++ b/Млаумчерб.Клиент/Млаумчерб.Клиент.csproj @@ -25,6 +25,7 @@ + diff --git a/Млаумчерб.Клиент/классы/GameArguments.cs b/Млаумчерб.Клиент/классы/GameArguments.cs index ecb0392..ec23bb5 100644 --- a/Млаумчерб.Клиент/классы/GameArguments.cs +++ b/Млаумчерб.Клиент/классы/GameArguments.cs @@ -9,7 +9,7 @@ public class GameArguments : ArgumentsWithPlaceholders "has_custom_resolution" ]; - public GameArguments(VersionDescriptor d) + public GameArguments(GameVersionDescriptor d) { if (d.minecraftArguments is not null) { diff --git a/Млаумчерб.Клиент/классы/VersionCatalog.cs b/Млаумчерб.Клиент/классы/GameVersionCatalog.cs similarity index 93% rename from Млаумчерб.Клиент/классы/VersionCatalog.cs rename to Млаумчерб.Клиент/классы/GameVersionCatalog.cs index 616bb0c..364a07d 100644 --- a/Млаумчерб.Клиент/классы/VersionCatalog.cs +++ b/Млаумчерб.Клиент/классы/GameVersionCatalog.cs @@ -1,6 +1,6 @@ namespace Млаумчерб.Клиент.классы; -public class VersionCatalog +public class GameVersionCatalog { [JsonRequired] public List versions { get; set; } = null!; } diff --git a/Млаумчерб.Клиент/классы/VersionDescriptor.cs b/Млаумчерб.Клиент/классы/GameVersionDescriptor.cs similarity index 96% rename from Млаумчерб.Клиент/классы/VersionDescriptor.cs rename to Млаумчерб.Клиент/классы/GameVersionDescriptor.cs index de0eff5..56e83d9 100644 --- a/Млаумчерб.Клиент/классы/VersionDescriptor.cs +++ b/Млаумчерб.Клиент/классы/GameVersionDescriptor.cs @@ -3,7 +3,7 @@ namespace Млаумчерб.Клиент.классы; -public class VersionDescriptor +public class GameVersionDescriptor { [JsonRequired] public string id { get; set; } = ""; [JsonRequired] public DateTime time { get; set; } diff --git a/Млаумчерб.Клиент/классы/JavaArguments.cs b/Млаумчерб.Клиент/классы/JavaArguments.cs index 1aa093c..6f18c40 100644 --- a/Млаумчерб.Клиент/классы/JavaArguments.cs +++ b/Млаумчерб.Клиент/классы/JavaArguments.cs @@ -12,7 +12,7 @@ public class JavaArguments : ArgumentsWithPlaceholders ]; - public JavaArguments(VersionDescriptor d) + public JavaArguments(GameVersionDescriptor d) { raw_args.AddRange(_initial_arguments); if (d.arguments is not null) diff --git a/Млаумчерб.Клиент/классы/JavaVersionCatalog.cs b/Млаумчерб.Клиент/классы/JavaVersionCatalog.cs new file mode 100644 index 0000000..c2c6380 --- /dev/null +++ b/Млаумчерб.Клиент/классы/JavaVersionCatalog.cs @@ -0,0 +1,30 @@ +namespace Млаумчерб.Клиент.классы; + +public class JavaVersionCatalog +{ + +} + +public class JavaVersionProps +{ + [JsonRequired] public Artifact manifest { get; set; } +} + +public class JavaVersionManifest +{ + [JsonRequired] public Dictionary manifest { get; set; } +} + +public class JavaDistributiveElementProps +{ + // "directory" / "file" + [JsonRequired] public string type { get; set; } = ""; + public bool? executable { get; set; } + public JavaCompressedArtifact? downloads { get; set; } +} + +public class JavaCompressedArtifact +{ + public Artifact? lzma { get; set; } + public Artifact raw { get; set; } = null!; +} \ No newline at end of file diff --git a/Млаумчерб.Клиент/классы/Libraries.cs b/Млаумчерб.Клиент/классы/Libraries.cs index 60556d9..e2effdd 100644 --- a/Млаумчерб.Клиент/классы/Libraries.cs +++ b/Млаумчерб.Клиент/классы/Libraries.cs @@ -12,7 +12,7 @@ public class Libraries public IReadOnlyCollection Libs { get; } - public Libraries(VersionDescriptor descriptor) + public Libraries(GameVersionDescriptor descriptor) { List libs = new(); HashSet libHashes = new(); diff --git a/Млаумчерб.Клиент/сеть/NetworkTaskFactories/AssetsDownloadTaskFactory.cs b/Млаумчерб.Клиент/сеть/NetworkTaskFactories/AssetsDownloadTaskFactory.cs index 672fa28..3e5b202 100644 --- a/Млаумчерб.Клиент/сеть/NetworkTaskFactories/AssetsDownloadTaskFactory.cs +++ b/Млаумчерб.Клиент/сеть/NetworkTaskFactories/AssetsDownloadTaskFactory.cs @@ -9,12 +9,12 @@ namespace Млаумчерб.Клиент.сеть.NetworkTaskFactories; public class AssetsDownloadTaskFactory : INetworkTaskFactory { private const string ASSET_SERVER_URL = "https://resources.download.minecraft.net/"; - private VersionDescriptor _descriptor; + private GameVersionDescriptor _descriptor; private SHA1 _hasher; private IOPath _indexFilePath; List _assetsToDownload = new(); - public AssetsDownloadTaskFactory(VersionDescriptor descriptor) + public AssetsDownloadTaskFactory(GameVersionDescriptor descriptor) { _descriptor = descriptor; _hasher = SHA1.Create(); @@ -86,7 +86,7 @@ public class AssetsDownloadTaskFactory : INetworkTaskFactory public string url; public IOPath filePath; - public AssetDownloadProperties(string key, AssetProperties p) + public AssetDownloadProperties(string key, GameAssetProperties p) { name = key; hash = p.hash; diff --git a/Млаумчерб.Клиент/сеть/NetworkTaskFactories/JavaDownloadTaskFactory.cs b/Млаумчерб.Клиент/сеть/NetworkTaskFactories/JavaDownloadTaskFactory.cs index 58cc118..df02e14 100644 --- a/Млаумчерб.Клиент/сеть/NetworkTaskFactories/JavaDownloadTaskFactory.cs +++ b/Млаумчерб.Клиент/сеть/NetworkTaskFactories/JavaDownloadTaskFactory.cs @@ -1,4 +1,5 @@ using System.Security.Cryptography; +using EasyCompressor; using Млаумчерб.Клиент.классы; using static Млаумчерб.Клиент.сеть.Сеть; @@ -6,15 +7,19 @@ namespace Млаумчерб.Клиент.сеть.NetworkTaskFactories; public class JavaDownloadTaskFactory : INetworkTaskFactory { - private VersionDescriptor _descriptor; + private const string INDEX_URL = + "https://launchermeta.mojang.com/v1/products/java-runtime/2ec0cc96c44e5a76b9c8b7c39df7210883d12871/all.json"; + private GameVersionDescriptor _descriptor; + private IOPath _javaVersionDir; private SHA1 _hasher; - IOPath _javaVersionDir; + private LZMACompressor _lzma; - public JavaDownloadTaskFactory(VersionDescriptor descriptor) + public JavaDownloadTaskFactory(GameVersionDescriptor descriptor) { _descriptor = descriptor; - _hasher = SHA1.Create(); _javaVersionDir = Пути.GetJavaRuntimeDir(_descriptor.javaVersion.component); + _hasher = SHA1.Create(); + _lzma = new LZMACompressor(); } public Task CreateAsync(bool checkHashes) @@ -31,16 +36,21 @@ public class JavaDownloadTaskFactory : INetworkTaskFactory private bool CheckFiles(bool checkHashes) { + //TODO: download catalog + //TODO: download manifest for required runtime + //TODO: check whether files from manifest exist and match hashes throw new NotImplementedException(); } private long GetTotalSize() { + //TODO: sum up size of all files invalidated by CheckFiles throw new NotImplementedException(); } private Task Download(NetworkProgressReporter pr, CancellationToken ct) { + //TODO: download files using lzma decompression throw new NotImplementedException(); } } \ No newline at end of file diff --git a/Млаумчерб.Клиент/сеть/NetworkTaskFactories/LibrariesDownloadTaskFactory.cs b/Млаумчерб.Клиент/сеть/NetworkTaskFactories/LibrariesDownloadTaskFactory.cs index 79fab6d..b6bb52c 100644 --- a/Млаумчерб.Клиент/сеть/NetworkTaskFactories/LibrariesDownloadTaskFactory.cs +++ b/Млаумчерб.Клиент/сеть/NetworkTaskFactories/LibrariesDownloadTaskFactory.cs @@ -9,13 +9,13 @@ namespace Млаумчерб.Клиент.сеть.NetworkTaskFactories; public class LibrariesDownloadTaskFactory : INetworkTaskFactory { - private VersionDescriptor _descriptor; + private GameVersionDescriptor _descriptor; private Libraries _libraries; private SHA1 _hasher; private List _libsToDownload = new(); private IOPath _nativesDir; - public LibrariesDownloadTaskFactory(VersionDescriptor descriptor, Libraries libraries) + public LibrariesDownloadTaskFactory(GameVersionDescriptor descriptor, Libraries libraries) { _descriptor = descriptor; _libraries = libraries; diff --git a/Млаумчерб.Клиент/сеть/NetworkTaskFactories/VersionFileDownloadTaskFactory.cs b/Млаумчерб.Клиент/сеть/NetworkTaskFactories/VersionFileDownloadTaskFactory.cs index 5cb4787..2488ed4 100644 --- a/Млаумчерб.Клиент/сеть/NetworkTaskFactories/VersionFileDownloadTaskFactory.cs +++ b/Млаумчерб.Клиент/сеть/NetworkTaskFactories/VersionFileDownloadTaskFactory.cs @@ -8,11 +8,11 @@ namespace Млаумчерб.Клиент.сеть.NetworkTaskFactories; public class VersionFileDownloadTaskFactory : INetworkTaskFactory { - private VersionDescriptor _descriptor; + private GameVersionDescriptor _descriptor; private IOPath _filePath; private SHA1 _hasher; - public VersionFileDownloadTaskFactory(VersionDescriptor descriptor) + public VersionFileDownloadTaskFactory(GameVersionDescriptor descriptor) { _descriptor = descriptor; _filePath = Пути.GetVersionJarFilePath(_descriptor.id); diff --git a/Млаумчерб.Клиент/сеть/Сеть.cs b/Млаумчерб.Клиент/сеть/Сеть.cs index 35b37fa..a6b8dc2 100644 --- a/Млаумчерб.Клиент/сеть/Сеть.cs +++ b/Млаумчерб.Клиент/сеть/Сеть.cs @@ -63,7 +63,7 @@ public static class Сеть try { var manifestText = await http.GetStringAsync(url); - var catalog = JsonConvert.DeserializeObject(manifestText); + var catalog = JsonConvert.DeserializeObject(manifestText); if (catalog != null) descriptors.AddRange(catalog.versions); }