Game version management

This commit is contained in:
2024-12-27 21:11:12 +05:00
parent 1f663902e2
commit cb85b132c3
17 changed files with 339 additions and 159 deletions

View File

@@ -1,4 +1,5 @@
using Mlaumcherb.Client.Avalonia.холопы;
using Mlaumcherb.Client.Avalonia.зримое;
using Mlaumcherb.Client.Avalonia.холопы;
namespace Mlaumcherb.Client.Avalonia.классы;
@@ -13,13 +14,14 @@ public class GameVersionProps : IComparable<GameVersionProps>, IEquatable<GameVe
get => _isDownloaded;
set
{
bool downloadCompleted = value && !_isDownloaded;
_isDownloaded = value;
if(downloadCompleted)
OnDownloadCompleted?.Invoke();
if(_isDownloaded != value)
{
_isDownloaded = value;
StatusChanged?.Invoke(value);
}
}
}
public event Action? OnDownloadCompleted;
public event Action<bool>? StatusChanged;
public GameVersionProps(string name, string? url)
{
@@ -29,6 +31,16 @@ public class GameVersionProps : IComparable<GameVersionProps>, IEquatable<GameVe
IsDownloaded = File.Exists(PathHelper.GetVersionJarFilePath(name));
}
public void DeleteFiles()
{
IsDownloaded = false;
LauncherApp.Logger.LogInfo(Name, "Deleting files...");
var verdir = PathHelper.GetVersionDir(Name);
if(Directory.Exists(verdir))
Directory.Delete(verdir);
LauncherApp.Logger.LogInfo(Name, "Files deleted");
}
public override string ToString() => Name;
public override int GetHashCode() => Name.GetHashCode();

View File

@@ -7,11 +7,19 @@ 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, Extract? extractionOptions)
public record JarLib(string name, IOPath? jarFilePath, Artifact artifact);
public record NativeLib(string name, IOPath? jarFilePath, Artifact artifact, Extract? extractionOptions)
: JarLib(name, jarFilePath, artifact);
public IReadOnlyCollection<JarLib> Libs { get; }
private IOPath? TryGetJarFilePath(Artifact artifact)
{
if(string.IsNullOrEmpty(artifact.url))
return null;
string urlTail = artifact.url.AsSpan().After("://").After('/').ToString();
return Path.Concat(PathHelper.GetLibrariesDir(), urlTail);
}
public Libraries(GameVersionDescriptor descriptor)
{
@@ -54,10 +62,8 @@ public class Libraries
// skipping duplicates (WHO THE HELL CREATES THIS DISCRIPTORS AAAAAAAAA)
if(!libHashes.Add(artifact.sha1))
continue;
string urlTail = artifact.url.AsSpan().After("://").After('/').ToString();
IOPath jarFilePath = Path.Concat(PathHelper.GetLibrariesDir(), urlTail);
libs.Add(new NativeLib(l.name, jarFilePath, artifact, l.extract));
libs.Add(new NativeLib(l.name, TryGetJarFilePath(artifact), artifact, l.extract));
}
else
{
@@ -69,9 +75,7 @@ public class Libraries
if(!libHashes.Add(artifact.sha1))
continue;
string urlTail = artifact.url.AsSpan().After("://").After('/').ToString();
IOPath jarFilePath = Path.Concat(PathHelper.GetLibrariesDir(), urlTail);
libs.Add(new JarLib(l.name, jarFilePath, artifact));
libs.Add(new JarLib(l.name, TryGetJarFilePath(artifact), artifact));
}
}

View File

@@ -0,0 +1,18 @@
using Mlaumcherb.Client.Avalonia.сеть;
namespace Mlaumcherb.Client.Avalonia.классы;
public class VersionCatalogProps
{
[JsonRequired] public required string Name { get; init; }
[JsonRequired] public required string Url { get; init; }
public override string ToString() => Name;
public async Task<GameVersionCatalog> GetVersionCatalogAsync()
{
return await NetworkHelper.DownloadStringAndDeserialize<GameVersionCatalog>(Url);
}
}