Exemple #1
0
        public bool SaveSelection()
        {
            try
            {
                var selections = new SCObject();

                var selectionsToSave = new SCObject {
                    [SavedSelectionKey] = new SCString(_currentlySaved?.Name), [SelectionsKey] = selections
                };

                foreach (var modSelection in Selections)
                {
                    var mods = new SCObject();

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

                    selections[new SCString(modSelection.Name)] = mods;
                }

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

            return(true);
        }
Exemple #2
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);
        }