Ejemplo n.º 1
0
        public bool RemoveSetting(string path)
        {
            ModSettingsEntry toRemove = Settings.FirstOrDefault(setting => setting.FilePath.Equals(path));

            if (toRemove == null)
            {
                return(false);
            }
            Settings.Remove(toRemove);
            return(true);
        }
Ejemplo n.º 2
0
        public bool AddSetting(string path, string contents)
        {
            if (Settings == null)
            {
                Settings = new List <ModSettingsEntry>();
            }
            // Check if this belongs to this mod
            var fullpath = GetPathFull(path);

            if (!File.Exists(fullpath))
            {
                MessageBox.Show(@"Error!\nThe file " + path + @" does not belong to mod " + Name + @".\nNothing was saved.", @"Error", MessageBoxButtons.OK);
                return(false);
            }

            var setting = GetSetting(path);

            if (setting == null)
            {
                setting = new ModSettingsEntry(path, FilePath.GetFileName(path), contents);
                Settings.Add(setting);
            }
            else
            {
                setting.Contents = contents;
            }

            try
            {
                using (var stream = new StreamWriter(fullpath))
                {
                    stream.Write(contents);
                }
            }
            catch (UnauthorizedAccessException ex)
            {
                Log.Warn("Error saving configuration file " + fullpath, ex);
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(true);
        }