wabbajack/Wabbajack.Lib/ModListRegistry/ModListMetadata.cs

88 lines
2.4 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2019-10-15 23:23:14 +00:00
using System.Net.Http;
using System.Windows.Media.Imaging;
using Newtonsoft.Json;
2019-10-15 23:23:14 +00:00
using Wabbajack.Common;
using File = System.IO.File;
2019-10-15 23:23:14 +00:00
using Game = Wabbajack.Common.Game;
namespace Wabbajack.Lib.ModListRegistry
2019-10-15 23:23:14 +00:00
{
public class ModlistMetadata
{
[JsonProperty("title")]
public string Title { get; set; }
2019-10-15 23:23:14 +00:00
[JsonProperty("description")]
public string Description { get; set; }
[JsonProperty("author")]
2019-10-15 23:23:14 +00:00
public string Author { get; set; }
[JsonProperty("game")]
2019-10-15 23:23:14 +00:00
public Game Game { get; set; }
[JsonIgnore] public string GameName => Game.ToDescriptionString();
2019-10-19 11:22:23 +00:00
[JsonProperty("official")]
public bool Official { get; set; }
[JsonProperty("links")]
public LinksObject Links { get; set; } = new LinksObject();
public class LinksObject
{
[JsonProperty("image")]
public string ImageUri { get; set; }
2019-10-15 23:23:14 +00:00
[JsonIgnore]
public BitmapImage Image { get; set; }
2019-10-15 23:23:14 +00:00
[JsonProperty("readme")]
public string Readme { get; set; }
[JsonProperty("download")]
public string Download { get; set; }
[JsonProperty("download_metadata")]
public DownloadMetadata DownloadMetadata { get; set; }
[JsonProperty("machineURL")]
public string MachineURL { get; set; }
}
2019-10-15 23:23:14 +00:00
public class DownloadMetadata
{
public string Hash { get; set; }
public long Size { get; set; }
2019-11-06 13:21:39 +00:00
public long NumberOfArchives { get; set; }
public long SizeOfArchives { get; set; }
public long NumberOfInstalledFiles { get; set; }
public long SizeOfInstalledFiles { get; set; }
}
2019-10-15 23:23:14 +00:00
public static List<ModlistMetadata> LoadFromGithub()
{
var client = new HttpClient();
Utils.Log("Loading ModLists from Github");
var result = client.GetStringSync(Consts.ModlistMetadataURL);
return result.FromJSONString<List<ModlistMetadata>>();
}
public bool NeedsDownload(string modlistPath)
{
if (!File.Exists(modlistPath)) return true;
if (Links.DownloadMetadata?.Hash == null)
{
2019-11-06 13:21:39 +00:00
return true;
}
return Links.DownloadMetadata.Hash != modlistPath.FileHash();
}
2019-10-15 23:23:14 +00:00
}
2019-10-15 23:23:14 +00:00
}