private void btnExtract_Click(object sender, EventArgs e) { object h = listBox1.SelectedItem; if (h is Stateheader) { Stateheader sh = (Stateheader)h; byte[] data; try { data = loaded_sram.Extract(sh); } catch (GoombaException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } SaveFileDialog d = new SaveFileDialog(); d.Title = btnExtract.Text; d.Filter = sh.Type == GameBoyAdvanceSRAMHeader.STATESAVE ? "Savestate (*.savestate)|*.savestate|All files (*.*)|*.*" : "Raw save data (*.sav, *.srm)|*.sav;*.srm|All files (*.*)|*.*"; d.AddExtension = true; if (d.ShowDialog() == DialogResult.OK) { File.WriteAllBytes(d.FileName, data); } } else if (h is ExtractedROM) { ExtractedROM r = (ExtractedROM)h; SaveFileDialog d = new SaveFileDialog(); d.Title = btnExtract.Text; d.Filter = h is GameBoyROM ? "Game Boy ROMs (*.gb, *.gbc)|*.gb;*.gbc|All files (*.*)|*.*" : h is PocketNESROM ? "NES/Famicom ROMs (*.nes)|*.nes|All files (*.*)|*.*" : h is SMSAdvanceROM ? "Master System/Game Gear ROMs (*.sms, *.gg)|*.sms;*.gg|All files (*.*)|*.*" : "All files (*.*)|*.*"; d.FileName = filePath == null || loaded_rom_contents.Count > 1 ? r.Name : Path.GetFileNameWithoutExtension(filePath); d.AddExtension = true; if (d.ShowDialog() == DialogResult.OK) { File.WriteAllBytes(d.FileName, r.Data); } } else { MessageBox.Show("Cannot export this type of data.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { object o = listBox1.SelectedItem; if (o is ExtractedROM) { ExtractedROM r = (ExtractedROM)o; lblSizeVal.Text = r.Data.Length + " bytes"; lblTypeVal.Text = "ROM image"; flpConfigdata.Visible = flpStateheader.Visible = false; lblChecksumVal.Text = r.GetChecksum().ToString("X8"); lblTitleVal.Text = r.Name; btnExtract.Enabled = true; btnReplace.Enabled = false; btnDelete.Enabled = false; return; } GameBoyAdvanceSRAMHeader h = (GameBoyAdvanceSRAMHeader)o; lblSizeVal.Text = h.Size + " bytes"; lblTypeVal.Text = h.Type == GameBoyAdvanceSRAMHeader.STATESAVE ? "Savestate" : h.Type == GameBoyAdvanceSRAMHeader.SRAMSAVE ? "SRAM" : h.Type == GameBoyAdvanceSRAMHeader.CONFIGSAVE ? "Config" : "Unknown"; if (h is Stateheader) { Stateheader sh = (Stateheader)h; flpConfigdata.Visible = false; flpStateheader.Visible = true; lblUncompressedSize.Text = sh.DataSize >= sh.Size ? "Uncompressed size:" : "Compressed size:"; lblUncompressedSizeVal.Text = sh.DataSize + " bytes"; lblFramecountVal.Text = sh.Framecount.ToString(); lblChecksumVal.Text = sh.ROMChecksum.ToString("X8"); btnExtract.Enabled = btnReplace.Enabled = sh.Type == GameBoyAdvanceSRAMHeader.SRAMSAVE || sh.Type == GameBoyAdvanceSRAMHeader.STATESAVE; } else if (h is Configdata) { flpStateheader.Visible = false; Configdata cd = (Configdata)h; if (h is GoombaConfigdata) { flpConfigdata.Visible = true; GoombaConfigdata gcd = (GoombaConfigdata)h; lblBorderVal.Text = gcd.BorderColor.ToString(); lblPaletteVal.Text = gcd.PaletteBank.ToString(); MiscStrings strs = gcd.GetMiscStrings; lblSleepVal.Text = strs.SleepStr; lblAutostateVal.Text = strs.AutoloadStateStr; lblGammaVal.Text = strs.GammaStr; } else { flpConfigdata.Visible = false; lblBorderVal.Text = ""; lblPaletteVal.Text = ""; lblSleepVal.Text = ""; lblAutostateVal.Text = ""; lblGammaVal.Text = ""; } lblChecksumVal.Text = cd.ROMChecksum.ToString("X8"); // The SRAM with this ROM checksum value is currently in 0xe000-0xffff btnExtract.Enabled = btnReplace.Enabled = false; } else { flpConfigdata.Visible = flpStateheader.Visible = false; btnExtract.Enabled = btnReplace.Enabled = false; } lblTitleVal.Text = h.Title; }