SettingsManager.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System.IO; 6 using Microsoft.CommandPalette.Extensions.Toolkit; 7 8 namespace Microsoft.CmdPal.Ext.Registry.Helpers; 9 10 public class SettingsManager : JsonSettingsManager, ISettingsInterface 11 { 12 private static readonly string _namespace = "registry"; 13 14 private static string Namespaced(string propertyName) => $"{_namespace}.{propertyName}"; 15 16 internal static string SettingsJsonPath() 17 { 18 var directory = Utilities.BaseSettingsPath("Microsoft.CmdPal"); 19 Directory.CreateDirectory(directory); 20 21 // now, the state is just next to the exe 22 return Path.Combine(directory, "settings.json"); 23 } 24 25 public SettingsManager() 26 { 27 FilePath = SettingsJsonPath(); 28 29 // Add settings here when needed 30 // Settings.Add(setting); 31 32 // Load settings from file upon initialization 33 LoadSettings(); 34 35 Settings.SettingsChanged += (s, a) => this.SaveSettings(); 36 } 37 }