Esempio n. 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);
        }
Esempio n. 2
0
        /// <summary>
        /// Attempts to save all modified stash files.
        /// </summary>
        private void SaveAllModifiedStashes()
        {
            // Save each stash as necessary
            foreach (KeyValuePair <string, Stash> kvp in this.stashes)
            {
                string stashFile = kvp.Key;
                Stash  stash     = kvp.Value;

                if (stash == null)
                {
                    continue;
                }

                if (stash.IsModified)
                {
                    bool done = false;

                    // backup the file
                    while (!done)
                    {
                        try
                        {
                            TQData.BackupFile(stash.PlayerName, stashFile);
                            StashProvider.Save(stash, stashFile);
                            done = true;
                        }
                        catch (IOException exception)
                        {
                            string title = string.Format(CultureInfo.InvariantCulture, Resources.MainFormSaveError, stash.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;
        }
Esempio n. 3
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, PlayerCollection> kvp in this.userContext.Vaults)
            {
                string           vaultFile = kvp.Key;
                PlayerCollection vault     = kvp.Value;

                if (vault == null)
                {
                    continue;
                }

                if (vault.IsModified)
                {
                    // backup the file
                    vaultOnError = vault;
                    TQData.BackupFile(vault.PlayerName, vaultFile);
                    PlayerCollectionProvider.Save(vault, vaultFile);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Attempts to save all modified stash files.
        /// </summary>
        /// <param name="stashOnError"></param>
        /// <exception cref="IOException">can happen during file save</exception>
        public void SaveAllModifiedStashes(ref Stash stashOnError)
        {
            // Save each stash as necessary
            foreach (KeyValuePair <string, Stash> kvp in this.userContext.Stashes)
            {
                string stashFile = kvp.Key;
                Stash  stash     = kvp.Value;

                if (stash == null)
                {
                    continue;
                }

                if (stash.IsModified)
                {
                    stashOnError = stash;
                    TQData.BackupFile(stash.PlayerName, stashFile);
                    StashProvider.Save(stash, stashFile);
                }
            }
        }
Esempio n. 5
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);
        }