Esempio n. 1
0
        /// <summary>
        /// Creates an instance of IRom, which represents a program ROM, given at least one valid file path.
        /// </summary>
        /// <param name="filePath">The path to the ROM file.</param>
        /// <param name="configFilePath">The path to the configuration file (as determined necessary depending on ROM format).</param>
        /// <returns>If the file at the given path appears to be a valid program ROM, returns an instance of IRom, otherwise <c>null</c>.</returns>
        public static IRom Create(string filePath, string configFilePath)
        {
            Rom rom    = null;
            var format = CheckRomFormat(filePath);

            switch (format)
            {
            case RomFormat.Intellicart:
            case RomFormat.CuttleCart3:
            case RomFormat.CuttleCart3Advanced:
                rom = RomFormatRom.Create(filePath);
                break;

            case RomFormat.Bin:
                rom = BinFormatRom.Create(filePath, configFilePath);
                break;

            case RomFormat.Luigi:
                rom = LuigiFormatRom.Create(filePath);
                break;

            case RomFormat.None:
                break;
            }
            return(rom);
        }
Esempio n. 2
0
        /// <summary>
        /// Get up-to-date CRC32 values for a ROM's file and, possibly, it's configuration file.
        /// </summary>
        /// <param name="filePath">Absolute path to the ROM file.</param>
        /// <param name="configFilePath">Absolute path to the configuration file (for .bin format ROMs). May be <c>null</c>.</param>
        /// <param name="cfgCrc">Receives the CRC32 of <paramref name="configFilePath"/> if it is valid.</param>
        /// <returns>CRC32 of <paramref name="filePath"/>.</returns>
        public static uint GetRefreshedCrcs(string filePath, string configFilePath, out uint cfgCrc)
        {
#if REPORT_PERFORMANCE
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();
#endif // REPORT_PERFORMANCE
            uint romCrc = 0;
            cfgCrc = 0;
            switch (CheckRomFormat(filePath))
            {
            case RomFormat.Bin:
                romCrc = BinFormatRom.GetCrcs(filePath, configFilePath, out cfgCrc);
                break;

            case RomFormat.Intellicart:
            case RomFormat.CuttleCart3:
            case RomFormat.CuttleCart3Advanced:
                romCrc = RomFormatRom.GetCrcs(filePath, configFilePath, out cfgCrc);
                break;

            case RomFormat.Luigi:
                romCrc = LuigiFormatRom.GetCrcs(filePath, configFilePath, out cfgCrc);
                break;

            case RomFormat.None:
                break;
            }
#if REPORT_PERFORMANCE
            stopwatch.Stop();
            AccumulatedRefreshCrcsTime += stopwatch.Elapsed;
#endif // REPORT_PERFORMANCE
            return(romCrc);
        }
Esempio n. 3
0
            /// <inheritdoc />
            protected override RomFormat GetMemo(string filePath, object data)
            {
                var format = LuigiFormatRom.CheckFormat(filePath);

                if (format == RomFormat.None)
                {
                    format = RomFormatRom.CheckFormat(filePath);
                }
                if (format == RomFormat.None)
                {
                    format = BinFormatRom.CheckFormat(filePath);
                }
                return(format);
            }
Esempio n. 4
0
        /// <summary>
        /// Inspects data in the stream to determine if it appears to be a ROM.
        /// </summary>
        /// <param name="stream">The stream containing the data to inspect.</param>
        /// <returns>A <see cref="RomFormat"/> value; a value of <c>RomFormat.None</c> indicates the stream is almost certainly not
        /// a known ROM format. It is possible to get false positive matches resulting in <c>RomFormat.Bin</c> as it is not a
        /// strongly structured format that can be identified with high confidence. It is incumbent upon the caller to do a modicum
        /// of checking, e.g. file name extension checks, or later exception handling, to deal with errors.</returns>
        public static RomFormat GetFormat(System.IO.Stream stream)
        {
            var format = LuigiFormatRom.CheckFormat(stream);

            if (format == RomFormat.None)
            {
                format = RomFormatRom.CheckFormat(stream);
            }
            if (format == RomFormat.None)
            {
                format = BinFormatRom.CheckFormat(stream);
            }
            return(format);
        }
Esempio n. 5
0
        /// <summary>
        /// Examines the given data stream and attempts to determine if it is in .bin format.
        /// </summary>
        /// <param name="filePath">The path to the ROM file.</param>
        /// <param name="configFilePath">The path to the config file.</param>
        /// <returns>A valid BinFormatRom if the file appears to be a valid .bin (or similar) file, otherwise <c>null</c>.</returns>
        /// <remarks>Apparently, there may be odd-sized files floating around out there, in which case this will fail.</remarks>
        internal static new BinFormatRom Create(string filePath, string configFilePath)
        {
            BinFormatRom bin    = null;
            var          format = CheckFormat(filePath);

            if (format == RomFormat.Bin)
            {
                using (System.IO.Stream configFile = (configFilePath == null) ? null : StreamUtilities.OpenFileStream(configFilePath))
                {
                    // any valid .bin file will be even sized -- except for some available through the Digital Press. For some reason, these all seem to be a multiple of
                    // 8KB + 1 byte in size. So allow those through, too.
                    var configFileCheck = ((configFile != null) && (configFile.Length > 0)) || configFile == null;
                    if (configFileCheck)
                    {
                        bin = new BinFormatRom()
                        {
                            Format = RomFormat.Bin, IsValid = true, RomPath = filePath, ConfigPath = configFilePath
                        };
                    }
                }
            }
            return(bin);
        }