コード例 #1
0
ファイル: Rom.cs プロジェクト: intvsteve/VINTage
        /// <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);
        }
コード例 #2
0
ファイル: Rom.cs プロジェクト: intvsteve/VINTage
        /// <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);
        }
コード例 #3
0
ファイル: Rom.cs プロジェクト: intvsteve/VINTage
            /// <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);
            }
コード例 #4
0
ファイル: Rom.cs プロジェクト: intvsteve/VINTage
        /// <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);
        }
コード例 #5
0
ファイル: RomFormatRom.cs プロジェクト: intvsteve/VINTage
        /// <summary>
        /// Examines the given file and attempts to determine if it is a program in .rom format.
        /// </summary>
        /// <param name="filePath">The path to the ROM file.</param>
        /// <returns>A valid RomFormatRom if file is a valid .rom (or compatible) file, otherwise <c>null</c>.</returns>
        internal static RomFormatRom Create(string filePath)
        {
            RomFormatRom rom    = null;
            var          format = CheckFormat(filePath);

            if (format != RomFormat.None)
            {
                // Valid header, so create the instance. Full validation would require walking
                // all the segments -- essentially most of the ROM.
                rom = new RomFormatRom()
                {
                    Format = format, IsValid = true, RomPath = filePath
                };
            }
            return(rom);
        }