From 1af594432c47f0f797468fd0f4ca8aa2656d23f2 Mon Sep 17 00:00:00 2001 From: "J. Ritchie Carroll" Date: Mon, 2 Feb 2026 10:47:03 -0600 Subject: [PATCH 1/3] Added optional configuration for a specific INI file path --- .../Configuration/INIConfigurationHelpers.cs | 7 +++- src/Gemstone/Configuration/Settings.cs | 40 ++++++------------- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/src/Gemstone/Configuration/INIConfigurationHelpers.cs b/src/Gemstone/Configuration/INIConfigurationHelpers.cs index 4772530fe7..5ac05998ef 100644 --- a/src/Gemstone/Configuration/INIConfigurationHelpers.cs +++ b/src/Gemstone/Configuration/INIConfigurationHelpers.cs @@ -23,6 +23,7 @@ using System; using System.IO; +using Gemstone.IO; namespace Gemstone.Configuration; @@ -35,9 +36,13 @@ internal static class INIConfigurationHelpers /// Gets file path for INI configuration file. /// /// Target file INI file name. + /// Any configured INI file path. /// INI file path. - public static string GetINIFilePath(string fileName) + public static string GetINIFilePath(string fileName, string? configuredPath) { + if (!string.IsNullOrWhiteSpace(configuredPath)) + return Path.Combine(FilePath.GetAbsolutePath(configuredPath), fileName); + Environment.SpecialFolder specialFolder = Environment.SpecialFolder.CommonApplicationData; string appDataPath = Environment.GetFolderPath(specialFolder); return Path.Combine(appDataPath, Common.ApplicationName, fileName); diff --git a/src/Gemstone/Configuration/Settings.cs b/src/Gemstone/Configuration/Settings.cs index ce5ebac940..87220b6131 100644 --- a/src/Gemstone/Configuration/Settings.cs +++ b/src/Gemstone/Configuration/Settings.cs @@ -128,6 +128,11 @@ public Settings() /// public ConfigurationOperation INIFile { get; init; } = ConfigurationOperation.ReadOnly; + /// + /// Gets or sets any configured INI path. Set to null for default %ProgramData% path. + /// + public string? ConfiguredINIPath { get; init; } = null; + /// /// Gets or sets configuration operation mode for SQLite settings. /// @@ -161,24 +166,12 @@ public ConfigurationOperation EnvironmentalVariables /// /// Gets the names for the settings sections. /// - public string[] SectionNames - { - get - { - return m_sections.Keys.ToArray(); - } - } + public string[] SectionNames => m_sections.Keys.ToArray(); /// /// Gets the sections count for the settings. /// - public int Count - { - get - { - return m_sections.Count; - } - } + public int Count => m_sections.Count; /// /// Gets the command line switch mappings for . @@ -189,23 +182,14 @@ public int Count /// Gets the for the specified key. /// /// Section key. - public SettingsSection this[string key] - { - get - { - return m_sections.GetOrAdd(key, _ => new SettingsSection(this, key)); - } - } + public SettingsSection this[string key] => m_sections.GetOrAdd(key, _ => new SettingsSection(this, key)); /// /// Gets flag that determines if any settings have been changed. /// public bool IsDirty { - get - { - return m_sections.Values.Any(section => section.IsDirty); - } + get => m_sections.Values.Any(section => section.IsDirty); private set { foreach (SettingsSection section in m_sections.Values) @@ -247,8 +231,8 @@ public void Bind(IConfigurationBuilder builder) if (iniProviderExists) { - string iniPath = GetINIFilePath("settings.ini"); - using TextReader reader = GetINIFileReader(iniPath); + string iniFilePath = GetINIFilePath("settings.ini", ConfiguredINIPath); + using TextReader reader = GetINIFileReader(iniFilePath); string[] iniFileContents = reader.ReadToEnd().Split(["\n", "\r", "\r\n"], StringSplitOptions.RemoveEmptyEntries); string currentSection = ""; StringBuilder currentDescription = new(); @@ -440,7 +424,7 @@ private void SaveSections() // Handle INI file as a special case, writing entire file contents on save string contents = Configuration!.GenerateINIFileContents(splitDescriptionLines: SplitDescriptionLines); - string iniFilePath = GetINIFilePath("settings.ini"); + string iniFilePath = GetINIFilePath("settings.ini", ConfiguredINIPath); using TextWriter writer = GetINIFileWriter(iniFilePath); writer.Write(contents); } From d2e97f08505b402ebefe71371504ccd2574e8291 Mon Sep 17 00:00:00 2001 From: "J. Ritchie Carroll" Date: Mon, 2 Feb 2026 10:54:56 -0600 Subject: [PATCH 2/3] Updated helper function variable to be constant --- src/Gemstone/Configuration/INIConfigurationHelpers.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Gemstone/Configuration/INIConfigurationHelpers.cs b/src/Gemstone/Configuration/INIConfigurationHelpers.cs index 5ac05998ef..16782dc9c9 100644 --- a/src/Gemstone/Configuration/INIConfigurationHelpers.cs +++ b/src/Gemstone/Configuration/INIConfigurationHelpers.cs @@ -43,8 +43,8 @@ public static string GetINIFilePath(string fileName, string? configuredPath) if (!string.IsNullOrWhiteSpace(configuredPath)) return Path.Combine(FilePath.GetAbsolutePath(configuredPath), fileName); - Environment.SpecialFolder specialFolder = Environment.SpecialFolder.CommonApplicationData; - string appDataPath = Environment.GetFolderPath(specialFolder); + const Environment.SpecialFolder SpecialFolder = Environment.SpecialFolder.CommonApplicationData; + string appDataPath = Environment.GetFolderPath(SpecialFolder); return Path.Combine(appDataPath, Common.ApplicationName, fileName); } From 7b102756ddfbeefbc3b7e0db67e73ff4ffe3ec4b Mon Sep 17 00:00:00 2001 From: "J. Ritchie Carroll" Date: Mon, 2 Feb 2026 10:56:11 -0600 Subject: [PATCH 3/3] Improved comment and parameter name for GetINIFilePath helper function --- src/Gemstone/Configuration/INIConfigurationHelpers.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Gemstone/Configuration/INIConfigurationHelpers.cs b/src/Gemstone/Configuration/INIConfigurationHelpers.cs index 16782dc9c9..b8ee774095 100644 --- a/src/Gemstone/Configuration/INIConfigurationHelpers.cs +++ b/src/Gemstone/Configuration/INIConfigurationHelpers.cs @@ -36,12 +36,12 @@ internal static class INIConfigurationHelpers /// Gets file path for INI configuration file. /// /// Target file INI file name. - /// Any configured INI file path. + /// Any configured path for the INI file. /// INI file path. - public static string GetINIFilePath(string fileName, string? configuredPath) + public static string GetINIFilePath(string fileName, string? configuredINIPath) { - if (!string.IsNullOrWhiteSpace(configuredPath)) - return Path.Combine(FilePath.GetAbsolutePath(configuredPath), fileName); + if (!string.IsNullOrWhiteSpace(configuredINIPath)) + return Path.Combine(FilePath.GetAbsolutePath(configuredINIPath), fileName); const Environment.SpecialFolder SpecialFolder = Environment.SpecialFolder.CommonApplicationData; string appDataPath = Environment.GetFolderPath(SpecialFolder);