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