Пример #1
0
        public static ROMInfo getROMInfo(Handler handler, ROMFile rom, DatfileCollection datfiles)
        {
            ROMInfo info = new ROMInfo();

            try {
                info.addInfo("Filename", rom.path.Name);
                info.addInfo("Folder", rom.path.DirectoryName);
                info.addInfo("Size", rom.length, FormatMode.SIZE);
                bool shouldSkipHeader = handler.shouldSkipHeader(rom);
                info.addInfo("Has extra header", shouldSkipHeader);

                if (rom.compressed)
                {
                    info.addInfo("Uncompressed filename", rom.name);
                    info.addInfo("Compressed size", rom.compressedLength, FormatMode.SIZE);
                    info.addInfo("Compression ratio", 1 - ((double)rom.compressedLength / rom.length), FormatMode.PERCENT);
                }

                string extension = rom.extension;
                string fileType  = handler.getFiletypeName(extension);
                info.addInfo("File type", fileType ?? "Unknown");

                if (handler.shouldCalculateHash)
                {
                    var hashes = DatfileCollection.hash(rom.stream, 0);
                    info.addInfo("CRC32", hashes.Item1, FormatMode.HEX_WITHOUT_0X);
                    info.addInfo("MD5", hashes.Item2, FormatMode.BYTEARRAY_WITHOUT_DASHES);
                    info.addInfo("SHA-1", hashes.Item3, FormatMode.BYTEARRAY_WITHOUT_DASHES);

                    Tuple <int, byte[], byte[]> hashesWithoutHeader = null;
                    if (shouldSkipHeader)
                    {
                        hashesWithoutHeader = DatfileCollection.hash(rom.stream, handler.skipHeaderBytes());
                        info.addInfo("CRC32 without header", hashesWithoutHeader.Item1, FormatMode.HEX_WITHOUT_0X);
                        info.addInfo("MD5 without header", hashesWithoutHeader.Item2, FormatMode.BYTEARRAY_WITHOUT_DASHES);
                        info.addInfo("SHA-1 without header", hashesWithoutHeader.Item3, FormatMode.BYTEARRAY_WITHOUT_DASHES);
                    }

                    if (datfiles != null)
                    {
                        var results = datfiles.identify(hashes.Item1, hashes.Item2, hashes.Item3);
                        if (hashesWithoutHeader != null)
                        {
                            var resultsWithoutHeader = datfiles.identify(hashesWithoutHeader.Item1, hashesWithoutHeader.Item2, hashesWithoutHeader.Item3);
                            foreach (var resultWithoutHeader in resultsWithoutHeader)
                            {
                                results.Add(resultWithoutHeader);
                            }
                        }
                        addDatfileResults(results, info);
                    }
                }

                handler.addROMInfo(info, rom);
            } catch (Exception e) {
                info.addInfo("Exception", e);
            }
            return(info);
        }
Пример #2
0
        static void addDatfileResults(IList <XMLDatfile.IdentifyResult> results, ROMInfo info)
        {
            int i = 1;

            foreach (var result in results)
            {
                string prefix = i == 1 ? "Datfile" : String.Format("Datfile {0}", i);
                info.addInfo(prefix, result?.datfile.name);
                info.addInfo(prefix + " game name", result?.game.name);
                info.addInfo(prefix + " game category", result?.game.category);
                info.addInfo(prefix + " game description", result?.game.description, true);                 //Generally the same as the name
                info.addInfo(prefix + " ROM name", result?.rom.name);
                info.addInfo(prefix + " ROM status", result?.rom.status);
                if (result != null)
                {
                    //Lowkey hate that I can't just do result? here
                    //Anyway, if there's a match, then this should just be equal to the file size anyway; if not, you know some hash collision shit occured
                    info.addInfo(prefix + " ROM size", result.rom.size, FormatMode.SIZE, true);
                }
                ++i;
            }
        }