Пример #1
0
        /// <summary>
        /// Loads the relic vault stash
        /// </summary>
        public LoadRelicVaultStashResult LoadRelicVaultStash()
        {
            var result = new LoadRelicVaultStashResult();

            result.RelicVaultStashFile = TQData.RelicVaultStashFile;

            // Get the relic vault stash
            try
            {
                result.Stash = this.userContext.Stashes[result.RelicVaultStashFile];
            }
            catch (KeyNotFoundException)
            {
                result.Stash = new Stash(Resources.GlobalRelicVaultStash, result.RelicVaultStashFile);
                result.Stash.CreateEmptySack();
                result.Stash.Sack.StashType = SackType.RelicVaultStash;

                try
                {
                    result.StashPresent = StashProvider.LoadFile(result.Stash);
                    if (result.StashPresent.Value)
                    {
                        result.Stash.Sack.StashType = SackType.RelicVaultStash;
                        this.userContext.Stashes.Add(result.RelicVaultStashFile, result.Stash);
                    }
                }
                catch (ArgumentException argumentException)
                {
                    result.ArgumentException = argumentException;
                }
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Loads the transfer stash for immortal throne
        /// </summary>
        public LoadTransferStashResult LoadTransferStash()
        {
            var result = new LoadTransferStashResult();

            result.TransferStashFile = TQData.TransferStashFile;

            try
            {
                result.Stash = this.userContext.Stashes[result.TransferStashFile];
            }
            catch (KeyNotFoundException)
            {
                result.Stash = new Stash(Resources.GlobalTransferStash, result.TransferStashFile);
                result.Stash.IsImmortalThrone = true;

                try
                {
                    result.StashPresent = StashProvider.LoadFile(result.Stash);
                    if (result.StashPresent.Value)
                    {
                        this.userContext.Stashes.Add(result.TransferStashFile, result.Stash);
                    }
                }
                catch (ArgumentException argumentException)
                {
                    result.ArgumentException = argumentException;
                }
            }

            return(result);
        }
Пример #3
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;
        }
Пример #4
0
        /// <summary>
        /// Loads the relic vault stash
        /// </summary>
        private void LoadRelicVaultStash()
        {
            string relicVaultStashFile = TQData.RelicVaultStashFile;

            // Get the relic vault stash
            try
            {
                Stash stash;
                try
                {
                    stash = this.stashes[relicVaultStashFile];
                }
                catch (KeyNotFoundException)
                {
                    bool stashLoaded = false;
                    stash = new Stash(Resources.GlobalRelicVaultStash, relicVaultStashFile);
                    stash.IsImmortalThrone = true;

                    try
                    {
                        // Throw a message if the stash does not exist.
                        bool stashPresent = StashProvider.LoadFile(stash);
                        if (!stashPresent)
                        {
                            MessageBox.Show(Resources.StashNotFoundMsg, Resources.StashNotFound, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, RightToLeftOptions);
                        }

                        stashLoaded = stashPresent;
                    }
                    catch (ArgumentException argumentException)
                    {
                        string msg = string.Format(CultureInfo.CurrentUICulture, "{0}\n{1}\n{2}", Resources.MainFormPlayerReadError, relicVaultStashFile, argumentException.Message);
                        MessageBox.Show(msg, Resources.GlobalError, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, RightToLeftOptions);
                        stashLoaded = false;
                    }

                    if (stashLoaded)
                    {
                        stash.Sack.StashType = SackType.RelicVaultStash;
                        this.stashes.Add(relicVaultStashFile, stash);
                    }
                }

                this.stashPanel.RelicVaultStash = stash;
            }
            catch (IOException exception)
            {
                string msg = string.Format(CultureInfo.InvariantCulture, Resources.MainFormReadError, relicVaultStashFile, exception.ToString());
                MessageBox.Show(msg, Resources.MainFormStashReadError, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, RightToLeftOptions);

                this.stashPanel.RelicVaultStash = null;
            }
        }
Пример #5
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);
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Loads a player using the drop down list.
        /// Assumes designators are appended to character name.
        /// </summary>
        /// <param name="selectedText">Player string from the drop down list.</param>
        /// <param name="isIT"></param>
        /// <returns></returns>
        public LoadPlayerResult LoadPlayer(string selectedText, bool isIT = false)
        {
            var result = new LoadPlayerResult();

            if (string.IsNullOrWhiteSpace(selectedText))
            {
                return(result);
            }

            result.IsCustom = selectedText.EndsWith(PlayerService.CustomDesignator, StringComparison.Ordinal);
            if (result.IsCustom)
            {
                // strip off the end from the player name.
                selectedText = selectedText.Remove(selectedText.IndexOf(PlayerService.CustomDesignator, StringComparison.Ordinal), PlayerService.CustomDesignator.Length);
            }

            #region Get the player

            result.PlayerFile = TQData.GetPlayerFile(selectedText);

            try
            {
                result.Player = this.userContext.Players[result.PlayerFile];
            }
            catch (KeyNotFoundException)
            {
                result.Player = new PlayerCollection(selectedText, result.PlayerFile);
                result.Player.IsImmortalThrone = isIT;
                try
                {
                    PlayerCollectionProvider.LoadFile(result.Player);
                    this.userContext.Players.Add(result.PlayerFile, result.Player);
                }
                catch (ArgumentException argumentException)
                {
                    result.PlayerArgumentException = argumentException;
                }
            }

            #endregion

            #region Get the player's stash

            result.StashFile = TQData.GetPlayerStashFile(selectedText);

            try
            {
                result.Stash = this.userContext.Stashes[result.StashFile];
            }
            catch (KeyNotFoundException)
            {
                result.Stash = new Stash(selectedText, result.StashFile);
                try
                {
                    result.StashFound = StashProvider.LoadFile(result.Stash);
                    if (result.StashFound.Value)
                    {
                        this.userContext.Stashes.Add(result.StashFile, result.Stash);
                    }
                }
                catch (ArgumentException argumentException)
                {
                    result.StashArgumentException = argumentException;
                }
            }

            #endregion

            return(result);
        }
