Example #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 int LoadAllFilesTotal()
        {
            int numIT = GamePathResolver.GetCharacterList()?.Count() ?? 0;

            numIT = numIT * 2;            // Assuming that there is 1 stash file per character
            int numVaults = GamePathResolver.GetVaultList()?.Count() ?? 0;

            return(Math.Max(0, numIT + numVaults - 1));
        }
Example #2
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 int LoadAllFilesTotal()
        {
            string[] list;

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

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

            return(Math.Max(0, numIT + numVaults - 1));
        }
        /// <summary>
        /// Gets the list of available vaults and loads them into the drop down list
        /// </summary>
        private void GetVaultList()
        {
            string[] vaults = GamePathResolver.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, VaultService.MAINVAULT) != -1)
                {
                    this.vaultListComboBox.Items.Add(VaultService.MAINVAULT);
                }

                foreach (string vault in vaults)
                {
                    if (!vault.Equals(VaultService.MAINVAULT))
                    {
                        // now add everything EXCEPT for main vault
                        this.vaultListComboBox.Items.Add(vault);
                    }
                }
            }
        }
Example #4
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       = GamePathResolver.GetVaultList();
            var      charactersIT = this.characterComboBox.Items.OfType <PlayerSave>().ToArray();

            int numIT     = charactersIT?.Length ?? 0;
            int numVaults = vaults?.Length ?? 0;

            // Since this takes a while, show a progress dialog box.
            int total = 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;
            }

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            // Load all of the Immortal Throne player files and stashes.
            var bagPlayer        = new ConcurrentBag <LoadPlayerResult>();
            var bagPlayerStashes = new ConcurrentBag <LoadPlayerStashResult>();
            var bagVault         = new ConcurrentBag <LoadVaultResult>();

            var lambdacharactersIT = charactersIT.Select(c => (Action)(() =>
            {
                // Get the player
                var result = this.playerService.LoadPlayer(c, true);
                bagPlayer.Add(result);
                this.backgroundWorkerLoadAllFiles.ReportProgress(1);
            })).ToArray();

            var lambdacharacterStashes = charactersIT.Select(c => (Action)(() =>
            {
                // Get the player's stash
                var result = this.stashService.LoadPlayerStash(c);
                bagPlayerStashes.Add(result);
                this.backgroundWorkerLoadAllFiles.ReportProgress(1);
            })).ToArray();

            var lambdaVault = vaults.Select(c => (Action)(() =>
            {
                // Load all of the vaults.
                var result = this.vaultService.LoadVault(c);
                bagVault.Add(result);
                this.backgroundWorkerLoadAllFiles.ReportProgress(1);
            })).ToArray();

            Parallel.Invoke(lambdacharactersIT.Concat(lambdacharacterStashes).Concat(lambdaVault).ToArray());            // Parallel loading

            // Dispay errors
            bagPlayer.Where(p => p.Player.ArgumentException != null).ToList()
            .ForEach(result =>
            {
                if (result.Player.ArgumentException != null)
                {
                    string msg = string.Format(CultureInfo.CurrentUICulture, "{0}\n{1}\n{2}", Resources.MainFormPlayerReadError, result.PlayerFile, result.Player.ArgumentException.Message);
                    MessageBox.Show(msg, Resources.GlobalError, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, RightToLeftOptions);
                }
            });
            bagPlayerStashes.Where(p => p.Stash.ArgumentException != null).ToList()
            .ForEach(result =>
            {
                if (result.Stash.ArgumentException != null)
                {
                    string msg = string.Format(CultureInfo.CurrentUICulture, "{0}\n{1}\n{2}", Resources.MainFormPlayerReadError, result.StashFile, result.Stash.ArgumentException.Message);
                    MessageBox.Show(msg, Resources.GlobalError, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, RightToLeftOptions);
                }
            });
            bagVault.Where(p => p.ArgumentException != null).ToList()
            .ForEach(result =>
            {
                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);
                }
            });


            stopWatch.Stop();
            // Get the elapsed time as a TimeSpan value.
            TimeSpan ts = stopWatch.Elapsed;

            // Format and display the TimeSpan value.
            Log.LogInformation("LoadTime {0:00}:{1:00}:{2:00}.{3:00}",
                               ts.Hours, ts.Minutes, ts.Seconds,
                               ts.Milliseconds / 10);

            // We made it so set the flag to indicate we were successful.
            Config.Settings.Default.LoadAllFilesCompleted = true;
            Config.Settings.Default.Save();
        }
Example #5
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)
        {
            string[] vaults = GamePathResolver.GetVaultList();

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

            // There was something already selected so we will save it.
            string currentVault = (this.vaultListComboBox.Items.Count > 0) ? this.vaultListComboBox.SelectedItem.ToString() : 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(GamePathResolver.GetVaultFile(currentVault)))
                {
                    currentVault = VaultService.MAINVAULT;
                }
            }

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

                // Finally load Vault
                this.LoadVault(currentVault, false);
            }
        }
Example #6
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 = GamePathResolver.GetVaultList();

            string[] charactersIT = GamePathResolver.GetCharacterList();

            int numIT = charactersIT?.Length ?? 0;

            int numVaults = vaults?.Length ?? 0;

            // Since this takes a while, show a progress dialog box.
            int total = 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();
        }