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); }
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); }
private void UpgradeFormat(SCObject selectionsDocument) { //Upgrade from Stellaris only names; var upgradeNeeded = selectionsDocument["SavedToStellaris"] != null; if (upgradeNeeded) { selectionsDocument[SavedSelectionKey] = selectionsDocument["SavedToStellaris"]; selectionsDocument.Remove("SavedToStellaris"); } }
public bool Initialize() { try { if (null == (_settingsRoot = LoadGameSettings(_gameConfiguration.SettingsPath))) { if (File.Exists(_gameConfiguration.BackupPath)) { if (_notificationService.RequestConfirmation("Settings.txt corrupted, backup available, reload from backup?", "Error")) { _settingsRoot = LoadGameSettings(_gameConfiguration.BackupPath); } else { return(false); } } // haven't managed to load from backup if (_settingsRoot == null) { _notificationService.ShowMessage( "Settings.txt corrupted - no backup available, please run stellaris to recreate default settings.", "Error"); return(false); } SaveSettings(); // this is a backup of an incorrect file, we should delete it. File.Delete(_gameConfiguration.BackupPath); } _installedModManager.Initialize(); LoadSavedSelection(); } catch (Exception ex) { _notificationService.ShowMessage(ex.Message, "Error"); return(false); } return(true); }