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>
        /// Gets a list of available player files and populates the drop down list.
        /// </summary>
        private void GetPlayerList()
        {
            // Initialize the character combo-box
            this.characterComboBox.Items.Clear();

            string[] charactersIT = GamePathResolver.GetCharacterList();

            int numIT = 0;

            if (charactersIT != null)
            {
                numIT = charactersIT.Length;
            }

            if (numIT == 0)
            {
                this.characterComboBox.Items.Add(Resources.MainFormNoCharacters);
                this.characterComboBox.SelectedIndex = 0;
            }
            else
            {
                this.characterComboBox.Items.Add(Resources.MainFormSelectCharacter);
                this.characterComboBox.SelectedIndex = 0;

                string characterDesignator = string.Empty;

                // Modified by VillageIdiot
                // Added to support custom Maps
                if (GamePathResolver.IsCustom)
                {
                    characterDesignator = string.Concat(characterDesignator, PlayerService.CustomDesignator);
                }

                string[] characters = charactersIT.Select(c => string.Concat(c, characterDesignator)).ToArray();
                this.characterComboBox.Items.AddRange(characters);
            }
        }
Example #5
0
 /// <summary>
 /// Gets a list of all of the custom maps.
 /// </summary>
 /// <returns>List of custom maps in a string array</returns>
 public static GamePathEntry[] GetCustomMapList()
 {
     return(GamePathResolver.ResolveTQModDirectories());
 }
Example #6
0
        /// <summary>
        /// Background worker has finished
        /// </summary>
        /// <param name="sender">sender object</param>
        /// <param name="e">RunWorkerCompletedEventArgs data</param>
        private void BackgroundWorkerLoadAllFiles_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            // First, handle the case where an exception was thrown.
            if (e.Error != null)
            {
                Log.LogError(e.Error, $"resourcesLoaded = {this.resourcesLoaded}");

                if (MessageBox.Show(
                        string.Concat(e.Error.Message, Resources.Form1BadLanguage)
                        , Resources.Form1ErrorLoadingResources
                        , MessageBoxButtons.YesNo
                        , MessageBoxIcon.Exclamation
                        , MessageBoxDefaultButton.Button1
                        , RightToLeftOptions) == DialogResult.Yes
                    )
                {
                    Application.Restart();
                }
                else
                {
                    Application.Exit();
                }
            }
            else if (e.Cancelled && !this.resourcesLoaded)
            {
                Application.Exit();
            }
            else if (e.Result.Equals(true))
            {
                this.loadingComplete = true;
                this.Enabled         = true;
                this.LoadTransferStash();
                this.LoadRelicVaultStash();

                // Load last character here if selected
                if (Config.Settings.Default.LoadLastCharacter)
                {
                    var lastPlayerSave = this.characterComboBox.Items.OfType <PlayerSave>()
                                         .FirstOrDefault(ps => ps.Name == Config.Settings.Default.LastCharacterName);

                    if (lastPlayerSave != null)
                    {
                        this.characterComboBox.SelectedItem = lastPlayerSave;
                    }
                }

                string currentVault = VaultService.MAINVAULT;

                // 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;
                    }
                }

                this.vaultListComboBox.SelectedItem = currentVault;

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

                this.splashScreen.UpdateText();
                this.splashScreen.ShowMainForm = true;

                CommandLineArgs args = new CommandLineArgs();

                // Allows skipping of title screen with setting
                if (args.IsAutomatic || Config.Settings.Default.SkipTitle == true)
                {
                    string player = args.Player;
                    int    index  = this.characterComboBox.FindStringExact(player);
                    if (index != -1)
                    {
                        this.characterComboBox.SelectedIndex = index;
                    }

                    this.splashScreen.CloseForm();
                }
            }
            else
            {
                Log.LogError(e.Error, $"resourcesLoaded = {this.resourcesLoaded}");
                // If for some reason the loading failed, but there was no error raised.
                MessageBox.Show(
                    Resources.Form1ErrorLoadingResources,
                    Resources.Form1ErrorLoadingResources,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation,
                    MessageBoxDefaultButton.Button1,
                    RightToLeftOptions);
                Application.Exit();
            }
        }
