/// <summary>
        ///  Converts an instance of <see cref="IProgramInformation"/> to an instance of <see cref="XmlRomInformation"/>.
        /// </summary>
        /// <param name="source">An instance of <see cref="IProgramInformation"/> to convert.</param>
        /// <param name="romVariant">The specific ROM variant to convert.</param>
        /// <param name="setFeatures">If <c>true</c>, set feature values.</param>
        /// <param name="setMetadata">If <c>true</c>, set metadata values.</param>
        /// <returns>An enumerable containing the <see cref="XmlRomInformation"/> objects that result from converting <paramref name="source"/>.</returns>
        public XmlRomInformation Convert(IProgramInformation source, CrcData romVariant, bool setFeatures, bool setMetadata)
        {
            var xmlRomInformation = CreateInitialXmlRomInformation(source, romVariant);

            if (setFeatures)
            {
                xmlRomInformation.SetProgramFeatures(source.Features);
            }
            if (setMetadata)
            {
                xmlRomInformation.SetProgramMetadata(source as IProgramMetadata);
            }
            return(xmlRomInformation);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Modify an existing CRC value in the program information.
        /// </summary>
        /// <param name="programInformation">The program information whose CRC data is to be modified.</param>
        /// <param name="crc">The CRC whose description is to be modified.</param>
        /// <param name="newCrcDescription">The new description of the CRC. If <c>null</c> the description is left unchanged.</param>
        /// <param name="newIncompatibilityFlags">The new incompatibility flags to assign.</param>
        /// <returns><c>true</c> if the new settings were applied, <c>false</c> if the CRC was not found.</returns>
        public static bool ModifyCrc(this IProgramInformation programInformation, uint crc, string newCrcDescription, IncompatibilityFlags newIncompatibilityFlags)
        {
            CrcData crcData     = programInformation.Crcs.FirstOrDefault(x => x.Crc == crc);
            bool    modifiedCrc = crcData != null;

            if (modifiedCrc)
            {
                if (newCrcDescription != null)
                {
                    crcData.Description = newCrcDescription;
                }
                crcData.Incompatibilities = newIncompatibilityFlags;
            }
            return(modifiedCrc);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="INTV.Core.Model.Program.LuigiFileMetadataProgramInformation"/> class.
 /// </summary>
 /// <param name="header">A LUIGI file header that describes the ROM's features.</param>
 /// <param name="metadata">Additional ROM metadata, if any.</param>
 public LuigiFileMetadataProgramInformation(LuigiFileHeader header, LuigiMetadataBlock metadata)
 {
     _features = ProgramFeatures.Combine(header.Features.ToProgramFeatures(), header.Features2.ToProgramFeatures());
     _crc      = new CrcData(header.OriginalRomCrc32, string.Empty, _features.ToIncompatibilityFlags());
     Metadata  = metadata;
     if (metadata != null)
     {
         _title  = metadata.LongNames.FirstOrDefault();
         _vendor = metadata.Publishers.FirstOrDefault();
         if (metadata.ReleaseDates.Any())
         {
             _year = metadata.ReleaseDates.First().Date.Year.ToString();
         }
         _shortName = metadata.ShortNames.FirstOrDefault();
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="INTV.Core.Model.Program.RomFileMetadataProgramInformation"/> class.
        /// </summary>
        /// <param name="rom">The ROM whose metadata program information is desired. If not a RomFormatRom, the
        /// metadata will be empty, and the features will be generic unrecognized ROM features.</param>
        public RomFileMetadataProgramInformation(IRom rom)
        {
            _features = ProgramFeatures.GetUnrecognizedRomFeatures();
            Metadata  = Enumerable.Empty <RomMetadataBlock>();
            var romFormatRom = Rom.AsSpecificRomType <RomFormatRom>(rom);

            if (romFormatRom != null)
            {
                Metadata = romFormatRom.Metadata;
                var stringMetaData = Metadata.FirstOrDefault(m => m.Type == RomMetadataIdTag.Title) as RomMetadataString;
                if ((stringMetaData != null) && !string.IsNullOrEmpty(stringMetaData.StringValue))
                {
                    _title = stringMetaData.StringValue;
                }
                stringMetaData = Metadata.FirstOrDefault(m => m.Type == RomMetadataIdTag.ShortTitle) as RomMetadataString;
                if ((stringMetaData != null) && !string.IsNullOrEmpty(stringMetaData.StringValue))
                {
                    _shortName = stringMetaData.StringValue;
                }
                var date = Metadata.OfType <RomMetadataDate>().FirstOrDefault(d => d.Type == RomMetadataIdTag.ReleaseDate);
                if ((date != null) && date.Date.Flags.HasFlag(MetadataDateTimeFlags.Year))
                {
                    _year = date.Date.Date.Year.ToString();
                }
                var vendor = Metadata.OfType <RomMetadataPublisher>().FirstOrDefault();
                if (vendor != null)
                {
                    _vendor = vendor.Publisher;
                }
                var features = Metadata.OfType <RomMetadataFeatures>().FirstOrDefault();
                if (features != null)
                {
                    _features = features.Features;
                }
                _crc = new CrcData(romFormatRom.Crc, string.Empty, _features.ToIncompatibilityFlags());
            }
        }
Exemplo n.º 5
0
        public CfgFileMetadataProgramInformation(IRom rom)
        {
            _features = ProgramFeatures.GetUnrecognizedRomFeatures();
            Metadata  = Enumerable.Empty <CfgVarMetadataBlock>();
            var binFormatRom = Rom.AsSpecificRomType <BinFormatRom>(rom);

            if (binFormatRom != null)
            {
                Metadata = binFormatRom.Metadata;
                var stringMetaData = Metadata.FirstOrDefault(m => m.Type == CfgVarMetadataIdTag.Name) as CfgVarMetadataString;
                if ((stringMetaData != null) && !string.IsNullOrEmpty(stringMetaData.StringValue))
                {
                    _title = stringMetaData.StringValue;
                }
                stringMetaData = Metadata.FirstOrDefault(m => m.Type == CfgVarMetadataIdTag.ShortName) as CfgVarMetadataString;
                if ((stringMetaData != null) && !string.IsNullOrEmpty(stringMetaData.StringValue))
                {
                    _shortName = stringMetaData.StringValue;
                }
                var date = Metadata.OfType <CfgVarMetadataDate>().FirstOrDefault(d => d.Type == CfgVarMetadataIdTag.ReleaseDate);
                if ((date != null) && date.Date.Flags.HasFlag(MetadataDateTimeFlags.Year))
                {
                    _year = date.Date.Date.Year.ToString();
                }
                var vendor = Metadata.FirstOrDefault(m => m.Type == CfgVarMetadataIdTag.Publisher) as CfgVarMetadataString;
                if (vendor != null)
                {
                    _vendor = vendor.StringValue;
                }

                // NOTE: If these are specified multiple times, the 'last one wins' rule will be in effect.
                // That's technically OK, since the behavior is unspecified. From as1600.txt:
                //
                // Lines marked with a "*" can be repeated.  For example, if a game has multiple
                // authors, you can list them all with their own author variable.  Likewise, if
                // a program was released multiple times, you can give a list of release dates.
                //
                // For other values, repeating a variable does not have a well defined meaning.
                // Typically (but not always), the first instance takes precedence.
                //
                // So in the case of specifying features multiple times, this code will result in
                // 'last one wins'.
                foreach (var feature in Metadata.OfType <CfgVarMetadataFeatureCompatibility>())
                {
                    switch (feature.Type)
                    {
                    case CfgVarMetadataIdTag.Ecs:
                    case CfgVarMetadataIdTag.EcsCompatibility:
                        _features.Ecs = (EcsFeatures)feature.Compatibility;
                        break;

                    case CfgVarMetadataIdTag.Voice:
                    case CfgVarMetadataIdTag.IntellivoiceCompatibility:
                        _features.Intellivoice = feature.Compatibility;
                        break;

                    case CfgVarMetadataIdTag.IntellivisionII:
                    case CfgVarMetadataIdTag.IntellivisionIICompatibility:
                        _features.IntellivisionII = feature.Compatibility;
                        break;

                    case CfgVarMetadataIdTag.KeyboardComponentCompatibility:
                        _features.KeyboardComponent = (KeyboardComponentFeatures)feature.Compatibility;
                        break;

                    case CfgVarMetadataIdTag.TutorvisionCompatibility:
                        _features.Tutorvision = feature.Compatibility;
                        break;

                    case CfgVarMetadataIdTag.JlpAccelerators:
                    case CfgVarMetadataIdTag.Jlp:
                        _features.Jlp = (JlpFeatures)feature.Compatibility;
                        if (_features.Jlp != JlpFeatures.Incompatible)
                        {
                            _features.JlpHardwareVersion = JlpHardwareVersion.Jlp03;     // Assume minimal hardware version needed
                            if (_features.Jlp > JlpFeatures.Tolerates)
                            {
                                // Flash storage is indicated, so check for it.
                                var flashStorage = Metadata.FirstOrDefault(m => m.Type == CfgVarMetadataIdTag.JlpFlash) as CfgVarMetadataInteger;
                                if ((flashStorage != null) && (flashStorage.IntegerValue > 0))
                                {
                                    // TODO: Min value checking here?
                                    _features.JlpFlashMinimumSaveSectors = (ushort)flashStorage.IntegerValue;
                                    _features.Jlp |= JlpFeatures.SaveDataRequired;
                                }
                            }
                        }
                        break;

                    default:
                        break;
                    }
                }
                var ltoMapper = Metadata.FirstOrDefault(m => m.Type == CfgVarMetadataIdTag.LtoFlashMapper) as CfgVarMetadataBoolean;
                if (ltoMapper != null)
                {
                    _features.LtoFlash = LtoFlashFeatures.Requires | LtoFlashFeatures.LtoFlashMemoryMapped;
                }
                _crc = new CrcData(binFormatRom.Crc, string.Empty, _features.ToIncompatibilityFlags());
            }
        }
        private static XmlRomInformation CreateInitialXmlRomInformation(IProgramInformation source, CrcData romVariant)
        {
            var xmlRomInformation = XmlRomInformation.CreateDefault();

            xmlRomInformation.GetColumn(XmlRomInformationDatabaseColumnName.title).Value      = source.Title.EncodeHtmlString();
            xmlRomInformation.GetColumn(XmlRomInformationDatabaseColumnName.vendor).Value     = source.Vendor.EncodeHtmlString();
            xmlRomInformation.GetColumn(XmlRomInformationDatabaseColumnName.short_name).Value = source.ShortName.EncodeHtmlString();
            xmlRomInformation.GetColumn(XmlRomInformationDatabaseColumnName.origin).Value     = ProgramInformationOriginToDatabaseString.Instance.Convert(source.DataOrigin);

            if (source.Features != null)
            {
                xmlRomInformation.GetColumn(XmlRomInformationDatabaseColumnName.type).Value = GeneralFeaturesToRomTypeStringConverter.Instance.Convert(source.Features.GeneralFeatures);
            }

            if (!string.IsNullOrEmpty(source.Year))
            {
                int year;
                if ((source.Year.Length == 4) && int.TryParse(source.Year, NumberStyles.None, CultureInfo.InvariantCulture, out year))
                {
                    // Only have year, so assume 01 Jan. This will be superseded if metadata contains release date (taking first one).
                    xmlRomInformation.GetColumn(XmlRomInformationDatabaseColumnName.release_date).Value = string.Format(CultureInfo.InvariantCulture, "{0:0000}-01-01", year);
                }
            }

            if (!string.IsNullOrEmpty(romVariant.Description))
            {
                xmlRomInformation.GetColumn(XmlRomInformationDatabaseColumnName.name).Value = romVariant.Description.EncodeHtmlString();
            }

            return(xmlRomInformation);
        }