2019-12-15 21:52:12 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2019-12-06 05:59:57 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2019-10-19 10:55:05 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2019-10-15 23:23:14 +00:00
|
|
|
|
using Wabbajack.Common;
|
2020-04-06 20:48:54 +00:00
|
|
|
|
using Wabbajack.Common.Serialization.Json;
|
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
|
|
|
|
{
|
2020-04-08 04:19:36 +00:00
|
|
|
|
[JsonName("ModListMetadata")]
|
2019-10-15 23:23:14 +00:00
|
|
|
|
public class ModlistMetadata
|
|
|
|
|
{
|
2019-10-19 10:55:05 +00:00
|
|
|
|
[JsonProperty("title")]
|
2020-04-10 01:29:53 +00:00
|
|
|
|
public string Title { get; set; } = string.Empty;
|
2019-10-15 23:23:14 +00:00
|
|
|
|
|
2019-10-19 10:55:05 +00:00
|
|
|
|
[JsonProperty("description")]
|
2020-04-10 01:29:53 +00:00
|
|
|
|
public string Description { get; set; } = string.Empty;
|
2019-10-19 10:55:05 +00:00
|
|
|
|
|
|
|
|
|
[JsonProperty("author")]
|
2020-04-10 01:29:53 +00:00
|
|
|
|
public string Author { get; set; } = string.Empty;
|
2019-10-15 23:23:14 +00:00
|
|
|
|
|
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
|
|
|
|
|
2020-05-09 04:19:40 +00:00
|
|
|
|
[JsonProperty("tags")]
|
|
|
|
|
public List<string> tags { get; set; } = new List<string>();
|
|
|
|
|
|
2020-04-27 10:18:08 +00:00
|
|
|
|
[JsonProperty("nsfw")]
|
|
|
|
|
public bool NSFW { get; set; }
|
2020-11-14 19:16:11 +00:00
|
|
|
|
|
|
|
|
|
[JsonProperty("utility_list")]
|
|
|
|
|
public bool UtilityList { get; set; }
|
2020-12-16 01:26:41 +00:00
|
|
|
|
|
|
|
|
|
[JsonProperty("image_contains_title")]
|
|
|
|
|
public bool ImageContainsTitle { get; set; }
|
2020-04-27 10:18:08 +00:00
|
|
|
|
|
2020-11-19 22:56:30 +00:00
|
|
|
|
[JsonProperty("force_down")]
|
|
|
|
|
public bool ForceDown { 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")]
|
2020-04-10 01:29:53 +00:00
|
|
|
|
public DownloadMetadata? DownloadMetadata { get; set; }
|
2019-11-29 05:52:33 +00:00
|
|
|
|
|
2019-12-15 21:52:12 +00:00
|
|
|
|
[JsonIgnore]
|
2020-04-08 04:19:36 +00:00
|
|
|
|
public ModListSummary ValidationSummary { get; set; } = new ModListSummary();
|
2019-12-15 21:52:12 +00:00
|
|
|
|
|
2020-04-08 04:19:36 +00:00
|
|
|
|
[JsonName("Links")]
|
2019-10-19 10:55:05 +00:00
|
|
|
|
public class LinksObject
|
|
|
|
|
{
|
2021-02-27 00:08:05 +00:00
|
|
|
|
[JsonProperty("image")]
|
|
|
|
|
public string ImageUri { get; set; } = string.Empty;
|
2019-10-15 23:23:14 +00:00
|
|
|
|
|
2019-10-19 10:55:05 +00:00
|
|
|
|
[JsonProperty("readme")]
|
2020-04-10 01:29:53 +00:00
|
|
|
|
public string Readme { get; set; } = string.Empty;
|
2019-10-19 10:55:05 +00:00
|
|
|
|
|
|
|
|
|
[JsonProperty("download")]
|
2020-04-10 01:29:53 +00:00
|
|
|
|
public string Download { get; set; } = string.Empty;
|
|
|
|
|
|
2019-10-19 10:55:05 +00:00
|
|
|
|
[JsonProperty("machineURL")]
|
2020-04-10 01:29:53 +00:00
|
|
|
|
public string MachineURL { get; set; } = string.Empty;
|
2019-10-19 10:55:05 +00:00
|
|
|
|
}
|
2019-10-16 23:05:51 +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-07-16 21:17:37 +00:00
|
|
|
|
var client = new 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);
|
2020-11-19 22:56:30 +00:00
|
|
|
|
var utilityResult = client.GetStringAsync(Consts.UtilityModlistMetadataURL);
|
2019-12-15 21:52:12 +00:00
|
|
|
|
var summaryResult = client.GetStringAsync(Consts.ModlistSummaryURL);
|
|
|
|
|
|
2020-04-06 20:48:54 +00:00
|
|
|
|
var metadata = (await metadataResult).FromJsonString<List<ModlistMetadata>>();
|
2020-11-19 22:56:30 +00:00
|
|
|
|
metadata = metadata.Concat((await utilityResult).FromJsonString<List<ModlistMetadata>>()).ToList();
|
2019-12-15 21:52:12 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2020-04-08 04:19:36 +00:00
|
|
|
|
var summaries = (await summaryResult).FromJsonString<List<ModListSummary>>().ToDictionary(d => d.MachineURL);
|
2019-12-15 21:52:12 +00:00
|
|
|
|
|
|
|
|
|
foreach (var data in metadata)
|
2020-04-08 04:19:36 +00:00
|
|
|
|
if (summaries.TryGetValue(data.Links.MachineURL, out var summary))
|
2019-12-15 21:52:12 +00:00
|
|
|
|
data.ValidationSummary = summary;
|
|
|
|
|
}
|
2020-03-28 13:33:39 +00:00
|
|
|
|
catch (Exception)
|
2019-12-15 21:52:12 +00:00
|
|
|
|
{
|
2020-03-28 13:33:39 +00:00
|
|
|
|
// ignored
|
2019-12-15 21:52:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
2020-07-16 21:17:37 +00:00
|
|
|
|
|
|
|
|
|
public static async Task<List<ModlistMetadata>> LoadUnlistedFromGithub()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var client = new Http.Client();
|
2020-08-12 04:25:12 +00:00
|
|
|
|
return (await client.GetStringAsync(Consts.UnlistedModlistMetadataURL)).FromJsonString<List<ModlistMetadata>>();
|
2020-07-16 21:17:37 +00:00
|
|
|
|
}
|
2020-10-01 03:50:09 +00:00
|
|
|
|
catch (Exception)
|
2020-07-16 21:17:37 +00:00
|
|
|
|
{
|
|
|
|
|
Utils.LogStatus("Error loading unlisted modlists");
|
|
|
|
|
return new List<ModlistMetadata>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2020-03-28 20:04:22 +00:00
|
|
|
|
|
2020-05-25 17:34:25 +00:00
|
|
|
|
public async ValueTask<bool> NeedsDownload(AbsolutePath modlistPath)
|
2020-03-28 20:04:22 +00:00
|
|
|
|
{
|
|
|
|
|
if (!modlistPath.Exists) return true;
|
|
|
|
|
if (DownloadMetadata?.Hash == null)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2021-01-09 19:04:11 +00:00
|
|
|
|
return DownloadMetadata.Hash != await modlistPath.FileHashCachedAsync();
|
2020-03-28 20:04:22 +00:00
|
|
|
|
}
|
2019-10-15 23:23:14 +00:00
|
|
|
|
}
|
2019-11-05 22:11:39 +00:00
|
|
|
|
|
2020-04-06 20:48:54 +00:00
|
|
|
|
[JsonName("DownloadMetadata")]
|
2019-11-29 05:52:33 +00:00
|
|
|
|
public class DownloadMetadata
|
|
|
|
|
{
|
2020-03-22 15:50:53 +00:00
|
|
|
|
public Hash Hash { get; set; }
|
2019-11-29 05:52:33 +00:00
|
|
|
|
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; }
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-08 04:19:36 +00:00
|
|
|
|
[JsonName("ModListSummary")]
|
|
|
|
|
public class ModListSummary
|
2019-12-15 21:52:12 +00:00
|
|
|
|
{
|
2020-01-08 04:41:50 +00:00
|
|
|
|
[JsonProperty("name")]
|
2020-04-10 01:29:53 +00:00
|
|
|
|
public string Name { get; set; } = string.Empty;
|
|
|
|
|
|
2020-02-27 13:46:34 +00:00
|
|
|
|
[JsonProperty("machineURL")]
|
2020-04-10 01:29:53 +00:00
|
|
|
|
public string MachineURL { get; set; } = string.Empty;
|
|
|
|
|
|
2020-01-08 04:41:50 +00:00
|
|
|
|
[JsonProperty("checked")]
|
|
|
|
|
public DateTime Checked { get; set; }
|
|
|
|
|
[JsonProperty("failed")]
|
|
|
|
|
public int Failed { get; set; }
|
|
|
|
|
[JsonProperty("passed")]
|
|
|
|
|
public int Passed { get; set; }
|
2020-04-15 03:25:00 +00:00
|
|
|
|
[JsonProperty("updating")]
|
|
|
|
|
public int Updating { get; set; }
|
2020-08-08 20:20:15 +00:00
|
|
|
|
|
|
|
|
|
[JsonProperty("mirrored")]
|
|
|
|
|
public int Mirrored { get; set; }
|
2020-04-15 03:25:00 +00:00
|
|
|
|
|
2020-01-08 04:41:50 +00:00
|
|
|
|
[JsonProperty("link")]
|
2020-02-27 13:46:34 +00:00
|
|
|
|
public string Link => $"/lists/status/{MachineURL}.json";
|
2020-01-08 04:41:50 +00:00
|
|
|
|
[JsonProperty("report")]
|
2020-02-27 13:46:34 +00:00
|
|
|
|
public string Report => $"/lists/status/{MachineURL}.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
|
|
|
|
}
|