mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-13 19:37:44 +01:00
Fix SeString serialization/deserialization (#840)
* chore: add SeString JSON conversion test * fix: SeString JSON serialization * chore: add SeString JSON deserialization test * chore: rename tests to abstract format away * chore: fix typos * fix: deserializable SeStrings * chore: add comment to test * chore: use DeserializeConfig in Load
This commit is contained in:
parent
6dcddb1f29
commit
387a820392
3 changed files with 104 additions and 14 deletions
|
|
@ -21,6 +21,36 @@ namespace Dalamud.Configuration
|
|||
this.configDirectory.Create();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes a plugin configuration object.
|
||||
/// </summary>
|
||||
/// <param name="config">The configuration object.</param>
|
||||
/// <returns>A string representing the serialized configuration object.</returns>
|
||||
internal static string SerializeConfig(object? config)
|
||||
{
|
||||
return JsonConvert.SerializeObject(config, Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
|
||||
TypeNameHandling = TypeNameHandling.Objects,
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes a plugin configuration from a string.
|
||||
/// </summary>
|
||||
/// <param name="data">The serialized configuration.</param>
|
||||
/// <returns>The configuration object, or null.</returns>
|
||||
internal static IPluginConfiguration? DeserializeConfig(string data)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<IPluginConfiguration>(
|
||||
data,
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
|
||||
TypeNameHandling = TypeNameHandling.Objects,
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save/Load plugin configuration.
|
||||
/// NOTE: Save/Load are still using Type information for now,
|
||||
|
|
@ -32,11 +62,7 @@ namespace Dalamud.Configuration
|
|||
/// <param name="pluginName">Plugin name.</param>
|
||||
public void Save(IPluginConfiguration config, string pluginName)
|
||||
{
|
||||
File.WriteAllText(this.GetConfigFile(pluginName).FullName, JsonConvert.SerializeObject(config, Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
|
||||
TypeNameHandling = TypeNameHandling.Objects,
|
||||
}));
|
||||
File.WriteAllText(this.GetConfigFile(pluginName).FullName, SerializeConfig(config));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -51,13 +77,7 @@ namespace Dalamud.Configuration
|
|||
if (!path.Exists)
|
||||
return null;
|
||||
|
||||
return JsonConvert.DeserializeObject<IPluginConfiguration>(
|
||||
File.ReadAllText(path.FullName),
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
|
||||
TypeNameHandling = TypeNameHandling.Objects,
|
||||
});
|
||||
return DeserializeConfig(File.ReadAllText(path.FullName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue