2019-10-15 23:23:14 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-10-16 23:05:51 +00:00
|
|
|
|
using System.Windows.Media.Imaging;
|
2019-11-18 15:46:55 +00:00
|
|
|
|
using CommonMark.Syntax;
|
2019-10-19 10:55:05 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2019-10-15 23:23:14 +00:00
|
|
|
|
using Wabbajack.Common;
|
2019-10-16 23:05:51 +00:00
|
|
|
|
using Wabbajack.Lib.Downloaders;
|
2019-10-16 03:10:34 +00:00
|
|
|
|
using Wabbajack.Lib.Validation;
|
2019-10-15 23:23:14 +00:00
|
|
|
|
using YamlDotNet.Serialization;
|
|
|
|
|
using YamlDotNet.Serialization.NamingConventions;
|
2019-10-16 23:05:51 +00:00
|
|
|
|
using File = System.IO.File;
|
2019-10-15 23:23:14 +00:00
|
|
|
|
using Game = Wabbajack.Common.Game;
|
|
|
|
|
|
2019-10-16 03:10:34 +00:00
|
|
|
|
namespace Wabbajack.Lib.ModListRegistry
|
2019-10-15 23:23:14 +00:00
|
|
|
|
{
|
|
|
|
|
public class ModlistMetadata
|
|
|
|
|
{
|
2019-10-19 10:55:05 +00:00
|
|
|
|
[JsonProperty("title")]
|
|
|
|
|
public string Title { get; set; }
|
2019-10-15 23:23:14 +00:00
|
|
|
|
|
2019-10-19 10:55:05 +00:00
|
|
|
|
[JsonProperty("description")]
|
|
|
|
|
public string Description { get; set; }
|
|
|
|
|
|
|
|
|
|
[JsonProperty("author")]
|
2019-10-15 23:23:14 +00:00
|
|
|
|
public string Author { get; set; }
|
|
|
|
|
|
2019-10-19 10:55:05 +00:00
|
|
|
|
[JsonProperty("game")]
|
2019-10-15 23:23:14 +00:00
|
|
|
|
public Game Game { get; set; }
|
|
|
|
|
|
2019-11-18 15:46:55 +00:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public string GameName { get; set; }
|
|
|
|
|
|
2019-10-19 11:22:23 +00:00
|
|
|
|
[JsonProperty("official")]
|
|
|
|
|
public bool Official { get; set; }
|
2019-10-19 10:55:05 +00:00
|
|
|
|
|
|
|
|
|
[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
|
|
|
|
|
2019-10-19 10:55:05 +00:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public BitmapImage Image { get; set; }
|
2019-10-15 23:23:14 +00:00
|
|
|
|
|
2019-10-19 10:55:05 +00:00
|
|
|
|
[JsonProperty("readme")]
|
|
|
|
|
public string Readme { get; set; }
|
|
|
|
|
|
|
|
|
|
[JsonProperty("download")]
|
|
|
|
|
public string Download { get; set; }
|
|
|
|
|
|
2019-11-05 22:11:39 +00:00
|
|
|
|
[JsonProperty("download_metadata")]
|
|
|
|
|
public DownloadMetadata DownloadMetadata { get; set; }
|
|
|
|
|
|
2019-10-19 10:55:05 +00:00
|
|
|
|
[JsonProperty("machineURL")]
|
|
|
|
|
public string MachineURL { get; set; }
|
|
|
|
|
}
|
2019-10-16 23:05:51 +00:00
|
|
|
|
|
2019-10-15 23:23:14 +00:00
|
|
|
|
|
2019-11-05 22:11:39 +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-11-05 22:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-10-15 23:23:14 +00:00
|
|
|
|
public static List<ModlistMetadata> LoadFromGithub()
|
|
|
|
|
{
|
|
|
|
|
var client = new HttpClient();
|
2019-11-18 15:46:55 +00:00
|
|
|
|
Utils.Log("Loading ModLists from Github");
|
2019-10-19 10:55:05 +00:00
|
|
|
|
var result = client.GetStringSync(Consts.ModlistMetadataURL);
|
2019-11-18 15:46:55 +00:00
|
|
|
|
var list = result.FromJSONString<List<ModlistMetadata>>();
|
|
|
|
|
list.Do(m =>
|
|
|
|
|
{
|
|
|
|
|
m.GameName = m.Game.ToDescriptionString();
|
|
|
|
|
if (string.IsNullOrWhiteSpace(m.GameName))
|
|
|
|
|
m.GameName = m.Game.ToString();
|
|
|
|
|
});
|
|
|
|
|
return list;
|
2019-10-16 23:05:51 +00:00
|
|
|
|
}
|
2019-11-05 22:11:39 +00:00
|
|
|
|
|
|
|
|
|
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;
|
2019-11-05 22:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
return Links.DownloadMetadata.Hash != modlistPath.FileHash();
|
|
|
|
|
}
|
2019-10-15 23:23:14 +00:00
|
|
|
|
}
|
2019-11-05 22:11:39 +00:00
|
|
|
|
|
2019-10-15 23:23:14 +00:00
|
|
|
|
}
|