Пример #7
0
        /// <summary>
        /// Loads a player using the drop down list.
        /// Assumes designators are appended to character name.
        /// Changed by VillageIdiot to a separate function.
        /// </summary>
        /// <param name="selectedText">Player string from the drop down list.</param>
        private void LoadPlayer(string selectedText)
        {
            string customDesignator = "<Custom Map>";

            bool isCustom = selectedText.EndsWith(customDesignator, StringComparison.Ordinal);

            if (isCustom)
            {
                // strip off the end from the player name.
                selectedText = selectedText.Remove(selectedText.IndexOf(customDesignator, StringComparison.Ordinal), customDesignator.Length);
            }

            string playerFile = TQData.GetPlayerFile(selectedText);

            // Get the player
            try
            {
                PlayerCollection player;
                try
                {
                    player = this.players[playerFile];
                }
                catch (KeyNotFoundException)
                {
                    bool playerLoaded = false;
                    player = new PlayerCollection(selectedText, playerFile);
                    try
                    {
                        PlayerCollectionProvider.LoadFile(player);
                        playerLoaded = true;
                    }
                    catch (ArgumentException argumentException)
                    {
                        string msg = string.Format(CultureInfo.CurrentUICulture, "{0}\n{1}\n{2}", Resources.MainFormPlayerReadError, playerFile, argumentException.Message);
                        MessageBox.Show(msg, Resources.GlobalError, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, RightToLeftOptions);
                        playerLoaded = false;
                    }

                    // Only add the player to the list if it loaded successfully.
                    if (playerLoaded)
                    {
                        this.players.Add(playerFile, player);
                    }
                }

                this.playerPanel.Player    = player;
                this.stashPanel.Player     = player;
                this.stashPanel.CurrentBag = 0;
            }
            catch (IOException exception)
            {
                string msg = string.Format(CultureInfo.InvariantCulture, Resources.MainFormReadError, playerFile, exception.ToString());
                MessageBox.Show(msg, Resources.MainFormPlayerReadError, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, RightToLeftOptions);
                Log.Error(msg, exception);
                this.playerPanel.Player = null;
                this.characterComboBox.SelectedIndex = 0;
            }

            string stashFile = TQData.GetPlayerStashFile(selectedText);

            // Get the player's stash
            try
            {
                Stash stash;
                try
                {
                    stash = this.stashes[stashFile];
                }
                catch (KeyNotFoundException)
                {
                    bool stashLoaded = false;
                    stash = new Stash(selectedText, stashFile);
                    try
                    {
                        bool stashPresent = StashProvider.LoadFile(stash);

                        // Throw a message if the stash is not present.
                        if (!stashPresent)
                        {
                            MessageBox.Show(Resources.StashNotFoundMsg, Resources.StashNotFound, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, RightToLeftOptions);
                        }

                        stashLoaded = stashPresent;
                    }
                    catch (ArgumentException argumentException)
                    {
                        string msg = string.Format(CultureInfo.CurrentUICulture, "{0}\n{1}\n{2}", Resources.MainFormPlayerReadError, stashFile, argumentException.Message);
                        MessageBox.Show(msg, Resources.GlobalError, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, RightToLeftOptions);
                        stashLoaded = false;
                    }

                    if (stashLoaded)
                    {
                        this.stashes.Add(stashFile, stash);
                    }
                }

                this.stashPanel.Stash = stash;
            }
            catch (IOException exception)
            {
                string msg = string.Concat(Resources.MainFormReadError, stashFile, exception.ToString());
                MessageBox.Show(msg, Resources.MainFormStashReadError, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, RightToLeftOptions);
                Log.Error(msg, exception);
                this.stashPanel.Stash = null;
            }
        }