Esempio n. 1
0
    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
        {
        }
    }
Esempio n. 2
0
        /// <summary>
        /// Load data base from file
        /// </summary>
        /// <param name="fileName">The full path of database file</param>
        public static void LoadDatabase(string fileName)
        {
            if (!File.Exists(fileName))
            {
                return;
            }
            //1 clear the database
            _databaseRoms.Clear();
            //2 read the xml file
            Stream databaseStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);

            XmlReaderSettings sett = new XmlReaderSettings();

            sett.DtdProcessing    = DtdProcessing.Ignore;
            sett.IgnoreWhitespace = true;
            XmlReader XMLread = XmlReader.Create(databaseStream, sett);

            NesCartDatabaseGameInfo drom = new NesCartDatabaseGameInfo();

            // To avoid nulls ..
            drom.Cartridges       = new List <NesCartDatabaseCartridgeInfo>();
            drom.Game_AltName     = "";
            drom.Game_Catalog     = "";
            drom.Game_Class       = "";
            drom.Game_Developer   = "";
            drom.Game_Name        = "";
            drom.Game_Players     = "";
            drom.Game_Publisher   = "";
            drom.Game_Region      = "";
            drom.Game_ReleaseDate = "";

            while (XMLread.Read())
            {
                //database Game info
                if (XMLread.Name == "xml" & XMLread.IsStartElement())
                {
                    if (XMLread.MoveToAttribute("version"))
                    {
                        DBVersion = XMLread.Value;
                    }
                    if (XMLread.MoveToAttribute("conformance"))
                    {
                        DBConformance = XMLread.Value;
                    }
                    if (XMLread.MoveToAttribute("agent"))
                    {
                        DBAgent = XMLread.Value;
                    }
                    if (XMLread.MoveToAttribute("author"))
                    {
                        DBAuthor = XMLread.Value;
                    }
                    if (XMLread.MoveToAttribute("timestamp"))
                    {
                        DBTimeStamp = XMLread.Value;
                    }
                }
                //Is it a game ?
                else if (XMLread.Name == "game" & XMLread.IsStartElement())
                {
                    drom = new NesCartDatabaseGameInfo();

                    if (XMLread.MoveToAttribute("name"))
                    {
                        drom.Game_Name = XMLread.Value;
                    }
                    if (XMLread.MoveToAttribute("altname"))
                    {
                        drom.Game_AltName = XMLread.Value;
                    }
                    if (XMLread.MoveToAttribute("class"))
                    {
                        drom.Game_Class = XMLread.Value;
                    }
                    if (XMLread.MoveToAttribute("catalog"))
                    {
                        drom.Game_Catalog = XMLread.Value;
                    }
                    if (XMLread.MoveToAttribute("publisher"))
                    {
                        drom.Game_Publisher = XMLread.Value;
                    }
                    if (XMLread.MoveToAttribute("developer"))
                    {
                        drom.Game_Developer = XMLread.Value;
                    }
                    if (XMLread.MoveToAttribute("region"))
                    {
                        drom.Game_Region = XMLread.Value;
                    }
                    if (XMLread.MoveToAttribute("players"))
                    {
                        drom.Game_Players = XMLread.Value;
                    }
                    if (XMLread.MoveToAttribute("date"))
                    {
                        drom.Game_ReleaseDate = XMLread.Value;
                    }

                    NesCartDatabaseCartridgeInfo crt = new NesCartDatabaseCartridgeInfo();
                    crt.PAD_h        = "";
                    crt.PAD_v        = "";
                    crt.PRG_crc      = "";
                    crt.PRG_name     = "";
                    crt.PRG_sha1     = "";
                    crt.PRG_size     = "";
                    crt.chip_type    = new List <string>();
                    crt.CHR_crc      = "";
                    crt.CHR_name     = "";
                    crt.CHR_sha1     = "";
                    crt.CHR_size     = "";
                    crt.CIC_type     = "";
                    crt.Board_Mapper = "";
                    crt.Board_Pcb    = "";
                    crt.Board_Type   = "";
                    crt.VRAM_sizes   = new List <string>();
                    crt.WRAMBanks    = new List <SRAMBankInfo>();
                    // Load carts
                    while (XMLread.Read())
                    {
                        //End of game info ?
                        if (XMLread.Name == "game" & !XMLread.IsStartElement())
                        {
                            _databaseRoms.Add(drom);
                            break;
                        }
                        //cartridge info
                        if (XMLread.Name == "cartridge" & XMLread.IsStartElement())
                        {
                            if (drom.Cartridges == null)
                            {
                                drom.Cartridges = new List <NesCartDatabaseCartridgeInfo>();
                            }
                            crt              = new NesCartDatabaseCartridgeInfo();
                            crt.PAD_h        = "";
                            crt.PAD_v        = "";
                            crt.PRG_crc      = "";
                            crt.PRG_name     = "";
                            crt.PRG_sha1     = "";
                            crt.PRG_size     = "";
                            crt.chip_type    = new List <string>();
                            crt.CHR_crc      = "";
                            crt.CHR_name     = "";
                            crt.CHR_sha1     = "";
                            crt.CHR_size     = "";
                            crt.CIC_type     = "";
                            crt.Board_Mapper = "";
                            crt.Board_Pcb    = "";
                            crt.Board_Type   = "";
                            crt.VRAM_sizes   = new List <string>();
                            crt.WRAMBanks    = new List <SRAMBankInfo>();
                            if (XMLread.MoveToAttribute("system"))
                            {
                                crt.System = XMLread.Value;
                            }
                            if (XMLread.MoveToAttribute("crc"))
                            {
                                crt.CRC = XMLread.Value;
                            }
                            if (XMLread.MoveToAttribute("sha1"))
                            {
                                crt.SHA1 = XMLread.Value;
                            }
                            if (XMLread.MoveToAttribute("dump"))
                            {
                                crt.Dump = XMLread.Value;
                            }
                            if (XMLread.MoveToAttribute("dumper"))
                            {
                                crt.Dumper = XMLread.Value;
                            }
                            if (XMLread.MoveToAttribute("datedumped"))
                            {
                                crt.DateDumped = XMLread.Value;
                            }
                        }
                        else if (XMLread.Name == "cartridge" & !XMLread.IsStartElement())
                        {
                            drom.Cartridges.Add(crt); continue;
                        }
                        //board info
                        else if (XMLread.Name == "board" & XMLread.IsStartElement())
                        {
                            if (XMLread.MoveToAttribute("type"))
                            {
                                crt.Board_Type = XMLread.Value;
                            }
                            if (XMLread.MoveToAttribute("pcb"))
                            {
                                crt.Board_Pcb = XMLread.Value;
                            }
                            if (XMLread.MoveToAttribute("mapper"))
                            {
                                crt.Board_Mapper = XMLread.Value;
                            }
                        }
                        //prg info
                        else if (XMLread.Name == "prg" & XMLread.IsStartElement())
                        {
                            if (XMLread.MoveToAttribute("name"))
                            {
                                crt.PRG_name = XMLread.Value;
                            }
                            if (XMLread.MoveToAttribute("size"))
                            {
                                crt.PRG_size = XMLread.Value;
                            }
                            if (XMLread.MoveToAttribute("crc"))
                            {
                                crt.PRG_crc = XMLread.Value;
                            }
                            if (XMLread.MoveToAttribute("sha1"))
                            {
                                crt.PRG_sha1 = XMLread.Value;
                            }
                        }
                        //chr info
                        else if (XMLread.Name == "chr" & XMLread.IsStartElement())
                        {
                            if (XMLread.MoveToAttribute("name"))
                            {
                                crt.CHR_name = XMLread.Value;
                            }
                            if (XMLread.MoveToAttribute("size"))
                            {
                                crt.CHR_size = XMLread.Value;
                            }
                            if (XMLread.MoveToAttribute("crc"))
                            {
                                crt.CHR_crc = XMLread.Value;
                            }
                            if (XMLread.MoveToAttribute("sha1"))
                            {
                                crt.CHR_sha1 = XMLread.Value;
                            }
                        }
                        //vram info
                        else if (XMLread.Name == "vram" & XMLread.IsStartElement())
                        {
                            if (XMLread.MoveToAttribute("size"))
                            {
                                crt.VRAM_sizes.Add(XMLread.Value);
                            }
                        }
                        //wram info
                        else if (XMLread.Name == "wram" & XMLread.IsStartElement())
                        {
                            string wsize   = "";
                            bool   battery = false;
                            int    id      = 0;

                            if (XMLread.MoveToAttribute("size"))
                            {
                                wsize = XMLread.Value;
                            }
                            if (XMLread.MoveToAttribute("battery"))
                            {
                                battery = XMLread.Value == "1";
                            }
                            if (XMLread.MoveToAttribute("id"))
                            {
                                int.TryParse(XMLread.Value, out id);
                            }
                            crt.WRAMBanks.Add(new SRAMBankInfo(id, wsize, battery));
                        }
                        //chip info
                        else if (XMLread.Name == "chip" & XMLread.IsStartElement())
                        {
                            if (XMLread.MoveToAttribute("type"))
                            {
                                if (crt.chip_type == null)
                                {
                                    crt.chip_type = new List <string>();
                                }
                                crt.chip_type.Add(XMLread.Value);
                            }
                        }
                        //cic info
                        else if (XMLread.Name == "cic" & XMLread.IsStartElement())
                        {
                            if (XMLread.MoveToAttribute("type"))
                            {
                                crt.CIC_type = XMLread.Value;
                            }
                        }
                        //pad info
                        else if (XMLread.Name == "pad" & XMLread.IsStartElement())
                        {
                            if (XMLread.MoveToAttribute("h"))
                            {
                                crt.PAD_h = XMLread.Value;
                            }
                            if (XMLread.MoveToAttribute("v"))
                            {
                                crt.PAD_v = XMLread.Value;
                            }
                        }
                    }
                }
            }
            XMLread.Close();
            databaseStream.Close();
        }
