/// <summary> /// Create new emulation engine /// </summary> /// <param name="fileName">The rom complete path. Not compressed</param> /// <param name="tvsetting">The tv system setting to use</param> /// <param name="makeThread">Indicates if the emulation engine should make an internal thread and run through it. Otherwise you should make a thread and use EMUClock to run the loop.</param> public static void CreateNew(string fileName, TVSystemSetting tvsetting, bool makeThread) { switch (Path.GetExtension(fileName).ToLower()) { case ".nes": { INes header = new INes(); header.Load(fileName, true); if (header.IsValid) { INITIALIZED = false; GAMEFILE = fileName; CheckGameVSUnisystem(header.SHA1, header.IsVSUnisystem, header.MapperNumber); // Make SRAM file name SRAMFileName = Path.Combine(SRAMFolder, Path.GetFileNameWithoutExtension(fileName) + ".srm"); STATESlot = 0; UpdateStateSlot(STATESlot); // Make snapshots file name SNAPSFileName = Path.GetFileNameWithoutExtension(fileName); // Initialzie MEMInitialize(header); TVFormatSetting = tvsetting; // Hard reset hardReset(); // Run emu EmulationPaused = true; EmulationON = true; // Let's go ! if (makeThread) { EmulationThread = new Thread(new ThreadStart(EMUClock)); EmulationThread.Start(); } // Done ! INITIALIZED = true; if (EMUInitialized != null) { EMUInitialized(null, new EventArgs()); } } else { throw new RomNotValidException(); } break; } } }
/// <summary> /// Check a rom file to see if it can be used or not /// </summary> /// <param name="fileName">The complete file path. Archive is NOT supported.</param> /// <param name="is_supported_mapper">Indicates if this rom mapper is supported or not</param> /// <param name="has_issues">Indicates if this rom mapper have issues or not</param> /// <param name="known_issues">Issues with this mapper.</param> /// <returns>True if My Nes car run this game otherwise false.</returns> public bool CheckRom(string fileName, out bool is_supported_mapper, out bool has_issues, out string known_issues) { switch (Path.GetExtension(fileName).ToLower()) { case ".nes": { INes header = new INes(); header.Load(fileName, true); if (header.IsValid) { // Check board existince bool found = false; string mapperName = "MyNes.Core.Mapper" + header.MapperNumber.ToString("D3"); Type[] types = Assembly.GetExecutingAssembly().GetTypes(); foreach (Type tp in types) { if (tp.FullName == mapperName) { this.memory.board = Activator.CreateInstance(tp) as Board; this.memory.board.Nes = this; is_supported_mapper = this.memory.board.Supported; has_issues = this.memory.board.NotImplementedWell; known_issues = this.memory.board.Issues; found = true; return(true); } } if (!found) { throw new MapperNotSupportedException(header.MapperNumber); } is_supported_mapper = false; has_issues = false; known_issues = ""; return(false); } is_supported_mapper = false; has_issues = false; known_issues = ""; return(false); } } is_supported_mapper = false; has_issues = false; known_issues = ""; return(false); }
public void CreateNew(string fileName, TVSystemSetting tvsetting, bool makeThread) { switch (Path.GetExtension(fileName).ToLower()) { case ".nes": { INes header = new INes(); header.Load(fileName, true); if (header.IsValid) { initialized = false; GAMEFILE = fileName; this.legacyNesEmu.CheckGameVSUnisystem(header.SHA1, header.IsVSUnisystem, header.MapperNumber); // Make SRAM file name SRAMFileName = Path.Combine(SRAMFolder, Path.GetFileNameWithoutExtension(fileName) + ".srm"); this.emulationState.STATESlot = 0; this.emulationState.UpdateStateSlot(this.emulationState.STATESlot); // Make snapshots file name SNAPSFileName = Path.GetFileNameWithoutExtension(fileName); // Initialzie this.memory.MEMInitialize(header); TVFormatSetting = tvsetting; // Hard reset HardReset(); // Run emu this.emulationState.EmulationPaused = true; this.emulationState.EmulationON = true; // Let's go ! if (makeThread) { EmulationThread = new Thread(new ThreadStart(GameLoop)); EmulationThread.Start(); } // Done ! initialized = true; } else { throw new RomNotValidException(); } break; } } }
private void RefreshFileInfo() { if (gameInfoList == null) return; try { gameInfoLines = new List<string>(); gameInfoList.Clear(); if (System.IO.Path.GetExtension(filechooserwidget2.Filename).ToLower() == ".nes") { Gtk.TreeIter iter; INes header = new INes(); header.Load(filechooserwidget2.Filename, false); if (header.IsValid) { #region Database // Add database info if found ! //Get database info bool found = false; NesCartDatabaseGameInfo info = NesCartDatabase.Find(header.SHA1, out found); NesCartDatabaseCartridgeInfo cart = new NesCartDatabaseCartridgeInfo(); if (info.Cartridges != null) { foreach (NesCartDatabaseCartridgeInfo cartinf in info.Cartridges) if (cartinf.SHA1.ToLower() == header.SHA1.ToLower()) { cart = cartinf; break; } } if (found) { iter = gameInfoList.AppendValues("Info From Database"); gameInfoLines.Add("[Info From Database]"); FieldInfo[] Fields = typeof(NesCartDatabaseGameInfo).GetFields(BindingFlags.Public | BindingFlags.Instance); for (int i = 0; i < Fields.Length; i++) { if (Fields[i].FieldType == typeof(System.String)) { try { gameInfoList.AppendValues(iter, Fields[i].Name.Replace("_", " "), Fields[i].GetValue (info).ToString()); gameInfoLines.Add(Fields[i].Name.Replace("_", " ") + " : " + Fields[i].GetValue (info).ToString()); } catch { } } } //chips if (cart.chip_type != null) { for (int i = 0; i < cart.chip_type.Count; i++) { gameInfoList.AppendValues(iter, "Chip " + (i + 1), cart.chip_type[i]); gameInfoLines.Add("Chip " + (i + 1) + " : " + cart.chip_type[i]); } } //Cartridge Fields = typeof(NesCartDatabaseCartridgeInfo).GetFields(BindingFlags.Public | BindingFlags.Instance); for (int i = 0; i < Fields.Length; i++) { if (Fields[i].FieldType == typeof(System.String)) { try { gameInfoList.AppendValues(iter, Fields[i].Name.Replace("_", " "), Fields[i].GetValue (cart).ToString()); gameInfoLines.Add(Fields[i].Name.Replace("_", " ") + " : " + Fields[i].GetValue (cart).ToString()); } catch { } } } //DataBase Fields = typeof(NesCartDatabase).GetFields(BindingFlags.Public | BindingFlags.Static); for (int i = 0; i < Fields.Length; i++) { if (Fields[i].FieldType == typeof(System.String)) { try { gameInfoList.AppendValues(iter, Fields[i].Name.Replace("_", " "), Fields[i].GetValue (info).ToString()); gameInfoLines.Add(Fields[i].Name.Replace("_", " ") + " : " + Fields[i].GetValue (info).ToString()); } catch { } } } } #endregion iter = gameInfoList.AppendValues("File Info"); gameInfoLines.Add("[File Info]"); string crc = ""; gameInfoList.AppendValues(iter, "CRC32", crc = CalculateCRC(filechooserwidget2.Filename, 16).ToString()); gameInfoLines.Add("CRC32 : " + crc); gameInfoLines.Add(""); iter = gameInfoList.AppendValues("INES Header"); gameInfoLines.Add("[INES Header]"); gameInfoList.AppendValues(iter, "SHA1", header.SHA1); gameInfoLines.Add("SHA1 : " + header.SHA1); gameInfoList.AppendValues(iter, "Mapper #", header.MapperNumber.ToString()); gameInfoLines.Add("Mapper # : " + header.MapperNumber.ToString()); gameInfoList.AppendValues(iter, "Mirroring", header.Mirroring.ToString()); gameInfoLines.Add("Mirroring : " + header.Mirroring.ToString()); gameInfoList.AppendValues(iter, "Has Battery", header.HasBattery.ToString()); gameInfoLines.Add("Has Battery : " + header.HasBattery.ToString()); gameInfoList.AppendValues(iter, "Has Trainer", header.HasTrainer.ToString()); gameInfoLines.Add("Has Trainer : " + header.HasTrainer.ToString()); gameInfoList.AppendValues(iter, "Is Playchoice10", header.IsPlaychoice10.ToString()); gameInfoLines.Add("Is Playchoice10 : " + header.IsPlaychoice10.ToString()); gameInfoList.AppendValues(iter, "Is VS Unisystem", header.IsVSUnisystem.ToString()); gameInfoLines.Add("Is VS Unisystem : " + header.IsVSUnisystem.ToString()); gameInfoList.AppendValues(iter, "PRG Count", header.PRGCount.ToString()); gameInfoLines.Add("PRG Count : " + header.PRGCount.ToString()); gameInfoList.AppendValues(iter, "PRG Size", GetSize(header.PRGCount * 0x4000)); gameInfoLines.Add("PRG Size : " + GetSize(header.PRGCount * 0x4000)); gameInfoList.AppendValues(iter, "CHR Count", header.CHRCount.ToString()); gameInfoLines.Add("CHR Count : " + header.CHRCount.ToString()); gameInfoList.AppendValues(iter, "CHR Size", GetSize(header.CHRCount * 0x2000)); gameInfoLines.Add("CHR Size : " + GetSize(header.CHRCount * 0x2000)); gameInfoLines.Add(""); } else { iter = gameInfoList.AppendValues("File Info"); gameInfoLines.Add("[File Info]"); string crc = ""; gameInfoList.AppendValues(iter, "CRC32", crc = CalculateCRC(filechooserwidget2.Filename, 0).ToString()); gameInfoLines.Add("CRC32 : " + crc); gameInfoLines.Add(""); } } else { Gtk.TreeIter iter = gameInfoList.AppendValues("File Info"); gameInfoLines.Add("[File Info]"); string crc = ""; gameInfoList.AppendValues(iter, "CRC32", crc = CalculateCRC(filechooserwidget2.Filename, 0).ToString()); gameInfoLines.Add("CRC32 : " + crc); gameInfoLines.Add(""); } treeview2.ExpandAll(); } catch { } }
private void AddFiles(string[] files) { // Create temp folder string tempFolder = Path.GetTempPath() + "\\MYNES\\"; string tempFile = tempFolder + "fileTemp"; Directory.CreateDirectory(tempFolder); Trace.WriteLine(Program.ResourceManager.GetString("Status_SearchingFiles")); DataSet ds = MyNesDB.GetDataSet("GAMES"); foreach (string file in files) { if (frmG.CancelRequest) { break; } switch (Path.GetExtension(file).ToLower()) { #region INES case ".nes": { // Read header ! INes header = new INes(); header.Load(file, false); // Search for the match, only NesCartDB get searched. bool found = false; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (ds.Tables[0].Rows[i]["SHA1"].ToString().ToLower() == header.SHA1.ToLower() && (bool)ds.Tables[0].Rows[i]["IsDB"]) { // This is it !! // MyNesDB.UpdateEntry(ds.Tables[0].Rows[i]["Id"].ToString(), file, GetFileSize(file)); string path = ds.Tables[0].Rows[i]["Path"].ToString().Replace("'", "'"); if (File.Exists(path) && path != "") { if (_assign_update_entries_already_assigned) { ds.Tables[0].Rows[i]["Path"] = file.Replace("'", "'"); ds.Tables[0].Rows[i]["Size"] = GetFileSize(file); Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryUPDATED") + ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]"); } else { Trace.WriteLine(Program.ResourceManager.GetString("Status_EntrySkipped") + ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]"); } } else// Force assign; no file assigned or file not exist { ds.Tables[0].Rows[i]["Path"] = file; ds.Tables[0].Rows[i]["Size"] = GetFileSize(file); Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryUPDATED") + ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]"); } found = true; break; } } if (!found && _assign_addFilesNotFound) { // File not found in the database, add brand new entry found = false; // Check if path already exist ... for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (ds.Tables[0].Rows[i]["Path"].ToString().Replace("'", "'") == file) { found = true; // File is exist here since 'file' value is real if (_assign_update_entries_already_assigned) { ds.Tables[0].Rows[i]["Path"] = file.Replace("'", "'"); ds.Tables[0].Rows[i]["Size"] = GetFileSize(file); Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryUPDATED") + ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]"); } else { Trace.WriteLine(Program.ResourceManager.GetString("Status_EntrySkipped") + ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]"); } break; } } if (!found) { DataRow row = ds.Tables[0].NewRow(); MyNesDBEntryInfo infEntry = new MyNesDBEntryInfo(); infEntry.IsDB = false; infEntry.AlternativeName = ""; infEntry.BoardMapper = header.IsValid ? header.MapperNumber : 0; infEntry.BoardPcb = ""; infEntry.BoardType = ""; infEntry.Catalog = ""; infEntry.Class = ""; infEntry.Developer = ""; infEntry.Name = Path.GetFileNameWithoutExtension(file); infEntry.Players = ""; infEntry.Publisher = ""; infEntry.Region = ""; infEntry.ReleaseDate = ""; infEntry.CRC = CalculateCRC(file, 16); infEntry.DateDumped = ""; infEntry.Dump = ""; infEntry.Dumper = ""; infEntry.System = ""; infEntry.SHA1 = header.SHA1.ToUpper(); // These info should be set when user detect files. infEntry.Path = file; infEntry.Rating = 0; infEntry.Size = GetFileSize(file); infEntry.LastPlayed = DateTimeFormater.ToFull(DateTime.MinValue); infEntry.Played = 0; infEntry.PlayTime = 0; MyNesDB.SetEntryToRow(infEntry, row); ds.Tables[0].Rows.Add(row); Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryADDED") + ":[" + infEntry.Name + "]"); } } break; } #endregion #region Archive file case ".7z": case ".zip": case ".rar": case ".gzip": case ".tar": case ".bzip2": case ".xz": { try { // Open the archive SevenZipExtractor extractor = new SevenZipExtractor(file); // Extract the archive first !! Directory.CreateDirectory(Path.GetTempPath() + "\\MyNes\\"); // Make sure the temp folder is clear string[] arFiles = Directory.GetFiles(Path.GetTempPath() + "\\MyNes\\"); foreach (string a in arFiles) File.Delete(a); extractor.ExtractArchive(Path.GetTempPath() + "\\MyNes\\"); arFiles = Directory.GetFiles(Path.GetTempPath() + "\\MyNes\\"); foreach (ArchiveFileInfo f in extractor.ArchiveFileData) { if (Path.GetExtension(f.FileName).ToLower() == ".nes") { string entryPath = "(" + f.Index + ")" + file; // Read header ! INes header = new INes(); header.Load(Path.GetTempPath() + "\\MyNes\\" + f.FileName, false); // Search for the match bool found = false; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (ds.Tables[0].Rows[i]["SHA1"].ToString().ToLower() == header.SHA1.ToLower() && (bool)ds.Tables[0].Rows[i]["IsDB"]) { string path = GetFilePathFromArchivePath(ds.Tables[0].Rows[i]["Path"].ToString().Replace("'", "'")); if (File.Exists(path) && path != "") { // This is it !! if (_assign_update_entries_already_assigned) { // The file path code is (index within archive)archivePath ds.Tables[0].Rows[i]["Path"] = entryPath; ds.Tables[0].Rows[i]["Size"] = GetFileSize(tempFile); Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryUPDATED") + ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]"); } else { Trace.WriteLine(Program.ResourceManager.GetString("Status_EntrySkipped") + ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]"); } } else { // Force assign since the file is not valid ds.Tables[0].Rows[i]["Path"] = entryPath; ds.Tables[0].Rows[i]["Size"] = GetFileSize(tempFile); Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryUPDATED") + ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]"); } found = true; break; } } if (!found && _assign_addFilesNotFound) { found = false; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (ds.Tables[0].Rows[i]["Path"].ToString().Replace("'", "'") == entryPath) { found = true; // This is it !! if (_assign_update_entries_already_assigned) { ds.Tables[0].Rows[i]["Path"] = entryPath; ds.Tables[0].Rows[i]["Size"] = GetFileSize(tempFile); Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryUPDATED") + ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]"); } else { Trace.WriteLine(Program.ResourceManager.GetString("Status_EntrySkipped") + ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]"); } break; } } if (!found) { DataRow row = ds.Tables[0].NewRow(); MyNesDBEntryInfo infEntry = new MyNesDBEntryInfo(); infEntry.IsDB = false; infEntry.AlternativeName = ""; infEntry.BoardMapper = header.IsValid ? header.MapperNumber : 0; infEntry.BoardPcb = ""; infEntry.BoardType = ""; infEntry.Catalog = ""; infEntry.Class = ""; infEntry.Developer = ""; infEntry.Name = Path.GetFileNameWithoutExtension(f.FileName); infEntry.Players = ""; infEntry.Publisher = ""; infEntry.Region = ""; infEntry.ReleaseDate = ""; infEntry.CRC = CalculateCRC(tempFile, 16); infEntry.DateDumped = ""; infEntry.Dump = ""; infEntry.Dumper = ""; infEntry.System = ""; infEntry.SHA1 = header.SHA1.ToUpper(); // These info should be set when user detect files. infEntry.Path = entryPath; infEntry.Rating = 0; infEntry.Size = GetFileSize(tempFile); infEntry.LastPlayed = DateTimeFormater.ToFull(DateTime.MinValue); infEntry.Played = 0; infEntry.PlayTime = 0; MyNesDB.SetEntryToRow(infEntry, row); ds.Tables[0].Rows.Add(row); Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryADDED") + ":[" + infEntry.Name + "]"); } } } } // Clear the temp folder (to make sure) foreach (string a in arFiles) File.Delete(a); /*foreach (ArchiveFileInfo f in extractor.ArchiveFileData) { if (Path.GetExtension(f.FileName).ToLower() == ".nes") { string entryPath = "(" + f.Index + ")" + file; // Extract it ! Stream aStream = new FileStream(tempFile, FileMode.Create, FileAccess.Write); extractor.ExtractFile(f.Index, aStream); aStream.Close(); // Read header ! INes header = new INes(); header.Load(tempFile, false); // Search for the match bool found = false; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (ds.Tables[0].Rows[i]["SHA1"].ToString().ToLower() == header.SHA1.ToLower() && (bool)ds.Tables[0].Rows[i]["IsDB"]) { string path = GetFilePathFromArchivePath(ds.Tables[0].Rows[i]["Path"].ToString().Replace("'", "'")); if (File.Exists(path) && path != "") { // This is it !! if (_assign_update_entries_already_assigned) { // The file path code is (index within archive)archivePath ds.Tables[0].Rows[i]["Path"] = entryPath; ds.Tables[0].Rows[i]["Size"] = GetFileSize(tempFile); Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryUPDATED") + ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]"); } else { Trace.WriteLine(Program.ResourceManager.GetString("Status_EntrySkipped") + ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]"); } } else { // Force assign since the file is not valid ds.Tables[0].Rows[i]["Path"] = entryPath; ds.Tables[0].Rows[i]["Size"] = GetFileSize(tempFile); Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryUPDATED") + ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]"); } found = true; break; } } if (!found && _assign_addFilesNotFound) { found = false; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (ds.Tables[0].Rows[i]["Path"].ToString().Replace("'", "'") == entryPath) { found = true; // This is it !! if (_assign_update_entries_already_assigned) { ds.Tables[0].Rows[i]["Path"] = entryPath; ds.Tables[0].Rows[i]["Size"] = GetFileSize(tempFile); Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryUPDATED") + ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]"); } else { Trace.WriteLine(Program.ResourceManager.GetString("Status_EntrySkipped") + ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]"); } break; } } if (!found) { DataRow row = ds.Tables[0].NewRow(); MyNesDBEntryInfo infEntry = new MyNesDBEntryInfo(); infEntry.IsDB = false; infEntry.AlternativeName = ""; infEntry.BoardMapper = header.IsValid ? header.MapperNumber : 0; infEntry.BoardPcb = ""; infEntry.BoardType = ""; infEntry.Catalog = ""; infEntry.Class = ""; infEntry.Developer = ""; infEntry.Name = Path.GetFileNameWithoutExtension(f.FileName); infEntry.Players = ""; infEntry.Publisher = ""; infEntry.Region = ""; infEntry.ReleaseDate = ""; infEntry.CRC = CalculateCRC(tempFile, 16); infEntry.DateDumped = ""; infEntry.Dump = ""; infEntry.Dumper = ""; infEntry.System = ""; infEntry.SHA1 = header.SHA1.ToUpper(); // These info should be set when user detect files. infEntry.Path = entryPath; infEntry.Rating = 0; infEntry.Size = GetFileSize(tempFile); infEntry.LastPlayed = DateTimeFormater.ToFull(DateTime.MinValue); infEntry.Played = 0; infEntry.PlayTime = 0; MyNesDB.SetEntryToRow(infEntry, row); ds.Tables[0].Rows.Add(row); Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryADDED") + ":[" + infEntry.Name + "]"); } } } }*/ } catch { Trace.WriteLine("File [" + file + "] is archive but can't be opened."); } break; } #endregion } } Trace.WriteLine(".... " + Program.ResourceManager.GetString("Status_UpdatingDatabase") + " ...."); MyNesDB.UpdateTableFromDataSet("GAMES", ds); }
/// <summary> /// Create new emulation engine /// </summary> /// <param name="fileName">The rom complete path. Not compressed</param> /// <param name="tvsetting">The tv system setting to use</param> /// <param name="makeThread">Indicates if the emulation engine should make an internal thread and run through it. Otherwise you should make a thread and use EMUClock to run the loop.</param> public static void CreateNew(string fileName, TVSystemSetting tvsetting, bool makeThread) { switch (Path.GetExtension(fileName).ToLower()) { case ".nes": { INes header = new INes(); header.Load(fileName, true); if (header.IsValid) { INITIALIZED = false; GAMEFILE = fileName; CheckGameVSUnisystem(header.SHA1, header.IsVSUnisystem, header.MapperNumber); // Make SRAM file name SRAMFileName = Path.Combine(SRAMFolder, Path.GetFileNameWithoutExtension(fileName) + ".srm"); STATESlot = 0; UpdateStateSlot(STATESlot); // Make snapshots file name SNAPSFileName = Path.GetFileNameWithoutExtension(fileName); // Initialzie MEMInitialize(header); TVFormatSetting = tvsetting; // Hard reset hardReset(); // Run emu EmulationPaused = true; EmulationON = true; // Let's go ! if (makeThread) { EmulationThread = new Thread(new ThreadStart(EMUClock)); EmulationThread.Start(); } // Done ! INITIALIZED = true; if (EMUInitialized != null) EMUInitialized(null, new EventArgs()); } else { throw new RomNotValidException(); } break; } } }
/// <summary> /// Check a rom file to see if it can be used or not /// </summary> /// <param name="fileName">The complete file path. Archive is NOT supported.</param> /// <param name="is_supported_mapper">Indicates if this rom mapper is supported or not</param> /// <param name="has_issues">Indicates if this rom mapper have issues or not</param> /// <param name="known_issues">Issues with this mapper.</param> /// <returns>True if My Nes can run this game otherwise false.</returns> public static bool CheckRom(string fileName, out bool is_supported_mapper, out bool has_issues, out string known_issues) { switch (Path.GetExtension(fileName).ToLower()) { case ".nes": { INes header = new INes(); header.Load(fileName, true); if (header.IsValid) { // Check board existince bool found = false; string mapperName = "MyNes.Core.Mapper" + header.MapperNumber.ToString("D3"); Type[] types = Assembly.GetExecutingAssembly().GetTypes(); foreach (Type tp in types) { if (tp.FullName == mapperName) { board = Activator.CreateInstance(tp) as Board; is_supported_mapper = board.Supported; has_issues = board.NotImplementedWell; known_issues = board.Issues; found = true; return true; } } if (!found) { throw new MapperNotSupportedException(header.MapperNumber); } is_supported_mapper = false; has_issues = false; known_issues = ""; return false; } is_supported_mapper = false; has_issues = false; known_issues = ""; return false; } } is_supported_mapper = false; has_issues = false; known_issues = ""; return false; }
public void LoadFile(string fileName) { // Clear tabs tabControl1.TabPages.Clear(); // See what header it is switch (Path.GetExtension(fileName).ToLower()) { case ".nes": { // INES INFO !! INes header = new INes(); header.Load(fileName, false); if (header.IsValid) { ListView listView = new ListView(); listView.View = View.Details; listView.ShowItemToolTips = true; listView.GridLines = true; listView.Columns.Add(Program.ResourceManager.GetString("Column_Property"), 100); listView.Columns.Add(Program.ResourceManager.GetString("Column_Value"), 100); listView.Dock = DockStyle.Fill; TabPage page = new TabPage(); page.Controls.Add(listView); page.Text = Program.ResourceManager.GetString("Title_INESHeader"); tabControl1.TabPages.Add(page); // Add list view items ListViewItem item = new ListViewItem(Program.ResourceManager.GetString("Title_Path")); item.SubItems.Add(fileName); listView.Items.Add(item); item = new ListViewItem(Program.ResourceManager.GetString("Title_Size")); item.SubItems.Add(GetFileSize(fileName)); listView.Items.Add(item); item = new ListViewItem("SHA1"); item.SubItems.Add(header.SHA1); listView.Items.Add(item); item = new ListViewItem("CRC32"); item.SubItems.Add(CalculateCRC(fileName, 16)); listView.Items.Add(item); item = new ListViewItem(Program.ResourceManager.GetString("Title_MapperNumber")); item.SubItems.Add(header.MapperNumber.ToString()); listView.Items.Add(item); item = new ListViewItem(Program.ResourceManager.GetString("Title_CHRCount")); item.SubItems.Add(header.CHRCount.ToString()); listView.Items.Add(item); item = new ListViewItem(Program.ResourceManager.GetString("Title_CHRSize")); item.SubItems.Add(GetSize(header.CHRCount * 0x2000)); listView.Items.Add(item); item = new ListViewItem(Program.ResourceManager.GetString("Title_PRGCount")); item.SubItems.Add(header.PRGCount.ToString()); listView.Items.Add(item); item = new ListViewItem(Program.ResourceManager.GetString("Title_PRGSize")); item.SubItems.Add(GetSize(header.PRGCount * 0x4000)); listView.Items.Add(item); item = new ListViewItem(Program.ResourceManager.GetString("Title_HasBattery")); item.SubItems.Add(header.HasBattery.ToString()); listView.Items.Add(item); item = new ListViewItem(Program.ResourceManager.GetString("Title_HasTrainer")); item.SubItems.Add(header.HasTrainer.ToString()); listView.Items.Add(item); item = new ListViewItem(Program.ResourceManager.GetString("Title_IsPlaychoice10")); item.SubItems.Add(header.IsPlaychoice10.ToString()); listView.Items.Add(item); item = new ListViewItem(Program.ResourceManager.GetString("Title_IsVSUnisystem")); item.SubItems.Add(header.IsVSUnisystem.ToString()); listView.Items.Add(item); item = new ListViewItem(Program.ResourceManager.GetString("Title_Mirroring")); item.SubItems.Add(header.Mirroring.ToString()); listView.Items.Add(item); } else { // Add normal file info ListView listView = new ListView(); listView.View = View.Details; listView.ShowItemToolTips = true; listView.GridLines = true; listView.Columns.Add(Program.ResourceManager.GetString("Column_Property"), 100); listView.Columns.Add(Program.ResourceManager.GetString("Column_Value"), 100); listView.Dock = DockStyle.Fill; TabPage page = new TabPage(); page.Controls.Add(listView); page.Text = Program.ResourceManager.GetString("Title_FileInfo"); tabControl1.TabPages.Add(page); // Add list view items ListViewItem item = new ListViewItem(Program.ResourceManager.GetString("Title_Path")); item.SubItems.Add(fileName); listView.Items.Add(item); item = new ListViewItem(Program.ResourceManager.GetString("Title_Size")); item.SubItems.Add(GetFileSize(fileName)); listView.Items.Add(item); item = new ListViewItem("SHA1"); item.SubItems.Add(header.SHA1); listView.Items.Add(item); item = new ListViewItem("CRC32"); item.SubItems.Add(CalculateCRC(fileName, 16)); listView.Items.Add(item); } // Add database info if found ! //Get database info bool found = false; NesCartDatabaseGameInfo info = NesCartDatabase.Find(header.SHA1, out found); NesCartDatabaseCartridgeInfo cart = new NesCartDatabaseCartridgeInfo(); if (info.Cartridges != null) { foreach (NesCartDatabaseCartridgeInfo cartinf in info.Cartridges) if (cartinf.SHA1.ToLower() == header.SHA1.ToLower()) { cart = cartinf; break; } } if (found) { ListView listView = new ListView(); listView.View = View.Details; listView.ShowItemToolTips = true; listView.GridLines = true; listView.Columns.Add(Program.ResourceManager.GetString("Column_Property"), 100); listView.Columns.Add(Program.ResourceManager.GetString("Column_Value"), 100); listView.Dock = DockStyle.Fill; TabPage page = new TabPage(); page.Controls.Add(listView); page.Text = Program.ResourceManager.GetString("Title_GameInfoFromNesCartDatabase"); tabControl1.TabPages.Add(page); //Game info ListViewGroup gr = new ListViewGroup(Program.ResourceManager.GetString("title_GameInfo")); listView.Groups.Add(gr); FieldInfo[] Fields = typeof(NesCartDatabaseGameInfo).GetFields(BindingFlags.Public | BindingFlags.Instance); bool ColorOr = false; for (int i = 0; i < Fields.Length; i++) { if (Fields[i].FieldType == typeof(System.String)) { listView.Items.Add(Fields[i].Name.Replace("_", " ")); gr.Items.Add(listView.Items[listView.Items.Count - 1]); try { listView.Items[listView.Items.Count - 1].SubItems.Add(Fields[i].GetValue (info).ToString()); } catch { listView.Items[listView.Items.Count - 1].SubItems.Add(""); } if (ColorOr) listView.Items[listView.Items.Count - 1].BackColor = Color.WhiteSmoke; ColorOr = !ColorOr; } } //chips if (cart.chip_type != null) { for (int i = 0; i < cart.chip_type.Count; i++) { listView.Items.Add("Chip " + (i + 1)); gr.Items.Add(listView.Items[listView.Items.Count - 1]); listView.Items[listView.Items.Count - 1].SubItems.Add(cart.chip_type[i]); if (ColorOr) listView.Items[listView.Items.Count - 1].BackColor = Color.WhiteSmoke; ColorOr = !ColorOr; } } //Cartridge gr = new ListViewGroup(Program.ResourceManager.GetString("Title_Cartridge")); listView.Groups.Add(gr); Fields = typeof(NesCartDatabaseCartridgeInfo).GetFields(BindingFlags.Public | BindingFlags.Instance); ColorOr = false; for (int i = 0; i < Fields.Length; i++) { if (Fields[i].FieldType == typeof(System.String)) { listView.Items.Add(Fields[i].Name.Replace("_", " ")); gr.Items.Add(listView.Items[listView.Items.Count - 1]); try { listView.Items[listView.Items.Count - 1].SubItems.Add(Fields[i].GetValue(cart).ToString()); } catch { listView.Items[listView.Items.Count - 1].SubItems.Add(""); } if (ColorOr) listView.Items[listView.Items.Count - 1].BackColor = Color.WhiteSmoke; ColorOr = !ColorOr; } } //DataBase gr = new ListViewGroup(Program.ResourceManager.GetString("Title_DataBase")); listView.Groups.Add(gr); Fields = typeof(NesCartDatabase).GetFields(BindingFlags.Public | BindingFlags.Static); ColorOr = false; for (int i = 0; i < Fields.Length; i++) { if (Fields[i].FieldType == typeof(System.String)) { listView.Items.Add(Fields[i].Name.Remove(0, 2)); gr.Items.Add(listView.Items[listView.Items.Count - 1]); try { listView.Items[listView.Items.Count - 1].SubItems.Add(Fields[i].GetValue(info).ToString()); } catch { listView.Items[listView.Items.Count - 1].SubItems.Add(""); } if (ColorOr) listView.Items[listView.Items.Count - 1].BackColor = Color.WhiteSmoke; ColorOr = !ColorOr; } } } break; } } }