55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
namespace Mlaumcherb.Client.Avalonia.классы;
|
||
|
||
public record VersionSearchParams
|
||
{
|
||
public bool ReleaseTypeAllowed;
|
||
public bool SnapshotTypeAllowed;
|
||
public bool OldTypeAllowed;
|
||
public bool OtherTypeAllowed;
|
||
}
|
||
|
||
public class GameVersionCatalog
|
||
{
|
||
[JsonRequired] public List<RemoteVersionDescriptorProps> versions { get; set; } = null!;
|
||
|
||
/// <returns>empty list if couldn't find any remote versions</returns>
|
||
public List<GameVersionProps> GetDownloadableVersions(VersionSearchParams p)
|
||
{
|
||
var _versionPropsList = new List<GameVersionProps>();
|
||
foreach (var r in versions)
|
||
{
|
||
bool match = r.type switch
|
||
{
|
||
"release" => p.ReleaseTypeAllowed,
|
||
"snapshot" => p.SnapshotTypeAllowed,
|
||
"old_alpha" or "old_beta" => p.OldTypeAllowed,
|
||
_ => p.OtherTypeAllowed
|
||
};
|
||
if(match)
|
||
_versionPropsList.Add(new GameVersionProps(r.id, r.url));
|
||
}
|
||
return _versionPropsList;
|
||
}
|
||
}
|
||
|
||
public class AssetProperties
|
||
{
|
||
[JsonRequired] public string hash { get; set; } = "";
|
||
[JsonRequired] public int size { get; set; }
|
||
}
|
||
|
||
public class AssetIndex
|
||
{
|
||
[JsonRequired] public Dictionary<string, AssetProperties> objects { get; set; } = new();
|
||
}
|
||
|
||
public class RemoteVersionDescriptorProps
|
||
{
|
||
[JsonRequired] public string id { get; set; } = "";
|
||
[JsonRequired] public string url { get; set; } = "";
|
||
[JsonRequired] public string type { get; set; } = "";
|
||
public string sha1 { get; set; } = "";
|
||
public DateTime time { get; set; }
|
||
public DateTime releaseTime { get; set; }
|
||
}
|