Modpack format v2

This commit is contained in:
2025-01-05 22:19:56 +05:00
parent 23ec6dd194
commit da58c11e59
5 changed files with 45 additions and 50 deletions

View File

@@ -0,0 +1,7 @@
namespace Mlaumcherb.Client.Avalonia.классы;
public class MyModpackRemoteProps
{
[JsonRequired] public int format_version { get; set; }
[JsonRequired] public Artifact artifact { get; set; } = null!;
}

View File

@@ -2,37 +2,30 @@
namespace Mlaumcherb.Client.Avalonia.классы;
public class MyModpackRemoteProps
public class MyModpackV2
{
[JsonRequired] public int format_version { get; set; }
[JsonRequired] public Artifact artifact { get; set; } = null!;
}
public class MyModpackV1
{
// 1
// 2
[JsonRequired] public int format_version { get; set; }
[JsonRequired] public string name { get; set; } = "";
// zip archive with all files
[JsonRequired] public Artifact zip { get; set; } = null!;
/// relative_path, hash
/// relative_path, props
// ReSharper disable once CollectionNeverUpdated.Global
[JsonRequired] public Dictionary<string, FileProps> files { get; set; } = new();
public class FileProps
{
[JsonRequired] public string sha1 { get; set; } = "";
[JsonRequired] public Artifact artifact { get; set; } = null!;
// disable hash validation, allowing users to edit this file
public bool allow_edit { get; set; }
// don't re-download file if it was deleted by user
public bool optional { get; set; }
}
/// <param name="unmatchedFilesLocalPaths">relative, absolute</param>
public Dictionary<IOPath, IOPath> CheckFiles(IOPath basedir, bool checkHashes, bool downloadOptionalFiles)
public record FileCheckResult(FileProps props, IOPath relativePath, IOPath absolutePath);
public List<FileCheckResult> CheckFiles(IOPath basedir, bool checkHashes, bool downloadOptionalFiles)
{
Dictionary<IOPath, IOPath> unmatchedFiles = new();
List<FileCheckResult> unmatchedFiles = new();
IOPath launcherRoot = PathHelper.GetRootFullPath();
foreach (var p in files)
{
@@ -40,11 +33,12 @@ public class MyModpackV1
continue;
IOPath relativePath = new IOPath(p.Key);
// libraries can be in modpacks, they are placed in global libraries directory
var absolutePath = Path.Concat(relativePath.StartsWith("libraries")
? launcherRoot : basedir, relativePath);
if (!HashHelper.CheckFileSHA1(absolutePath, p.Value.sha1, checkHashes && !p.Value.allow_edit))
if (!HashHelper.CheckFileSHA1(absolutePath, p.Value.artifact.sha1, checkHashes && !p.Value.allow_edit))
{
unmatchedFiles.Add(relativePath, absolutePath);
unmatchedFiles.Add(new FileCheckResult(p.Value, relativePath, absolutePath));
}
}