Beispiel #1
0
        public XMLDatfile(string path)
        {
            var doc    = XDocument.Load(path).Element("datafile");
            var header = doc.Element("header");

            name        = header.Element("name")?.Value;
            description = header.Element("description")?.Value;
            version     = header.Element("version")?.Value;
            author      = header.Element("author")?.Value;
            homepage    = header.Element("homepage")?.Value;
            url         = header.Element("url")?.Value;

            games = new List <Game>();

            foreach (XElement gameNode in doc.Elements("game"))
            {
                Game game = new Game {
                    name        = gameNode.Attribute("name")?.Value,              //Technically this is mandatory according to the DTD, but I'd rather it not crash
                    description = gameNode.Element("description")?.Value,
                    category    = gameNode.Element("category")?.Value,

                    roms = new List <ROM>()
                };
                foreach (XElement romNode in gameNode.Elements("rom"))
                {
                    ROM rom = new ROM {
                        name = romNode.Attribute("name")?.Value
                    };
                    string sizeString = romNode.Attribute("size")?.Value;
                    long   actualSize = 0;
                    if ("0".Equals(sizeString))
                    {
                        //Empty files are not of use to us
                        continue;
                    }
                    else if (sizeString != null && long.TryParse(sizeString, out actualSize))
                    {
                        rom.size = actualSize;
                    }

                    var crc32Attrib = romNode.Attribute("crc");
                    rom.crc32 = null;
                    if (crc32Attrib != null)
                    {
                        rom.crc32 = Convert.ToInt32(crc32Attrib.Value, 16);
                    }

                    rom.md5    = parseHexBytes(romNode.Attribute("md5")?.Value);
                    rom.sha1   = parseHexBytes(romNode.Attribute("sha1")?.Value);
                    rom.status = romNode.Attribute("status")?.Value;
                    if (rom.status == null)
                    {
                        //The DTD (which I don't feel like using and don't really need to use) defines this as the default
                        rom.status = "good";
                    }

                    game.roms.Add(rom);
                }

                games.Add(game);
            }
        }
Beispiel #2
0
 public IdentifyResult(XMLDatfile datfile, Game game, ROM rom)
 {
     this.datfile = datfile;
     this.game    = game;
     this.rom     = rom;
 }