コード例 #1
0
ファイル: GameContext.cs プロジェクト: treiduce/SCModManager
        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);
        }
コード例 #2
0
ファイル: GameContext.cs プロジェクト: treiduce/SCModManager
        public void DuplicateCurrentSelection(string newName)
        {
            var sel = new ModSelection(newName);

            sel.Contents.AddRange(CurrentSelection.Contents);
            CurrentSelection = sel;
            Selections.Add(sel);
            SaveSelection();
        }
コード例 #3
0
ファイル: GameContext.cs プロジェクト: treiduce/SCModManager
 public void DeleteCurrentSelection()
 {
     Selections.Remove(CurrentSelection);
     CurrentSelection = Selections.FirstOrDefault();
     if (!Selections.Contains(_currentlySaved))
     {
         _currentlySaved = null;
     }
     SaveSelection();
 }
コード例 #4
0
ファイル: GameContext.cs プロジェクト: treiduce/SCModManager
        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();
        }
コード例 #5
0
ファイル: GameContext.cs プロジェクト: treiduce/SCModManager
        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);
        }