Example #7
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 #8
0
        /// <summary>
        /// Initializes a new instance of the SettingsDialog class.
        /// </summary>
        public SettingsDialog(MainForm instance) : base(instance.ServiceProvider)
        {
            this.Owner = instance;

            this.InitializeComponent();

            #region Apply custom font

            this.characterEditCheckBox.Font     = FontService.GetFontAlbertusMTLight(11.25F);
            this.allowItemEditCheckBox.Font     = FontService.GetFontAlbertusMTLight(11.25F);
            this.allowItemCopyCheckBox.Font     = FontService.GetFontAlbertusMTLight(11.25F);
            this.skipTitleCheckBox.Font         = FontService.GetFontAlbertusMTLight(11.25F);
            this.loadLastCharacterCheckBox.Font = FontService.GetFontAlbertusMTLight(11.25F);
            this.loadLastVaultCheckBox.Font     = FontService.GetFontAlbertusMTLight(11.25F);
            this.vaultPathTextBox.Font          = FontService.GetFontAlbertusMTLight(11.25F);
            this.vaultPathLabel.Font            = FontService.GetFontAlbertusMTLight(11.25F);
            this.cancelButton.Font                   = FontService.GetFontAlbertusMTLight(12F);
            this.okayButton.Font                     = FontService.GetFontAlbertusMTLight(12F);
            this.resetButton.Font                    = FontService.GetFontAlbertusMTLight(12F);
            this.vaultPathBrowseButton.Font          = FontService.GetFontAlbertusMTLight(12F);
            this.enableCustomMapsCheckBox.Font       = FontService.GetFontAlbertusMTLight(11.25F);
            this.loadAllFilesCheckBox.Font           = FontService.GetFontAlbertusMTLight(11.25F);
            this.suppressWarningsCheckBox.Font       = FontService.GetFontAlbertusMTLight(11.25F);
            this.playerReadonlyCheckbox.Font         = FontService.GetFontAlbertusMTLight(11.25F);
            this.languageComboBox.Font               = FontService.GetFontAlbertusMTLight(11.25F);
            this.languageLabel.Font                  = FontService.GetFontAlbertusMTLight(11.25F);
            this.detectLanguageCheckBox.Font         = FontService.GetFontAlbertusMTLight(11.25F);
            this.titanQuestPathTextBox.Font          = FontService.GetFontAlbertusMTLight(11.25F);
            this.titanQuestPathLabel.Font            = FontService.GetFontAlbertusMTLight(11.25F);
            this.immortalThronePathLabel.Font        = FontService.GetFontAlbertusMTLight(11.25F);
            this.immortalThronePathTextBox.Font      = FontService.GetFontAlbertusMTLight(11.25F);
            this.detectGamePathsCheckBox.Font        = FontService.GetFontAlbertusMTLight(11.25F);
            this.titanQuestPathBrowseButton.Font     = FontService.GetFontAlbertusMTLight(12F);
            this.immortalThronePathBrowseButton.Font = FontService.GetFontAlbertusMTLight(12F);
            this.customMapLabel.Font                 = FontService.GetFontAlbertusMTLight(11.25F);
            this.mapListComboBox.Font                = FontService.GetFontAlbertusMTLight(11.25F);
            this.baseFontLabel.Font                  = FontService.GetFontAlbertusMTLight(11.25F);
            this.baseFontComboBox.Font               = FontService.GetFontAlbertusMTLight(11.25F);
            this.Font = FontService.GetFontAlbertusMTLight(11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, (byte)(0));

            #endregion

            this.vaultPathLabel.Text           = Resources.SettingsLabel1;
            this.languageLabel.Text            = Resources.SettingsLabel2;
            this.titanQuestPathLabel.Text      = Resources.SettingsLabel3;
            this.immortalThronePathLabel.Text  = Resources.SettingsLabel4;
            this.customMapLabel.Text           = Resources.SettingsLabel5;
            this.detectGamePathsCheckBox.Text  = Resources.SettingsDetectGamePath;
            this.detectLanguageCheckBox.Text   = Resources.SettingsDetectLanguage;
            this.enableCustomMapsCheckBox.Text = Resources.SettingsEnableMod;
            this.toolTip.SetToolTip(this.enableCustomMapsCheckBox, Resources.SettingsEnableModTT);
            this.skipTitleCheckBox.Text = Resources.SettingsSkipTitle;
            this.toolTip.SetToolTip(this.skipTitleCheckBox, Resources.SettingsSkipTitleTT);
            this.allowItemCopyCheckBox.Text = Resources.SettingsAllowCopy;
            this.toolTip.SetToolTip(this.allowItemCopyCheckBox, Resources.SettingsAllowCopyTT);
            this.allowItemEditCheckBox.Text = Resources.SettingsAllowEdit;
            this.toolTip.SetToolTip(this.allowItemEditCheckBox, Resources.SettingsAllowEdit);
            this.characterEditCheckBox.Text = Resources.SettingsAllowEditCE;
            this.toolTip.SetToolTip(this.characterEditCheckBox, Resources.SettingsAllowEditCE);
            this.loadLastCharacterCheckBox.Text = Resources.SettingsLoadChar;
            this.toolTip.SetToolTip(this.loadLastCharacterCheckBox, Resources.SettingsLoadCharTT);
            this.loadLastVaultCheckBox.Text = Resources.SettingsLoadVault;
            this.toolTip.SetToolTip(this.loadLastVaultCheckBox, Resources.SettingsLoadVaultTT);
            this.loadAllFilesCheckBox.Text = Resources.SettingsPreLoad;
            this.toolTip.SetToolTip(this.loadAllFilesCheckBox, Resources.SettingsPreLoadTT);
            this.suppressWarningsCheckBox.Text = Resources.SettingsNoWarning;
            this.toolTip.SetToolTip(this.suppressWarningsCheckBox, Resources.SettingsNoWarningTT);
            this.playerReadonlyCheckbox.Text = Resources.SettingsPlayerReadonly;
            this.toolTip.SetToolTip(this.playerReadonlyCheckbox, Resources.SettingsPlayerReadonlyTT);
            this.resetButton.Text = Resources.SettingsReset;
            this.toolTip.SetToolTip(this.resetButton, Resources.SettingsResetTT);
            this.cancelButton.Text = Resources.GlobalCancel;
            this.okayButton.Text   = Resources.GlobalOK;
            this.Text = Resources.SettingsTitle;

            this.DrawCustomBorder = true;

            this.mapListComboBox.Items.Clear();

            var maps = GamePathResolver.GetCustomMapList();

            if (maps?.Any() ?? false)
            {
                this.mapListComboBox.Items.AddRange(maps);
            }

            if (!Config.Settings.Default.AllowCheats)
            {
                this.allowItemEditCheckBox.Visible = false;
                this.allowItemCopyCheckBox.Visible = false;
                this.characterEditCheckBox.Visible = false;
            }
        }
