feat: batch config saves

This commit is contained in:
goat 2022-11-01 19:43:38 +01:00
parent 4769239b19
commit 9c16359914
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
17 changed files with 69 additions and 37 deletions

View file

@ -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);
}

View file

@ -334,7 +334,7 @@ public sealed class EntryPoint
Log.Information("User chose to disable plugins on next launch...");
var config = Service<DalamudConfiguration>.Get();
config.PluginSafeMode = true;
config.Save();
config.QueueSave();
}
Log.CloseAndFlush();

View file

@ -269,7 +269,7 @@ public class ChatHandlers : IServiceType
}
this.configuration.LastVersion = assemblyVersion;
this.configuration.Save();
this.configuration.QueueSave();
}
this.hasSeenLoadingMsg = true;

View file

@ -6,6 +6,7 @@ using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Dalamud.Configuration.Internal;
using Dalamud.Game.Gui;
using Dalamud.Game.Gui.Toast;
using Dalamud.Game.Network;
@ -372,12 +373,15 @@ public sealed class Framework : IDisposable, IServiceType
var chatGui = Service<ChatGui>.GetNullable();
var toastGui = Service<ToastGui>.GetNullable();
var gameNetwork = Service<GameNetwork>.GetNullable();
var config = Service<DalamudConfiguration>.GetNullable();
if (chatGui == null || toastGui == null || gameNetwork == null)
goto original;
chatGui.UpdateQueue();
toastGui.UpdateQueue();
gameNetwork.UpdateQueue();
config?.Update();
}
catch (Exception ex)
{

View file

@ -41,7 +41,7 @@ public sealed unsafe class DtrBar : IDisposable, IServiceType
this.configuration.DtrOrder ??= new List<string>();
this.configuration.DtrIgnore ??= new List<string>();
this.configuration.Save();
this.configuration.QueueSave();
}
/// <summary>

View file

@ -65,10 +65,12 @@ public class SwapChainVtableResolver : BaseAddressResolver, ISwapChainAddressRes
// var p = processModule.BaseAddress + 0x82C7E0; // DXGISwapChain::Present
// var p = processModule.BaseAddress + 0x82FAC0; // DXGISwapChain::runtime_present
// DXGISwapChain::handle_device_loss => DXGISwapChain::Present => DXGISwapChain::runtime_present
var scanner = new SigScanner(processModule);
try
{
var p = scanner.ScanText("F6 C2 01 0F 85 ?? ?? ?? ??");
var p = scanner.ScanText("E8 ?? ?? ?? ?? 45 0F B6 5E ??");
Log.Information($"ReShade DLL: {processModule.FileName} with DXGISwapChain::runtime_present at {p:X}");
this.Present = p;

View file

@ -179,7 +179,7 @@ internal class DalamudCommands : IServiceType
configuration.BadWords.Add(arguments);
configuration.Save();
configuration.QueueSave();
chatGui.Print(string.Format(Loc.Localize("DalamudMuted", "Muted \"{0}\"."), arguments));
}
@ -197,7 +197,7 @@ internal class DalamudCommands : IServiceType
return;
}
configuration.Save();
configuration.QueueSave();
foreach (var word in configuration.BadWords)
chatGui.Print($"\"{word}\"");
@ -212,7 +212,7 @@ internal class DalamudCommands : IServiceType
configuration.BadWords.RemoveAll(x => x == arguments);
configuration.Save();
configuration.QueueSave();
chatGui.Print(string.Format(Loc.Localize("DalamudUnmuted", "Unmuted \"{0}\"."), arguments));
}
@ -354,7 +354,7 @@ internal class DalamudCommands : IServiceType
chatGui.Print(string.Format(Loc.Localize("DalamudLanguageSetTo", "Language set to {0}"), "default"));
}
configuration.Save();
configuration.QueueSave();
}
private void OnOpenSettingsCommand(string command, string arguments)

View file

