コード例 #1
0
        /// <summary>
        /// Fill any missing size and hash information from another Rom
        /// </summary>
        /// <param name="other">Rom to fill information from</param>
        public void FillMissingInformation(Rom other)
        {
            if (Size == null && other.Size != null)
            {
                Size = other.Size;
            }

            if (_crc.IsNullOrEmpty() && !other._crc.IsNullOrEmpty())
            {
                _crc = other._crc;
            }

            if (_md5.IsNullOrEmpty() && !other._md5.IsNullOrEmpty())
            {
                _md5 = other._md5;
            }

#if NET_FRAMEWORK
            if (_ripemd160.IsNullOrEmpty() && !other._ripemd160.IsNullOrEmpty())
            {
                _ripemd160 = other._ripemd160;
            }
#endif

            if (_sha1.IsNullOrEmpty() && !other._sha1.IsNullOrEmpty())
            {
                _sha1 = other._sha1;
            }

            if (_sha256.IsNullOrEmpty() && !other._sha256.IsNullOrEmpty())
            {
                _sha256 = other._sha256;
            }

            if (_sha384.IsNullOrEmpty() && !other._sha384.IsNullOrEmpty())
            {
                _sha384 = other._sha384;
            }

            if (_sha512.IsNullOrEmpty() && !other._sha512.IsNullOrEmpty())
            {
                _sha512 = other._sha512;
            }

            if (_spamsum.IsNullOrEmpty() && !other._spamsum.IsNullOrEmpty())
            {
                _spamsum = other._spamsum;
            }
        }
コード例 #2
0
        /// <summary>
        /// Convert a media to the closest Rom approximation
        /// </summary>
        /// <returns></returns>
        public Rom ConvertToRom()
        {
            var rom = new Rom()
            {
                ItemType = ItemType.Rom,
                DupeType = this.DupeType,

                Machine = this.Machine.Clone() as Machine,
                Source  = this.Source.Clone() as Source,
                Remove  = this.Remove,

                Name    = this.Name + ".aif",
                MD5     = this.MD5,
                SHA1    = this.SHA1,
                SHA256  = this.SHA256,
                SpamSum = this.SpamSum,
            };

            return(rom);
        }
コード例 #3
0
        /// <summary>
        /// Resolve name duplicates in an arbitrary set of ROMs based on the supplied information
        /// </summary>
        /// <param name="infiles">List of File objects representing the roms to be merged</param>
        /// <returns>A List of DatItem objects representing the renamed roms</returns>
        public static List <DatItem> ResolveNames(List <DatItem> infiles)
        {
            // Create the output list
            List <DatItem> output = new List <DatItem>();

            // First we want to make sure the list is in alphabetical order
            Sort(ref infiles, true);

            // Now we want to loop through and check names
            DatItem lastItem    = null;
            string  lastrenamed = null;
            int     lastid      = 0;

            for (int i = 0; i < infiles.Count; i++)
            {
                DatItem datItem = infiles[i];

                // If we have the first item, we automatically add it
                if (lastItem == null)
                {
                    output.Add(datItem);
                    lastItem = datItem;
                    continue;
                }

                // If the current item exactly matches the last item, then we don't add it
                if ((datItem.GetDuplicateStatus(lastItem) & DupeType.All) != 0)
                {
                    Globals.Logger.Verbose("Exact duplicate found for '{0}'", datItem.Name);
                    continue;
                }

                // If the current name matches the previous name, rename the current item
                else if (datItem.Name == lastItem.Name)
                {
                    Globals.Logger.Verbose("Name duplicate found for '{0}'", datItem.Name);

                    if (datItem.ItemType == ItemType.Disk)
                    {
                        Disk disk = (Disk)datItem;
                        disk.Name += "_" + (!String.IsNullOrWhiteSpace(disk.MD5)
                            ? disk.MD5
                            : !String.IsNullOrWhiteSpace(disk.SHA1)
                                ? disk.SHA1
                                : "1");
                        datItem     = disk;
                        lastrenamed = lastrenamed ?? datItem.Name;
                    }
                    else if (datItem.ItemType == ItemType.Rom)
                    {
                        Rom rom = (Rom)datItem;
                        rom.Name += "_" + (!String.IsNullOrWhiteSpace(rom.CRC)
                            ? rom.CRC
                            : !String.IsNullOrWhiteSpace(rom.MD5)
                                ? rom.MD5
                                : !String.IsNullOrWhiteSpace(rom.SHA1)
                                    ? rom.SHA1
                                    : "1");
                        datItem     = rom;
                        lastrenamed = lastrenamed ?? datItem.Name;
                    }

                    // If we have a conflict with the last renamed item, do the right thing
                    if (datItem.Name == lastrenamed)
                    {
                        lastrenamed   = datItem.Name;
                        datItem.Name += (lastid == 0 ? "" : "_" + lastid);
                        lastid++;
                    }
                    // If we have no conflict, then we want to reset the lastrenamed and id
                    else
                    {
                        lastrenamed = null;
                        lastid      = 0;
                    }

                    output.Add(datItem);
                }

                // Otherwise, we say that we have a valid named file
                else
                {
                    output.Add(datItem);
                    lastItem    = datItem;
                    lastrenamed = null;
                    lastid      = 0;
                }
            }

            // One last sort to make sure this is ordered
            Sort(ref output, true);

            return(output);
        }