Esempio n. 3
0
        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;
                    }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Load data base from file
        /// </summary>
        /// <param name="fileName">The full path of database file</param>
        public static void LoadDatabase(string fileName)
        {
            if (!File.Exists(fileName))
                return;
            //1 clear the database
            _databaseRoms.Clear();
            //2 read the xml file
            Stream databaseStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);

            XmlReaderSettings sett = new XmlReaderSettings();
            sett.DtdProcessing = DtdProcessing.Ignore;
            sett.IgnoreWhitespace = true;
            XmlReader XMLread = XmlReader.Create(databaseStream, sett);

            NesCartDatabaseGameInfo drom = new NesCartDatabaseGameInfo();
            // To avoid nulls ..
            drom.Cartridges = new List<NesCartDatabaseCartridgeInfo>();
            drom.Game_AltName = "";
            drom.Game_Catalog = "";
            drom.Game_Class = "";
            drom.Game_Developer = "";
            drom.Game_Name = "";
            drom.Game_Players = "";
            drom.Game_Publisher = "";
            drom.Game_Region = "";
            drom.Game_ReleaseDate = "";

            while (XMLread.Read())
            {
                //database Game info
                if (XMLread.Name == "xml" & XMLread.IsStartElement())
                {
                    if (XMLread.MoveToAttribute("version"))
                        DBVersion = XMLread.Value;
                    if (XMLread.MoveToAttribute("conformance"))
                        DBConformance = XMLread.Value;
                    if (XMLread.MoveToAttribute("agent"))
                        DBAgent = XMLread.Value;
                    if (XMLread.MoveToAttribute("author"))
                        DBAuthor = XMLread.Value;
                    if (XMLread.MoveToAttribute("timestamp"))
                        DBTimeStamp = XMLread.Value;
                }
                //Is it a game ?
                else if (XMLread.Name == "game" & XMLread.IsStartElement())
                {
                    drom = new NesCartDatabaseGameInfo();

                    if (XMLread.MoveToAttribute("name"))
                        drom.Game_Name = XMLread.Value;
                    if (XMLread.MoveToAttribute("altname"))
                        drom.Game_AltName = XMLread.Value;
                    if (XMLread.MoveToAttribute("class"))
                        drom.Game_Class = XMLread.Value;
                    if (XMLread.MoveToAttribute("catalog"))
                        drom.Game_Catalog = XMLread.Value;
                    if (XMLread.MoveToAttribute("publisher"))
                        drom.Game_Publisher = XMLread.Value;
                    if (XMLread.MoveToAttribute("developer"))
                        drom.Game_Developer = XMLread.Value;
                    if (XMLread.MoveToAttribute("region"))
                        drom.Game_Region = XMLread.Value;
                    if (XMLread.MoveToAttribute("players"))
                        drom.Game_Players = XMLread.Value;
                    if (XMLread.MoveToAttribute("date"))
                        drom.Game_ReleaseDate = XMLread.Value;

                    NesCartDatabaseCartridgeInfo crt = new NesCartDatabaseCartridgeInfo();
                    crt.PAD_h = "";
                    crt.PAD_v = "";
                    crt.PRG_crc = "";
                    crt.PRG_name = "";
                    crt.PRG_sha1 = "";
                    crt.PRG_size = "";
                    crt.chip_type = new List<string>();
                    crt.CHR_crc = "";
                    crt.CHR_name = "";
                    crt.CHR_sha1 = "";
                    crt.CHR_size = "";
                    crt.CIC_type = "";
                    crt.Board_Mapper = "";
                    crt.Board_Pcb = "";
                    crt.Board_Type = "";
                    crt.VRAM_sizes = new List<string>();
                    crt.WRAMBanks = new List<SRAMBankInfo>();
                    // Load carts
                    while (XMLread.Read())
                    {
                        //End of game info ?
                        if (XMLread.Name == "game" & !XMLread.IsStartElement())
                        {
                            _databaseRoms.Add(drom);
                            break;
                        }
                        //cartridge info
                        if (XMLread.Name == "cartridge" & XMLread.IsStartElement())
                        {
                            if (drom.Cartridges == null)
                                drom.Cartridges = new List<NesCartDatabaseCartridgeInfo>();
                            crt = new NesCartDatabaseCartridgeInfo();
                            crt.PAD_h = "";
                            crt.PAD_v = "";
                            crt.PRG_crc = "";
                            crt.PRG_name = "";
                            crt.PRG_sha1 = "";
                            crt.PRG_size = "";
                            crt.chip_type = new List<string>();
                            crt.CHR_crc = "";
                            crt.CHR_name = "";
                            crt.CHR_sha1 = "";
                            crt.CHR_size = "";
                            crt.CIC_type = "";
                            crt.Board_Mapper = "";
                            crt.Board_Pcb = "";
                            crt.Board_Type = "";
                            crt.VRAM_sizes = new List<string>();
                            crt.WRAMBanks = new List<SRAMBankInfo>();
                            if (XMLread.MoveToAttribute("system"))
                                crt.System = XMLread.Value;
                            if (XMLread.MoveToAttribute("crc"))
                                crt.CRC = XMLread.Value;
                            if (XMLread.MoveToAttribute("sha1"))
                                crt.SHA1 = XMLread.Value;
                            if (XMLread.MoveToAttribute("dump"))
                                crt.Dump = XMLread.Value;
                            if (XMLread.MoveToAttribute("dumper"))
                                crt.Dumper = XMLread.Value;
                            if (XMLread.MoveToAttribute("datedumped"))
                                crt.DateDumped = XMLread.Value;
                        }
                        else if (XMLread.Name == "cartridge" & !XMLread.IsStartElement())
                        {
                            drom.Cartridges.Add(crt); continue;
                        }
                        //board info
                        else if (XMLread.Name == "board" & XMLread.IsStartElement())
                        {
                            if (XMLread.MoveToAttribute("type"))
                                crt.Board_Type  = XMLread.Value;
                            if (XMLread.MoveToAttribute("pcb"))
                                crt.Board_Pcb = XMLread.Value;
                            if (XMLread.MoveToAttribute("mapper"))
                                crt.Board_Mapper = XMLread.Value;
                        }
                        //prg info
                        else if (XMLread.Name == "prg" & XMLread.IsStartElement())
                        {
                            if (XMLread.MoveToAttribute("name"))
                                crt.PRG_name = XMLread.Value;
                            if (XMLread.MoveToAttribute("size"))
                                crt.PRG_size = XMLread.Value;
                            if (XMLread.MoveToAttribute("crc"))
                                crt.PRG_crc = XMLread.Value;
                            if (XMLread.MoveToAttribute("sha1"))
                                crt.PRG_sha1 = XMLread.Value;
                        }
                        //chr info
                        else if (XMLread.Name == "chr" & XMLread.IsStartElement())
                        {
                            if (XMLread.MoveToAttribute("name"))
                                crt.CHR_name = XMLread.Value;
                            if (XMLread.MoveToAttribute("size"))
                                crt.CHR_size = XMLread.Value;
                            if (XMLread.MoveToAttribute("crc"))
                                crt.CHR_crc = XMLread.Value;
                            if (XMLread.MoveToAttribute("sha1"))
                                crt.CHR_sha1 = XMLread.Value;
                        }
                        //vram info
                        else if (XMLread.Name == "vram" & XMLread.IsStartElement())
                        {
                            if (XMLread.MoveToAttribute("size"))
                                crt.VRAM_sizes.Add(XMLread.Value);
                        }
                        //wram info
                        else if (XMLread.Name == "wram" & XMLread.IsStartElement())
                        {
                            string wsize = "";
                            bool battery = false;
                            int id = 0;

                            if (XMLread.MoveToAttribute("size"))
                                wsize = XMLread.Value;
                            if (XMLread.MoveToAttribute("battery"))
                                battery = XMLread.Value == "1";
                            if (XMLread.MoveToAttribute("id"))
                                int.TryParse(XMLread.Value, out id);
                            crt.WRAMBanks.Add(new SRAMBankInfo(id, wsize, battery));
                        }
                        //chip info
                        else if (XMLread.Name == "chip" & XMLread.IsStartElement())
                        {
                            if (XMLread.MoveToAttribute("type"))
                            {
                                if (crt.chip_type == null)
                                    crt.chip_type = new List<string>();
                                crt.chip_type.Add(XMLread.Value);
                            }
                        }
                        //cic info
                        else if (XMLread.Name == "cic" & XMLread.IsStartElement())
                        {
                            if (XMLread.MoveToAttribute("type"))
                                crt.CIC_type = XMLread.Value;
                        }
                        //pad info
                        else if (XMLread.Name == "pad" & XMLread.IsStartElement())
                        {
                            if (XMLread.MoveToAttribute("h"))
                                crt.PAD_h = XMLread.Value;
                            if (XMLread.MoveToAttribute("v"))
                                crt.PAD_v = XMLread.Value;
                        }
                    }
                }
            }
            XMLread.Close();
            databaseStream.Close();
        }
