Example #1
0
        /// <summary>
        /// Locates a program in the table given a program's unique identifier.
        /// </summary>
        /// <param name="programIdentifier">The unique identifier of the ROM to be located.</param>
        /// <returns>The <see cref="IProgramInformation"/> that matches the given <see cref="ProgramIdentifier"/> as the table is best able to determine, otherwise <c>null</c>.</returns>
        protected virtual IProgramInformation FindProgramCore(ProgramIdentifier programIdentifier)
        {
            // TODO: Improve behaver w.r.t. CFG CRC.
            var programInformation = Programs.FirstOrDefault(p => p.Crcs.FirstOrDefault(c => c.Crc == programIdentifier.DataCrc) != null);

            return(programInformation);
        }
Example #2
0
        /// <inheritdoc />
        public override IProgramInformation FindProgram(ProgramIdentifier programIdentifier)
        {
            var programInformation = base.FindProgram(programIdentifier);

            System.Diagnostics.Debug.WriteLineIf((programIdentifier.OtherData != 0) && (programInformation != null), "Support for ProgramIdentifier lookups not implemented.");
            return(programInformation);
        }
        private IProgramDescription GetProgramDescription(ProgramIdentifier programIdentifier, RomFormat format, string code)
        {
            IProgramDescription programDescription = null;

            if (DefaultDescriptionsSource != null)
            {
                // Try the strictest match first.
                programDescription = DefaultDescriptionsSource.FirstOrDefault(d => d.IsMatchingProgramDescription(programIdentifier, format, true, code));
                if (programDescription == null)
                {
                    programDescription = DefaultDescriptionsSource.FirstOrDefault(d => d.IsMatchingProgramDescription(programIdentifier, format, true));
                }
                if (programDescription == null)
                {
                    programDescription = DefaultDescriptionsSource.FirstOrDefault(d => d.IsMatchingProgramDescription(programIdentifier, format, false));
                }
                if (programDescription == null)
                {
                    programDescription = DefaultDescriptionsSource.FirstOrDefault(d => d.IsMatchingProgramDescription(programIdentifier));
                }
                if (programDescription == null)
                {
                    programDescription = DefaultDescriptionsSource.FirstOrDefault(d => d.Crc == programIdentifier.DataCrc);
                }
            }
            return(programDescription);
        }
Example #4
0
        /// <inheritdoc />
        protected override IProgramInformation FindProgramCore(ProgramIdentifier programIdentifier)
        {
            IProgramInformation programInfo;

            if (!_programs.TryGetValue(programIdentifier.DataCrc, out programInfo))
            {
                programInfo = null;
            }
            return(programInfo);
        }
 /// <inheritdoc />
 public IProgramRomInformationBuilder WithId(ProgramIdentifier id)
 {
     _programRomInformation.Id = id;
     return(this);
 }