コード例 #4
0
        /// <summary>
        /// Merge an arbitrary set of ROMs based on the supplied information
        /// </summary>
        /// <param name="infiles">List of File objects representing the roms to be merged</param>
        /// <returns>A List of DatItem objects representing the merged roms</returns>
        public static List <DatItem> Merge(List <DatItem> infiles)
        {
            // Check for null or blank roms first
            if (infiles == null || infiles.Count == 0)
            {
                return(new List <DatItem>());
            }

            // Create output list
            List <DatItem> outfiles = new List <DatItem>();

            // Then deduplicate them by checking to see if data matches previous saved roms
            int nodumpCount = 0;

            foreach (DatItem file in infiles)
            {
                // If we don't have a Rom or a Disk, we skip checking for duplicates
                if (file.ItemType != ItemType.Rom && file.ItemType != ItemType.Disk)
                {
                    continue;
                }

                // If it's a nodump, add and skip
                if (file.ItemType == ItemType.Rom && ((Rom)file).ItemStatus == ItemStatus.Nodump)
                {
                    outfiles.Add(file);
                    nodumpCount++;
                    continue;
                }
                else if (file.ItemType == ItemType.Disk && ((Disk)file).ItemStatus == ItemStatus.Nodump)
                {
                    outfiles.Add(file);
                    nodumpCount++;
                    continue;
                }
                // If it's the first non-nodump rom in the list, don't touch it
                else if (outfiles.Count == 0 || outfiles.Count == nodumpCount)
                {
                    outfiles.Add(file);
                    continue;
                }

                // Check if the rom is a duplicate
                DupeType dupetype  = 0x00;
                DatItem  saveditem = new Rom();
                int      pos       = -1;
                for (int i = 0; i < outfiles.Count; i++)
                {
                    DatItem lastrom = outfiles[i];

                    // Get the duplicate status
                    dupetype = file.GetDuplicateStatus(lastrom);

                    // If it's a duplicate, skip adding it to the output but add any missing information
                    if (dupetype != 0x00)
                    {
                        saveditem = lastrom;
                        pos       = i;

                        // Roms have more infomration to save
                        if (file.ItemType == ItemType.Rom)
                        {
                            ((Rom)saveditem).Size = (((Rom)saveditem).Size == -1 && ((Rom)file).Size != -1
                                ? ((Rom)file).Size
                                : ((Rom)saveditem).Size);
                            ((Rom)saveditem).CRC = (String.IsNullOrWhiteSpace(((Rom)saveditem).CRC) && !String.IsNullOrWhiteSpace(((Rom)file).CRC)
                                ? ((Rom)file).CRC
                                : ((Rom)saveditem).CRC);
                            ((Rom)saveditem).MD5 = (String.IsNullOrWhiteSpace(((Rom)saveditem).MD5) && !String.IsNullOrWhiteSpace(((Rom)file).MD5)
                                ? ((Rom)file).MD5
                                : ((Rom)saveditem).MD5);
                            ((Rom)saveditem).SHA1 = (String.IsNullOrWhiteSpace(((Rom)saveditem).SHA1) && !String.IsNullOrWhiteSpace(((Rom)file).SHA1)
                                ? ((Rom)file).SHA1
                                : ((Rom)saveditem).SHA1);
                            ((Rom)saveditem).SHA256 = (String.IsNullOrWhiteSpace(((Rom)saveditem).SHA256) && !String.IsNullOrWhiteSpace(((Rom)file).SHA256)
                                ? ((Rom)file).SHA256
                                : ((Rom)saveditem).SHA256);
                            ((Rom)saveditem).SHA384 = (String.IsNullOrWhiteSpace(((Rom)saveditem).SHA384) && !String.IsNullOrWhiteSpace(((Rom)file).SHA384)
                                ? ((Rom)file).SHA384
                                : ((Rom)saveditem).SHA384);
                            ((Rom)saveditem).SHA512 = (String.IsNullOrWhiteSpace(((Rom)saveditem).SHA512) && !String.IsNullOrWhiteSpace(((Rom)file).SHA512)
                                ? ((Rom)file).SHA512
                                : ((Rom)saveditem).SHA512);
                        }
                        else if (file.ItemType == ItemType.Disk)
                        {
                            ((Disk)saveditem).MD5 = (String.IsNullOrWhiteSpace(((Disk)saveditem).MD5) && !String.IsNullOrWhiteSpace(((Disk)file).MD5)
                                ? ((Disk)file).MD5
                                : ((Disk)saveditem).MD5);
                            ((Disk)saveditem).SHA1 = (String.IsNullOrWhiteSpace(((Disk)saveditem).SHA1) && !String.IsNullOrWhiteSpace(((Disk)file).SHA1)
                                ? ((Disk)file).SHA1
                                : ((Disk)saveditem).SHA1);
                            ((Disk)saveditem).SHA256 = (String.IsNullOrWhiteSpace(((Disk)saveditem).SHA256) && !String.IsNullOrWhiteSpace(((Disk)file).SHA256)
                                ? ((Disk)file).SHA256
                                : ((Disk)saveditem).SHA256);
                            ((Disk)saveditem).SHA384 = (String.IsNullOrWhiteSpace(((Disk)saveditem).SHA384) && !String.IsNullOrWhiteSpace(((Disk)file).SHA384)
                                ? ((Disk)file).SHA384
                                : ((Disk)saveditem).SHA384);
                            ((Disk)saveditem).SHA512 = (String.IsNullOrWhiteSpace(((Disk)saveditem).SHA512) && !String.IsNullOrWhiteSpace(((Disk)file).SHA512)
                                ? ((Disk)file).SHA512
                                : ((Disk)saveditem).SHA512);
                        }

                        saveditem.DupeType = dupetype;

                        // If the current system has a lower ID than the previous, set the system accordingly
                        if (file.SystemID < saveditem.SystemID)
                        {
                            saveditem.SystemID = file.SystemID;
                            saveditem.System   = file.System;
                            saveditem.CopyMachineInformation(file);
                            saveditem.Name = file.Name;
                        }

                        // If the current source has a lower ID than the previous, set the source accordingly
                        if (file.SourceID < saveditem.SourceID)
                        {
                            saveditem.SourceID = file.SourceID;
                            saveditem.Source   = file.Source;
                            saveditem.CopyMachineInformation(file);
                            saveditem.Name = file.Name;
                        }

                        // If the current machine is a child of the new machine, use the new machine instead
                        if (saveditem.CloneOf == file.MachineName || saveditem.RomOf == file.MachineName)
                        {
                            saveditem.CopyMachineInformation(file);
                            saveditem.Name = file.Name;
                        }

                        break;
                    }
                }

                // If no duplicate is found, add it to the list
                if (dupetype == 0x00)
                {
                    outfiles.Add(file);
                }
                // Otherwise, if a new rom information is found, add that
                else
                {
                    outfiles.RemoveAt(pos);
                    outfiles.Insert(pos, saveditem);
                }
            }

            // Then return the result
            return(outfiles);
        }
