Fix upgrading test broken by Nexus JSON property name change

This commit is contained in:
Timothy Baldridge 2020-04-01 06:17:38 -06:00
parent 8e5647c474
commit 8946389da4
3 changed files with 57 additions and 37 deletions

View File

@ -15,18 +15,17 @@ namespace Wabbajack.Common
new RelativePathConverter(),
new AbolutePathConverter(),
new HashRelativePathConverter(),
new FullPathConverter()
new FullPathConverter(),
new GameConverter()
};
public static void ToJSON<T>(this T obj, string filename)
{
if (File.Exists(filename))
File.Delete(filename);
File.WriteAllText(filename,
JsonConvert.SerializeObject(obj, Formatting.Indented,
new JsonSerializerSettings {
TypeNameHandling = TypeNameHandling.Auto,
Converters = Converters}));
new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.Auto, Converters = Converters}));
}
public static string ToJSON<T>(this T obj,
@ -35,7 +34,9 @@ namespace Wabbajack.Common
bool prettyPrint = false)
{
return JsonConvert.SerializeObject(obj, Formatting.Indented,
new JsonSerializerSettings {TypeNameHandling = handling,
new JsonSerializerSettings
{
TypeNameHandling = handling,
TypeNameAssemblyFormatHandling = format,
Formatting = prettyPrint ? Formatting.Indented : Formatting.None,
Converters = Converters
@ -47,9 +48,9 @@ namespace Wabbajack.Common
TypeNameAssemblyFormatHandling format = TypeNameAssemblyFormatHandling.Full)
{
return JsonConvert.DeserializeObject<T>(filename.ReadAllText(),
new JsonSerializerSettings {TypeNameHandling = handling,
TypeNameAssemblyFormatHandling = format,
Converters = Converters
new JsonSerializerSettings
{
TypeNameHandling = handling, TypeNameAssemblyFormatHandling = format, Converters = Converters
});
}
@ -58,9 +59,9 @@ namespace Wabbajack.Common
TypeNameAssemblyFormatHandling format = TypeNameAssemblyFormatHandling.Full)
{
return JsonConvert.DeserializeObject<T>(data,
new JsonSerializerSettings {TypeNameHandling = handling,
TypeNameAssemblyFormatHandling = format,
Converters = Converters
new JsonSerializerSettings
{
TypeNameHandling = handling, TypeNameAssemblyFormatHandling = format, Converters = Converters
});
}
@ -70,11 +71,7 @@ namespace Wabbajack.Common
try
{
return JsonConvert.DeserializeObject<T>(s,
new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto,
Converters = Converters
});
new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.Auto, Converters = Converters});
}
catch (JsonSerializationException)
{
@ -94,7 +91,8 @@ namespace Wabbajack.Common
writer.WriteValue(value.ToBase64());
}
public override Hash ReadJson(JsonReader reader, Type objectType, Hash existingValue, bool hasExistingValue, JsonSerializer serializer)
public override Hash ReadJson(JsonReader reader, Type objectType, Hash existingValue, bool hasExistingValue,
JsonSerializer serializer)
{
return Hash.FromBase64((string)reader.Value);
}
@ -107,7 +105,8 @@ namespace Wabbajack.Common
writer.WriteValue((string)value);
}
public override RelativePath ReadJson(JsonReader reader, Type objectType, RelativePath existingValue, bool hasExistingValue,
public override RelativePath ReadJson(JsonReader reader, Type objectType, RelativePath existingValue,
bool hasExistingValue,
JsonSerializer serializer)
{
return (RelativePath)(string)reader.Value;
@ -121,7 +120,8 @@ namespace Wabbajack.Common
writer.WriteValue((string)value);
}
public override AbsolutePath ReadJson(JsonReader reader, Type objectType, AbsolutePath existingValue, bool hasExistingValue,
public override AbsolutePath ReadJson(JsonReader reader, Type objectType, AbsolutePath existingValue,
bool hasExistingValue,
JsonSerializer serializer)
{
return (AbsolutePath)(string)reader.Value;
@ -139,7 +139,8 @@ namespace Wabbajack.Common
writer.WriteEndArray();
}
public override HashRelativePath ReadJson(JsonReader reader, Type objectType, HashRelativePath existingValue, bool hasExistingValue,
public override HashRelativePath ReadJson(JsonReader reader, Type objectType,
HashRelativePath existingValue, bool hasExistingValue,
JsonSerializer serializer)
{
if (reader.TokenType != JsonToken.StartArray)
@ -171,7 +172,8 @@ namespace Wabbajack.Common
writer.WriteEndArray();
}
public override FullPath ReadJson(JsonReader reader, Type objectType, FullPath existingValue, bool hasExistingValue,
public override FullPath ReadJson(JsonReader reader, Type objectType, FullPath existingValue,
bool hasExistingValue,
JsonSerializer serializer)
{
if (reader.TokenType != JsonToken.StartArray)
@ -192,6 +194,19 @@ namespace Wabbajack.Common
}
}
public class GameConverter : JsonConverter<Game>
{
public override void WriteJson(JsonWriter writer, Game value, JsonSerializer serializer)
{
writer.WriteValue(Enum.GetName(typeof(Game), value));
}
public override Game ReadJson(JsonReader reader, Type objectType, Game existingValue,
bool hasExistingValue,
JsonSerializer serializer)
{
return GameRegistry.GetByFuzzyName((string)reader.Value).Game;
}
}
}
}

View File

@ -102,6 +102,7 @@ namespace Wabbajack.Lib.Downloaders
Utils.Log($"No upgrade found for {archive.Hash}");
return false;
}
Utils.Log($"Upgrading via {upgrade.State.PrimaryKeyString}");
Utils.Log($"Upgrading {archive.Hash}");
var upgradePath = destination.Parent.Combine("_Upgrade_" + archive.Name);

View File

@ -5,9 +5,11 @@ using System.Reactive.Linq;
using System.Threading.Tasks;
using MessagePack;
using MongoDB.Bson.Serialization.Attributes;
using Newtonsoft.Json;
using ReactiveUI;
using Wabbajack.Common;
using Wabbajack.Common.StatusFeed.Errors;
using Wabbajack.Lib.CompilationSteps;
using Wabbajack.Lib.NexusApi;
using Wabbajack.Lib.Validation;
using Game = Wabbajack.Common.Game;
@ -146,6 +148,8 @@ namespace Wabbajack.Lib.Downloaders
public string Description { get; set; }
[Key(6)]
[JsonProperty("GameName")]
[JsonConverter(typeof(Utils.GameConverter))]
public Game Game { get; set; }
[Key(7)]