/// <summary> /// Obtains the name details of the currently selected game in the combobox. /// </summary> private GameComboBoxDetails GetSelectedGame() { // Return empty if the index is -1 if (borderless_CurrentGame.SelectedIndex == -1) { return(null); } // Split name of currently selected game. string currentGame = (string)borderless_CurrentGame.Items[borderless_CurrentGame.SelectedIndex]; // Splitstring string splitString = " " + Theme.ThemeProperties.TitleProperties.LoaderTitleDelimiter + " "; // Split the game details string[] gameDetails = currentGame.Split(new[] { splitString }, StringSplitOptions.None); // gameDetails[0] = Game Name // gameDetails[1] = Game Executable Relative Location // gameDetails[2] = Game Version GameComboBoxDetails comboBoxDetails = new GameComboBoxDetails(); comboBoxDetails.GameName = gameDetails[0]; comboBoxDetails.ExecutableRelativeLocation = gameDetails[1]; comboBoxDetails.GameVersion = gameDetails[2]; return(comboBoxDetails); }
/// <summary> /// Allow user to select a new banner image. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SelectNewGameBanner(object sender, EventArgs e) { // Dialog for launching executables. CommonOpenFileDialog imageDialog = new CommonOpenFileDialog(); imageDialog.Title = "Select the new banner image for the game."; imageDialog.Multiselect = false; // Open dialog. if (imageDialog.ShowDialog() == CommonFileDialogResult.Ok) { // Get current selected game. GameComboBoxDetails comboBoxDetails = GetSelectedGame(); // Find current config by details. GameConfigParser.GameConfig gameConfig = Global.GameConfigurations.First ( x => x.GameName == comboBoxDetails.GameName && x.ExecutableLocation == comboBoxDetails.ExecutableRelativeLocation && x.GameVersion == comboBoxDetails.GameVersion ); // Copy the banner to new location. File.Copy(imageDialog.FileName, GameConfigParser.GameConfig.GetBannerPath(gameConfig), true); // Set new image. box_GameBanner.BackgroundImage = Image.FromFile(GameConfigParser.GameConfig.GetBannerPath(gameConfig)); } // Dispose dialog. imageDialog.Dispose(); }
/// <summary> /// Deletes a game configuration from the known configurations. /// </summary> private void DeleteGame(object sender, EventArgs e) { // Get current selected game. GameComboBoxDetails comboBoxDetails = GetSelectedGame(); // If there is no game (null), return. if (comboBoxDetails == null) { return; } // Find and remove first by details. for (int x = 0; x < Global.GameConfigurations.Count; x++) { // Find the first match to game name, executable and version. if (Global.GameConfigurations[x].GameName == comboBoxDetails.GameName && Global.GameConfigurations[x].ExecutableLocation == comboBoxDetails.ExecutableRelativeLocation && Global.GameConfigurations[x].GameVersion == comboBoxDetails.GameVersion) { // Check if global config. if (Global.GameConfigurations[x].ConfigLocation == LoaderPaths.GetGlobalGameConfigDirectory()) { MessageBox.Show($"It's no use {Environment.UserName}, give up."); return; } // Maintain currently open banners. try { Global.BaseForm.ChildrenForms.MainMenu.item_GameBanner.BackgroundImage.Dispose(); } catch { } try { box_GameBanner.BackgroundImage.Dispose(); } catch { } // Remove game from list & Switch game. borderless_CurrentGame.Items.RemoveAt(x); try { borderless_CurrentGame.SelectedIndex = borderless_CurrentGame.Items.Count - 1; } catch { } // Garbage collect old possible image references. GC.Collect(); GC.WaitForPendingFinalizers(); // Remove game config & physical location. try { Directory.Delete(Global.GameConfigurations[x].ConfigLocation, true); } catch { } Global.GameConfigurations.RemoveAt(x); break; } } }
/// <summary> /// Saves the current game configuration. /// </summary> private void SaveCurrentGame() { // Get current selected game. GameComboBoxDetails comboBoxDetails = GetSelectedGame(); // Find and remove first by details. foreach (GameConfig gameConfig in Global.GameConfigurations) { // Find the first match to game name, executable and version. if (gameConfig.GameName == comboBoxDetails.GameName && gameConfig.ExecutableLocation == comboBoxDetails.ExecutableRelativeLocation && gameConfig.GameVersion == comboBoxDetails.GameVersion) { // Check if global config. if (gameConfig.ConfigLocation == LoaderPaths.GetGlobalGameConfigDirectory()) { MessageBox.Show($"I'm sorry {Environment.UserName}, I'm afraid I can't let you do that."); return; } // Set the new game details. gameConfig.GameName = borderless_GameName.Text; gameConfig.GameVersion = borderless_GameVersion.Text; gameConfig.GameDirectory = borderless_GameDirectory.Text; gameConfig.ExecutableLocation = borderless_GameExecutableDirectory.Text; gameConfig.ModDirectory = borderless_GameModDirectory.Text; gameConfig.CommandLineArgs = borderless_CommandLineArguments.Text; // Change the current item name to reflect new changes. borderless_CurrentGame.Items[borderless_CurrentGame.SelectedIndex] = borderless_GameName.Text + " " + Theme.ThemeProperties.TitleProperties.LoaderTitleDelimiter + " " + borderless_GameExecutableDirectory.Text + " " + Theme.ThemeProperties.TitleProperties.LoaderTitleDelimiter + " " + borderless_GameVersion.Text; break; } } }
/// <summary> /// Loads the details of the currently loaded game. /// </summary> private void SelectedGameChanged(object sender, EventArgs e) { // Get current selected game. GameComboBoxDetails comboBoxDetails = GetSelectedGame(); // Find by details. GameConfigParser.GameConfig gameConfig = Global.GameConfigurations.First ( x => x.GameName == comboBoxDetails.GameName && x.ExecutableLocation == comboBoxDetails.ExecutableRelativeLocation && x.GameVersion == comboBoxDetails.GameVersion ); // Populate fields. borderless_GameName.Text = gameConfig.GameName; borderless_GameModDirectory.Text = gameConfig.ModDirectory; borderless_GameVersion.Text = gameConfig.GameVersion; borderless_GameExecutableDirectory.Text = gameConfig.ExecutableLocation; borderless_GameDirectory.Text = gameConfig.GameDirectory; // Load the game image. try { box_GameBanner.BackgroundImage = Image.FromFile(GameConfigParser.GameConfig.GetBannerPath(gameConfig)); } catch { box_GameBanner.BackgroundImage = null; } }
/// <summary> /// Loads the details of the currently loaded game. /// </summary> private void SelectedGameChanged(object sender, EventArgs e) { // Get current selected game. GameComboBoxDetails comboBoxDetails = GetSelectedGame(); // Find by details. GameConfig gameConfig = Global.GameConfigurations.First ( x => x.GameName == comboBoxDetails.GameName && x.ExecutableLocation == comboBoxDetails.ExecutableRelativeLocation && x.GameVersion == comboBoxDetails.GameVersion ); // Set global configuration. Global.CurrentGameConfig = gameConfig; // Populate fields. borderless_GameName.Text = gameConfig.GameName; borderless_GameModDirectory.Text = gameConfig.ModDirectory; borderless_GameVersion.Text = gameConfig.GameVersion; borderless_GameExecutableDirectory.Text = gameConfig.ExecutableLocation; borderless_GameDirectory.Text = gameConfig.GameDirectory; borderless_CommandLineArguments.Text = gameConfig.CommandLineArgs; // Load the game image. try { // We do not want to keep open file handles. Image image; using (var bmpTemp = new Bitmap(GameConfig.GetBannerPath(gameConfig))) { image = new Bitmap(bmpTemp); } box_GameBanner.BackgroundImage = image; } catch { box_GameBanner.BackgroundImage = null; } }