コード例 #5
0
        /// <summary>
        /// Replace fields from another item
        /// </summary>
        /// <param name="item">DatItem to pull new information from</param>
        /// <param name="fields">List of Fields representing what should be updated</param>
        public override void ReplaceFields(DatItem item, List <Field> fields)
        {
            // Replace common fields first
            base.ReplaceFields(item, fields);

            // If we don't have a Rom to replace from, ignore specific fields
            if (item.ItemType != ItemType.Rom)
            {
                return;
            }

            // Cast for easier access
            Rom newItem = item as Rom;

            // Replace the fields

            #region Common

            if (fields.Contains(Field.DatItem_Name))
            {
                Name = newItem.Name;
            }

            if (fields.Contains(Field.DatItem_Bios))
            {
                Bios = newItem.Bios;
            }

            if (fields.Contains(Field.DatItem_Size))
            {
                Size = newItem.Size;
            }

            if (fields.Contains(Field.DatItem_CRC))
            {
                if (string.IsNullOrEmpty(CRC) && !string.IsNullOrEmpty(newItem.CRC))
                {
                    CRC = newItem.CRC;
                }
            }

            if (fields.Contains(Field.DatItem_MD5))
            {
                if (string.IsNullOrEmpty(MD5) && !string.IsNullOrEmpty(newItem.MD5))
                {
                    MD5 = newItem.MD5;
                }
            }

#if NET_FRAMEWORK
            if (fields.Contains(Field.DatItem_RIPEMD160))
            {
                if (string.IsNullOrEmpty(RIPEMD160) && !string.IsNullOrEmpty(newItem.RIPEMD160))
                {
                    RIPEMD160 = newItem.RIPEMD160;
                }
            }
#endif

            if (fields.Contains(Field.DatItem_SHA1))
            {
                if (string.IsNullOrEmpty(SHA1) && !string.IsNullOrEmpty(newItem.SHA1))
                {
                    SHA1 = newItem.SHA1;
                }
            }

            if (fields.Contains(Field.DatItem_SHA256))
            {
                if (string.IsNullOrEmpty(SHA256) && !string.IsNullOrEmpty(newItem.SHA256))
                {
                    SHA256 = newItem.SHA256;
                }
            }

            if (fields.Contains(Field.DatItem_SHA384))
            {
                if (string.IsNullOrEmpty(SHA384) && !string.IsNullOrEmpty(newItem.SHA384))
                {
                    SHA384 = newItem.SHA384;
                }
            }

            if (fields.Contains(Field.DatItem_SHA512))
            {
                if (string.IsNullOrEmpty(SHA512) && !string.IsNullOrEmpty(newItem.SHA512))
                {
                    SHA512 = newItem.SHA512;
                }
            }

            if (fields.Contains(Field.DatItem_SpamSum))
            {
                if (string.IsNullOrEmpty(SpamSum) && !string.IsNullOrEmpty(newItem.SpamSum))
                {
                    SpamSum = newItem.SpamSum;
                }
            }

            if (fields.Contains(Field.DatItem_Merge))
            {
                MergeTag = newItem.MergeTag;
            }

            if (fields.Contains(Field.DatItem_Region))
            {
                Region = newItem.Region;
            }

            if (fields.Contains(Field.DatItem_Offset))
            {
                Offset = newItem.Offset;
            }

            if (fields.Contains(Field.DatItem_Date))
            {
                Date = newItem.Date;
            }

            if (fields.Contains(Field.DatItem_Status))
            {
                ItemStatus = newItem.ItemStatus;
            }

            if (fields.Contains(Field.DatItem_Optional))
            {
                Optional = newItem.Optional;
            }

            if (fields.Contains(Field.DatItem_Inverted))
            {
                Inverted = newItem.Inverted;
            }

            #endregion

            #region AttractMode

            if (fields.Contains(Field.DatItem_AltName))
            {
                AltName = newItem.AltName;
            }

            if (fields.Contains(Field.DatItem_AltTitle))
            {
                AltTitle = newItem.AltTitle;
            }

            #endregion

            #region OpenMSX

            if (fields.Contains(Field.DatItem_Original))
            {
                Original = newItem.Original;
            }

            if (fields.Contains(Field.DatItem_OpenMSXSubType))
            {
                OpenMSXSubType = newItem.OpenMSXSubType;
            }

            if (fields.Contains(Field.DatItem_OpenMSXType))
            {
                OpenMSXType = newItem.OpenMSXType;
            }

            if (fields.Contains(Field.DatItem_Remark))
            {
                Remark = newItem.Remark;
            }

            if (fields.Contains(Field.DatItem_Boot))
            {
                Boot = newItem.Boot;
            }

            #endregion

            #region SoftwareList

            if (fields.Contains(Field.DatItem_LoadFlag))
            {
                LoadFlag = newItem.LoadFlag;
            }

            if (fields.Contains(Field.DatItem_Value))
            {
                Value = newItem.Value;
            }

            if (DataAreaSpecified && newItem.DataAreaSpecified)
            {
                DataArea.ReplaceFields(newItem.DataArea, fields);
            }

            if (PartSpecified && newItem.PartSpecified)
            {
                Part.ReplaceFields(newItem.Part, fields);
            }

            #endregion
        }