Example #9
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 #10
0
        /// <summary>
        /// Method for the maintain vault files dialog
        /// </summary>
        private void MaintainVaultFilesDialog()
        {
            try
            {
                this.SaveAllModifiedFiles();

                var dlg = this.ServiceProvider.GetService <VaultMaintenanceDialog>();
                dlg.Scale(new SizeF(UIService.Scale, UIService.Scale));

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    string newName = dlg.Target;
                    string oldName = dlg.Source;
                    bool   handled = false;

                    // Create a new vault?
                    if (dlg.Action == VaultMaintenanceDialog.VaultMaintenance.New && newName != null)
                    {
                        // Add the name to the list
                        this.vaultListComboBox.Items.Add(newName);

                        // Select it
                        this.vaultListComboBox.SelectedItem = newName;

                        // Load it
                        this.LoadVault(newName, false);
                        handled = true;
                    }
                    else if (dlg.Action == VaultMaintenanceDialog.VaultMaintenance.Copy && newName != null && oldName != null)
                    {
                        string oldFilename = GamePathResolver.GetVaultFile(oldName);
                        string newFilename = GamePathResolver.GetVaultFile(newName);

                        // Make sure we save all modifications first.
                        this.SaveAllModifiedFiles();

                        // Make sure the vault file to copy exists and the new name does not.
                        if (File.Exists(oldFilename) && !File.Exists(newFilename))
                        {
                            File.Copy(oldFilename, newFilename);

                            // Add the new name to the list
                            this.vaultListComboBox.Items.Add(newName);

                            // Select the new name
                            this.vaultListComboBox.SelectedItem = newName;

                            // Load the new file.
                            this.LoadVault(newName, false);
                            handled = true;
                        }
                    }
                    else if (dlg.Action == VaultMaintenanceDialog.VaultMaintenance.Delete && oldName != null)
                    {
                        string filename = GamePathResolver.GetVaultFile(oldName);

                        // Make sure we save all modifications first.
                        this.SaveAllModifiedFiles();

                        // Make sure the vault file to delete exists.
                        if (File.Exists(filename))
                        {
                            File.Delete(filename);
                        }

                        // Remove the file from the cache.
                        userContext.Vaults.TryRemove(filename, out var remVault);

                        // Remove the deleted file from the list.
                        this.vaultListComboBox.Items.Remove(oldName);

                        // Select the Main Vault since we know it's still there.
                        this.vaultListComboBox.SelectedIndex = 1;

                        handled = true;
                    }
                    else if (dlg.Action == VaultMaintenanceDialog.VaultMaintenance.Rename && newName != null && oldName != null)
                    {
                        string oldFilename = GamePathResolver.GetVaultFile(oldName);
                        string newFilename = GamePathResolver.GetVaultFile(newName);

                        // Make sure we save all modifications first.
                        this.SaveAllModifiedFiles();

                        // Make sure the vault file to rename exists and the new name does not.
                        if (File.Exists(oldFilename) && !File.Exists(newFilename))
                        {
                            File.Move(oldFilename, newFilename);

                            // Remove the old vault from the cache.
                            userContext.Vaults.TryRemove(oldFilename, out var remOldVault);

                            // Get rid of the old name from the list
                            this.vaultListComboBox.Items.Remove(oldName);

                            // If we renamed something to main vault we need to remove it,
                            // since the list always contains Main Vault.
                            if (newName == VaultService.MAINVAULT)
                            {
                                userContext.Vaults.TryRemove(newFilename, out var remMainVault);
                                this.vaultListComboBox.Items.Remove(newName);
                            }

                            // Add the new name to the list
                            this.vaultListComboBox.Items.Add(newName);

                            // Select the new name
                            this.vaultListComboBox.SelectedItem = newName;

                            // Load the new file.
                            this.LoadVault(newName, false);
                            handled = true;
                        }
                    }

                    if ((newName == null && oldName == null) || !handled)
                    {
                        // put the vault back to what it was
                        if (this.vaultPanel.Player != null)
                        {
                            this.vaultListComboBox.SelectedItem = this.vaultPanel.Player.PlayerName;
                        }
                    }
                }
                else
                {
                    // put the vault back to what it was
                    if (this.vaultPanel.Player != null)
                    {
                        this.vaultListComboBox.SelectedItem = this.vaultPanel.Player.PlayerName;
                    }
                }
            }
            catch (IOException exception)
            {
                Log.ErrorException(exception);
                MessageBox.Show(Log.FormatException(exception), Resources.GlobalError, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, RightToLeftOptions);
            }
        }
Example #11
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();
        }