mlaumcherb/Mlaumcherb.Client.Avalonia/классы/Пролетариат/MyModpackV2.cs
2025-01-05 22:19:56 +05:00

47 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Mlaumcherb.Client.Avalonia.холопы;
namespace Mlaumcherb.Client.Avalonia.классы;
public class MyModpackV2
{
// 2
[JsonRequired] public int format_version { get; set; }
[JsonRequired] public string name { get; set; } = "";
/// relative_path, props
// ReSharper disable once CollectionNeverUpdated.Global
[JsonRequired] public Dictionary<string, FileProps> files { get; set; } = new();
public class FileProps
{
[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; }
}
public record FileCheckResult(FileProps props, IOPath relativePath, IOPath absolutePath);
public List<FileCheckResult> CheckFiles(IOPath basedir, bool checkHashes, bool downloadOptionalFiles)
{
List<FileCheckResult> unmatchedFiles = new();
IOPath launcherRoot = PathHelper.GetRootFullPath();
foreach (var p in files)
{
if(!downloadOptionalFiles && p.Value.optional)
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.artifact.sha1, checkHashes && !p.Value.allow_edit))
{
unmatchedFiles.Add(new FileCheckResult(p.Value, relativePath, absolutePath));
}
}
return unmatchedFiles;
}
}