Example #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);
        }
Example #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);
        }
Example #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);
            }
Example #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);
        }
Example #5
0
        /// <summary>
        /// Examines the given file and attempts to determine if it is a program in .luigi format.
        /// </summary>
        /// <param name="filePath">The path to the LUIGI file.</param>
        /// <returns>A valid LuigiFormatRom if file is a valid .luigi file, otherwise <c>null</c>.</returns>
        internal static LuigiFormatRom Create(string filePath)
        {
            LuigiFormatRom rom = null;

            if (CheckFormat(filePath) == RomFormat.Luigi)
            {
                LuigiFileHeader header = LuigiFileHeader.GetHeader(filePath);
                if (header != null)
                {
                    rom = new LuigiFormatRom()
                    {
                        Format = RomFormat.Luigi, IsValid = true, RomPath = filePath, Header = header
                    };
                }
            }
            return(rom);
        }