diff --git a/Glamourer/Configuration.cs b/Glamourer/Configuration.cs index 4490fa0..841fe68 100644 --- a/Glamourer/Configuration.cs +++ b/Glamourer/Configuration.cs @@ -19,40 +19,34 @@ namespace Glamourer; public class Configuration : IPluginConfiguration, ISavable { - public bool UseRestrictedGearProtection { get; set; } = false; - public bool OpenFoldersByDefault { get; set; } = false; - public bool AutoRedrawEquipOnChanges { get; set; } = false; - public bool EnableAutoDesigns { get; set; } = true; - public bool IncognitoMode { get; set; } = false; - public bool UnlockDetailMode { get; set; } = true; - public bool HideApplyCheckmarks { get; set; } = false; - public bool SmallEquip { get; set; } = false; - public bool UnlockedItemMode { get; set; } = false; - public byte DisableFestivals { get; set; } = 1; - public bool EnableGameContextMenu { get; set; } = true; - public bool HideWindowInCutscene { get; set; } = false; - public bool ShowAutomationSetEditing { get; set; } = true; - public bool ShowAllAutomatedApplicationRules { get; set; } = true; - public bool ShowUnlockedItemWarnings { get; set; } = true; - public bool RevertManualChangesOnZoneChange { get; set; } = false; - public bool ShowDesignQuickBar { get; set; } = false; - public bool LockDesignQuickBar { get; set; } = false; - public bool ShowQuickBarInTabs { get; set; } = true; - public bool LockMainWindow { get; set; } = false; - public bool OpenWindowAtStart { get; set; } = false; + [JsonIgnore] + public readonly EphemeralConfig Ephemeral; - public ModifiableHotkey ToggleQuickDesignBar { get; set; } = new(VirtualKey.NO_KEY); - public MainWindow.TabType SelectedTab { get; set; } = MainWindow.TabType.Settings; - public DoubleModifier DeleteDesignModifier { get; set; } = new(ModifierHotkey.Control, ModifierHotkey.Shift); - - public int LastSeenVersion { get; set; } = GlamourerChangelog.LastChangelogVersion; - public ChangeLogDisplayType ChangeLogDisplayType { get; set; } = ChangeLogDisplayType.New; + public bool UseRestrictedGearProtection { get; set; } = false; + public bool OpenFoldersByDefault { get; set; } = false; + public bool AutoRedrawEquipOnChanges { get; set; } = false; + public bool EnableAutoDesigns { get; set; } = true; + public bool HideApplyCheckmarks { get; set; } = false; + public bool SmallEquip { get; set; } = false; + public bool UnlockedItemMode { get; set; } = false; + public byte DisableFestivals { get; set; } = 1; + public bool EnableGameContextMenu { get; set; } = true; + public bool HideWindowInCutscene { get; set; } = false; + public bool ShowAutomationSetEditing { get; set; } = true; + public bool ShowAllAutomatedApplicationRules { get; set; } = true; + public bool ShowUnlockedItemWarnings { get; set; } = true; + public bool RevertManualChangesOnZoneChange { get; set; } = false; + public bool ShowQuickBarInTabs { get; set; } = true; + public bool OpenWindowAtStart { get; set; } = false; + public ModifiableHotkey ToggleQuickDesignBar { get; set; } = new(VirtualKey.NO_KEY); + public DoubleModifier DeleteDesignModifier { get; set; } = new(ModifierHotkey.Control, ModifierHotkey.Shift); + public ChangeLogDisplayType ChangeLogDisplayType { get; set; } = ChangeLogDisplayType.New; [JsonConverter(typeof(SortModeConverter))] [JsonProperty(Order = int.MaxValue)] public ISortMode SortMode { get; set; } = ISortMode.FoldersFirst; - public List<(string Code, bool Enabled)> Codes { get; set; } = new(); + public List<(string Code, bool Enabled)> Codes { get; set; } = []; #if DEBUG public bool DebugMode { get; set; } = true; @@ -68,9 +62,10 @@ public class Configuration : IPluginConfiguration, ISavable [JsonIgnore] private readonly SaveService _saveService; - public Configuration(SaveService saveService, ConfigMigrationService migrator) + public Configuration(SaveService saveService, ConfigMigrationService migrator, EphemeralConfig ephemeral) { _saveService = saveService; + Ephemeral = ephemeral; Load(migrator); } @@ -120,7 +115,7 @@ public class Configuration : IPluginConfiguration, ISavable public static class Constants { - public const int CurrentVersion = 4; + public const int CurrentVersion = 5; public static readonly ISortMode[] ValidSortModes = { diff --git a/Glamourer/EphemeralConfig.cs b/Glamourer/EphemeralConfig.cs new file mode 100644 index 0000000..349a021 --- /dev/null +++ b/Glamourer/EphemeralConfig.cs @@ -0,0 +1,73 @@ +using System; +using System.IO; +using Dalamud.Interface.Internal.Notifications; +using Glamourer.Gui; +using Glamourer.Services; +using Newtonsoft.Json; +using OtterGui.Classes; +using ErrorEventArgs = Newtonsoft.Json.Serialization.ErrorEventArgs; + +namespace Glamourer; + +public class EphemeralConfig : ISavable +{ + public int Version { get; set; } = Configuration.Constants.CurrentVersion; + public bool IncognitoMode { get; set; } = false; + public bool UnlockDetailMode { get; set; } = true; + public bool ShowDesignQuickBar { get; set; } = false; + public bool LockDesignQuickBar { get; set; } = false; + public bool LockMainWindow { get; set; } = false; + public MainWindow.TabType SelectedTab { get; set; } = MainWindow.TabType.Settings; + public int LastSeenVersion { get; set; } = GlamourerChangelog.LastChangelogVersion; + + + [JsonIgnore] + private readonly SaveService _saveService; + + public EphemeralConfig(SaveService saveService) + { + _saveService = saveService; + Load(); + } + + public void Save() + => _saveService.DelaySave(this, TimeSpan.FromSeconds(5)); + + public void Load() + { + static void HandleDeserializationError(object? sender, ErrorEventArgs errorArgs) + { + Glamourer.Log.Error( + $"Error parsing ephemeral Configuration at {errorArgs.ErrorContext.Path}, using default or migrating:\n{errorArgs.ErrorContext.Error}"); + errorArgs.ErrorContext.Handled = true; + } + + if (!File.Exists(_saveService.FileNames.EphemeralConfigFile)) + return; + + try + { + var text = File.ReadAllText(_saveService.FileNames.EphemeralConfigFile); + JsonConvert.PopulateObject(text, this, new JsonSerializerSettings + { + Error = HandleDeserializationError, + }); + } + catch (Exception ex) + { + Glamourer.Messager.NotificationMessage(ex, + "Error reading ephemeral Configuration, reverting to default.", + "Error reading ephemeral Configuration", NotificationType.Error); + } + } + + public string ToFilename(FilenameService fileNames) + => fileNames.EphemeralConfigFile; + + public void Save(StreamWriter writer) + { + using var jWriter = new JsonTextWriter(writer) { Formatting = Formatting.Indented }; + var serializer = new JsonSerializer { Formatting = Formatting.Indented }; + serializer.Serialize(jWriter, this); + } +} diff --git a/Glamourer/Gui/DesignCombo.cs b/Glamourer/Gui/DesignCombo.cs index 49359b2..19d73c4 100644 --- a/Glamourer/Gui/DesignCombo.cs +++ b/Glamourer/Gui/DesignCombo.cs @@ -18,15 +18,15 @@ namespace Glamourer.Gui; public abstract class DesignComboBase : FilterComboCache>, IDisposable { - private readonly Configuration _config; - private readonly DesignChanged _designChanged; - private readonly DesignColors _designColors; - protected readonly TabSelected TabSelected; - protected float InnerWidth; - private Design? _currentDesign; + private readonly EphemeralConfig _config; + private readonly DesignChanged _designChanged; + private readonly DesignColors _designColors; + protected readonly TabSelected TabSelected; + protected float InnerWidth; + private Design? _currentDesign; protected DesignComboBase(Func>> generator, Logger log, DesignChanged designChanged, - TabSelected tabSelected, Configuration config, DesignColors designColors) + TabSelected tabSelected, EphemeralConfig config, DesignColors designColors) : base(generator, log) { _designChanged = designChanged; @@ -136,7 +136,7 @@ public sealed class DesignCombo : DesignComboBase private readonly DesignManager _manager; public DesignCombo(DesignManager designs, DesignFileSystem fileSystem, Logger log, DesignChanged designChanged, TabSelected tabSelected, - Configuration config, DesignColors designColors) + EphemeralConfig config, DesignColors designColors) : base(() => designs.Designs .Select(d => new Tuple(d, fileSystem.FindLeaf(d, out var l) ? l.FullName() : string.Empty)) .OrderBy(d => d.Item2) @@ -180,12 +180,13 @@ public sealed class RevertDesignCombo : DesignComboBase, IDisposable public RevertDesignCombo(DesignManager designs, DesignFileSystem fileSystem, TabSelected tabSelected, DesignColors designColors, ItemManager items, CustomizationService customize, Logger log, DesignChanged designChanged, AutoDesignManager autoDesignManager, - Configuration config) - : this(designs, fileSystem, tabSelected, designColors, CreateRevertDesign(customize, items), log, designChanged, autoDesignManager, config) + EphemeralConfig config) + : this(designs, fileSystem, tabSelected, designColors, CreateRevertDesign(customize, items), log, designChanged, autoDesignManager, + config) { } private RevertDesignCombo(DesignManager designs, DesignFileSystem fileSystem, TabSelected tabSelected, DesignColors designColors, - Design revertDesign, Logger log, DesignChanged designChanged, AutoDesignManager autoDesignManager, Configuration config) + Design revertDesign, Logger log, DesignChanged designChanged, AutoDesignManager autoDesignManager, EphemeralConfig config) : base(() => designs.Designs .Select(d => new Tuple(d, fileSystem.FindLeaf(d, out var l) ? l.FullName() : string.Empty)) .OrderBy(d => d.Item2) diff --git a/Glamourer/Gui/DesignQuickBar.cs b/Glamourer/Gui/DesignQuickBar.cs index 97cb68c..e6f5eac 100644 --- a/Glamourer/Gui/DesignQuickBar.cs +++ b/Glamourer/Gui/DesignQuickBar.cs @@ -21,7 +21,7 @@ namespace Glamourer.Gui; public class DesignQuickBar : Window, IDisposable { private ImGuiWindowFlags GetFlags - => _config.LockDesignQuickBar + => _config.Ephemeral.LockDesignQuickBar ? ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.NoMove : ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoFocusOnAppearing; @@ -45,7 +45,7 @@ public class DesignQuickBar : Window, IDisposable _keyState = keyState; _objects = objects; _autoDesignApplier = autoDesignApplier; - IsOpen = _config.ShowDesignQuickBar; + IsOpen = _config.Ephemeral.ShowDesignQuickBar; DisableWindowSounds = true; Size = Vector2.Zero; } @@ -56,7 +56,7 @@ public class DesignQuickBar : Window, IDisposable public override void PreOpenCheck() { CheckHotkeys(); - IsOpen = _config.ShowDesignQuickBar; + IsOpen = _config.Ephemeral.ShowDesignQuickBar; } public override void PreDraw() @@ -133,7 +133,7 @@ public class DesignQuickBar : Window, IDisposable if (_playerIdentifier.IsValid && _playerData.Valid) { available |= 1; - tooltip = $"Left-Click: Apply {(_config.IncognitoMode ? design.Incognito : design.Name)} to yourself."; + tooltip = $"Left-Click: Apply {(_config.Ephemeral.IncognitoMode ? design.Incognito : design.Name)} to yourself."; } if (_targetIdentifier.IsValid && _targetData.Valid) @@ -141,7 +141,7 @@ public class DesignQuickBar : Window, IDisposable if (available != 0) tooltip += '\n'; available |= 2; - tooltip += $"Right-Click: Apply {(_config.IncognitoMode ? design.Incognito : design.Name)} to {_targetIdentifier}."; + tooltip += $"Right-Click: Apply {(_config.Ephemeral.IncognitoMode ? design.Incognito : design.Name)} to {_targetIdentifier}."; } if (available == 0) @@ -248,9 +248,9 @@ public class DesignQuickBar : Window, IDisposable if (_keyboardToggle > DateTime.UtcNow || !CheckKeyState(_config.ToggleQuickDesignBar, false)) return; - _keyboardToggle = DateTime.UtcNow.AddMilliseconds(500); - _config.ShowDesignQuickBar = !_config.ShowDesignQuickBar; - _config.Save(); + _keyboardToggle = DateTime.UtcNow.AddMilliseconds(500); + _config.Ephemeral.ShowDesignQuickBar = !_config.Ephemeral.ShowDesignQuickBar; + _config.Ephemeral.Save(); } public bool CheckKeyState(ModifiableHotkey key, bool noKey) diff --git a/Glamourer/Gui/GlamourerChangelog.cs b/Glamourer/Gui/GlamourerChangelog.cs index a06eb09..7e66fcc 100644 --- a/Glamourer/Gui/GlamourerChangelog.cs +++ b/Glamourer/Gui/GlamourerChangelog.cs @@ -26,24 +26,36 @@ public class GlamourerChangelog } private (int, ChangeLogDisplayType) ConfigData() - => (_config.LastSeenVersion, _config.ChangeLogDisplayType); + => (_config.Ephemeral.LastSeenVersion, _config.ChangeLogDisplayType); private void Save(int version, ChangeLogDisplayType type) { - _config.LastSeenVersion = version; - _config.ChangeLogDisplayType = type; - _config.Save(); + if (_config.Ephemeral.LastSeenVersion != version) + { + _config.Ephemeral.LastSeenVersion = version; + _config.Ephemeral.Save(); + } + + if (_config.ChangeLogDisplayType != type) + { + _config.ChangeLogDisplayType = type; + _config.Save(); + } } private static void Add1_0_5_0(Changelog log) => log.NextVersion("Version 1.0.5.0") .RegisterHighlight("Dyes are can now be favorited the same way equipment pieces can.") - .RegisterHighlight("The quick design bar combo can now be scrolled through via mousewheel when hovering over the combo without opening it.") - .RegisterEntry("Control-Rightclicking the quick design bar now not only jumps to the corresponding design, but also opens the main window if it is not currently open.") + .RegisterHighlight( + "The quick design bar combo can now be scrolled through via mousewheel when hovering over the combo without opening it.") + .RegisterEntry( + "Control-Rightclicking the quick design bar now not only jumps to the corresponding design, but also opens the main window if it is not currently open.") .RegisterHighlight("You can now filter for designs containing specific items by using \"i:partial item name\".") - .RegisterEntry("When overwriting a saved designs data entirely from clipboard, you can now undo this change and restore the prior design data once via a button top-left.") + .RegisterEntry( + "When overwriting a saved designs data entirely from clipboard, you can now undo this change and restore the prior design data once via a button top-left.") .RegisterEntry("Removed the \"Enabled\" checkbox in the settings since it was barely doing anything but breaking Glamourer.") - .RegisterEntry("If you want to disable Glamourers state-tracking and hooking, you will need to disable the entire Plugin via Dalamud now.", 1) + .RegisterEntry( + "If you want to disable Glamourers state-tracking and hooking, you will need to disable the entire Plugin via Dalamud now.", 1) .RegisterEntry("Added a reference to \"/glamour\" in the \"/glamourer help\" section.") .RegisterEntry("Updated BNPC Data with new crowd-sourced data from the gubal library.") .RegisterEntry("Fixed an issue with the quick design bar when no designs are saved.") diff --git a/Glamourer/Gui/MainWindow.cs b/Glamourer/Gui/MainWindow.cs index e26ea50..d4e19b2 100644 --- a/Glamourer/Gui/MainWindow.cs +++ b/Glamourer/Gui/MainWindow.cs @@ -81,7 +81,7 @@ public class MainWindow : Window, IDisposable public override void PreDraw() { - Flags = _config.LockMainWindow + Flags = _config.Ephemeral.LockMainWindow ? Flags | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoResize : Flags & ~(ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoResize); } @@ -94,9 +94,9 @@ public class MainWindow : Window, IDisposable var yPos = ImGui.GetCursorPosY(); if (TabBar.Draw("##tabs", ImGuiTabBarFlags.None, ToLabel(SelectTab), out var currentTab, () => { }, _tabs)) { - SelectTab = TabType.None; - _config.SelectedTab = FromLabel(currentTab); - _config.Save(); + SelectTab = TabType.None; + _config.Ephemeral.SelectedTab = FromLabel(currentTab); + _config.Ephemeral.Save(); } if (_config.ShowQuickBarInTabs) diff --git a/Glamourer/Gui/Tabs/ActorTab/ActorSelector.cs b/Glamourer/Gui/Tabs/ActorTab/ActorSelector.cs index 334b78a..b8d1ba4 100644 --- a/Glamourer/Gui/Tabs/ActorTab/ActorSelector.cs +++ b/Glamourer/Gui/Tabs/ActorTab/ActorSelector.cs @@ -15,13 +15,13 @@ namespace Glamourer.Gui.Tabs.ActorTab; public class ActorSelector { - private readonly Configuration _config; + private readonly EphemeralConfig _config; private readonly ObjectManager _objects; private readonly ActorService _actors; private ActorIdentifier _identifier = ActorIdentifier.Invalid; - public ActorSelector(ObjectManager objects, ActorService actors, Configuration config) + public ActorSelector(ObjectManager objects, ActorService actors, EphemeralConfig config) { _objects = objects; _actors = actors; diff --git a/Glamourer/Gui/Tabs/AutomationTab/SetSelector.cs b/Glamourer/Gui/Tabs/AutomationTab/SetSelector.cs index 2aaf120..5ca3adf 100644 --- a/Glamourer/Gui/Tabs/AutomationTab/SetSelector.cs +++ b/Glamourer/Gui/Tabs/AutomationTab/SetSelector.cs @@ -31,11 +31,11 @@ public class SetSelector : IDisposable public bool IncognitoMode { - get => _config.IncognitoMode; + get => _config.Ephemeral.IncognitoMode; set { - _config.IncognitoMode = value; - _config.Save(); + _config.Ephemeral.IncognitoMode = value; + _config.Ephemeral.Save(); } } diff --git a/Glamourer/Gui/Tabs/DesignTab/DesignFileSystemSelector.cs b/Glamourer/Gui/Tabs/DesignTab/DesignFileSystemSelector.cs index 22fe597..e9d182a 100644 --- a/Glamourer/Gui/Tabs/DesignTab/DesignFileSystemSelector.cs +++ b/Glamourer/Gui/Tabs/DesignTab/DesignFileSystemSelector.cs @@ -6,7 +6,6 @@ using Dalamud.Interface.Internal.Notifications; using Dalamud.Plugin.Services; using Glamourer.Designs; using Glamourer.Events; -using Glamourer.Services; using ImGuiNET; using OtterGui; using OtterGui.Classes; @@ -32,11 +31,11 @@ public sealed class DesignFileSystemSelector : FileSystemSelector _config.IncognitoMode; + get => _config.Ephemeral.IncognitoMode; set { - _config.IncognitoMode = value; - _config.Save(); + _config.Ephemeral.IncognitoMode = value; + _config.Ephemeral.Save(); } } diff --git a/Glamourer/Gui/Tabs/SettingsTab.cs b/Glamourer/Gui/Tabs/SettingsTab.cs index dc20f78..f8395fe 100644 --- a/Glamourer/Gui/Tabs/SettingsTab.cs +++ b/Glamourer/Gui/Tabs/SettingsTab.cs @@ -105,11 +105,11 @@ public class SettingsTab : ITab if (!ImGui.CollapsingHeader("Interface")) return; - Checkbox("Show Quick Design Bar", + EphemeralCheckbox("Show Quick Design Bar", "Show a bar separate from the main window that allows you to quickly apply designs or revert your character and target.", - _config.ShowDesignQuickBar, v => _config.ShowDesignQuickBar = v); - Checkbox("Lock Quick Design Bar", "Prevent the quick design bar from being moved and lock it in place.", _config.LockDesignQuickBar, - v => _config.LockDesignQuickBar = v); + _config.Ephemeral.ShowDesignQuickBar, v => _config.Ephemeral.ShowDesignQuickBar = v); + EphemeralCheckbox("Lock Quick Design Bar", "Prevent the quick design bar from being moved and lock it in place.", _config.Ephemeral.LockDesignQuickBar, + v => _config.Ephemeral.LockDesignQuickBar = v); if (Widget.ModifiableKeySelector("Hotkey to Toggle Quick Design Bar", "Set a hotkey that opens or closes the quick design bar.", 100 * ImGuiHelpers.GlobalScale, _config.ToggleQuickDesignBar, v => _config.ToggleQuickDesignBar = v, _validKeys)) @@ -138,8 +138,8 @@ public class SettingsTab : ITab _config.HideWindowInCutscene = v; _uiBuilder.DisableCutsceneUiHide = !v; }); - Checkbox("Lock Main Window", "Prevent the main window from being moved and lock it in place.", _config.LockMainWindow, - v => _config.LockMainWindow = v); + EphemeralCheckbox("Lock Main Window", "Prevent the main window from being moved and lock it in place.", _config.Ephemeral.LockMainWindow, + v => _config.Ephemeral.LockMainWindow = v); Checkbox("Open Main Window at Game Start", "Whether the main Glamourer window should be open or closed after launching the game.", _config.OpenWindowAtStart, v => _config.OpenWindowAtStart = v); ImGui.Dummy(Vector2.Zero); @@ -285,6 +285,21 @@ public class SettingsTab : ITab ImGuiUtil.LabeledHelpMarker(label, tooltip); } + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] + private void EphemeralCheckbox(string label, string tooltip, bool current, Action setter) + { + using var id = ImRaii.PushId(label); + var tmp = current; + if (ImGui.Checkbox(string.Empty, ref tmp) && tmp != current) + { + setter(tmp); + _config.Ephemeral.Save(); + } + + ImGui.SameLine(); + ImGuiUtil.LabeledHelpMarker(label, tooltip); + } + /// Different supported sort modes as a combo. private void DrawFolderSortType() { diff --git a/Glamourer/Gui/Tabs/UnlocksTab/UnlocksTab.cs b/Glamourer/Gui/Tabs/UnlocksTab/UnlocksTab.cs index 30f7ad3..d7b8162 100644 --- a/Glamourer/Gui/Tabs/UnlocksTab/UnlocksTab.cs +++ b/Glamourer/Gui/Tabs/UnlocksTab/UnlocksTab.cs @@ -11,11 +11,11 @@ namespace Glamourer.Gui.Tabs.UnlocksTab; public class UnlocksTab : Window, ITab { - private readonly Configuration _config; + private readonly EphemeralConfig _config; private readonly UnlockOverview _overview; private readonly UnlockTable _table; - public UnlocksTab(Configuration config, UnlockOverview overview, UnlockTable table) + public UnlocksTab(EphemeralConfig config, UnlockOverview overview, UnlockTable table) : base("Unlocked Equipment") { _config = config; diff --git a/Glamourer/Services/CommandService.cs b/Glamourer/Services/CommandService.cs index 0cb4eab..6435568 100644 --- a/Glamourer/Services/CommandService.cs +++ b/Glamourer/Services/CommandService.cs @@ -76,13 +76,13 @@ public class CommandService : IDisposable case "designs": case "design": case "design bar": - _config.ShowDesignQuickBar = !_config.ShowDesignQuickBar; - _config.Save(); + _config.Ephemeral.ShowDesignQuickBar = !_config.Ephemeral.ShowDesignQuickBar; + _config.Ephemeral.Save(); return; case "lock": case "unlock": - _config.LockMainWindow = !_config.LockMainWindow; - _config.Save(); + _config.Ephemeral.LockMainWindow = !_config.Ephemeral.LockMainWindow; + _config.Ephemeral.Save(); return; default: _chat.Print("Use without argument to toggle the main window."); diff --git a/Glamourer/Services/ConfigMigrationService.cs b/Glamourer/Services/ConfigMigrationService.cs index bc75a17..3be7c29 100644 --- a/Glamourer/Services/ConfigMigrationService.cs +++ b/Glamourer/Services/ConfigMigrationService.cs @@ -25,7 +25,7 @@ public class ConfigMigrationService public void Migrate(Configuration config) { - _config = config; + _config = config; if (config.Version >= Configuration.Constants.CurrentVersion || !File.Exists(_saveService.FileNames.ConfigFile)) { AddColors(config, false); @@ -35,9 +35,28 @@ public class ConfigMigrationService _data = JObject.Parse(File.ReadAllText(_saveService.FileNames.ConfigFile)); MigrateV1To2(); MigrateV2To4(); + MigrateV4To5(); AddColors(config, true); } + // Ephemeral Config. + private void MigrateV4To5() + { + if (_config.Version > 4) + return; + + _config.Ephemeral.IncognitoMode = _data["IncognitoMode"]?.ToObject() ?? _config.Ephemeral.IncognitoMode; + _config.Ephemeral.UnlockDetailMode = _data["UnlockDetailMode"]?.ToObject() ?? _config.Ephemeral.UnlockDetailMode; + _config.Ephemeral.ShowDesignQuickBar = _data["ShowDesignQuickBar"]?.ToObject() ?? _config.Ephemeral.ShowDesignQuickBar; + _config.Ephemeral.LockDesignQuickBar = _data["LockDesignQuickBar"]?.ToObject() ?? _config.Ephemeral.LockDesignQuickBar; + _config.Ephemeral.LockMainWindow = _data["LockMainWindow"]?.ToObject() ?? _config.Ephemeral.LockMainWindow; + _config.Ephemeral.SelectedTab = _data["SelectedTab"]?.ToObject() ?? _config.Ephemeral.SelectedTab; + _config.Ephemeral.LastSeenVersion = _data["LastSeenVersion"]?.ToObject() ?? _config.Ephemeral.LastSeenVersion; + _config.Version = 5; + _config.Ephemeral.Version = 5; + _config.Ephemeral.Save(); + } + private void MigrateV1To2() { if (_config.Version > 1) @@ -58,7 +77,7 @@ public class ConfigMigrationService { if (_config.Version > 4) return; - + _config.Version = 4; _config.Codes = _config.Codes.DistinctBy(c => c.Code).ToList(); } diff --git a/Glamourer/Services/FilenameService.cs b/Glamourer/Services/FilenameService.cs index 607bcb3..2ca573f 100644 --- a/Glamourer/Services/FilenameService.cs +++ b/Glamourer/Services/FilenameService.cs @@ -17,6 +17,7 @@ public class FilenameService public readonly string UnlockFileItems; public readonly string FavoriteFile; public readonly string DesignColorFile; + public readonly string EphemeralConfigFile; public FilenameService(DalamudPluginInterface pi) { @@ -29,7 +30,8 @@ public class FilenameService UnlockFileItems = Path.Combine(ConfigDirectory, "unlocks_items.json"); DesignDirectory = Path.Combine(ConfigDirectory, "designs"); FavoriteFile = Path.Combine(ConfigDirectory, "favorites.json"); - DesignColorFile = Path.Combine(ConfigDirectory, "design_colors.json"); + DesignColorFile = Path.Combine(ConfigDirectory, "design_colors.json"); + EphemeralConfigFile = Path.Combine(ConfigDirectory, "ephemeral_config.json"); } diff --git a/Glamourer/Services/ServiceManager.cs b/Glamourer/Services/ServiceManager.cs index eefa761..0d38099 100644 --- a/Glamourer/Services/ServiceManager.cs +++ b/Glamourer/Services/ServiceManager.cs @@ -57,6 +57,7 @@ public static class ServiceManager .AddSingleton() .AddSingleton() .AddSingleton() + .AddSingleton() .AddSingleton() .AddSingleton();