Exemplo n.º 1
0
            /// <summary>
            /// Creates a DBMatch object
            /// </summary>
            /// <param name="database">The ROM database this match corresponds to.</param>
            /// <param name="entry">The matched entry.</param>
            /// <exception cref="NullReferenceException">Thrown if any arguments are null.</exception>
            public DBMatch(RomDB database, RomDB.Entry entry)
                : this()
            {
                this.Database = database;
                this.Entry    = entry;

                if (this.Database == null || this.Entry == null)
                {
                    throw new ArgumentNullException();
                }
            }
Exemplo n.º 2
0
        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);
            }
        }