67 lines
2.7 KiB
C#
67 lines
2.7 KiB
C#
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;
|
||
}
|
||
} |