/// <summary> /// Attempts to save all modified player files /// </summary> /// <param name="playerOnError"></param> /// <returns>True if there were any modified player files.</returns> /// <exception cref="IOException">can happen during file save</exception> public bool SaveAllModifiedPlayers(ref PlayerCollection playerOnError) { int numModified = 0; // Save each player as necessary foreach (KeyValuePair <string, PlayerCollection> kvp in this.userContext.Players) { string playerFile = kvp.Key; PlayerCollection player = kvp.Value; if (player == null) { continue; } if (player.IsModified) { ++numModified; playerOnError = player; // if needed by caller TQData.BackupFile(player.PlayerName, playerFile); TQData.BackupStupidPlayerBackupFolder(playerFile); PlayerCollectionProvider.Save(player, playerFile); } } return(numModified > 0); }
/// <summary> /// Handler for clicking Open on the menu. Opens a file. /// </summary> /// <param name="sender">sender object</param> /// <param name="e">EventArgs data</param> private void OpenToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Filter = "Compressed TQ files (*.arz;*.arc)|*.arz;*.arc|All files (*.*)|*.*"; openDialog.FilterIndex = 1; openDialog.RestoreDirectory = true; // Try to read the game path from the registry string[] path = new string[4]; path[0] = "SOFTWARE"; path[1] = "Iron Lore"; path[2] = "Titan Quest"; path[3] = "Install Location"; string startPath = TQData.ReadRegistryKey(Microsoft.Win32.Registry.LocalMachine, path); // If the registry fails then default to the save folder. if (startPath.Length < 1) { startPath = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "My Games"), "Titan Quest"); } openDialog.InitialDirectory = startPath; DialogResult result = openDialog.ShowDialog(); if (result == DialogResult.OK) { this.OpenFile(openDialog.FileName); } else { return; } }
public Bitmap LoadBitmap(string resourceId, byte[] texData) { Bitmap result = null; if (string.IsNullOrEmpty(resourceId) || texData is null || !texData.Any()) { return(result); } if (TQDebug.DatabaseDebugLevel > 0) { Log.DebugFormat(CultureInfo.InvariantCulture, "Database.LoadBitmap({0})", resourceId); } resourceId = TQData.NormalizeRecordPath(resourceId); Bitmap bitmap; if (bitmaps.ContainsKey(resourceId)) { bitmap = this.bitmaps[resourceId]; } else { bitmap = AddBitmap(resourceId, texData); } if (TQDebug.DatabaseDebugLevel > 0) { Log.Debug("Exiting Database.LoadBitmap()"); } return(bitmap); }
/// <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; }
/// <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)); }
/// <summary> /// Initializes a new instance of the SettingsDialog class. /// </summary> public SettingsDialog() { this.InitializeComponent(); 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.SettingsAllowEditTT); 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(); this.mapListComboBox.Items.Add(string.Empty); string[] maps = TQData.GetCustomMapList(); if (maps != null && maps.Length > 0) { this.mapListComboBox.Items.AddRange(maps); } if (!IniProperties.ShowEditingCopyFeatures) { this.allowItemEditCheckBox.Visible = false; this.allowItemCopyCheckBox.Visible = false; } }
/// <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 = TQData.GetCharacterList(); int numIT = 0; if (charactersIT != null) { numIT = charactersIT.Length; } if (numIT < 1) { 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 (TQData.IsCustom) { characterDesignator = string.Concat(characterDesignator, "<Custom Map>"); } // Combine the 2 arrays into 1 then add them string[] characters = new string[numIT]; int i; int j = 0; // Put the IT chars first since that is most likely what people want to use. for (i = 0; i < numIT; ++i) { characters[j++] = string.Concat(charactersIT[i], characterDesignator); } this.characterComboBox.Items.AddRange(characters); } }
/// <summary> /// Loads a vault file /// </summary> /// <param name="vaultName">Name of the vault</param> public LoadVaultResult LoadVault(string vaultName) { var result = new LoadVaultResult(); // Get the filename result.Filename = TQData.GetVaultFile(vaultName); // Check the cache try { result.Vault = this.userContext.Vaults[result.Filename]; } catch (KeyNotFoundException) { // We need to load the vault. if (!File.Exists(result.Filename)) { // the file does not exist so create a new vault. result.Vault = this.CreateVault(vaultName, result.Filename); result.VaultLoaded = true; } else { result.Vault = new PlayerCollection(vaultName, result.Filename); result.Vault.IsVault = true; try { PlayerCollectionProvider.LoadFile(result.Vault); result.VaultLoaded = true; } catch (ArgumentException argumentException) { result.ArgumentException = argumentException; } } // Add the vault to the cache, but only if we create it or it successfully loads. if (result.VaultLoaded) { this.userContext.Vaults.Add(result.Filename, result.Vault); } } return(result); }
/// <summary> /// Gets a list of available player files and populates the drop down list. /// </summary> private void GetPlayerList() { if (this.playerService is null) { this.playerService = new PlayerService(this.userContext); } // Initialize the character combo-box this.characterComboBox.Items.Clear(); string[] charactersIT = TQData.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 (TQData.IsCustom) { characterDesignator = string.Concat(characterDesignator, PlayerService.CustomDesignator); } string[] characters = charactersIT.Select(c => string.Concat(c, characterDesignator)).ToArray(); this.characterComboBox.Items.AddRange(characters); } }
/// <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); } } }
/// <summary> /// Attempts to save all modified vault files /// </summary> /// <param name="vaultOnError"></param> /// <exception cref="IOException">can happen during file save</exception> public void SaveAllModifiedVaults(ref PlayerCollection vaultOnError) { foreach (KeyValuePair <string, PlayerCollection> kvp in this.userContext.Vaults) { string vaultFile = kvp.Key; PlayerCollection vault = kvp.Value; if (vault == null) { continue; } if (vault.IsModified) { // backup the file vaultOnError = vault; TQData.BackupFile(vault.PlayerName, vaultFile); PlayerCollectionProvider.Save(vault, vaultFile); } } }
/// <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); } } } }
/// <summary> /// Loads a vault file /// </summary> /// <param name="vaultName">Name of the vault</param> /// <param name="secondaryVault">flag indicating whether this selection is for the secondary panel</param> private void LoadVault(string vaultName, bool secondaryVault) { PlayerCollection vault = null; if (secondaryVault && vaultName == Resources.MainFormSelectVault) { if (this.secondaryVaultPanel.Player != null) { this.secondaryVaultPanel.Player = null; } } else { // Get the filename string filename = TQData.GetVaultFile(vaultName); // Check the cache try { vault = this.vaults[filename]; } catch (KeyNotFoundException) { // We need to load the vault. bool vaultLoaded = false; if (!File.Exists(filename)) { // the file does not exist so create a new vault. vault = CreateVault(vaultName, filename); vaultLoaded = true; } else { vault = new PlayerCollection(vaultName, filename); vault.IsVault = true; try { PlayerCollectionProvider.LoadFile(vault); vaultLoaded = true; } catch (ArgumentException argumentException) { string msg = string.Format(CultureInfo.CurrentUICulture, "{0}\n{1}\n{2}", Resources.MainFormPlayerReadError, filename, argumentException.Message); MessageBox.Show(msg, Resources.GlobalError, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, RightToLeftOptions); vaultLoaded = false; } } // Add the vault to the cache, but only if we create it or it successfully loads. if (vaultLoaded) { this.vaults.Add(filename, vault); } } } // Now assign the vault to the vaultpanel if (secondaryVault) { this.secondaryVaultPanel.Player = vault; } else { this.vaultPanel.Player = vault; } }
/// <summary> /// Method for the maintain vault files dialog /// </summary> private void MaintainVaultFilesDialog() { try { this.SaveAllModifiedFiles(); VaultMaintenanceDialog dlg = new VaultMaintenanceDialog(); dlg.Scale(new SizeF(UIService.UI.Scale, UIService.UI.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 = TQData.GetVaultFile(oldName); string newFilename = TQData.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 = TQData.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.Remove(filename); // 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 = TQData.GetVaultFile(oldName); string newFilename = TQData.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.Remove(oldFilename); // 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.Remove(newFilename); 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); } }
/// <summary> /// Initializes a new instance of the SettingsDialog class. /// </summary> public SettingsDialog() { this.InitializeComponent(); #region Apply custom font this.allowItemEditCheckBox.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.allowItemCopyCheckBox.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.skipTitleCheckBox.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.loadLastCharacterCheckBox.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.loadLastVaultCheckBox.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.vaultPathTextBox.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.vaultPathLabel.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.cancelButton.Font = FontHelper.GetFontAlbertusMTLight(12F); this.okayButton.Font = FontHelper.GetFontAlbertusMTLight(12F); this.resetButton.Font = FontHelper.GetFontAlbertusMTLight(12F); this.vaultPathBrowseButton.Font = FontHelper.GetFontAlbertusMTLight(12F); this.enableCustomMapsCheckBox.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.loadAllFilesCheckBox.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.suppressWarningsCheckBox.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.playerReadonlyCheckbox.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.languageComboBox.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.languageLabel.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.detectLanguageCheckBox.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.titanQuestPathTextBox.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.titanQuestPathLabel.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.immortalThronePathLabel.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.immortalThronePathTextBox.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.detectGamePathsCheckBox.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.titanQuestPathBrowseButton.Font = FontHelper.GetFontAlbertusMTLight(12F); this.immortalThronePathBrowseButton.Font = FontHelper.GetFontAlbertusMTLight(12F); this.customMapLabel.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.mapListComboBox.Font = FontHelper.GetFontAlbertusMTLight(11.25F); this.Font = FontHelper.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(); this.mapListComboBox.Items.Add(string.Empty); string[] maps = TQData.GetCustomMapList(); if (maps != null && maps.Length > 0) { this.mapListComboBox.Items.AddRange(maps); } if (!Config.Settings.Default.AllowCheats) { this.allowItemEditCheckBox.Visible = false; this.allowItemCopyCheckBox.Visible = false; this.characterEditCheckBox.Visible = false; } }
/// <summary> /// Background worker has finished /// </summary> /// <param name="sender">sender object</param> /// <param name="e">RunWorkerCompletedEventArgs data</param> private void BackgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { // First, handle the case where an exception was thrown. if (e.Error != null) { 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) { int ind = this.characterComboBox.FindStringExact(Config.Settings.Default.LastCharacterName); if (ind != -1) { this.characterComboBox.SelectedIndex = ind; } } 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(TQData.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 { // 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(); } }
/// <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); } }
/// <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(); }
/// <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; } }
/// <summary> /// Attempts to save all modified player files /// </summary> /// <returns>True if there were any modified player files.</returns> private bool SaveAllModifiedPlayers() { int numModified = 0; // Save each player as necessary foreach (KeyValuePair <string, PlayerCollection> kvp in this.players) { string playerFile = kvp.Key; PlayerCollection player = kvp.Value; if (player == null) { continue; } if (player.IsModified) { ++numModified; bool done = false; // backup the file while (!done) { try { TQData.BackupFile(player.PlayerName, playerFile); TQData.BackupStupidPlayerBackupFolder(playerFile); PlayerCollectionProvider.Save(player, playerFile); done = true; } catch (IOException exception) { string title = string.Format(CultureInfo.InvariantCulture, Resources.MainFormSaveError, player.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(numModified > 0); }
/// <summary> /// Initializes a new instance of the SettingsDialog class. /// </summary> public SettingsDialog() { this.InitializeComponent(); 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.playerListGroupBox.Text = Resources.SettingsFilterGroup; this.playerListGroupBox.ForeColor = Color.White; this.noFilterRadioButton.Text = Resources.SettingsFilterNone; this.toolTip.SetToolTip(this.noFilterRadioButton, Resources.SettingsFilterNoneTT); this.filterITCharsRadioButton.Text = Resources.SettingsFilterIT; this.toolTip.SetToolTip(this.filterITCharsRadioButton, Resources.SettingsFilterITTT); this.filterTQCharsRadioButton.Text = Resources.SettingsFilterTQ; this.toolTip.SetToolTip(this.filterTQCharsRadioButton, Resources.SettingsFilterTQTT); 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.SettingsAllowEditTT); 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.checkForUpdatesCheckBox.Text = Resources.SettingsAutoUpdate; this.toolTip.SetToolTip(this.checkForUpdatesCheckBox, Resources.SettingsAutoUpdateTT); this.resetButton.Text = Resources.SettingsReset; this.toolTip.SetToolTip(this.resetButton, Resources.SettingsResetTT); this.checkNowButton.Text = Resources.SettingsForceCheck; this.toolTip.SetToolTip(this.checkNowButton, Resources.SettingsForceCheckTT); this.enableNewUICheckBox.Text = Resources.SettingsEnableNewUI; this.toolTip.SetToolTip(this.enableNewUICheckBox, Resources.SettingsEnableNewUITT); this.cancelButton.Text = Resources.GlobalCancel; this.okayButton.Text = Resources.GlobalOK; this.Text = Resources.SettingsTitle; if (Settings.Default.EnableNewUI) { this.DrawCustomBorder = true; } else { this.Revert(new Size(713, 399)); } this.mapListComboBox.Items.Clear(); this.mapListComboBox.Items.Add(string.Empty); string[] maps = TQData.GetCustomMapList(TQData.IsITInstalled); if (maps != null && maps.Length > 0) { this.mapListComboBox.Items.AddRange(maps); } }
/// <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); }