private void swapSlotsBgmSwapButton_Click(object sender, EventArgs e)
        {
            String controllerPath = swapSlotsBgmControllerTextBox.Text;
            String parentPath = Path.GetDirectoryName(controllerPath);

            if (controllerPath == null || controllerPath.Equals(""))
            {
                MessageBoxEx.Show(this, "You have to select a controller!");
                return;
            }

            if (swapSlotsBgmSlotComboBox.SelectedItem == null)
            {
                MessageBoxEx.Show(this, "Select valid values in the highlighted fields");
                return;
            }

            try
            {
                // Test if the given file is a valid controller
                BgmTable table = new BgmTable(controllerPath);
                int newBgmDlcSlotNumber = (int)swapSlotsBgmSlotComboBox.SelectedIndex + 1;

                // First, try to find the text file so we can also change its slots by cracking
                // its name
                int originalBgmDlcSlotNumber = 0;
                foreach (int i in Enumerable.Range(1, 999))
                {
                    if (controllerPath.Contains(Hasher.hash(String.Format("dlc/bgm/dlc_{0}.bin", i.ToString("D3")))))
                    {
                        originalBgmDlcSlotNumber = i;
                        break;
                    }
                }
                String textHashedFileName = Hasher.hash(String.Format("text/jp/dlc/bgm_{0}t.bin", originalBgmDlcSlotNumber.ToString("D3"))) + ".edat";
                String textHashedFilePath = System.IO.Path.Combine(parentPath, textHashedFileName);
                if (!File.Exists(textHashedFilePath))
                {
                    MessageBoxEx.Show(this, "The selected BGM DLC controller doesn't have a text file!");
                    return;
                }

                // Here we should already have all the needed data, so swap slots!
                // Change DLC id to one valid with the slot if needed
                if (swapSlotsBgmChangeIdsCheckBox.Checked)
                {
                    table.generateRandomEntryNamesAndIds(newBgmDlcSlotNumber, true, false);
                }
                // Rename old files to new ones
                File.Delete(controllerPath);
                table.writeToFile(Path.Combine(parentPath, Hasher.hash(String.Format("dlc/bgm/dlc_{0}.bin", newBgmDlcSlotNumber.ToString("D3"))) + ".edat"));
                // Move text entry
                File.Move(textHashedFilePath, Path.Combine(parentPath, Hasher.hash(String.Format("text/jp/dlc/bgm_{0}t.bin", newBgmDlcSlotNumber.ToString("D3"))) + ".edat"));
                MessageBoxEx.Show(this, "Success!");

            }
            catch (Exception ex)
            {
                MessageBoxEx.Show(this, "Select a valid controller");
                Logger.Log("MainFormSwapSlotsUserControl", ex);
                return;
            }
        }
        private void saveDataToFiles()
        {
            try
            {
                // Validate data
                if (bgmGenDlcSlotComboBox.SelectedItem == null)
                {
                    MessageBoxEx.Show(this, "Select valid values in the highlighted fields.");
                    return;
                }

                int selectedBgmSlotIndex = bgmGenDlcSlotComboBox.SelectedIndex;
                if (selectedBgmSlotIndex < 0)
                {
                    MessageBoxEx.Show(this, "You have to select a valid DLC slot");
                    return;
                }
                int bgmDlcSlot = (int)bgmGenDlcSlotComboBox.SelectedIndex + 1;

                if (bgmFormEntries.Count <= 0)
                {
                    MessageBoxEx.Show(this, "You have to add at least one BGM to the list");
                    return;
                }

                // Get DLC folder
                String baseFolder = Settings.getDlcMainFolder();
                String dlcFolder = System.IO.Path.Combine(baseFolder,
                    "[BGM][Slot " + bgmGenDlcSlotComboBox.Text + "]");
                createDlcFolder(dlcFolder);

                // Prepare copy
                List<String> bgmNames = new List<String>();
                List<String> bgmFileNames = new List<String>();
                BgmTable bgmTable = new BgmTable();
                foreach (FormBgmEntry formEntry in bgmFormEntries)
                {
                    // Save text strings
                    bgmNames.Add(formEntry.bgmTitle);
                    bgmTable.addEntry(formEntry.entry);
                }

                // Ready bgmTable
                bgmTable.generateRandomEntryNamesAndIds(bgmDlcSlot);

                // Save bgm names
                String textHashedFileName = Hasher.hash(String.Format("text/jp/dlc/bgm_{0}t.bin", bgmDlcSlot.ToString("D3"))) + ".edat";
                String textHashedFilePath = System.IO.Path.Combine(dlcFolder, textHashedFileName);
                MessFileWriter.encodeDLCText(bgmNames, textHashedFilePath);

                // Save bgm controller
                String controllerHashedFileName = Hasher.hash(String.Format("dlc/bgm/dlc_{0}.bin", bgmDlcSlot.ToString("D3"))) + ".edat";
                String controllerHashedFilePath = System.IO.Path.Combine(dlcFolder, controllerHashedFileName);
                bgmTable.writeToFile(controllerHashedFilePath);

                // Copy bgm to dlc folder
                foreach (FormBgmEntry formEntry in bgmFormEntries)
                {
                    String hashedInternalFileName = Hasher.hash(String.Format("bgm/{0}", formEntry.entry.internalFileName)) + ".edat";
                    String hashedInternalFilePath = System.IO.Path.Combine(dlcFolder, hashedInternalFileName);
                    if (File.Exists(formEntry.filePath))
                    {
                        File.Copy(formEntry.filePath, hashedInternalFilePath, true);
                    }
                    bgmFileNames.Add(hashedInternalFileName);
                }

                // Generate readme
                if (Settings.getBgmReadmeEnabled())
                {
                    String readmeFilePath = System.IO.Path.Combine(dlcFolder, "readme.txt");
                    using (StreamWriter readmeFileWriter = new StreamWriter(new FileStream(readmeFilePath, FileMode.Create)))
                    {
                        readmeFileWriter.WriteLine("BGM DLC Slot " + bgmGenDlcSlotComboBox.Text);
                        readmeFileWriter.WriteLine("-----------------------");
                        for (int i = 0; i < bgmNames.Count; i++)
                        {
                            readmeFileWriter.WriteLine(bgmNames[i] + " -> " + bgmFileNames[i]);
                        }
                    }
                }

                MessageBoxEx.Show(this, "Success!");
            }
            catch (Exception ex)
            {
                MessageBoxEx.Show(this, "There was a problem saving the BGM files. Check 'log.txt' for more details");
                Logger.Log("MainFormBgmGenUserControl", ex);
                return;
            }
        }