Exemple #1
0
        /// <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, PlayerCollection> kvp in this.userContext.Players)
            {
                string           playerFile = kvp.Key;
                PlayerCollection player     = kvp.Value;

                if (player == null)
                {
                    continue;
                }

                if (player.IsModified)
                {
                    ++numModified;
                    playerOnError = player;                    // if needed by caller
                    TQData.BackupFile(player.PlayerName, playerFile);
                    TQData.BackupStupidPlayerBackupFolder(playerFile);
                    PlayerCollectionProvider.Save(player, playerFile);
                }
            }

            return(numModified > 0);
        }
Exemple #2
0
        /// <summary>
        /// Attempts to save all modified player files
        /// </summary>
        /// <returns>True if there were any modified player files.</returns>
        private bool SaveAllModifiedPlayers()
        {
            int numModified = 0;

            // Save each player as necessary
            foreach (KeyValuePair <string, PlayerCollection> kvp in this.players)
            {
                string           playerFile = kvp.Key;
                PlayerCollection player     = kvp.Value;

                if (player == null)
                {
                    continue;
                }

                if (player.IsModified)
                {
                    ++numModified;
                    bool done = false;

                    // backup the file
                    while (!done)
                    {
                        try
                        {
                            TQData.BackupFile(player.PlayerName, playerFile);
                            TQData.BackupStupidPlayerBackupFolder(playerFile);
                            PlayerCollectionProvider.Save(player, playerFile);
                            done = true;
                        }
                        catch (IOException exception)
                        {
                            string title = string.Format(CultureInfo.InvariantCulture, Resources.MainFormSaveError, player.PlayerName);
                            Log.Error(title, exception);
                            switch (MessageBox.Show(Log.FormatException(exception), title, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, RightToLeftOptions))
                            {
                            case DialogResult.Abort:
                            {
                                // rethrow the exception
                                throw;
                            }

                            case DialogResult.Retry:
                            {
                                // retry
                                break;
                            }

                            case DialogResult.Ignore:
                            {
                                done = true;
                                break;
                            }
                            }
                        }
                    }
                }
            }

            return(numModified > 0);
        }