예제 #1
0
        public void SaveSystemSettingsBackup(SystemSettings backup)
        {
            // argument checks
            if (backup == null)
            {
                throw new ArgumentNullException(nameof(backup));
            }

            // save the backup settings to the file
            string         backupFilePath = GetSystemSettingsBackupPath();
            JsonObjectData data           = JsonObjectData.CreateEmpty();

            backup.SaveToObjectData(data);
            data.Save(backupFilePath);

            return;
        }
예제 #2
0
        protected void SaveSettingsToFile(CommandSettings settings, string settingsFilePath = null)
        {
            // argument checks
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            int backupHistory = GetBackupHistoryFor(settingsFilePath);

            if (settingsFilePath == null)
            {
                settingsFilePath = EnsureSettingsFilePathSet();
            }

            // get object data to be saved
            JsonObjectData settingsData = JsonObjectData.CreateEmpty();

            settings.SaveToObjectData(settingsData, true);

            // save settings to the file
            Util.BackupAndSave(settingsFilePath, settingsData.Save, backupHistory);
        }
예제 #3
0
        private IObjectData GetBaseSettings(IDictionary <string, string> options)
        {
            // argument checks
            Debug.Assert(options != null);

            // create base settings
            IObjectData settingsData = null;
            bool        noSetting    = options.ContainsKey(OptionNames.NoSettings);

            if (noSetting == false)
            {
                // load the settings

                // find the settings file path
                string settingsFilePath;
                if (options.TryGetValue(OptionNames.SettingsFile, out settingsFilePath) == false)
                {
                    // default location is %LOCALAPPDATA%\MAPE
                    settingsFilePath = Path.Combine(GetMAPEAppDataFolder(), "Settings.json");
                }

                // load settings from the config file
                try {
                    settingsData          = LoadSettingsFromFile(true, settingsFilePath);
                    this.SettingsFilePath = settingsFilePath;
                } catch (Exception exception) {
                    string message = string.Format(Resources.CommandBase_Message_FailToLoadSettingsFile, settingsFilePath, exception.Message);
                    ShowErrorMessage(message);
                }
            }
            if (settingsData == null)
            {
                settingsData = JsonObjectData.CreateEmpty();
            }

            return(settingsData);
        }