now it works

This commit is contained in:
2024-11-06 00:04:12 +05:00
parent 612976dfe6
commit 1f663902e2
54 changed files with 763 additions and 586 deletions

View File

@@ -0,0 +1,27 @@
namespace Mlaumcherb.Client.Avalonia.классы;
public class GameVersionCatalog
{
[JsonRequired] public List<RemoteVersionDescriptorProps> versions { get; set; } = null!;
}
public class AssetProperties
{
[JsonRequired] public string hash { get; set; } = "";
[JsonRequired] public int size { get; set; }
}
public class AssetIndex
{
[JsonRequired] public Dictionary<string, AssetProperties> objects { get; set; } = new();
}
public class RemoteVersionDescriptorProps
{
[JsonRequired] public string id { get; set; } = "";
[JsonRequired] public string type { get; set; } = "";
[JsonRequired] public string url { get; set; } = "";
[JsonRequired] public string sha1 { get; set; } = "";
[JsonRequired] public DateTime time { get; set; }
[JsonRequired] public DateTime releaseTime { get; set; }
}

View File

@@ -0,0 +1,114 @@
using System.Linq;
// ReSharper disable CollectionNeverUpdated.Global
namespace Mlaumcherb.Client.Avalonia.классы;
public class GameVersionDescriptor
{
[JsonRequired] public string id { get; set; } = "";
[JsonRequired] public DateTime time { get; set; }
[JsonRequired] public DateTime releaseTime { get; set; }
[JsonRequired] public string type { get; set; } = "";
[JsonRequired] public string mainClass { get; set; } = "";
[JsonRequired] public Downloads downloads { get; set; } = null!;
[JsonRequired] public List<Library> libraries { get; set; } = null!;
[JsonRequired] public AssetIndexProperties assetIndex { get; set; } = null!;
[JsonRequired] public string assets { get; set; } = "";
public JavaVersion javaVersion { get; set; } = new() { component = "jre-legacy", majorVersion = 8 };
public string? minecraftArguments { get; set; }
public ArgumentsNew? arguments { get; set; }
}
public class Artifact
{
[JsonRequired] public string url { get; set; } = "";
[JsonRequired] public string sha1 { get; set; } = "";
[JsonRequired] public int size { get; set; }
}
public class Os
{
public string? name { get; set; }
public string? arch { get; set; }
}
public class Rule
{
[JsonRequired] public string action { get; set; } = "";
public Os? os { get; set; }
public Dictionary<string, bool>? features { get; set; }
}
public class LibraryDownloads
{
public Artifact? artifact { get; set; }
public Dictionary<string, Artifact>? classifiers { get; set; }
}
public class Extract
{
public List<string>? exclude { get; set; }
}
public class Natives
{
public string? linux { get; set; }
public string? osx { get; set; }
public string? windows { get; set; }
}
public class Library
{
[JsonRequired] public string name { get; set; } = "";
public List<Rule>? rules { get; set; }
public Natives? natives { get; set; }
public Extract? extract { get; set; }
[JsonRequired] public LibraryDownloads downloads { get; set; } = null!;
}
public class AssetIndexProperties
{
[JsonRequired] public string id { get; set; } = "";
[JsonRequired] public string url { get; set; } = "";
[JsonRequired] public string sha1 { get; set; } = "";
[JsonRequired] public int size { get; set; }
[JsonRequired] public int totalSize { get; set; }
}
public class Downloads
{
[JsonRequired] public Artifact client { get; set; } = null!;
}
public class JavaVersion
{
[JsonRequired] public string component { get; set; } = "";
[JsonRequired] public int majorVersion { get; set; }
}
public class ArgValue
{
public struct StringOrArray : IEnumerable<string>
{
private string[] ar;
public StringOrArray(ICollection<string> v) => ar = v.ToArray();
public StringOrArray(string v) => ar = [v];
public static implicit operator StringOrArray(string[] v) => new(v);
public static implicit operator StringOrArray(string v) => new(v);
public static implicit operator string[](StringOrArray sar) => sar.ar;
public IEnumerator<string> GetEnumerator() => ar.AsEnumerable().GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => ar.GetEnumerator();
}
public ArgValue() { }
public ArgValue(string arg) => value = arg;
public static implicit operator ArgValue(string arg) => new(arg);
[JsonRequired] public StringOrArray value { get; set; } = [];
public List<Rule> rules { get; set; } = new();
}
public class ArgumentsNew
{
[JsonRequired] public List<ArgValue> jvm { get; set; } = new();
[JsonRequired] public List<ArgValue> game { get; set; } = new();
}

