JavaVersionCatalog

This commit is contained in:
Timerix 2024-10-18 18:13:22 +05:00
parent beb701ca40
commit ae7e5096fc
13 changed files with 60 additions and 19 deletions

View File

@ -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<VersionDescriptor>(descriptorText)
descriptor = JsonConvert.DeserializeObject<GameVersionDescriptor>(descriptorText)
?? throw new Exception($"can't parse descriptor file '{props.LocalDescriptorPath}'");
javaArgs = new JavaArguments(descriptor);
gameArgs = new GameArguments(descriptor);

View File

@ -25,6 +25,7 @@
<PackageReference Include="DTLib" Version="1.4.3" />
<PackageReference Include="MessageBox.Avalonia" Version="3.1.*" />
<PackageReference Include="Newtonsoft.Json" Version="13.*" />
<PackageReference Include="EasyCompressor.LZMA" Version="2.0.2" />
</ItemGroup>
<ItemGroup>

View File

@ -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)
{

View File

@ -1,6 +1,6 @@
namespace Млаумчерб.Клиент.классы;
public class VersionCatalog
public class GameVersionCatalog
{
[JsonRequired] public List<RemoteVersionDescriptorProps> versions { get; set; } = null!;
}

View File

@ -3,7 +3,7 @@
namespace Млаумчерб.Клиент.классы;
public class VersionDescriptor
public class GameVersionDescriptor
{
[JsonRequired] public string id { get; set; } = "";
[JsonRequired] public DateTime time { get; set; }

View File

@ -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)

View File

@ -0,0 +1,30 @@
namespace Млаумчерб.Клиент.классы;
public class JavaVersionCatalog
{
}
public class JavaVersionProps
{
[JsonRequired] public Artifact manifest { get; set; }
}
public class JavaVersionManifest
{
[JsonRequired] public Dictionary<string, JavaDistributiveElementProps> 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!;
}

View File

@ -12,7 +12,7 @@ public class Libraries
public IReadOnlyCollection<JarLib> Libs { get; }
public Libraries(VersionDescriptor descriptor)
public Libraries(GameVersionDescriptor descriptor)
{
List<JarLib> libs = new();
HashSet<string> libHashes = new();

View File

@ -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<AssetDownloadProperties> _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;

View File

@ -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<NetworkTask?> 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();
}
}

View File

@ -9,13 +9,13 @@ namespace Млаумчерб.Клиент.сеть.NetworkTaskFactories;
public class LibrariesDownloadTaskFactory : INetworkTaskFactory
{
private VersionDescriptor _descriptor;
private GameVersionDescriptor _descriptor;
private Libraries _libraries;
private SHA1 _hasher;
private List<Libraries.JarLib> _libsToDownload = new();
private IOPath _nativesDir;
public LibrariesDownloadTaskFactory(VersionDescriptor descriptor, Libraries libraries)
public LibrariesDownloadTaskFactory(GameVersionDescriptor descriptor, Libraries libraries)
{
_descriptor = descriptor;
_libraries = libraries;

View File

@ -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);

View File

@ -63,7 +63,7 @@ public static class Сеть
try
{
var manifestText = await http.GetStringAsync(url);
var catalog = JsonConvert.DeserializeObject<VersionCatalog>(manifestText);
var catalog = JsonConvert.DeserializeObject<GameVersionCatalog>(manifestText);
if (catalog != null)
descriptors.AddRange(catalog.versions);
}