mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-02 05:43:40 +01:00
feat: also use reliable storage for plugin configs
This commit is contained in:
parent
125034155b
commit
1d8b579b04
5 changed files with 94 additions and 62 deletions
|
|
@ -436,6 +436,10 @@ internal sealed class DalamudConfiguration : IServiceType, IDisposable
|
|||
{
|
||||
deserialized =
|
||||
JsonConvert.DeserializeObject<DalamudConfiguration>(text, SerializerSettings);
|
||||
|
||||
// If this reads as null, the file was empty, that's no good
|
||||
if (deserialized == null)
|
||||
throw new Exception("Read config was null.");
|
||||
});
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
using System.IO;
|
||||
|
||||
using Dalamud.Utility;
|
||||
using Dalamud.Storage;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dalamud.Configuration;
|
||||
|
|
@ -33,22 +33,36 @@ public sealed class PluginConfigurations
|
|||
/// <param name="pluginName">Plugin name.</param>
|
||||
public void Save(IPluginConfiguration config, string pluginName)
|
||||
{
|
||||
Util.WriteAllTextSafe(this.GetConfigFile(pluginName).FullName, SerializeConfig(config));
|
||||
Service<ReliableFileStorage>.Get()
|
||||
.WriteAllText(this.GetConfigFile(pluginName).FullName, SerializeConfig(config));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load plugin configuration.
|
||||
/// </summary>
|
||||
/// <param name="pluginName">Plugin name.</param>
|
||||
/// <param name="workingPluginId">WorkingPluginID of the plugin.</param>
|
||||
/// <returns>Plugin configuration.</returns>
|
||||
public IPluginConfiguration? Load(string pluginName)
|
||||
public IPluginConfiguration? Load(string pluginName, Guid workingPluginId)
|
||||
{
|
||||
var path = this.GetConfigFile(pluginName);
|
||||
|
||||
if (!path.Exists)
|
||||
return null;
|
||||
IPluginConfiguration? config = null;
|
||||
try
|
||||
{
|
||||
Service<ReliableFileStorage>.Get().ReadAllText(path.FullName, text =>
|
||||
{
|
||||
config = DeserializeConfig(text);
|
||||
if (config == null)
|
||||
throw new Exception("Read config was null.");
|
||||
}, workingPluginId);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
|
||||
return DeserializeConfig(File.ReadAllText(path.FullName));
|
||||
return config;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue