mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Merge pull request #108 from wabbajack-tools/rework-json
rework modlist metadata code to use static site json
This commit is contained in:
commit
f471a534c6
@ -50,7 +50,7 @@ namespace Wabbajack.Common
|
||||
|
||||
public static string ModPermissionsURL = "https://raw.githubusercontent.com/wabbajack-tools/opt-out-lists/master/NexusModPermissions.yml";
|
||||
public static string ServerWhitelistURL = "https://raw.githubusercontent.com/wabbajack-tools/opt-out-lists/master/ServerWhitelist.yml";
|
||||
public static string ModlistMetadataURL = "https://raw.githubusercontent.com/wabbajack-tools/mod-lists/master/Modlists.yaml";
|
||||
public static string ModlistMetadataURL = "https://raw.githubusercontent.com/wabbajack-tools/wabbajack-tools.github.io/code/src/assets/states/modlistState.json";
|
||||
|
||||
public static string UserAgent
|
||||
{
|
||||
|
@ -11,6 +11,7 @@ using Microsoft.Win32;
|
||||
namespace Wabbajack.Common
|
||||
{
|
||||
public enum Game {
|
||||
Morrowind,
|
||||
Oblivion,
|
||||
Fallout3,
|
||||
FalloutNewVegas,
|
||||
@ -55,6 +56,9 @@ namespace Wabbajack.Common
|
||||
|
||||
public static Dictionary<Game, GameMetaData> Games = new Dictionary<Game, GameMetaData>
|
||||
{
|
||||
{
|
||||
Game.Morrowind, new GameMetaData()
|
||||
},
|
||||
{
|
||||
Game.Oblivion, new GameMetaData
|
||||
{
|
||||
|
@ -6,6 +6,7 @@ using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Newtonsoft.Json;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Lib.Downloaders;
|
||||
using Wabbajack.Lib.Validation;
|
||||
@ -18,59 +19,49 @@ namespace Wabbajack.Lib.ModListRegistry
|
||||
{
|
||||
public class ModlistMetadata
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of the modlist
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("title")]
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of the author of the modlist
|
||||
/// </summary>
|
||||
public string Author { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Game this modlist is for
|
||||
/// </summary>
|
||||
public Game Game { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Short description of the modlist
|
||||
/// </summary>
|
||||
[JsonProperty("description")]
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// URL of the logo for the modlist
|
||||
/// </summary>
|
||||
public string LogoUrl { get; set; }
|
||||
[JsonProperty("author")]
|
||||
public string Author { get; set; }
|
||||
|
||||
[YamlIgnore]
|
||||
public BitmapSource Logo { get; set; }
|
||||
[JsonProperty("game")]
|
||||
public Game Game { get; set; }
|
||||
|
||||
[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; }
|
||||
|
||||
[JsonIgnore]
|
||||
public BitmapImage Image { get; set; }
|
||||
|
||||
[JsonProperty("readme")]
|
||||
public string Readme { get; set; }
|
||||
|
||||
[JsonProperty("download")]
|
||||
public string Download { get; set; }
|
||||
|
||||
[JsonProperty("machineURL")]
|
||||
public string MachineURL { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download URL
|
||||
/// </summary>
|
||||
public string DownloadUrl { get; set; }
|
||||
|
||||
public static List<ModlistMetadata> LoadFromGithub()
|
||||
{
|
||||
var d = new DeserializerBuilder()
|
||||
.WithNamingConvention(PascalCaseNamingConvention.Instance)
|
||||
.Build();
|
||||
var client = new HttpClient();
|
||||
Utils.Log("Loading Modlists from Github");
|
||||
using (var result = new StringReader(client.GetStringSync(Consts.ModlistMetadataURL)))
|
||||
{
|
||||
return d.Deserialize<List<ModlistMetadata>>(result);
|
||||
}
|
||||
}
|
||||
|
||||
public ModlistMetadata LoadLogo()
|
||||
{
|
||||
// Todo: look at making this stream based instead of requiring a file
|
||||
var temp_file = Path.GetTempFileName();
|
||||
DownloadDispatcher.ResolveArchive(LogoUrl).Download(new Archive {Name = LogoUrl}, temp_file);
|
||||
Logo = new BitmapImage(new Uri(temp_file));
|
||||
return this;
|
||||
var result = client.GetStringSync(Consts.ModlistMetadataURL);
|
||||
return result.FromJSONString<List<ModlistMetadata>>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,14 +24,14 @@ namespace Wabbajack.Test
|
||||
{
|
||||
var modlists = ModlistMetadata.LoadFromGithub();
|
||||
|
||||
foreach (var modlist in modlists)
|
||||
foreach (var modlist in modlists.Select(m => m.Links))
|
||||
{
|
||||
var logo_state = DownloadDispatcher.ResolveArchive(modlist.LogoUrl);
|
||||
var logo_state = DownloadDispatcher.ResolveArchive(modlist.ImageUri);
|
||||
Assert.IsNotNull(logo_state);
|
||||
Assert.IsTrue(logo_state.Verify(), $"{modlist.LogoUrl} is not valid");
|
||||
Assert.IsTrue(logo_state.Verify(), $"{modlist.ImageUri} is not valid");
|
||||
|
||||
modlist.LoadLogo();
|
||||
Assert.IsNotNull(modlist.Logo);
|
||||
//modlist.LoadLogo();
|
||||
//Assert.IsNotNull(modlist.Logo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user