Example #1
0
        /// <summary>
        /// Load the relevant game details when the selection is changed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ModList_SelectionChanged(object sender, EventArgs e)
        {
            try
            {
                // Cast the sender to the datagridview
                var senderGrid = (DataGridView)sender;

                // Obtain current row index. (Note: CurrentRow is invalid)
                int rowIndex = senderGrid.SelectedCells[0].RowIndex;

                // Get the mod title and version.
                string modTitle   = (string)senderGrid.Rows[rowIndex].Cells[1].Value;
                string modVersion = (string)senderGrid.Rows[rowIndex].Cells[4].Value;

                // Cells[0] = Enabled/Disabled Tickbox
                // Cells[1] = Mod Title
                // Cells[2] = Author
                // Cells[3] = Separator
                // Cells[4] = Version

                // Get the mod configuration.
                ModConfigParser.ModConfig modConfiguration = FindModConfiguration(modTitle, modVersion);
                Global.CurrentModConfig = modConfiguration;

                // Set the description.
                item_ModDescription.Text = modConfiguration.ModDescription;

                // Set the button text for website, config, source.
                borderless_ConfigBox.Text = modConfiguration.ModConfigExe.Length == 0     ? "N/A" : "Configuration";
                borderless_WebBox.Text    = modConfiguration.ThemeSite.Length == 0        ? "N/A" : "Webpage";
                borderless_SourceBox.Text = modConfiguration.ThemeGithub.Length == 0      ? "N/A" : "Source Code";

                // Obtain mod directory.
                string modDirectory = Path.GetDirectoryName(modConfiguration.ModLocation);

                // Attempt to load image.
                try { box_ModPreview.BackgroundImage = Image.FromFile(modDirectory + $"\\{Strings.Launcher.BannerName}"); }
                catch { box_ModPreview.BackgroundImage = null; }
            }
            catch { }
        }
Example #2
0
        /// <summary>
        /// Saves the mods from their listview onto the mod configuration for the game.
        /// </summary>
        private void SaveMods()
        {
            // Stores the currently enabled mods.
            List <string> enabledMods = new List <string>();

            // Cycle each row of the DataGridView
            for (int x = 0; x < box_ModList.Rows.Count; x++)
            {
                // Assign DataGridView Row
                DataGridViewRow row = box_ModList.Rows[x];

                // Check if the mod in the row is enabled.
                bool modEnabled = (string)row.Cells[0].Value == TextButtons.ButtonEnabled;

                // If the mod is enabled.
                if (modEnabled)
                {
                    // Find the mod configuration from the set row and column.
                    // Match by mod title and version.
                    ModConfigParser.ModConfig modConfiguration = FindModConfiguration((string)row.Cells[1].Value, (string)row.Cells[4].Value);

                    // Append the folder name only to the list of mods.
                    // Reloaded-Mods/SA2/Testmod => Testmod
                    enabledMods.Add(Path.GetFileName(Path.GetDirectoryName(modConfiguration.ModLocation)));
                }
            }

            // Reverse the mod order such that mods on top take priority.
            enabledMods.Reverse();

            // Assign the currently enabled mods for the game.
            Global.CurrentGameConfig.EnabledMods = enabledMods;

            // Save the game configuration.
            GameConfigParser.WriteConfig(Global.CurrentGameConfig);
        }