mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-29 03:49:19 +01:00
fix: save plugin configs with type, in external directory
This commit is contained in:
parent
dabe178fd5
commit
6529b3429f
8 changed files with 64 additions and 40 deletions
|
|
@ -29,14 +29,12 @@ namespace Dalamud
|
|||
|
||||
public string LastVersion { get; set; }
|
||||
|
||||
public Dictionary<string, object> PluginConfigurations { get; set; }
|
||||
|
||||
public static DalamudConfiguration Load(string path) {
|
||||
return JsonConvert.DeserializeObject<DalamudConfiguration>(File.ReadAllText(path));
|
||||
}
|
||||
|
||||
public void Save(string path) {
|
||||
File.WriteAllText(path, JsonConvert.SerializeObject(this));
|
||||
File.WriteAllText(path, JsonConvert.SerializeObject(this, Formatting.Indented));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
43
Dalamud/Configuration/PluginConfigurations.cs
Normal file
43
Dalamud/Configuration/PluginConfigurations.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dalamud.Configuration
|
||||
{
|
||||
public class PluginConfigurations {
|
||||
private DirectoryInfo configDirectory;
|
||||
|
||||
public PluginConfigurations(string storageFolder) {
|
||||
this.configDirectory = new DirectoryInfo(storageFolder);
|
||||
this.configDirectory.Create();
|
||||
}
|
||||
|
||||
public void Save(IPluginConfiguration config, string pluginName) {
|
||||
File.WriteAllText(GetPath(pluginName).FullName, JsonConvert.SerializeObject(config, Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
|
||||
TypeNameHandling = TypeNameHandling.Objects
|
||||
}));
|
||||
}
|
||||
|
||||
public IPluginConfiguration Load(string pluginName) {
|
||||
var path = GetPath(pluginName);
|
||||
|
||||
if (!path.Exists)
|
||||
return null;
|
||||
|
||||
return JsonConvert.DeserializeObject<IPluginConfiguration>(File.ReadAllText(path.FullName),
|
||||
new JsonSerializerSettings {
|
||||
TypeNameAssemblyFormatHandling =
|
||||
TypeNameAssemblyFormatHandling.Simple,
|
||||
TypeNameHandling = TypeNameHandling.Objects
|
||||
});
|
||||
}
|
||||
|
||||
private FileInfo GetPath(string pluginName) => new FileInfo(Path.Combine(this.configDirectory.FullName, $"{pluginName}.json"));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue