private void TryParseDatHeader(CmpReader reader, out string version, out string comment)
        {
            version = comment = null;

            if (reader.OpenItem())
            {
                while (reader.NextItem())
                {
                    if (reader.SelectionName == "version")
                    {
                        if (version == null)
                        {
                            version = reader.SelectionValue;
                        }
                    }
                    else if (reader.SelectionName == "comment")
                    {
                        if (comment == null)
                        {
                            comment = reader.SelectionValue;
                        }
                    }
                }
            }
            reader.CloseItem();
        }
        private void TryParseGame(CmpReader reader)
        {
            if (reader.OpenItem())
            {
                RomDB.Entry entry = new RomDB.Entry();

                string name    = null;
                string crc32   = null;
                string sha1    = null;
                string md5     = null;
                string size    = null;
                bool   romRead = false;

                while (reader.NextItem())
                {
                    if (reader.SelectionName == "name" & name == null)
                    {
                        name = reader.SelectionValue;
                    }
                    else if (reader.SelectionName == "rom" & !romRead)
                    {
                        if (reader.OpenItem())
                        {
                            romRead = true;
                            while (reader.NextItem())
                            {
                                if (reader.SelectionName == "size" & size == null)
                                {
                                    size = reader.SelectionValue;
                                }
                                else if (reader.SelectionName == "crc" & crc32 == null)
                                {
                                    crc32 = reader.SelectionValue;
                                }
                                else if (reader.SelectionName == "sha1" & sha1 == null)
                                {
                                    sha1 = reader.SelectionValue;
                                }
                                else if (reader.SelectionName == "md5" && md5 == null)
                                {
                                    md5 = reader.SelectionValue;
                                }
                            }
                        }
                        reader.CloseItem();
                    }
                }
                if (name != null)
                {
                    entry.name = name;
                    if (size != null)
                    {
                        entry.size = ParseInt(size);
                    }
                    // Todo: report invalidly sized hashes?
                    if (crc32 != null)
                    {
                        var crc32hash = new RomHash(ParseHexBytes(crc32), GetHashFlags(HashFlags.CRC32));
                        if (crc32hash.Value.Length == 4)
                        {
                            entry.Hashes.Add(crc32hash);
                        }
                    }
                    if (sha1 != null)
                    {
                        var sha1Hash = new RomHash(ParseHexBytes(sha1), GetHashFlags(HashFlags.SHA1));
                        if (sha1Hash.Value.Length == 20)
                        {
                            entry.Hashes.Add(sha1Hash);
                        }
                    }
                    if (md5 != null)
                    {
                        var md5Hash = new RomHash(ParseHexBytes(md5), GetHashFlags(HashFlags.MD5));
                        if (md5Hash.Value.Length == 16)
                        {
                            entry.Hashes.Add(md5Hash);
                        }
                    }
                }
                reader.CloseItem();

                result.AddEntry(entry);
            }
        }