コード例 #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
        public static void viewFile(ROMFile rom, bool isCDTrack = false)
        {
            Handler handler = null;

            if (isCDTrack)
            {
                handler = chooseChoices(Handler.allHandlers.Where(h => h is CDBasedSystem), "name", "Which system is this?", "Choose hander");
            }
            else
            {
                IList <Handler> handlers = findHandlersForExtension(rom.extension);

                if (handlers.Count == 0)
                {
                    handler = chooseChoices(Handler.allHandlers.Where(h => h.shouldSeeInChooseView()).OrderBy(h => h.name), "name", "I don't know what this file extension means. Do you want to try and read it as something else?", "Force Handler");
                }
                else
                {
                    handler = chooseChoices(handlers.OrderBy((h) => h.name), "name",
                                            "This file extension could be a number of things. Which handler do you want to try and read this with?", "Choose Handler");
                }
            }
            if (handler == null)
            {
                return;
            }

            string            datFolderSetting = SettingsManager.readSetting("datfiles");
            DatfileCollection datfiles         = null;

            if (datFolderSetting != null && handler.shouldCalculateHash)
            {
                List <DirectoryInfo> directories = new List <DirectoryInfo>();
                foreach (var datFolder in datFolderSetting.Split(';'))
                {
                    directories.Add(new DirectoryInfo(datFolder));
                }
                datfiles = DatfileCollection.loadFromFolders(directories);
            }

            ROMInfo info = ROMInfo.getROMInfo(handler, rom, datfiles);

            viewFile(info, rom, String.Format("ROMniscience: {0} ({1})", rom.path, handler.name));
        }