2019-12-15 21:52:12 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-01-07 13:50:11 +00:00
|
|
|
|
using System.Drawing;
|
2019-12-15 21:52:12 +00:00
|
|
|
|
using System.Linq;
|
2019-10-15 23:23:14 +00:00
|
|
|
|
using System.Net.Http;
|
2019-12-06 05:59:57 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2020-01-16 05:06:25 +00:00
|
|
|
|
using MongoDB.Bson.Serialization.Attributes;
|
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 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-21 15:06:17 +00:00
|
|
|
|
[JsonIgnore] public string GameName => Game.ToDescriptionString();
|
2019-11-18 15:46:55 +00:00
|
|
|
|
|
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();
|
|
|
|
|
|
2019-11-29 05:52:33 +00:00
|
|
|
|
[JsonProperty("download_metadata")]
|
|
|
|
|
public DownloadMetadata DownloadMetadata { get; set; }
|
|
|
|
|
|
2019-12-15 21:52:12 +00:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public ModlistSummary ValidationSummary { get; set; } = new ModlistSummary();
|
|
|
|
|
|
2020-01-16 05:06:25 +00:00
|
|
|
|
[BsonIgnoreExtraElements]
|
2019-10-19 10:55:05 +00:00
|
|
|
|
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
|
|
|
|
[JsonProperty("readme")]
|
|
|
|
|
public string Readme { get; set; }
|
|
|
|
|
|
|
|
|
|
[JsonProperty("download")]
|
|
|
|
|
public string Download { get; set; }
|
2019-11-29 05:52:33 +00:00
|
|
|
|
|
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-06 13:21:39 +00:00
|
|
|
|
|
2019-11-05 22:11:39 +00:00
|
|
|
|
|
|
|
|
|
|
2019-12-06 05:59:57 +00:00
|
|
|
|
public static async Task<List<ModlistMetadata>> LoadFromGithub()
|
2019-10-15 23:23:14 +00:00
|
|
|
|
{
|
2020-02-26 04:00:28 +00:00
|
|
|
|
var client = new Common.Http.Client();
|
2020-01-13 21:11:07 +00:00
|
|
|
|
Utils.Log("Loading ModLists from GitHub");
|
2019-12-15 21:52:12 +00:00
|
|
|
|
var metadataResult = client.GetStringAsync(Consts.ModlistMetadataURL);
|
|
|
|
|
var summaryResult = client.GetStringAsync(Consts.ModlistSummaryURL);
|
|
|
|
|
|
|
|
|
|
var metadata = (await metadataResult).FromJSONString<List<ModlistMetadata>>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var summaries = (await summaryResult).FromJSONString<List<ModlistSummary>>().ToDictionary(d => d.Name);
|
|
|
|
|
|
|
|
|
|
foreach (var data in metadata)
|
|
|
|
|
if (summaries.TryGetValue(data.Title, out var summary))
|
|
|
|
|
data.ValidationSummary = summary;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-08 14:47:56 +00:00
|
|
|
|
return metadata.OrderBy(m => (m.ValidationSummary?.HasFailures ?? false ? 1 : 0, m.Title)).ToList();
|
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;
|
2019-11-29 05:52:33 +00:00
|
|
|
|
if (DownloadMetadata?.Hash == null)
|
2019-11-05 22:11:39 +00:00
|
|
|
|
{
|
2019-11-06 13:21:39 +00:00
|
|
|
|
return true;
|
2019-11-05 22:11:39 +00:00
|
|
|
|
}
|
2019-12-18 04:30:36 +00:00
|
|
|
|
return DownloadMetadata.Hash != modlistPath.FileHashCached(true);
|
2019-11-05 22:11:39 +00:00
|
|
|
|
}
|
2019-10-15 23:23:14 +00:00
|
|
|
|
}
|
2019-11-05 22:11:39 +00:00
|
|
|
|
|
2019-11-29 05:52:33 +00:00
|
|
|
|
public class DownloadMetadata
|
|
|
|
|
{
|
|
|
|
|
public string Hash { get; set; }
|
|
|
|
|
public long Size { get; set; }
|
|
|
|
|
|
|
|
|
|
public long NumberOfArchives { get; set; }
|
|
|
|
|
public long SizeOfArchives { get; set; }
|
|
|
|
|
public long NumberOfInstalledFiles { get; set; }
|
|
|
|
|
public long SizeOfInstalledFiles { get; set; }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-15 21:52:12 +00:00
|
|
|
|
public class ModlistSummary
|
|
|
|
|
{
|
2020-01-08 04:41:50 +00:00
|
|
|
|
[JsonProperty("name")]
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
[JsonProperty("checked")]
|
|
|
|
|
public DateTime Checked { get; set; }
|
|
|
|
|
[JsonProperty("failed")]
|
|
|
|
|
public int Failed { get; set; }
|
|
|
|
|
[JsonProperty("passed")]
|
|
|
|
|
public int Passed { get; set; }
|
|
|
|
|
[JsonProperty("link")]
|
2019-12-15 21:52:12 +00:00
|
|
|
|
public string Link => $"/lists/status/{Name}.json";
|
2020-01-08 04:41:50 +00:00
|
|
|
|
[JsonProperty("report")]
|
2019-12-15 21:52:12 +00:00
|
|
|
|
public string Report => $"/lists/status/{Name}.html";
|
2020-01-08 04:41:50 +00:00
|
|
|
|
[JsonProperty("has_failures")]
|
2019-12-15 21:52:12 +00:00
|
|
|
|
public bool HasFailures => Failed > 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-15 23:23:14 +00:00
|
|
|
|
}
|