mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Fix serialization of IPaths
This commit is contained in:
parent
8f08ac8003
commit
8efdfcd5f0
@ -9,6 +9,7 @@ using Newtonsoft.Json;
|
|||||||
using Newtonsoft.Json.Serialization;
|
using Newtonsoft.Json.Serialization;
|
||||||
using Wabbajack.Common.Serialization.Json;
|
using Wabbajack.Common.Serialization.Json;
|
||||||
using File = Alphaleonis.Win32.Filesystem.File;
|
using File = Alphaleonis.Win32.Filesystem.File;
|
||||||
|
using Path = Alphaleonis.Win32.Filesystem.Path;
|
||||||
|
|
||||||
namespace Wabbajack.Common
|
namespace Wabbajack.Common
|
||||||
{
|
{
|
||||||
@ -23,6 +24,7 @@ namespace Wabbajack.Common
|
|||||||
new FullPathConverter(),
|
new FullPathConverter(),
|
||||||
new GameConverter(),
|
new GameConverter(),
|
||||||
new PercentConverter(),
|
new PercentConverter(),
|
||||||
|
new IPathConverter(),
|
||||||
};
|
};
|
||||||
|
|
||||||
public static JsonSerializerSettings JsonSettings =>
|
public static JsonSerializerSettings JsonSettings =>
|
||||||
@ -233,6 +235,28 @@ namespace Wabbajack.Common
|
|||||||
return game.Game;
|
return game.Game;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class IPathConverter : JsonConverter<IPath>
|
||||||
|
{
|
||||||
|
public override void WriteJson(JsonWriter writer, IPath value, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
writer.WriteValue(Enum.GetName(typeof(Game), value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IPath ReadJson(JsonReader reader, Type objectType, IPath existingValue,
|
||||||
|
bool hasExistingValue,
|
||||||
|
JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
// Backwards compatibility support
|
||||||
|
var str = reader.Value?.ToString();
|
||||||
|
if (string.IsNullOrWhiteSpace(str)) return default(RelativePath);
|
||||||
|
|
||||||
|
if (Path.IsPathRooted(str))
|
||||||
|
return (AbsolutePath)str;
|
||||||
|
return (RelativePath)str;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user