diff --git a/src/Config/ConfigManager.cs b/src/Config/ConfigManager.cs index 2c2ef2d..4c95aa4 100644 --- a/src/Config/ConfigManager.cs +++ b/src/Config/ConfigManager.cs @@ -12,10 +12,14 @@ namespace UnityExplorer.Config { public static class ConfigManager { + internal static readonly Dictionary ConfigElements = new(); + internal static readonly Dictionary InternalConfigs = new(); + // Each Mod Loader has its own ConfigHandler. // See the UnityExplorer.Loader namespace for the implementations. public static ConfigHandler Handler { get; private set; } + // Actual UE Settings public static ConfigElement Master_Toggle; public static ConfigElement Main_Navbar_Anchor; public static ConfigElement Force_Unlock_Mouse; @@ -26,22 +30,18 @@ namespace UnityExplorer.Config public static ConfigElement Log_Unity_Debug; public static ConfigElement Hide_On_Startup; public static ConfigElement Startup_Delay_Time; - public static ConfigElement Reflection_Signature_Blacklist; // internal configs internal static InternalConfigHandler InternalHandler { get; private set; } + internal static readonly Dictionary> PanelSaveData = new(); - public static ConfigElement ObjectExplorerData; - public static ConfigElement InspectorData; - public static ConfigElement CSConsoleData; - public static ConfigElement OptionsPanelData; - public static ConfigElement ConsoleLogData; - public static ConfigElement HookManagerData; - public static ConfigElement ClipboardData; - - internal static readonly Dictionary ConfigElements = new Dictionary(); - internal static readonly Dictionary InternalConfigs = new Dictionary(); + internal static ConfigElement GetPanelSaveData(UIManager.Panels panel) + { + if (!PanelSaveData.ContainsKey(panel)) + PanelSaveData.Add(panel, new ConfigElement(panel.ToString(), string.Empty, string.Empty, true)); + return PanelSaveData[panel]; + } public static void Init(ConfigHandler configHandler) { @@ -124,16 +124,6 @@ namespace UnityExplorer.Config "Seperate signatures with a semicolon ';'.\r\n" + "For example, to blacklist Camera.main, you would add 'UnityEngine.Camera.main;'", ""); - - // Internal configs (panel save data) - - ObjectExplorerData = new ConfigElement("ObjectExplorer", "", "", true); - InspectorData = new ConfigElement("Inspector", "", "", true); - CSConsoleData = new ConfigElement("CSConsole", "", "", true); - OptionsPanelData = new ConfigElement("OptionsPanel", "", "", true); - ConsoleLogData = new ConfigElement("ConsoleLog", "", "", true); - HookManagerData = new ConfigElement("HookManager", "", "", true); - ClipboardData = new ConfigElement("Clipboard", "", "", true); } } } diff --git a/src/Config/InternalConfigHandler.cs b/src/Config/InternalConfigHandler.cs index cedb154..86cc527 100644 --- a/src/Config/InternalConfigHandler.cs +++ b/src/Config/InternalConfigHandler.cs @@ -1,24 +1,22 @@ -using IniParser.Parser; -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using UnityEngine; using UnityExplorer.UI; +using Tomlet; +using Tomlet.Models; namespace UnityExplorer.Config { public class InternalConfigHandler : ConfigHandler { - internal static IniDataParser _parser; - internal static string INI_PATH; + internal static string CONFIG_PATH; public override void Init() { - INI_PATH = Path.Combine(ExplorerCore.Loader.ExplorerFolder, "data.ini"); - _parser = new IniDataParser(); - _parser.Configuration.CommentString = "#"; + CONFIG_PATH = Path.Combine(ExplorerCore.Loader.ExplorerFolder, "data.cfg"); } public override void LoadConfig() @@ -37,32 +35,24 @@ namespace UnityExplorer.Config // Not necessary } - public override T GetConfigValue(ConfigElement element) - { - // Not necessary, just return the value. - return element.Value; - } + // Not necessary, just return the value. + public override T GetConfigValue(ConfigElement element) => element.Value; - public override void OnAnyConfigChanged() - { - SaveConfig(); - } + // Always just auto-save. + public override void OnAnyConfigChanged() => SaveConfig(); public bool TryLoadConfig() { try { - if (!File.Exists(INI_PATH)) + if (!File.Exists(CONFIG_PATH)) return false; - string ini = File.ReadAllText(INI_PATH); - - var data = _parser.Parse(ini); - - foreach (var config in data.Sections["Config"]) + TomlDocument document = TomlParser.ParseFile(CONFIG_PATH); + foreach (var key in document.Keys) { - if (ConfigManager.InternalConfigs.TryGetValue(config.KeyName, out IConfigElement configElement)) - configElement.BoxedValue = StringToConfigValue(config.Value, configElement.ElementType); + var panelKey = (UIManager.Panels)Enum.Parse(typeof(UIManager.Panels), key); + ConfigManager.GetPanelSaveData(panelKey).Value = document.GetString(key); } return true; @@ -79,27 +69,11 @@ namespace UnityExplorer.Config if (UIManager.Initializing) return; - var data = new IniParser.Model.IniData(); - - data.Sections.AddSection("Config"); - var sec = data.Sections["Config"]; - + var tomlDocument = TomlDocument.CreateEmpty(); foreach (var entry in ConfigManager.InternalConfigs) - sec.AddKey(entry.Key, entry.Value.BoxedValue.ToString()); + tomlDocument.Put(entry.Key, entry.Value.BoxedValue as string, false); - File.WriteAllText(INI_PATH, data.ToString()); - } - - public object StringToConfigValue(string value, Type elementType) - { - if (elementType.IsEnum) - return Enum.Parse(elementType, value); - else if (elementType == typeof(bool)) - return bool.Parse(value); - else if (elementType == typeof(int)) - return int.Parse(value); - else - return value; + File.WriteAllText(CONFIG_PATH, tomlDocument.SerializedValue); } } } diff --git a/src/ILRepack.targets b/src/ILRepack.targets index 8932a8d..606c6ae 100644 --- a/src/ILRepack.targets +++ b/src/ILRepack.targets @@ -6,9 +6,9 @@ - + - + diff --git a/src/Inspectors/InspectUnderMouse.cs b/src/Inspectors/InspectUnderMouse.cs index 1dfb901..859c0ac 100644 --- a/src/Inspectors/InspectUnderMouse.cs +++ b/src/Inspectors/InspectUnderMouse.cs @@ -208,9 +208,5 @@ namespace UnityExplorer.Inspectors UIRoot.SetActive(false); } - - public override void DoSaveToConfigElement() { } - - public override string GetSaveDataFromConfigManager() => null; } } diff --git a/src/UI/Panels/CSConsolePanel.cs b/src/UI/Panels/CSConsolePanel.cs index 4d2176c..3b1c4ca 100644 --- a/src/UI/Panels/CSConsolePanel.cs +++ b/src/UI/Panels/CSConsolePanel.cs @@ -55,15 +55,6 @@ namespace UnityExplorer.UI.Panels ConsoleController.Update(); } - // Saving - - public override void DoSaveToConfigElement() - { - ConfigManager.CSConsoleData.Value = this.ToSaveData(); - } - - public override string GetSaveDataFromConfigManager() => ConfigManager.CSConsoleData.Value; - // UI Construction public override void OnFinishResize(RectTransform panel) diff --git a/src/UI/Panels/ClipboardPanel.cs b/src/UI/Panels/ClipboardPanel.cs index 5368a87..19732de 100644 --- a/src/UI/Panels/ClipboardPanel.cs +++ b/src/UI/Panels/ClipboardPanel.cs @@ -27,8 +27,6 @@ namespace UnityExplorer.UI.Panels public override bool NavButtonWanted => true; public override bool ShouldSaveActiveState => true; public override bool ShowByDefault => true; - public override string GetSaveDataFromConfigManager() => ConfigManager.ClipboardData.Value; - public override void DoSaveToConfigElement() => ConfigManager.ClipboardData.Value = this.ToSaveData(); private static Text CurrentPasteLabel; diff --git a/src/UI/Panels/HookManagerPanel.cs b/src/UI/Panels/HookManagerPanel.cs index 9643835..1a24d9b 100644 --- a/src/UI/Panels/HookManagerPanel.cs +++ b/src/UI/Panels/HookManagerPanel.cs @@ -46,10 +46,6 @@ namespace UnityExplorer.UI.Panels public Text EditorInputText { get; private set; } public Text EditorHighlightText { get; private set; } - public override string GetSaveDataFromConfigManager() => ConfigManager.HookManagerData.Value; - - public override void DoSaveToConfigElement() => ConfigManager.HookManagerData.Value = this.ToSaveData(); - private void OnClassInputAddClicked() { HookManager.Instance.OnClassSelectedForHooks(this.classSelectorInputField.Text); diff --git a/src/UI/Panels/InspectorPanel.cs b/src/UI/Panels/InspectorPanel.cs index 05cb7cd..28678c8 100644 --- a/src/UI/Panels/InspectorPanel.cs +++ b/src/UI/Panels/InspectorPanel.cs @@ -44,10 +44,6 @@ namespace UnityExplorer.UI.Panels InspectorManager.OnPanelResized(panel.rect.width); } - public override string GetSaveDataFromConfigManager() => ConfigManager.InspectorData.Value; - - public override void DoSaveToConfigElement() => ConfigManager.InspectorData.Value = this.ToSaveData(); - protected internal override void DoSetDefaultPosAndAnchors() { Rect.localPosition = Vector2.zero; diff --git a/src/UI/Panels/LogPanel.cs b/src/UI/Panels/LogPanel.cs index c619855..5dc50a0 100644 --- a/src/UI/Panels/LogPanel.cs +++ b/src/UI/Panels/LogPanel.cs @@ -144,18 +144,6 @@ namespace UnityExplorer.UI.Panels RuntimeProvider.Instance.SetColorBlock(cell.Input.Component, color); } - // Panel save data - - public override string GetSaveDataFromConfigManager() - { - return ConfigManager.ConsoleLogData.Value; - } - - public override void DoSaveToConfigElement() - { - ConfigManager.ConsoleLogData.Value = this.ToSaveData(); - } - protected internal override void DoSetDefaultPosAndAnchors() { Rect.localPosition = Vector2.zero; diff --git a/src/UI/Panels/ObjectExplorerPanel.cs b/src/UI/Panels/ObjectExplorerPanel.cs index 638266c..f9d0ad5 100644 --- a/src/UI/Panels/ObjectExplorerPanel.cs +++ b/src/UI/Panels/ObjectExplorerPanel.cs @@ -46,7 +46,7 @@ namespace UnityExplorer.UI.Panels RuntimeProvider.Instance.SetColorBlock(button.Component, UniversalUI.enabledButtonColor, UniversalUI.enabledButtonColor * 1.2f); SelectedTab = tabIndex; - SaveToConfigManager(); + SaveInternalData(); } private void DisableTab(int tabIndex) @@ -63,21 +63,12 @@ namespace UnityExplorer.UI.Panels ObjectSearch.Update(); } - public override string GetSaveDataFromConfigManager() => ConfigManager.ObjectExplorerData.Value; - - public override void DoSaveToConfigElement() - { - ConfigManager.ObjectExplorerData.Value = this.ToSaveData(); - } - public override string ToSaveData() { - string ret = base.ToSaveData(); - ret += "|" + SelectedTab; - return ret; + return string.Join("|", new string[] { base.ToSaveData(), SelectedTab.ToString() }); } - public override void ApplySaveData(string data) + protected override void ApplySaveData(string data) { base.ApplySaveData(data); diff --git a/src/UI/Panels/OptionsPanel.cs b/src/UI/Panels/OptionsPanel.cs index a457468..d8f6761 100644 --- a/src/UI/Panels/OptionsPanel.cs +++ b/src/UI/Panels/OptionsPanel.cs @@ -55,17 +55,7 @@ namespace UnityExplorer.UI.Panels CacheObjectControllerHelper.SetCell(cell, index, this.configEntries, null); } - // Panel save data - - public override string GetSaveDataFromConfigManager() - { - return ConfigManager.OptionsPanelData.Value; - } - - public override void DoSaveToConfigElement() - { - ConfigManager.OptionsPanelData.Value = this.ToSaveData(); - } + // UI Construction protected internal override void DoSetDefaultPosAndAnchors() { @@ -76,8 +66,6 @@ namespace UnityExplorer.UI.Panels Rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 600f); } - // UI Construction - public override void ConstructPanelContent() { // Save button diff --git a/src/UI/Panels/UIPanel.cs b/src/UI/Panels/UIPanel.cs index 844dd63..5384e58 100644 --- a/src/UI/Panels/UIPanel.cs +++ b/src/UI/Panels/UIPanel.cs @@ -92,19 +92,16 @@ namespace UnityExplorer.UI.Panels protected GameObject uiRoot; public RectTransform Rect; public GameObject content; - public GameObject titleBar; - public abstract void ConstructPanelContent(); - public virtual void OnFinishResize(RectTransform panel) { - SaveToConfigManager(); + SaveInternalData(); } public virtual void OnFinishDrag(RectTransform panel) { - SaveToConfigManager(); + SaveInternalData(); } public override void SetActive(bool active) @@ -115,7 +112,7 @@ namespace UnityExplorer.UI.Panels base.SetActive(active); if (!ApplyingSaveData) - SaveToConfigManager(); + SaveInternalData(); if (NavButtonWanted) { @@ -162,29 +159,30 @@ namespace UnityExplorer.UI.Panels panel.localPosition = pos; } - #region Save Data + // Save Data - public abstract void DoSaveToConfigElement(); + public bool ApplyingSaveData { get; set; } - public void SaveToConfigManager() + public void SaveInternalData() { if (UIManager.Initializing) return; - DoSaveToConfigElement(); + SetSaveDataToConfigValue(); } - public abstract string GetSaveDataFromConfigManager(); - - public bool ApplyingSaveData { get; set; } + private void SetSaveDataToConfigValue() => ConfigManager.GetPanelSaveData(this.PanelType).Value = this.ToSaveData(); public virtual string ToSaveData() { try { - return $"{ShouldSaveActiveState && Enabled}" + - $"|{Rect.RectAnchorsToString()}" + - $"|{Rect.RectPositionToString()}"; + return string.Join("|", new string[] + { + $"{ShouldSaveActiveState && Enabled}", + Rect.RectAnchorsToString(), + Rect.RectPositionToString() + }); } catch (Exception ex) { @@ -193,7 +191,13 @@ namespace UnityExplorer.UI.Panels } } - public virtual void ApplySaveData(string data) + public virtual void ApplySaveData() + { + string data = ConfigManager.GetPanelSaveData(this.PanelType).Value; + ApplySaveData(data); + } + + protected virtual void ApplySaveData(string data) { if (string.IsNullOrEmpty(data)) return; @@ -210,17 +214,14 @@ namespace UnityExplorer.UI.Panels { ExplorerCore.LogWarning("Invalid or corrupt panel save data! Restoring to default."); SetTransformDefaults(); - UIManager.Initializing = false; - DoSaveToConfigElement(); - ConfigManager.InternalHandler.SaveConfig(); - UIManager.Initializing = true; + SetSaveDataToConfigValue(); } } - #endregion - // UI Construction + public abstract void ConstructPanelContent(); + public void ConstructUI() { //this.Enabled = true; @@ -275,7 +276,7 @@ namespace UnityExplorer.UI.Panels closeBtn.OnClick += () => { UIManager.SetPanelActive(this.PanelType, false); - SaveToConfigManager(); + SaveInternalData(); }; if (!CanDragAndResize) @@ -300,7 +301,7 @@ namespace UnityExplorer.UI.Panels // apply panel save data or revert to default try { - ApplySaveData(GetSaveDataFromConfigManager()); + ApplySaveData(); } catch (Exception ex) { @@ -320,7 +321,7 @@ namespace UnityExplorer.UI.Panels // simple listener for saving enabled state this.OnToggleEnabled += (bool val) => { - SaveToConfigManager(); + SaveInternalData(); }; ApplyingSaveData = false; diff --git a/src/UI/Panels/UiInspectorResultsPanel.cs b/src/UI/Panels/UiInspectorResultsPanel.cs index b5f2baf..34ad8e0 100644 --- a/src/UI/Panels/UiInspectorResultsPanel.cs +++ b/src/UI/Panels/UiInspectorResultsPanel.cs @@ -72,8 +72,5 @@ namespace UnityExplorer.UI.Panels this.Rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 500f); this.Rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 500f); } - - public override void DoSaveToConfigElement() { } - public override string GetSaveDataFromConfigManager() => null; } } diff --git a/src/UI/Widgets/AutoComplete/AutoCompleteModal.cs b/src/UI/Widgets/AutoComplete/AutoCompleteModal.cs index b542dc7..9291634 100644 --- a/src/UI/Widgets/AutoComplete/AutoCompleteModal.cs +++ b/src/UI/Widgets/AutoComplete/AutoCompleteModal.cs @@ -315,12 +315,5 @@ namespace UnityExplorer.UI.Widgets.AutoComplete UIRoot.SetActive(false); } - - public override void DoSaveToConfigElement() - { - // not savable - } - - public override string GetSaveDataFromConfigManager() => null; } } diff --git a/src/UnityExplorer.csproj b/src/UnityExplorer.csproj index cde598e..ed6055a 100644 --- a/src/UnityExplorer.csproj +++ b/src/UnityExplorer.csproj @@ -106,8 +106,8 @@ ..\lib\mcs-unity\mcs\bin\Release\mcs.dll False - - packages\ini-parser.2.5.2\lib\net20\INIFileParser.dll + + packages\Samboy063.Tomlet.3.1.3\lib\net35\Tomlet.dll False diff --git a/src/packages.config b/src/packages.config index e001b03..8f3c0b6 100644 --- a/src/packages.config +++ b/src/packages.config @@ -2,7 +2,7 @@ - + \ No newline at end of file