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