@ -515,7 +515,7 @@ internal class DalamudInterface : IDisposable, IServiceType
if (ImGui.MenuItem("Draw dev menu at startup", string.Empty, ref devBarAtStartup))
{
configuration.DevBarOpenAtStartup ^= true;
configuration.Save();
configuration.QueueSave();
}
ImGui.Separator();
@ -533,7 +533,7 @@ internal class DalamudInterface : IDisposable, IServiceType
{
EntryPoint.LogLevelSwitch.MinimumLevel = logLevel;
configuration.LogLevel = logLevel;
configuration.Save();
configuration.QueueSave();
}
}
@ -544,7 +544,7 @@ internal class DalamudInterface : IDisposable, IServiceType
if (ImGui.MenuItem("Log Synchronously", null, ref logSynchronously))
{
configuration.LogSynchronously = logSynchronously;
configuration.Save();
configuration.QueueSave();
var startupInfo = Service<DalamudStartInfo>.Get();
EntryPoint.InitLogging(
@ -563,7 +563,7 @@ internal class DalamudInterface : IDisposable, IServiceType
antiDebug.Disable();
configuration.IsAntiAntiDebugEnabled = newEnabled;
configuration.Save();
configuration.QueueSave();
}
ImGui.Separator();
@ -693,7 +693,7 @@ internal class DalamudInterface : IDisposable, IServiceType
if (ImGui.MenuItem("Enable asserts at startup", null, configuration.AssertsEnabledAtStartup))
{
configuration.AssertsEnabledAtStartup = !configuration.AssertsEnabledAtStartup;
configuration.Save();
configuration.QueueSave();
}
if (ImGui.MenuItem("Clear focus"))

View file

@ -484,7 +484,7 @@ internal class InterfaceManager : IDisposable, IServiceType
{
style = StyleModelV1.DalamudStandard;
configuration.ChosenStyle = style.Name;
configuration.Save();
configuration.QueueSave();
}
style.Apply();

View file

@ -88,7 +88,7 @@ public class BranchSwitcherWindow : Window
var config = Service<DalamudConfiguration>.Get();
config.DalamudBetaKind = pickedBranch.Key;
config.DalamudBetaKey = pickedBranch.Value.Key;
config.Save();
config.QueueSave();
}
if (ImGui.Button("Pick"))

View file

@ -130,13 +130,13 @@ internal class ConsoleWindow : Window, IDisposable
if (ImGui.Checkbox("Auto-scroll", ref this.autoScroll))
{
configuration.LogAutoScroll = this.autoScroll;
configuration.Save();
configuration.QueueSave();
}
if (ImGui.Checkbox("Open at startup", ref this.openAtStartup))
{
configuration.LogOpenAtStartup = this.openAtStartup;
configuration.Save();
configuration.QueueSave();
}
var prevLevel = (int)EntryPoint.LogLevelSwitch.MinimumLevel;
@ -144,7 +144,7 @@ internal class ConsoleWindow : Window, IDisposable
{
EntryPoint.LogLevelSwitch.MinimumLevel = (LogEventLevel)prevLevel;
configuration.LogLevel = (LogEventLevel)prevLevel;
configuration.Save();
configuration.QueueSave();
}
ImGui.EndPopup();

View file

@ -207,7 +207,7 @@ internal class PluginInstallerWindow : Window, IDisposable
/// <inheritdoc/>
public override void OnClose()
{
Service<DalamudConfiguration>.Get().Save();
Service<DalamudConfiguration>.Get().QueueSave();
}
/// <inheritdoc/>
@ -477,7 +477,7 @@ internal class PluginInstallerWindow : Window, IDisposable
if (ImGui.Button(closeText))
{
this.IsOpen = false;
configuration.Save();
configuration.QueueSave();
}
}
@ -1834,7 +1834,7 @@ internal class PluginInstallerWindow : Window, IDisposable
if (ImGui.Selectable(Locs.PluginContext_MarkAllSeen))
{
configuration.SeenPluginInternalName.AddRange(this.pluginListAvailable.Select(x => x.InternalName));
configuration.Save();
configuration.QueueSave();
pluginManager.RefilterPluginMasters();
}
@ -1842,7 +1842,7 @@ internal class PluginInstallerWindow : Window, IDisposable
{
Log.Debug($"Adding {manifest.InternalName} to hidden plugins");
configuration.HiddenPluginInternalName.Add(manifest.InternalName);
configuration.Save();
configuration.QueueSave();
pluginManager.RefilterPluginMasters();
}
@ -2146,7 +2146,7 @@ internal class PluginInstallerWindow : Window, IDisposable
configuration.PluginTestingOptIns!.Add(new PluginTestingOptIn(plugin.Manifest.InternalName));
}
configuration.Save();
configuration.QueueSave();
}
if (repoManifest?.IsTestingExclusive == true)
@ -2419,7 +2419,7 @@ internal class PluginInstallerWindow : Window, IDisposable
if (ImGuiComponents.IconButton(FontAwesomeIcon.PowerOff))
{
plugin.StartOnBoot ^= true;
configuration.Save();
configuration.QueueSave();
}
ImGui.PopStyleColor(2);
@ -2437,7 +2437,7 @@ internal class PluginInstallerWindow : Window, IDisposable
if (ImGuiComponents.IconButton(FontAwesomeIcon.SyncAlt))
{
plugin.AutomaticReload ^= true;
configuration.Save();
configuration.QueueSave();
}
ImGui.PopStyleColor(2);

