コード例 #1
0
ファイル: Main.cs プロジェクト: n13i/GB-Memory-Binary-Maker
        private void CreateBinariesButtonClick(object sender, EventArgs e)
        {
            if (ROMList.Count < 1)
            {
                return;
            }

            if (FreeROMSpace < 0)
            {
                MessageBox.Show("Your ROMs exceed the 896kByte of free space!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Byte[] MenuBuffer;
            if (File.Exists(Application.StartupPath + @"\Menu.gbc"))
            {
                MenuBuffer = File.ReadAllBytes(Application.StartupPath + @"\Menu.gbc");
            }
            else if ((File.Exists(Application.StartupPath + @"\Menu.gb")))
            {
                MenuBuffer = File.ReadAllBytes(Application.StartupPath + @"\Menu.gb");
            }
            else
            {
                MessageBox.Show("Couldn't find Menu.gb or Menu.gbc", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Array.Resize(ref MenuBuffer, 1024 * 1024);

            String SavePath;

            using (SaveFileDialog ToSave = new SaveFileDialog())
            {
                if (ToSave.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                if (!Directory.Exists(Path.GetDirectoryName(ToSave.FileName)))
                {
                    return;
                }
                if (!CheckFolderPermissions(Path.GetDirectoryName(ToSave.FileName)))
                {
                    return;
                }
                SavePath = ToSave.FileName;
            }

            Processing.CreateMenuBinary(ROMList, ref MenuBuffer);

            Byte[] MAPBytes = Processing.GenerateMAPForMenuBinary(ROMList);

            String[] FilesToCreate = new String[2];
            FilesToCreate[0] = Path.GetDirectoryName(SavePath) + @"\" + Path.GetFileName(SavePath) + ".gb";
            FilesToCreate[1] = Path.GetDirectoryName(SavePath) + @"\" + Path.GetFileName(SavePath) + ".map";
            File.WriteAllBytes(FilesToCreate[0], MenuBuffer);
            File.WriteAllBytes(FilesToCreate[1], MAPBytes);

            MessageBox.Show("Created:" + Environment.NewLine + FilesToCreate[0] + Environment.NewLine + FilesToCreate[1]);
        }