NetworkTaskFactory
This commit is contained in:
@@ -9,7 +9,7 @@ public class GameArguments : ArgumentsWithPlaceholders
|
||||
"has_custom_resolution"
|
||||
];
|
||||
|
||||
public GameArguments(MinecraftVersionDescriptor d)
|
||||
public GameArguments(VersionDescriptor d)
|
||||
{
|
||||
if (d.minecraftArguments is not null)
|
||||
{
|
||||
|
||||
@@ -11,11 +11,13 @@ public class GameVersionProps
|
||||
get => _isDownloaded;
|
||||
set
|
||||
{
|
||||
bool downloadCompleted = value && !_isDownloaded;
|
||||
_isDownloaded = value;
|
||||
DownloadCompleted?.Invoke();
|
||||
if(downloadCompleted)
|
||||
OnDownloadCompleted?.Invoke();
|
||||
}
|
||||
}
|
||||
public event Action? DownloadCompleted;
|
||||
public event Action? OnDownloadCompleted;
|
||||
|
||||
public GameVersionProps(string name, string? url, IOPath descriptorPath)
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@ public class JavaArguments : ArgumentsWithPlaceholders
|
||||
|
||||
];
|
||||
|
||||
public JavaArguments(MinecraftVersionDescriptor d)
|
||||
public JavaArguments(VersionDescriptor d)
|
||||
{
|
||||
raw_args.AddRange(_initial_arguments);
|
||||
if (d.arguments is not null)
|
||||
|
||||
67
Млаумчерб.Клиент/классы/Libraries.cs
Normal file
67
Млаумчерб.Клиент/классы/Libraries.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using DTLib.Extensions;
|
||||
|
||||
namespace Млаумчерб.Клиент.классы;
|
||||
|
||||
public class Libraries
|
||||
{
|
||||
private static readonly string[] enabled_features = [];
|
||||
|
||||
public record JarLib(string name, IOPath jarFilePath, Artifact artifact);
|
||||
public record NativeLib(string name, IOPath jarFilePath, Artifact artifact, IOPath nativeFilesDir, Extract? extractionOptions)
|
||||
: JarLib(name, jarFilePath, artifact);
|
||||
|
||||
public IReadOnlyCollection<JarLib> Libs { get; }
|
||||
|
||||
public Libraries(VersionDescriptor descriptor)
|
||||
{
|
||||
List<JarLib> libs = new();
|
||||
HashSet<string> libHashes = new();
|
||||
|
||||
foreach (var l in descriptor.libraries)
|
||||
{
|
||||
if (l.rules != null && !Буржуазия.CheckRules(l.rules, enabled_features))
|
||||
continue;
|
||||
|
||||
if (l.natives != null)
|
||||
{
|
||||
string? nativesKey;
|
||||
if (OperatingSystem.IsWindows())
|
||||
nativesKey = l.natives.windows;
|
||||
else if (OperatingSystem.IsLinux())
|
||||
nativesKey = l.natives.linux;
|
||||
else if (OperatingSystem.IsMacOS())
|
||||
nativesKey = l.natives.osx;
|
||||
else throw new PlatformNotSupportedException();
|
||||
if(nativesKey is null)
|
||||
throw new Exception($"nativesKey for '{l.name}' is null");
|
||||
|
||||
Artifact artifact = null!;
|
||||
if(l.downloads.classifiers != null && !l.downloads.classifiers.TryGetValue(nativesKey, out artifact!))
|
||||
throw new Exception($"can't find artifact for '{l.name}' with nativesKey '{nativesKey}'");
|
||||
|
||||
// skipping duplicates (WHO THE HELL CREATES THIS DISCRIPTORS AAAAAAAAA)
|
||||
if(!libHashes.Add(artifact.sha1))
|
||||
continue;
|
||||
|
||||
IOPath dir = Пути.GetVersionDir(descriptor.id);
|
||||
IOPath jarPath = Path.Concat(dir, Path.ReplaceRestrictedChars(l.name));
|
||||
libs.Add(new NativeLib(l.name, jarPath, artifact, dir, l.extract));
|
||||
}
|
||||
else
|
||||
{
|
||||
Artifact? artifact = l.downloads.artifact;
|
||||
if (artifact == null)
|
||||
throw new NullReferenceException($"artifact for '{l.name}' is null");
|
||||
|
||||
// skipping duplicates
|
||||
if(!libHashes.Add(artifact.sha1))
|
||||
continue;
|
||||
|
||||
IOPath path = artifact.url.AsSpan().After("://").After('/').ToString();
|
||||
libs.Add(new JarLib(l.name, Path.Concat(Пути.GetLibrariesDir(), path), artifact));
|
||||
}
|
||||
}
|
||||
|
||||
Libs = libs;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
namespace Млаумчерб.Клиент.классы;
|
||||
|
||||
public class MinecraftVersionDescriptor
|
||||
public class VersionDescriptor
|
||||
{
|
||||
[JsonRequired] public string id { get; set; } = "";
|
||||
[JsonRequired] public DateTime time { get; set; }
|
||||
@@ -39,22 +39,10 @@ public class Rule
|
||||
public Dictionary<string, bool>? features { get; set; }
|
||||
}
|
||||
|
||||
public class Classifiers
|
||||
{
|
||||
[JsonProperty("natives-linux")]
|
||||
public Artifact? nativeslinux { get; set; }
|
||||
|
||||
[JsonProperty("natives-osx")]
|
||||
public Artifact? nativesosx { get; set; }
|
||||
|
||||
[JsonProperty("natives-windows")]
|
||||
public Artifact? nativeswindows { get; set; }
|
||||
}
|
||||
|
||||
public class LibraryDownloads
|
||||
{
|
||||
public Artifact? artifact { get; set; }
|
||||
public Classifiers? classifiers { get; set; }
|
||||
public Dictionary<string, Artifact>? classifiers { get; set; }
|
||||
}
|
||||
|
||||
public class Extract
|
||||
@@ -9,7 +9,7 @@ public static class Буржуазия
|
||||
os.name switch
|
||||
{
|
||||
null => true,
|
||||
"osx" => OperatingSystem.IsWindows(),
|
||||
"osx" => OperatingSystem.IsMacOS(),
|
||||
"linux" => OperatingSystem.IsLinux(),
|
||||
"windows" => OperatingSystem.IsWindows(),
|
||||
_ => throw new ArgumentOutOfRangeException(os.name)
|
||||
|
||||
@@ -16,12 +16,23 @@ public static class Пути
|
||||
public static IOPath GetVersionDescriptorPath(string name) =>
|
||||
Path.Concat(GetVersionDescriptorDir(), Path.ReplaceRestrictedChars(name) + ".json");
|
||||
|
||||
public static IOPath GetVersionDir() =>
|
||||
Path.Concat(Приложение.Настройки.путь_к_кубачу, "versions");
|
||||
public static IOPath GetVersionDir(string id) =>
|
||||
Path.Concat(Приложение.Настройки.путь_к_кубачу, "versions", id);
|
||||
|
||||
public static IOPath GetVersionJarFilePath(string name) =>
|
||||
Path.Concat(GetVersionDir(), name + ".jar");
|
||||
public static IOPath GetVersionJarFilePath(string id) =>
|
||||
Path.Concat(GetVersionDir(id), id + ".jar");
|
||||
|
||||
public static IOPath GetLibrariesDir() =>
|
||||
Path.Concat(Приложение.Настройки.путь_к_кубачу, "libraries");
|
||||
|
||||
public static IOPath GetJavaRuntimesDir() =>
|
||||
Path.Concat(Приложение.Настройки.путь_к_кубачу, "java");
|
||||
|
||||
|
||||
public static IOPath GetJavaRuntimeDir(string id) =>
|
||||
Path.Concat(GetJavaRuntimesDir(), id);
|
||||
|
||||
public static IOPath GetJavaExecutablePath(string id) =>
|
||||
Path.Concat(GetJavaRuntimeDir(id), "bin",
|
||||
OperatingSystem.IsWindows() ? "javaw.exe" : "javaw");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user