Ejemplo n.º 1
0
 /// <summary>
 /// Remove fields with given values
 /// </summary>
 /// <param name="diskArea">DiskArea to remove fields from</param>
 private void RemoveFields(DiskArea diskArea)
 {
     if (DatItemFields.Contains(DatItemField.AreaName))
     {
         diskArea.Name = null;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Read diskarea information
        /// </summary>
        /// <param name="reader">XmlReader representing a diskarea block</param>
        /// <param name="diskArea">DiskArea representing the enclosing area</param>
        private List <DatItem> ReadDiskArea(XmlReader reader, DiskArea diskArea)
        {
            List <DatItem> items = new List <DatItem>();

            while (!reader.EOF)
            {
                // We only want elements
                if (reader.NodeType != XmlNodeType.Element)
                {
                    reader.Read();
                    continue;
                }

                // Get the elements from the software
                switch (reader.Name)
                {
                case "disk":
                    DatItem disk = new Disk
                    {
                        Name       = reader.GetAttribute("name"),
                        SHA1       = reader.GetAttribute("sha1"),
                        ItemStatus = reader.GetAttribute("status").AsItemStatus(),
                        Writable   = reader.GetAttribute("writable").AsYesNo(),

                        DiskArea = diskArea,
                    };

                    items.Add(disk);
                    reader.Read();
                    break;

                default:
                    reader.Read();
                    break;
                }
            }

            return(items);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Read part information
        /// </summary>
        /// <param name="reader">XmlReader representing a part block</param>
        /// <param name="machine">Machine information to pass to contained items</param>
        /// <param name="part">Part information to pass to contained items</param>
        /// <param name="filename">Name of the file to be parsed</param>
        /// <param name="indexId">Index ID for the DAT</param>
        private bool ReadPart(XmlReader reader, Machine machine, Part part, string filename, int indexId)
        {
            // If we have an empty port, skip it
            if (reader == null)
            {
                return(false);
            }

            // Get lists ready
            part.Features = new List <PartFeature>();
            List <DatItem> items = new List <DatItem>();

            while (!reader.EOF)
            {
                // We only want elements
                if (reader.NodeType != XmlNodeType.Element)
                {
                    reader.Read();
                    continue;
                }

                // Get the elements from the software
                switch (reader.Name)
                {
                case "feature":
                    var feature = new PartFeature()
                    {
                        Name  = reader.GetAttribute("name"),
                        Value = reader.GetAttribute("value"),
                    };

                    part.Features.Add(feature);

                    reader.Read();
                    break;

                case "dataarea":
                    var dataArea = new DataArea
                    {
                        Name       = reader.GetAttribute("name"),
                        Size       = Sanitizer.CleanLong(reader.GetAttribute("size")),
                        Width      = Sanitizer.CleanLong(reader.GetAttribute("width")),
                        Endianness = reader.GetAttribute("endianness").AsEndianness(),
                    };

                    List <DatItem> roms = ReadDataArea(reader.ReadSubtree(), dataArea);

                    // If we got valid roms, add them to the list
                    if (roms != null)
                    {
                        items.AddRange(roms);
                    }

                    // Skip the dataarea now that we've processed it
                    reader.Skip();
                    break;

                case "diskarea":
                    var diskArea = new DiskArea
                    {
                        Name = reader.GetAttribute("name"),
                    };

                    List <DatItem> disks = ReadDiskArea(reader.ReadSubtree(), diskArea);

                    // If we got valid disks, add them to the list
                    if (disks != null)
                    {
                        items.AddRange(disks);
                    }

                    // Skip the diskarea now that we've processed it
                    reader.Skip();
                    break;

                case "dipswitch":
                    var dipSwitch = new DipSwitch
                    {
                        Name = reader.GetAttribute("name"),
                        Tag  = reader.GetAttribute("tag"),
                        Mask = reader.GetAttribute("mask"),
                    };

                    // Now read the internal tags
                    ReadDipSwitch(reader.ReadSubtree(), dipSwitch);

                    items.Add(dipSwitch);

                    // Skip the dipswitch now that we've processed it
                    reader.Skip();
                    break;

                default:
                    reader.Read();
                    break;
                }
            }

            // Loop over all of the items, if they exist
            string key = string.Empty;

            foreach (DatItem item in items)
            {
                // Add all missing information
                switch (item.ItemType)
                {
                case ItemType.DipSwitch:
                    (item as DipSwitch).Part = part;
                    break;

                case ItemType.Disk:
                    (item as Disk).Part = part;
                    break;

                case ItemType.Rom:
                    (item as Rom).Part = part;

                    // If the rom is continue or ignore, add the size to the previous rom
                    // TODO: Can this be done on write? We technically lose information this way.
                    // Order is not guaranteed, and since these don't tend to have any way
                    // of determining what the "previous" item was after this, that info would
                    // have to be stored *with* the item somehow
                    if ((item as Rom).LoadFlag == LoadFlag.Continue || (item as Rom).LoadFlag == LoadFlag.Ignore)
                    {
                        int     index   = Items[key].Count - 1;
                        DatItem lastrom = Items[key][index];
                        if (lastrom.ItemType == ItemType.Rom)
                        {
                            (lastrom as Rom).Size += (item as Rom).Size;
                            Items[key].RemoveAt(index);
                            Items[key].Add(lastrom);
                        }

                        continue;
                    }

                    break;
                }

                item.Source = new Source(indexId, filename);
                item.CopyMachineInformation(machine);

                // Finally add each item
                key = ParseAddHelper(item);
            }

            return(items.Any());
        }