예제 #1
0
        /// <summary>
        /// Counts the number of files which LoadAllFiles will load.  Used to set the max value of the progress bar.
        /// </summary>
        /// <returns>Total number of files that LoadAllFiles() will load.</returns>
        private static int LoadAllFilesTotal()
        {
            string[] list;

            list = TQData.GetCharacterList();
            int numIT = list?.Length ?? 0;

            list = TQData.GetVaultList();
            int numVaults = list?.Length ?? 0;

            return(Math.Max(0, numIT + numIT + numVaults - 1));
        }
예제 #2
0
        /// <summary>
        /// Gets the list of available vaults and loads them into the drop down list
        /// </summary>
        private void GetVaultList()
        {
            string[] vaults = TQData.GetVaultList();

            // Make sure we have something to add.
            if (vaults != null && vaults.Length > 0)
            {
                // Put Main Vault at the top of the list only if it exists.
                if (Array.IndexOf(vaults, "Main Vault") != -1)
                {
                    this.vaultListComboBox.Items.Add("Main Vault");
                }

                foreach (string vault in vaults)
                {
                    if (!vault.Equals("Main Vault"))
                    {
                        // now add everything EXCEPT for main vault
                        this.vaultListComboBox.Items.Add(vault);
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Loads all of the players, stashes, and vaults.
        /// Shows a progress dialog.
        /// Used for the searching function.
        /// </summary>
        private void LoadAllFiles()
        {
            // Check to see if we failed the last time we tried loading all of the files.
            // If we did fail then turn it off and skip it.
            if (!Config.Settings.Default.LoadAllFilesCompleted)
            {
                if (MessageBox.Show(
                        Resources.MainFormDisableLoadAllFiles,
                        Resources.MainFormDisableLoadAllFilesCaption,
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Information,
                        MessageBoxDefaultButton.Button1,
                        RightToLeftOptions) == DialogResult.Yes)
                {
                    Config.Settings.Default.LoadAllFilesCompleted = true;
                    Config.Settings.Default.LoadAllFiles          = false;
                    Config.Settings.Default.Save();
                    return;
                }
            }

            string[] vaults = TQData.GetVaultList();

            string[] charactersIT = TQData.GetCharacterList();

            int numIT = charactersIT?.Length ?? 0;

            int numVaults = vaults?.Length ?? 0;

            // Since this takes a while, show a progress dialog box.
            int total = numIT + numIT + numVaults - 1;

            if (total > 0)
            {
                // We were successful last time so we reset the flag for this attempt.
                Config.Settings.Default.LoadAllFilesCompleted = false;
                Config.Settings.Default.Save();
            }
            else
            {
                return;
            }

            // Load all of the Immortal Throne player files and stashes.
            for (int i = 0; i < numIT; ++i)
            {
                // Get the player & player's stash
                try
                {
                    var result = this.playerService.LoadPlayer(charactersIT[i], true);

                    if (result.PlayerArgumentException != null)
                    {
                        string msg = string.Format(CultureInfo.CurrentUICulture, "{0}\n{1}\n{2}", Resources.MainFormPlayerReadError, result.PlayerFile, result.PlayerArgumentException.Message);
                        MessageBox.Show(msg, Resources.GlobalError, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, RightToLeftOptions);
                    }
                    if (result.StashArgumentException != null)
                    {
                        string msg = string.Format(CultureInfo.CurrentUICulture, "{0}\n{1}\n{2}", Resources.MainFormPlayerReadError, result.StashFile, result.StashArgumentException.Message);
                        MessageBox.Show(msg, Resources.GlobalError, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, RightToLeftOptions);
                    }
                }
                catch (IOException exception)
                {
                    Log.ErrorException(exception);
                    MessageBox.Show(Log.FormatException(exception), Resources.GlobalError, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, RightToLeftOptions);
                }

                this.backgroundWorker1.ReportProgress(1);
            }

            // Load all of the vaults.
            for (int i = 0; i < numVaults; ++i)
            {
                var result = this.vaultService.LoadVault(vaults[i]);
                if (result.ArgumentException != null)
                {
                    string msg = string.Format(CultureInfo.CurrentUICulture, "{0}\n{1}\n{2}", Resources.MainFormPlayerReadError, result.Filename, result.ArgumentException.Message);
                    MessageBox.Show(msg, Resources.GlobalError, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, RightToLeftOptions);
                }

                this.backgroundWorker1.ReportProgress(1);
            }

            // We made it so set the flag to indicate we were successful.
            Config.Settings.Default.LoadAllFilesCompleted = true;
            Config.Settings.Default.Save();
        }
예제 #4
0
        /// <summary>
        /// Gets a list of all available vault files and populates the drop down list.
        /// </summary>
        /// <param name="loadVault">Indicates whether the list will also load the last vault selected.</param>
        private void GetVaultList(bool loadVault)
        {
            if (this.vaultService is null)
            {
                this.vaultService = new VaultService(userContext);
            }

            string[] vaults = TQData.GetVaultList();

            // Added by VillageIdiot
            // See if the Vault path was set during GetVaultList and update the key accordingly
            if (TQData.VaultFolderChanged)
            {
                this.vaultService.UpdateVaultPath(TQData.TQVaultSaveFolder);
            }

            string currentVault;

            // There was something already selected so we will save it.
            if (this.vaultListComboBox.Items.Count > 0)
            {
                currentVault = this.vaultListComboBox.SelectedItem.ToString();
            }
            else
            {
                currentVault = VaultService.MAINVAULT;
            }

            // Added by VillageIdiot
            // Clear the list before creating since this function can be called multiple times.
            this.vaultListComboBox.Items.Clear();

            this.vaultListComboBox.Items.Add(Resources.MainFormMaintainVault);

            // Add Main Vault first
            if (this.secondaryVaultListComboBox.SelectedItem == null || this.secondaryVaultListComboBox.SelectedItem.ToString() != VaultService.MAINVAULT)
            {
                this.vaultListComboBox.Items.Add(VaultService.MAINVAULT);
            }

            if ((vaults?.Length ?? 0) > 0)
            {
                // now add everything EXCEPT for main vault
                foreach (string vault in vaults)
                {
                    if (!vault.Equals(VaultService.MAINVAULT))
                    {
                        // we already added main vault
                        if (this.secondaryVaultListComboBox.SelectedItem != null && vault.Equals(this.secondaryVaultListComboBox.SelectedItem.ToString()) && this.showSecondaryVault)
                        {
                            break;
                        }

                        this.vaultListComboBox.Items.Add(vault);
                    }
                }
            }

            // See if we should load the last loaded vault
            if (Config.Settings.Default.LoadLastVault)
            {
                currentVault = Config.Settings.Default.LastVaultName;

                // Make sure there is something in the config file to load else load the Main Vault
                // We do not want to create new here.
                if (string.IsNullOrEmpty(currentVault) || !File.Exists(TQData.GetVaultFile(currentVault)))
                {
                    currentVault = VaultService.MAINVAULT;
                }
            }

            if (loadVault)
            {
                this.vaultListComboBox.SelectedItem = currentVault;

                // Finally load Vault
                this.LoadVault(currentVault, false);
            }
        }