View file

@ -974,7 +974,7 @@ internal class SettingsWindow : Window
configuration.DoButtonsSystemMenu = this.doButtonsSystemMenu;
configuration.DisableRmtFiltering = this.disableRmtFiltering;
configuration.Save();
configuration.QueueSave();
_ = Service<PluginManager>.Get().ReloadPluginMastersAsync();
Service<InterfaceManager>.Get().RebuildFonts();

View file

@ -105,7 +105,7 @@ public class StyleEditorWindow : Window
newStyle.Apply();
appliedThisFrame = true;
config.Save();
config.QueueSave();
}
ImGui.SameLine();
@ -119,7 +119,7 @@ public class StyleEditorWindow : Window
config.SavedStyles.RemoveAt(this.currentSel + 1);
config.Save();
config.QueueSave();
}
if (ImGui.IsItemHovered())
@ -180,7 +180,7 @@ public class StyleEditorWindow : Window
this.currentSel = config.SavedStyles.Count - 1;
config.Save();
config.QueueSave();
}
catch (Exception ex)
{
@ -366,7 +366,7 @@ public class StyleEditorWindow : Window
if (ImGui.Button("OK", new Vector2(buttonWidth, 40)))
{
config.SavedStyles[this.currentSel].Name = this.renameText;
config.Save();
config.QueueSave();
ImGui.CloseCurrentPopup();
}
@ -396,6 +396,6 @@ public class StyleEditorWindow : Window
config.SavedStyles[this.currentSel] = newStyle;
newStyle.Apply();
config.Save();
config.QueueSave();
}
}

View file

@ -93,7 +93,7 @@ public abstract class StyleModel
Log.Information("Transferred {NumStyles} styles", configuration.SavedStyles.Count);
configuration.SavedStylesOld = null;
configuration.Save();
configuration.QueueSave();
}
/// <summary>

View file

@ -106,7 +106,7 @@ Thanks and have fun!";
if (this.SafeMode)
{
this.configuration.PluginSafeMode = false;
this.configuration.Save();
this.configuration.QueueSave();
}
this.PluginConfigs = new PluginConfigurations(Path.Combine(Path.GetDirectoryName(this.startInfo.ConfigurationPath) ?? string.Empty, "pluginConfigs"));
@ -409,7 +409,7 @@ Thanks and have fun!";
}
}
this.configuration.Save();
this.configuration.QueueSave();
try
{
@ -716,8 +716,9 @@ Thanks and have fun!";
// Ensure that we have a testing opt-in for this plugin if we are installing a testing version
if (useTesting && this.configuration.PluginTestingOptIns!.All(x => x.InternalName != repoManifest.InternalName))
{
// TODO: this isn't safe
this.configuration.PluginTestingOptIns.Add(new PluginTestingOptIn(repoManifest.InternalName));
this.configuration.Save();
this.configuration.QueueSave();
}
var downloadUrl = useTesting ? repoManifest.DownloadLinkTesting : repoManifest.DownloadLinkInstall;

View file

@ -37,7 +37,7 @@ internal class LocalDevPlugin : LocalPlugin, IDisposable
if (!configuration.DevPluginSettings.TryGetValue(dllFile.FullName, out this.devSettings))
{
configuration.DevPluginSettings[dllFile.FullName] = this.devSettings = new DevPluginSettings();
configuration.Save();
configuration.QueueSave();
}
if (this.AutomaticReload)