Esempio n. 5
0
 /// <summary>
 /// Initialize the board
 /// </summary>
 /// <param name="sha1">The rom sha1 calculated without the header</param>
 /// <param name="prg_dump">The prg data dump.</param>
 /// <param name="chr_dump">The chr data dump</param>
 /// <param name="trainer_dump">The trainer data dump.</param>
 /// <param name="defaultMirroring">The default mirroring as defined in rom.</param>
 public virtual void Initialize(string sha1, byte[] prg_dump, byte[] chr_dump, byte[] trainer_dump, Mirroring defaultMirroring)
 {
     RomSHA1 = sha1;
     // Find on DB
     GameInfo = NesCartDatabase.Find(sha1, out IsGameFoundOnDB);
     //set cart info
     if (GameInfo.Cartridges != null)
     {
         foreach (NesCartDatabaseCartridgeInfo cartinf in GameInfo.Cartridges)
             if (cartinf.SHA1.ToLower() == sha1.ToLower())
             {
                 GameCartInfo = cartinf;
                 break;
             }
     }
     BoardType = "N/A";
     BoardPCB = "N/A";
     this.Chips = new List<string>();
     if (IsGameFoundOnDB)
     {
         Console.WriteLine("Game found in Database !!");
         Console.WriteLine("> Game name: " + GameInfo.Game_Name);
         Console.WriteLine("> Game alt name: " + GameInfo.Game_AltName);
         BoardType = GameCartInfo.Board_Type;
         Console.WriteLine("> Board Type: " + BoardType);
         BoardPCB = GameCartInfo.Board_Pcb;
         Console.WriteLine("> Board Pcb: " + BoardPCB);
         // Chips ... important for some boards
         if (GameCartInfo.chip_type != null)
             for (int i = 0; i < GameCartInfo.chip_type.Count; i++)
             {
                 Console.WriteLine(string.Format("> CHIP {0}: {1}", (i + 1).ToString(),
                    GameCartInfo.chip_type[i]));
                 this.Chips.Add(GameCartInfo.chip_type[i]);
             }
     }
     // Mirroring
     this.default_mirroring = defaultMirroring;
     nmt_banks = new byte[4][]
     {
         new byte[0x0400], new byte[0x0400], new byte[0x0400], new byte[0x0400]
         /*Only 2 nmt banks should be used in normal state*/
     };
     nmt_indexes = new int[4];
     SwitchNMT(defaultMirroring);
     // PRG data ***********************************************
     List<BankInfo> prgBanks = new List<BankInfo>(GetPRGRAM());
     prg_rom_bank_offset = prgBanks.Count;
     prgBanks.AddRange(GetPRGROM(prg_dump));
     SRAMSaveRequired = false;
     prg_banks = new byte[prgBanks.Count][];
     prg_enable = new bool[prgBanks.Count];
     prg_isram = new bool[prgBanks.Count];
     prg_writable = new bool[prgBanks.Count];
     prg_battery = new bool[prgBanks.Count];
     for (int i = 0; i < prgBanks.Count; i++)
     {
         prg_banks[i] = prgBanks[i].DATA;
         prg_enable[i] = prgBanks[i].Enabled;
         prg_writable[i] = prgBanks[i].Writable;
         prg_isram[i] = prgBanks[i].IsRAM;
         prg_battery[i] = prgBanks[i].IsBattery;
         if (!SRAMSaveRequired)
         {
             if (prg_battery[i])
                 SRAMSaveRequired = true;
         }
     }
     prg_indexes = new int[5];
     // ********************************************************
     // Trainer ************************************************
     // Put trainer at first ram bank.
     if (trainer_dump != null)
     {
         if (trainer_dump.Length > 0)
         {
             for (int i = 0; i < prgBanks.Count; i++)
             {
                 if (prg_isram[i])
                 {
                     trainer_dump.CopyTo(prg_banks[i], 0x1000);
                     break;
                 }
             }
         }
     }
     // ********************************************************
     // CHR data ***********************************************
     List<BankInfo> chrBanks = new List<BankInfo>(GetCHRRAM());
     chr_rom_bank_offset = chrBanks.Count;
     chrBanks.AddRange(GetCHRROM(chr_dump));
     chr_banks = new byte[chrBanks.Count][];
     chr_enable = new bool[chrBanks.Count];
     chr_isram = new bool[chrBanks.Count];
     chr_writable = new bool[chrBanks.Count];
     for (int i = 0; i < chrBanks.Count; i++)
     {
         chr_banks[i] = chrBanks[i].DATA;
         chr_enable[i] = chrBanks[i].Enabled;
         chr_writable[i] = chrBanks[i].Writable;
         chr_isram[i] = chrBanks[i].IsRAM;
     }
     chr_indexes = new int[8];
     // ********************************************************
 }