[DatItems] Add reading Blanks where appropriate

This commit is contained in:
Matt Nadareski
2018-01-04 01:12:49 -08:00
parent 8f85f7af8a
commit 33283b7ea5
4 changed files with 72 additions and 39 deletions

View File

@@ -58,7 +58,7 @@ namespace SabreTools.Library.DatFiles
Encoding enc = Utilities.GetEncoding(filename);
StreamReader sr = new StreamReader(Utilities.TryOpenRead(filename), enc);
bool block = false, superdat = false;
bool block = false, superdat = false, containsItems = false;
string blockname = "", tempgamename = "", gamedesc = "", cloneof = "",
romof = "", sampleof = "", year = "", manufacturer = "";
while (!sr.EndOfStream)
@@ -82,6 +82,7 @@ namespace SabreTools.Library.DatFiles
}
block = true;
containsItems = false;
}
// If the line is a rom-like item and we're in a block
@@ -91,6 +92,7 @@ namespace SabreTools.Library.DatFiles
|| (line.Trim().StartsWith("sample") && !line.Trim().StartsWith("sampleof"))
) && block)
{
containsItems = true;
ItemType temptype = ItemType.Rom;
if (line.Trim().StartsWith("rom ("))
{
@@ -535,52 +537,19 @@ namespace SabreTools.Library.DatFiles
case "forcemerging":
if (ForceMerging == ForceMerging.None)
{
switch (itemval)
{
case "none":
ForceMerging = ForceMerging.None;
break;
case "split":
ForceMerging = ForceMerging.Split;
break;
case "merged":
ForceMerging = ForceMerging.Merged;
break;
case "nonmerged":
ForceMerging = ForceMerging.NonMerged;
break;
case "full":
ForceMerging = ForceMerging.Full;
break;
}
ForceMerging = Utilities.GetForceMerging(itemval);
}
break;
case "forcezipping":
if (ForcePacking == ForcePacking.None)
{
switch (itemval)
{
case "yes":
ForcePacking = ForcePacking.Zip;
break;
case "no":
ForcePacking = ForcePacking.Unzip;
break;
}
ForcePacking = Utilities.GetForcePacking(itemval);
}
break;
case "forcepacking":
if (ForcePacking == ForcePacking.None)
{
switch (itemval)
{
case "zip":
ForcePacking = ForcePacking.Zip;
break;
case "unzip":
ForcePacking = ForcePacking.Unzip;
break;
}
ForcePacking = Utilities.GetForcePacking(itemval);
}
break;
}
@@ -590,7 +559,28 @@ namespace SabreTools.Library.DatFiles
// If we find an end bracket that's not associated with anything else, the block is done
else if (Regex.IsMatch(line, Constants.EndPatternCMP) && block)
{
block = false;
// If no items were found for this machine, add a Blank placeholder
if (!containsItems)
{
Blank blank = new Blank()
{
MachineName = tempgamename,
MachineDescription = gamedesc,
CloneOf = cloneof,
RomOf = romof,
SampleOf = sampleof,
Manufacturer = manufacturer,
Year = year,
SystemID = sysid,
SourceID = srcid,
};
// Now process and add the rom
ParseAddHelper(blank, clean, remUnicode);
}
block = false, containsItems = false;
blockname = ""; tempgamename = ""; gamedesc = ""; cloneof = "";
romof = ""; sampleof = ""; year = ""; manufacturer = "";
}

View File

@@ -2957,10 +2957,13 @@ namespace SabreTools.Library.DatFiles
foreach (DatItem item in parentItems)
{
DatItem datItem = (DatItem)item.Clone();
while (this[game].Contains(datItem))
{
Remove(game, datItem);
}
}
}
}
/// <summary>
/// Use cloneof tags to remove roms from the children
@@ -3274,6 +3277,7 @@ namespace SabreTools.Library.DatFiles
{
case ItemType.Archive:
case ItemType.BiosSet:
case ItemType.Blank:
case ItemType.Release:
case ItemType.Sample:
key = item.Type.ToString();

View File

@@ -501,6 +501,7 @@ namespace SabreTools.Library.DatFiles
long? areasize = null;
List<Tuple<string, string>> infos = new List<Tuple<string, string>>();
List<Tuple<string, string>> features = new List<Tuple<string, string>>();
bool containsItems = false;
// We want to process the entire subtree of the game
subreader = xtr.ReadSubtree();
@@ -623,6 +624,7 @@ namespace SabreTools.Library.DatFiles
break;
case "romCRC":
empty = false;
containsItems = true;
ext = (subreader.GetAttribute("extension") ?? "");
@@ -698,6 +700,7 @@ namespace SabreTools.Library.DatFiles
break;
case "release":
empty = false;
containsItems = true;
bool? defaultrel = null;
if (subreader.GetAttribute("default") != null)
@@ -739,6 +742,7 @@ namespace SabreTools.Library.DatFiles
break;
case "biosset":
empty = false;
containsItems = true;
bool? defaultbios = null;
if (subreader.GetAttribute("default") != null)
@@ -782,6 +786,7 @@ namespace SabreTools.Library.DatFiles
break;
case "archive":
empty = false;
containsItems = true;
DatItem archiverom = new Archive
{
@@ -810,6 +815,7 @@ namespace SabreTools.Library.DatFiles
break;
case "sample":
empty = false;
containsItems = true;
DatItem samplerom = new Sample
{
@@ -839,6 +845,7 @@ namespace SabreTools.Library.DatFiles
case "rom":
case "disk":
empty = false;
containsItems = true;
// If the rom has a merge tag, add it
string merge = subreader.GetAttribute("merge");
@@ -983,6 +990,31 @@ namespace SabreTools.Library.DatFiles
}
}
// If no items were found for this machine, add a Blank placeholder
if (!containsItems)
{
Blank blank = new Blank()
{
Supported = supported,
Publisher = publisher,
Infos = infos,
PartName = partname,
PartInterface = partinterface,
Features = features,
AreaName = areaname,
AreaSize = areasize,
SystemID = sysid,
System = filename,
SourceID = srcid,
}
blank.CopyMachineInformation(machine);
// Now process and add the rom
key = ParseAddHelper(blank, clean, remUnicode);
}
xtr.Skip();
break;
case "dir":
@@ -1004,6 +1036,7 @@ namespace SabreTools.Library.DatFiles
break;
case "file":
empty = false;
containsItems = true;
// If the rom is itemStatus, flag it
its = ItemStatus.None;

View File

@@ -665,6 +665,10 @@ namespace SabreTools.Library.Tools
return ForceMerging.None;
case "split":
return ForceMerging.Split;
case "merged":
return ForceMerging.Merged;
case "nonmerged":
return ForceMerging.NonMerged;
case "full":
return ForceMerging.Full;
}
@@ -703,8 +707,10 @@ namespace SabreTools.Library.Tools
case "none":
default:
return ForcePacking.None;
case "yes":
case "zip":
return ForcePacking.Zip;
case "no":
case "unzip":
return ForcePacking.Unzip;
}