Beispiel #1
0
        public bool SaveSettings()
        {
            try
            {
                _currentlySaved = CurrentSelection;
                SaveSelection();

                var mods = new SCObject();

                foreach (var sm in CurrentSelection.Contents)
                {
                    mods.Add(SCKeyValObject.Create(sm.Key));
                }

                _settingsRoot["last_mods"] = mods;

                if (File.Exists(_gameConfiguration.BackupPath))
                {
                    File.Delete(_gameConfiguration.BackupPath);
                }
                File.Move(_gameConfiguration.SettingsPath, _gameConfiguration.BackupPath);

                using (var stream = new FileStream(_gameConfiguration.SettingsPath, FileMode.Create, FileAccess.Write))
                {
                    _settingsRoot.WriteToStream(stream);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Error saving game settings");
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        public void DuplicateCurrentSelection(string newName)
        {
            var sel = new ModSelection(newName);

            sel.Contents.AddRange(CurrentSelection.Contents);
            CurrentSelection = sel;
            Selections.Add(sel);
            SaveSelection();
        }
Beispiel #3
0
 public void DeleteCurrentSelection()
 {
     Selections.Remove(CurrentSelection);
     CurrentSelection = Selections.FirstOrDefault();
     if (!Selections.Contains(_currentlySaved))
     {
         _currentlySaved = null;
     }
     SaveSelection();
 }
Beispiel #4
0
        public void LoadSavedSelection()
        {
            if (File.Exists(_gameConfiguration.SavedSelections))
            {
                using (var stream = new FileStream(_gameConfiguration.SavedSelections, FileMode.Open, FileAccess.Read))
                {
                    var selectionParser = new Parser(new Scanner(stream));

                    selectionParser.Parse();

                    if (!selectionParser.ParseError && selectionParser.Root.Any())
                    {
                        var selectionDocument = selectionParser.Root;
                        UpgradeFormat(selectionDocument);

                        var selectionIdx = selectionDocument[SavedSelectionKey] as SCString;

                        var selections = selectionDocument[SelectionsKey] as SCObject ?? new SCObject();

                        foreach (var selection in selections)
                        {
                            var          key = (selection.Key as SCString).Text;
                            ModSelection modSelection;
                            if (selection.Key.Equals(selectionIdx))
                            {
                                modSelection     = CreateDefaultSelection(key);
                                CurrentSelection = modSelection;
                            }
                            else
                            {
                                modSelection = CreateFromScObject(key, selection.Value);
                            }

                            Selections.Add(modSelection);
                        }
                    }
                }
            }

            // only happens if the config file couldn't have been loaded
            if (CurrentSelection == null)
            {
                CurrentSelection = CreateDefaultSelection();
                Selections.Add(CurrentSelection);
            }

            _currentlySaved = CurrentSelection;
            SaveSelection();
        }
Beispiel #5
0
        private ModSelection CreateFromScObject(string name, SCValue contents)
        {
            var selection    = new ModSelection(name);
            var defSelection = contents as SCObject ?? new SCObject();

            foreach (var mod in defSelection)
            {
                var installed = _installedModManager.Mods.FirstOrDefault(m => m.Key == (mod.Value as SCString)?.Text);
                if (installed != null)
                {
                    selection.Contents.Add(installed);
                }
            }
            return(selection);
        }