/// <summary> /// Attempts to save all modified player files /// </summary> /// <param name="playerOnError"></param> /// <returns>True if there were any modified player files.</returns> /// <exception cref="IOException">can happen during file save</exception> public bool SaveAllModifiedPlayers(ref PlayerCollection playerOnError) { int numModified = 0; // Save each player as necessary foreach (KeyValuePair <string, Lazy <PlayerCollection> > kvp in this.userContext.Players) { string playerFile = kvp.Key; PlayerCollection player = kvp.Value.Value; if (player == null) { continue; } if (player.IsModified) { ++numModified; playerOnError = player; // if needed by caller GamePathResolver.BackupFile(player.PlayerName, playerFile); GamePathResolver.BackupStupidPlayerBackupFolder(playerFile); PlayerCollectionProvider.Save(player, playerFile); } } return(numModified > 0); }
/// <summary> /// Attempts to save all modified vault files /// </summary> /// <param name="vaultOnError"></param> /// <exception cref="IOException">can happen during file save</exception> public void SaveAllModifiedVaults(ref PlayerCollection vaultOnError) { foreach (KeyValuePair <string, Lazy <PlayerCollection> > kvp in this.userContext.Vaults) { string vaultFile = kvp.Key; PlayerCollection vault = kvp.Value.Value; if (vault == null) { continue; } if (vault.IsModified) { // backup the file vaultOnError = vault; GamePathResolver.BackupFile(vault.PlayerName, vaultFile); PlayerCollectionProvider.Save(vault, vaultFile); } } }