View File

@@ -0,0 +1,85 @@
using System.Runtime.InteropServices;
using Mlaumcherb.Client.Avalonia.холопы;
namespace Mlaumcherb.Client.Avalonia.классы;
public class JavaVersionCatalog
{
[JsonProperty("linux")]
public Dictionary<string, JavaVersionProps[]>? linux_x86 { get; set; }
[JsonProperty("linux-i386")]
public Dictionary<string, JavaVersionProps[]>? linux_x64 { get; set; }
[JsonProperty("mac-os")]
public Dictionary<string, JavaVersionProps[]>? osx_x64 { get; set; }
[JsonProperty("mac-os-arm64")]
public Dictionary<string, JavaVersionProps[]>? osx_arm64 { get; set; }
[JsonProperty("windows-arm64")]
public Dictionary<string, JavaVersionProps[]>? windows_arm64 { get; set; }
[JsonProperty("windows-x64")]
public Dictionary<string, JavaVersionProps[]>? windows_x64 { get; set; }
[JsonProperty("windows-x86")]
public Dictionary<string, JavaVersionProps[]>? windows_x86 { get; set; }
public JavaVersionProps GetVersionProps(JavaVersion version)
{
var arch = RuntimeInformation.OSArchitecture;
Dictionary<string, JavaVersionProps[]>? propsDict = null;
switch (arch)
{
case Architecture.X86:
if (OperatingSystem.IsWindows())
propsDict = windows_x86;
else if (OperatingSystem.IsLinux())
propsDict = linux_x86;
break;
case Architecture.X64:
if (OperatingSystem.IsWindows())
propsDict = windows_x64;
else if (OperatingSystem.IsLinux())
propsDict = linux_x64;
else if (OperatingSystem.IsMacOS())
propsDict = osx_x64;
break;
case Architecture.Arm64:
if (OperatingSystem.IsWindows())
propsDict = windows_arm64;
else if (OperatingSystem.IsMacOS())
propsDict = osx_arm64;
break;
}
if (propsDict != null && propsDict.TryGetValue(version.component, out var props_array))
{
if (props_array.Length != 0)
return props_array[0];
}
throw new PlatformNotSupportedException($"Can't download java {version.majorVersion} for your operating system. " +
$"Download it manually to directory {PathHelper.GetJavaRuntimeDir(version.component)}");
}
}
public class JavaVersionProps
{
/// url of JavaDistributiveManifest
[JsonRequired] public Artifact manifest { get; set; } = null!;
}
public class JavaDistributiveManifest
{
[JsonRequired] public Dictionary<string, JavaDistributiveElementProps> files { get; set; } = null!;
}
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; }
[JsonRequired] public Artifact raw { get; set; } = null!;
}

View File

@@ -0,0 +1,40 @@
using Mlaumcherb.Client.Avalonia.холопы;
namespace Mlaumcherb.Client.Avalonia.классы;
public static class Rules
{
public static bool Check(ICollection<Rule>? rules, ICollection<string> features)
{
if(rules is null || rules.Count == 0)
return true;
bool allowed = false;
foreach (var r in rules)
{
if (r.os != null && !PlatformHelper.CheckOs(r.os))
continue;
if (r.features == null)
allowed = r.action == "allow";
else
{
foreach (var feature in features)
{
if (r.features.TryGetValue(feature, out bool is_enabled))
{
if (is_enabled)
{
allowed = r.action == "allow";
}
}
}
}
if(allowed)
break;
}
return allowed;
}
}