mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-18 22:07:44 +01:00
feat: batch config saves
This commit is contained in:
parent
4769239b19
commit
9c16359914
17 changed files with 69 additions and 37 deletions
|
|
@ -6,6 +6,7 @@ using System.Linq;
|
|||
|
||||
using Dalamud.Game.Text;
|
||||
using Dalamud.Interface.Style;
|
||||
using Dalamud.Utility;
|
||||
using Newtonsoft.Json;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
|
|
@ -28,6 +29,9 @@ internal sealed class DalamudConfiguration : IServiceType
|
|||
[JsonIgnore]
|
||||
private string configPath;
|
||||
|
||||
[JsonIgnore]
|
||||
private bool isSaveQueued;
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for the <see cref="DalamudConfiguration.DalamudConfigurationSaved"/> event that occurs when the dalamud configuration is saved.
|
||||
/// </summary>
|
||||
|
|
@ -368,8 +372,29 @@ internal sealed class DalamudConfiguration : IServiceType
|
|||
/// <summary>
|
||||
/// Save the configuration at the path it was loaded from.
|
||||
/// </summary>
|
||||
public void Save()
|
||||
public void QueueSave()
|
||||
{
|
||||
this.isSaveQueued = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save the file, if needed. Only needs to be done once a frame.
|
||||
/// </summary>
|
||||
internal void Update()
|
||||
{
|
||||
if (this.isSaveQueued)
|
||||
{
|
||||
this.Save();
|
||||
this.isSaveQueued = false;
|
||||
|
||||
Log.Verbose("Config saved");
|
||||
}
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
ThreadSafety.AssertMainThread();
|
||||
|
||||
File.WriteAllText(this.configPath, JsonConvert.SerializeObject(this, SerializerSettings));
|
||||
this.DalamudConfigurationSaved?.Invoke(this);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue