Пример #1
0
        private void FileDrop(object sender, DragEventArgs e)
        {
            String[]   FileTypes = new String[] { ".gb", ".gbc", ".bin" };
            String[]   Files     = (String[])e.Data.GetData(DataFormats.FileDrop);
            List <ROM> ROMsToAdd = new List <ROM>();

            foreach (String FileToProcess in Files)
            {
                if (File.Exists(FileToProcess) && FileTypes.Contains(Path.GetExtension(FileToProcess)))
                {
                    Byte[] temp = new Byte[15], temp1 = new Byte[0x10];
                    using (FileStream Reader = new FileStream(FileToProcess, FileMode.Open, FileAccess.Read))
                    {
                        Reader.Position = 0x134;
                        //ROM ASCII title
                        Reader.Read(temp, 0, 15);
                        //Info entry header for Menu
                        Reader.Position = 0x1C000;
                        Reader.Read(temp1, 0, 0x10);
                        if (Encoding.ASCII.GetString(temp) == "NP M-MENU  MENU" && temp1.SequenceEqual(new Byte[] { 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x44, 0x4D, 0x47, 0x20, 0x2D, 0x4D, 0x45, 0x4E, 0x55 }))
                        {
                            ROMsToAdd.AddRange(Processing.ParseGBMBinary(FileToProcess));
                        }
                        else if (Path.GetExtension(FileToProcess) != ".bin")
                        {
                            using (MemoryStream Mem = new MemoryStream())
                            {
                                Reader.Position = 0;
                                Reader.CopyTo(Mem);;
                                ROMsToAdd.Add(Processing.ParseROM(Mem, FileToProcess));
                            }
                        }
                    }
                }
            }

            foreach (ROM R in ROMsToAdd)
            {
                TitleEntry ROMTitle = new TitleEntry(R.ASCIITitle);
                if (ROMTitle.ShowDialog() == DialogResult.OK)
                {
                    R.Title = ROMTitle.Title;
                }
                else
                {
                    return;
                }
                AddROMToInterface(R);
            }
        }
Пример #2
0
        private void AddButtonClick(object sender, EventArgs e)
        {
            using (OpenFileDialog AddRom = new OpenFileDialog())
            {
                AddRom.Filter      = "All GB/C ROMs|*.gb;*.gbc";
                AddRom.Multiselect = true;
                if (AddRom.ShowDialog() == DialogResult.OK)
                {
                    List <ROM> ROMsToAdd = new List <ROM>();
                    foreach (String BinaryFile in AddRom.FileNames)
                    {
                        if (!File.Exists(BinaryFile))
                        {
                            continue;
                        }

                        using (FileStream FileToAdd = new FileStream(BinaryFile, FileMode.Open, FileAccess.Read))
                        {
                            using (MemoryStream Mem = new MemoryStream())
                            {
                                FileToAdd.CopyTo(Mem);
                                ROMsToAdd.Add(Processing.ParseROM(Mem, BinaryFile));
                            }
                        }
                    }
                    foreach (ROM R in ROMsToAdd)
                    {
                        TitleEntry ROMTitle = new TitleEntry(R.ASCIITitle);
                        if (ROMTitle.ShowDialog() == DialogResult.OK)
                        {
                            R.Title = ROMTitle.Title;
                        }
                        else
                        {
                            return;
                        }
                        AddROMToInterface(R);
                    }
                }
            }
        }
Пример #3
0
        private void ImportButtonClick(object sender, EventArgs e)
        {
            using (OpenFileDialog ImportMenu = new OpenFileDialog())
            {
                ImportMenu.Filter      = "1024kB GBM binary|*.gb;*.gbc;*.bin";
                ImportMenu.Multiselect = true;
                if (ImportMenu.ShowDialog() == DialogResult.OK)
                {
                    List <ROM> ROMsToAdd = new List <ROM>();
                    foreach (String BinaryFile in ImportMenu.FileNames)
                    {
                        if (!File.Exists(BinaryFile))
                        {
                            continue;
                        }
                        if (new FileInfo(BinaryFile).Length / 1024 != 1024)
                        {
                            MessageBox.Show(String.Format("GBM binary {1}{0}{1} has to be 1024kByte in size!", Path.GetFileName(BinaryFile), '"'), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            continue;
                        }

                        ROMsToAdd.AddRange(Processing.ParseGBMBinary(BinaryFile));
                    }

                    foreach (ROM R in ROMsToAdd)
                    {
                        TitleEntry ROMTitle = new TitleEntry(R.ASCIITitle);
                        if (ROMTitle.ShowDialog() == DialogResult.OK)
                        {
                            R.Title = ROMTitle.Title;
                        }
                        else
                        {
                            return;
                        }
                        AddROMToInterface(R);
                    }
                }
            }
        }
Пример #4
0
        private void AddROMToInterface(ROM ROMToAdd)
        {
            //Create new sub-panel for ROM
            Panel ROMPanel = new Panel();

            ROMPanel.Width       = ROMListPanel.Width - 22;
            ROMPanel.Height      = 90;
            ROMPanel.Location    = new Point(1, 1 + ROMListPanel.Controls.Count * 91);
            ROMPanel.BorderStyle = BorderStyle.FixedSingle;

            //Invisible that contains the entered title in String format for later
            Label T = new Label();

            T.Visible = false;
            T.Text    = ROMToAdd.Title;
            ROMPanel.Controls.Add(T);

            //Invisible that contains just the ASCII-title in String format for later
            Label AT = new Label();

            AT.Visible = false;
            AT.Text    = ROMToAdd.ASCIITitle;
            ROMPanel.Controls.Add(AT);

            Label ASCIITitleDisplay = new Label();

            ASCIITitleDisplay.AutoSize = true;
            ASCIITitleDisplay.Text     = "ASCII-Title: " + ROMToAdd.ASCIITitle;
            ASCIITitleDisplay.Location = new Point(5, 4);
            ROMPanel.Controls.Add(ASCIITitleDisplay);

            Label CartTypeDisplay = new Label();

            CartTypeDisplay.AutoSize = true;
            CartTypeDisplay.Text     = "Cart-Type: " + ROMToAdd.CartridgeTypeString;
            CartTypeDisplay.Location = new Point(5, 36);
            ROMPanel.Controls.Add(CartTypeDisplay);

            Label TitleIMDisplay = new Label();

            TitleIMDisplay.AutoSize = true;
            TitleIMDisplay.Text     = "Title:";
            TitleIMDisplay.Location = new Point(5, 19);
            ROMPanel.Controls.Add(TitleIMDisplay);

            PictureBox TitleIMG = new PictureBox();

            TitleIMG.Image       = TitleImage.CreateTitleBitmap(ROMToAdd.Title);
            TitleIMG.SizeMode    = PictureBoxSizeMode.AutoSize;
            TitleIMG.Location    = new Point(35, 21);
            TitleIMG.BorderStyle = BorderStyle.FixedSingle;
            ROMPanel.Controls.Add(TitleIMG);

            Label ROMSizeDisplay = new Label();

            ROMSizeDisplay.AutoSize = true;
            ROMSizeDisplay.Text     = "ROMSize: " + ROMToAdd.ROMSizeKByte + "kByte" + (ROMToAdd.padded ? " (padded to 128kByte)" : "");
            ROMSizeDisplay.Location = new Point(5, 53);
            ROMPanel.Controls.Add(ROMSizeDisplay);

            Label RAMSizeDisplay = new Label();

            RAMSizeDisplay.AutoSize = true;
            RAMSizeDisplay.Text     = "RAMSize: " + ROMToAdd.RAMSizeKByte + "kByte";
            RAMSizeDisplay.Location = new Point(5, 70);
            ROMPanel.Controls.Add(RAMSizeDisplay);

            Button Remove = new Button();

            Remove.Text     = "Remove";
            Remove.Location = new Point(300, 60);
            Remove.Click   += (s, ev) =>
            {
                foreach (ROM R in ROMList)
                {
                    if (R.Title == ((Button)s).Parent.Controls[0].Text && R.ASCIITitle == ((Button)s).Parent.Controls[1].Text)
                    {
                        ROMList.Remove(R);
                        break;
                    }
                }
                ROMListPanel.Controls.Remove(((Button)s).Parent);
                updateROMSpace();
            };
            ROMPanel.Controls.Add(Remove);

            Button Edit = new Button();

            Edit.Text     = "Edit Title";
            Edit.Location = new Point(300, 30);
            Edit.Click   += (s, ev) =>
            {
                foreach (ROM R in ROMList)
                {
                    if (R.Title == ((Button)s).Parent.Controls[0].Text && R.ASCIITitle == ((Button)s).Parent.Controls[1].Text)
                    {
                        TitleEntry ROMEditTitle = new TitleEntry();
                        if (ROMEditTitle.ShowDialog() == DialogResult.OK)
                        {
                            R.Title = ROMEditTitle.Title;
                            ((PictureBox)(((Button)s).Parent.Controls[5])).Image = TitleImage.CreateTitleBitmap(R.Title);
                            (((Button)s).Parent.Controls[0]).Text = R.Title;
                        }
                        break;
                    }
                }
            };
            ROMPanel.Controls.Add(Edit);

            if (ROMToAdd.embedded)
            {
                PictureBox Rip = new PictureBox();
                Rip.Location = new Point(382, 1);
                Rip.SizeMode = PictureBoxSizeMode.AutoSize;
                Rip.Cursor   = Cursors.Hand;
                Rip.Image    = GB_Memory.Properties.Resources.icon_save;
                Rip.Click   += (s, ev) =>
                {
                    if (MessageBox.Show("Rip ROM from binary?", "Rip ROM", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        foreach (ROM R in ROMList)
                        {
                            if (R.Title == ((PictureBox)s).Parent.Controls[0].Text && R.ASCIITitle == ((PictureBox)s).Parent.Controls[1].Text && R.embedded)
                            {
                                if (File.Exists(R.File))
                                {
                                    Byte[] buffer = new Byte[R.ROMSizeKByte * 1024];
                                    using (FileStream Reader = new FileStream(R.File, FileMode.Open, FileAccess.Read))
                                    {
                                        Reader.Position = R.ROMPos;
                                        Reader.Read(buffer, 0, R.ROMSizeKByte * 1024);
                                    }
                                    using (SaveFileDialog ToSave = new SaveFileDialog())
                                    {
                                        ToSave.FileName = R.ASCIITitle;
                                        ToSave.Filter   = R.CGB ? "GBC ROM|*.gbc" : "GB ROM|*.gb";
                                        if (ToSave.ShowDialog() != DialogResult.OK)
                                        {
                                            return;
                                        }
                                        if (!Directory.Exists(Path.GetDirectoryName(ToSave.FileName)))
                                        {
                                            return;
                                        }
                                        if (!CheckFolderPermissions(Path.GetDirectoryName(ToSave.FileName)))
                                        {
                                            return;
                                        }
                                        File.WriteAllBytes(ToSave.FileName, buffer);
                                    }
                                }
                                break;
                            }
                        }
                    }
                };
                ROMPanel.Controls.Add(Rip);
            }

            ROMListPanel.Controls.Add(ROMPanel);
            ROMList.Add(ROMToAdd);
            updateROMSpace();

            ShowRAMSizeOverflowWarning(ROMToAdd);
        }