示例#1
0
        public static void SaveSettings()
        {
            //SettingsManager.GlobalSettings?.Shortcuts = SettingsManager.GlobalSettings?.Shortcuts?.OrderBy(u => u.Command).ToList();
            SettingsManager.GlobalSettings?.Shortcuts?.Sort((x, y) => x.Action.CompareTo(y.Action));


            foreach (var item in SettingsManager.GlobalSettings.GetType().GetProperties())
            {
                if (item.Name == "Item")
                {
                    continue;
                }
                string text = string.Empty;
                var    obj  = item.GetValue(SettingsManager.GlobalSettings);
                if (obj is IList)
                {
                    text = $"[\n{SettingsInterpreter.GetListText((IList)obj).Replace("{", "\t{")}\n]";
                }
                else
                {
                    text = JsonConvert.SerializeObject(item.GetValue(SettingsManager.GlobalSettings), Formatting.Indented);
                }

                try
                {
                    File.WriteAllText($"{SettingsManager.GetSettingsDirectoryPath()}\\{item.Name}.json", text);
                }
                catch (Exception q)
                {
                    throw q;
                }
            }
        }
示例#2
0
        public static void LoadSettings()
        {
            GlobalSettings = SettingsInterpreter.LoadSettings();

            //get all shortcuts from the entire program, remove their default shortcuts and add to shortcut list
            GlobalSettings?.Shortcuts.AddRange(ShortcutManager.GetShortcutsFromAssembliesInexecutingFolder());
        }
示例#3
0
        internal static List <ShortcutKeyBinding> GetUdatedShortcuts(string path)
        {
            string fileText = SettingsInterpreter.GetJsonFormFile(path);
            var    temp     = new List <ShortcutKeyBinding>(JsonConvert.DeserializeObject <SettingsContainer>(fileText).Shortcuts);

            //clone all the temp ones
            return(temp.Select(x => new ShortcutKeyBinding()
            {
                Command = x.Command, Shortcut = x.Shortcut
            }).ToList());
        }
示例#4
0
        public static void UpdateSettingsFromFile(string path)
        {
            //check if the file exists and is in the poper folder
            if (!File.Exists(path) || Path.GetDirectoryName(path) != GetSettingsDirectoryPath())
            {
                return;
            }

            //update the settings by reading the Json from the file
            UpdateSettings(JsonConvert.DeserializeObject <SettingsContainer>($"{{{SettingsInterpreter.GetJsonFormFile(path)}}}"));
        }