Esempio n. 1
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);
        }
Esempio n. 2
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;
            }
        }