Example #6
0
 /// <inheritdoc />
 public virtual IProgramInformation FindProgram(ProgramIdentifier programIdentifier)
 {
     return(FindProgramCore(programIdentifier));
 }
        /// <summary>
        /// Determines if a given <see cref="IProgramDescription"/> is considered a match based on given criteria.
        /// </summary>
        /// <param name="programDescription">An instance</param>
        /// <param name="programIdentifier">Provides the unique identifier that must match the value that can be determined from <paramref name="programDescription"/>.</param>
        /// <returns><c>true</c> if all of the specified criteria match the corresponding data in <paramref name="programDescription"/>.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="programDescription"/> is <c>null</c>.</exception>
        /// <exception cref="System.ArgumentException">Thrown if <paramref name="programIdentifier"/> is invalid.</exception>
        public static bool IsMatchingProgramDescription(this IProgramDescription programDescription, ProgramIdentifier programIdentifier)
        {
            var match = IsMatchingProgramDescription(programDescription, programIdentifier, RomFormat.None, false, null);

            return(match);
        }
        /// <summary>
        /// Determines if a given <see cref="IProgramDescription"/> is considered a match based on given criteria.
        /// </summary>
        /// <param name="programDescription">An instance</param>
        /// <param name="programIdentifier">Provides the unique identifier that must match the value that can be determined from <paramref name="programDescription"/>.</param>
        /// <param name="romFormat">If this value is not <see cref="RomFormat.None"/>, then <paramref name="programDescription"/> must have the same ROM format to be a match.</param>
        /// <param name="cfgCrcMustMatch">If <paramref name="romFormat"/> matches and is <see cref="RomFormat.Bin"/>, and this value is <c>true</c>, the CRC of the CFG file must also match.</param>
        /// <param name="code">If specified (not <c>null</c> or empty), and it can be determined that <paramref name="programDescription"/> has a value, value is used in determining match.</param>
        /// <returns><c>true</c> if all of the specified criteria match the corresponding data in <paramref name="programDescription"/>.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="programDescription"/> is <c>null</c>.</exception>
        /// <exception cref="System.ArgumentException">Thrown if <paramref name="programIdentifier"/> is invalid.</exception>
        public static bool IsMatchingProgramDescription(this IProgramDescription programDescription, ProgramIdentifier programIdentifier, RomFormat romFormat, bool cfgCrcMustMatch, string code)
        {
            if (programDescription == null)
            {
                throw new ArgumentNullException("programDescription");
            }
            if (programIdentifier == ProgramIdentifier.Invalid)
            {
                throw new ArgumentException("programIdentifier");
            }

            var crcMatch        = programDescription.Crc == programIdentifier.DataCrc;
            var cfgCrcsMatch    = !cfgCrcMustMatch;
            var romFormatsMatch = romFormat == RomFormat.None; // don't care
            var codesMatch      = string.IsNullOrEmpty(code);

            if (programDescription.Rom != null)
            {
                if (!romFormatsMatch)
                {
                    romFormatsMatch = programDescription.Rom.MatchingRomFormat(romFormat, considerOriginalFormat: true);
                }
                crcMatch = programDescription.Rom.MatchesProgramIdentifier(programIdentifier, cfgCrcMustMatch);
                if (cfgCrcMustMatch)
                {
                    cfgCrcsMatch = crcMatch;
                }
            }

            // This may be nearly worthless -- how many XML ProgramInformation implementations are hooked to ProgramDescriptions -- don't they all end up being UserSpecifiedProgramInformation?
            if (!codesMatch && programDescription.ProgramInformation is IntvFunhouseXmlProgramInformation)
            {
                codesMatch = ((IntvFunhouseXmlProgramInformation)programDescription.ProgramInformation).Code == code;
            }
            var match = crcMatch && cfgCrcsMatch && romFormatsMatch && codesMatch;

            return(match);
        }
        /// <summary>
        /// Determines if a given <see cref="IProgramDescription"/> is considered a match based on given criteria.
        /// </summary>
        /// <param name="programDescription">An instance</param>
        /// <param name="programIdentifier">Provides the unique identifier that must match the value that can be determined from <paramref name="programDescription"/>.</param>
        /// <param name="romFormat">If this value is not <see cref="RomFormat.None"/>, then <paramref name="programDescription"/> must have the same ROM format to be a match.</param>
        /// <param name="cfgCrcMustMatch">If <paramref name="romFormat"/> matches and is <see cref="RomFormat.Bin"/>, and this value is <c>true</c>, the CRC of the CFG file must also match.</param>
        /// <returns><c>true</c> if all of the specified criteria match the corresponding data in <paramref name="programDescription"/>.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="programDescription"/> is <c>null</c>.</exception>
        /// <exception cref="System.ArgumentException">Thrown if <paramref name="programIdentifier"/> is invalid.</exception>
        public static bool IsMatchingProgramDescription(this IProgramDescription programDescription, ProgramIdentifier programIdentifier, RomFormat romFormat, bool cfgCrcMustMatch)
        {
            var match = IsMatchingProgramDescription(programDescription, programIdentifier, romFormat, cfgCrcMustMatch, null);

            return(match);
        }
        private IProgramInformation GetProgramInformation(IProgramDescription programDescription, ProgramIdentifier programIdentifier)
        {
            var programInformation = programDescription == null ? null : programDescription.ProgramInformation;

            if ((DefaultInformationSource != null) && (programInformation == null))
            {
                programInformation = DefaultInformationSource.FindProgram(programIdentifier);
            }
            return(programInformation);
        }