Пример #1
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;
        }
Пример #2
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);
                }
            }
        }