[DatTools] Add even more things to read

This commit is contained in:
Matt Nadareski
2016-09-13 10:48:45 -07:00
parent 2722ab668e
commit 35160ecf6e
2 changed files with 269 additions and 120 deletions

View File

@@ -205,6 +205,12 @@ namespace SabreTools.Helper
public string Date;
public SourceMetadata Metadata;
// Non rom or disk
public string Region;
public string Language;
public bool? Default;
public string Description;
public int CompareTo(object obj)
{
int ret = 0;

View File

@@ -280,9 +280,31 @@ namespace SabreTools.Helper
block = true;
}
// If the line is a rom or disk and we're in a block
else if ((line.Trim().StartsWith("rom (") || line.Trim().StartsWith("disk (") || line.Trim().StartsWith("file (")) && block)
// If the line is a rom-like item and we're in a block
else if ((line.Trim().StartsWith("rom (")
|| line.Trim().StartsWith("disk (")
|| line.Trim().StartsWith("file (")
|| (line.Trim().StartsWith("sample") && !line.Trim().StartsWith("sampleof"))
) && block)
{
ItemType temptype = ItemType.Rom;
if (line.Trim().StartsWith("rom ("))
{
temptype = ItemType.Rom;
}
else if (line.Trim().StartsWith("disk ("))
{
temptype = ItemType.Disk;
}
else if (line.Trim().StartsWith("file ("))
{
temptype = ItemType.Rom;
}
else if (line.Trim().StartsWith("sample"))
{
temptype = ItemType.Sample;
}
Rom rom = new Rom
{
Machine = new Machine
@@ -295,10 +317,20 @@ namespace SabreTools.Helper
Manufacturer = manufacturer,
Year = year,
},
Type = (line.Trim().StartsWith("disk (") ? ItemType.Disk : ItemType.Rom),
Type = temptype,
Metadata = new SourceMetadata { SystemID = sysid, SourceID = srcid },
};
// If we have a sample, treat it special
if (temptype == ItemType.Sample)
{
line = line.Trim().Remove(0, 6).Trim().Replace("\"", ""); // Remove "sample" from the input string
rom.Name = line;
}
// Otherwise, process the rest of the line
else
{
string[] gc = line.Trim().Split(' ');
// Loop over all attributes and add them if possible
@@ -348,7 +380,7 @@ namespace SabreTools.Helper
}
break;
case "date":
rom.Date = gc[i].Replace("\"", "") + " " + gc[i+1].Replace("\"", "");
rom.Date = gc[i].Replace("\"", "") + " " + gc[i + 1].Replace("\"", "");
i++;
break;
}
@@ -419,6 +451,7 @@ namespace SabreTools.Helper
val = "";
}
}
}
// Now process and add the rom
string key = "";
@@ -529,7 +562,15 @@ namespace SabreTools.Helper
}
break;
case "forcezipping":
datdata.ForcePacking = (itemval == "yes" ? ForcePacking.Zip : ForcePacking.Unzip);
switch (itemval)
{
case "yes":
datdata.ForcePacking = ForcePacking.Zip;
break;
case "no":
datdata.ForcePacking = ForcePacking.Unzip;
break;
}
break;
}
}
@@ -962,10 +1003,15 @@ namespace SabreTools.Helper
superdat = superdat || content.Contains("SuperDAT");
break;
case "clrmamepro":
case "romcenter":
if (headreader.GetAttribute("header") != null)
{
datdata.Header = (String.IsNullOrEmpty(datdata.Header) ? headreader.GetAttribute("header") : datdata.Header);
}
if (headreader.GetAttribute("plugin") != null)
{
datdata.Header = (String.IsNullOrEmpty(datdata.Header) ? headreader.GetAttribute("plugin") : datdata.Header);
}
if (headreader.GetAttribute("forcemerging") != null)
{
switch (headreader.GetAttribute("forcemerging"))
@@ -1172,6 +1218,101 @@ namespace SabreTools.Helper
case "manufacturer":
manufacturer = subreader.ReadElementContentAsString();
break;
case "release":
bool? defaultrel = null;
if (subreader.GetAttribute("default") != null)
{
if (subreader.GetAttribute("default") == "yes")
{
defaultrel = true;
}
else if (subreader.GetAttribute("default") == "no")
{
defaultrel = false;
}
}
Rom relrom = new Rom
{
Machine = new Machine
{
Name = tempname,
Description = gamedesc,
RomOf = romof,
CloneOf = cloneof,
SampleOf = sampleof,
},
Name = subreader.GetAttribute("name"),
Type = ItemType.Release,
Region = subreader.GetAttribute("region"),
Language = subreader.GetAttribute("language"),
Default = defaultrel,
Metadata = new SourceMetadata { SystemID = sysid, System = filename, SourceID = srcid },
};
// Now process and add the rom
datdata = ParseAddHelper(relrom, datdata, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, trim, single, root, clean, logger, out key);
subreader.Read();
break;
case "biosset":
bool? defaultbios = null;
if (subreader.GetAttribute("default") != null)
{
if (subreader.GetAttribute("default") == "yes")
{
defaultbios = true;
}
else if (subreader.GetAttribute("default") == "no")
{
defaultbios = false;
}
}
Rom biosrom = new Rom
{
Machine = new Machine
{
Name = tempname,
Description = gamedesc,
RomOf = romof,
CloneOf = cloneof,
SampleOf = sampleof,
},
Name = subreader.GetAttribute("name"),
Type = ItemType.BiosSet,
Description = subreader.GetAttribute("description"),
Default = defaultbios,
Metadata = new SourceMetadata { SystemID = sysid, System = filename, SourceID = srcid },
};
// Now process and add the rom
datdata = ParseAddHelper(biosrom, datdata, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, trim, single, root, clean, logger, out key);
subreader.Read();
break;
case "archive":
case "sample":
Rom samplerom = new Rom
{
Machine = new Machine
{
Name = tempname,
Description = gamedesc,
RomOf = romof,
CloneOf = cloneof,
SampleOf = sampleof,
},
Name = subreader.GetAttribute("name"),
Type = (subreader.Name == "sample" ? ItemType.Sample : ItemType.Archive),
Metadata = new SourceMetadata { SystemID = sysid, System = filename, SourceID = srcid },
};
// Now process and add the rom
datdata = ParseAddHelper(samplerom, datdata, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, trim, single, root, clean, logger, out key);
subreader.Read();
break;
case "rom":
case "disk":
empty = false;
@@ -3071,7 +3212,9 @@ namespace SabreTools.Helper
state += rom.HashData.SHA1 + " *" + rom.Name + "\n";
break;
case OutputFormat.RomCenter:
state += ¬¬" + HttpUtility.HtmlEncode(rom.Machine) +
state += "¬" + (String.IsNullOrEmpty(rom.Machine.CloneOf) ? "" : HttpUtility.HtmlEncode(rom.Machine.CloneOf)) +
"¬" + (String.IsNullOrEmpty(rom.Machine.CloneOf) ? "" : HttpUtility.HtmlEncode(rom.Machine.CloneOf)) +
"¬" + HttpUtility.HtmlEncode(rom.Machine.Name) +
"¬" + HttpUtility.HtmlEncode((String.IsNullOrEmpty(rom.Machine.Description) ? rom.Machine.Name : rom.Machine.Description)) +
"¬" + HttpUtility.HtmlEncode(rom.Name) +
"¬" + rom.HashData.CRC.ToLowerInvariant() +