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 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 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
|
public static string UserAgent
|
||||||
{
|
{
|
||||||
|
@ -11,6 +11,7 @@ using Microsoft.Win32;
|
|||||||
namespace Wabbajack.Common
|
namespace Wabbajack.Common
|
||||||
{
|
{
|
||||||
public enum Game {
|
public enum Game {
|
||||||
|
Morrowind,
|
||||||
Oblivion,
|
Oblivion,
|
||||||
Fallout3,
|
Fallout3,
|
||||||
FalloutNewVegas,
|
FalloutNewVegas,
|
||||||
@ -55,6 +56,9 @@ namespace Wabbajack.Common
|
|||||||
|
|
||||||
public static Dictionary<Game, GameMetaData> Games = new Dictionary<Game, GameMetaData>
|
public static Dictionary<Game, GameMetaData> Games = new Dictionary<Game, GameMetaData>
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
Game.Morrowind, new GameMetaData()
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Game.Oblivion, new GameMetaData
|
Game.Oblivion, new GameMetaData
|
||||||
{
|
{
|
||||||
|
@ -6,6 +6,7 @@ using System.Net.Http;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Wabbajack.Common;
|
using Wabbajack.Common;
|
||||||
using Wabbajack.Lib.Downloaders;
|
using Wabbajack.Lib.Downloaders;
|
||||||
using Wabbajack.Lib.Validation;
|
using Wabbajack.Lib.Validation;
|
||||||
@ -18,59 +19,49 @@ namespace Wabbajack.Lib.ModListRegistry
|
|||||||
{
|
{
|
||||||
public class ModlistMetadata
|
public class ModlistMetadata
|
||||||
{
|
{
|
||||||
/// <summary>
|
[JsonProperty("title")]
|
||||||
/// Name of the modlist
|
public string Title { get; set; }
|
||||||
/// </summary>
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
[JsonProperty("description")]
|
||||||
/// 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>
|
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
[JsonProperty("author")]
|
||||||
/// URL of the logo for the modlist
|
public string Author { get; set; }
|
||||||
/// </summary>
|
|
||||||
public string LogoUrl { get; set; }
|
|
||||||
|
|
||||||
[YamlIgnore]
|
[JsonProperty("game")]
|
||||||
public BitmapSource Logo { get; set; }
|
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()
|
public static List<ModlistMetadata> LoadFromGithub()
|
||||||
{
|
{
|
||||||
var d = new DeserializerBuilder()
|
|
||||||
.WithNamingConvention(PascalCaseNamingConvention.Instance)
|
|
||||||
.Build();
|
|
||||||
var client = new HttpClient();
|
var client = new HttpClient();
|
||||||
Utils.Log("Loading Modlists from Github");
|
Utils.Log("Loading Modlists from Github");
|
||||||
using (var result = new StringReader(client.GetStringSync(Consts.ModlistMetadataURL)))
|
var result = client.GetStringSync(Consts.ModlistMetadataURL);
|
||||||
{
|
return result.FromJSONString<List<ModlistMetadata>>();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,14 +24,14 @@ namespace Wabbajack.Test
|
|||||||
{
|
{
|
||||||
var modlists = ModlistMetadata.LoadFromGithub();
|
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.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();
|
//modlist.LoadLogo();
|
||||||
Assert.IsNotNull(modlist.Logo);
|
//Assert.IsNotNull(modlist.Logo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user