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); } }