[Structs, Enums] Add ItemType enum

This commit is contained in:
Matt Nadareski
2016-08-29 13:50:55 -07:00
parent 19a210562e
commit 638ba055eb
8 changed files with 51 additions and 38 deletions

View File

@@ -59,6 +59,19 @@ namespace SabreTools.Helper
ExternalAll = 4, ExternalAll = 4,
} }
/// <summary>
/// Determine what type of file an item is
/// </summary>
public enum ItemType
{
Rom = 0,
Disk = 1,
Sample = 2,
Release = 3,
BiosSet = 4,
Archive = 5,
}
/// <summary> /// <summary>
/// Determines forcemerging tag for DAT output /// Determines forcemerging tag for DAT output
/// </summary> /// </summary>

View File

@@ -48,7 +48,7 @@ namespace SabreTools.Helper
{ {
public Machine Machine; public Machine Machine;
public string Name; public string Name;
public string Type; public ItemType Type;
public HashData HashData; public HashData HashData;
public DupeType Dupe; public DupeType Dupe;
public bool Nodump; public bool Nodump;

View File

@@ -536,7 +536,7 @@ namespace SabreTools.Helper
roms.Add(new Rom roms.Add(new Rom
{ {
Type = "rom", Type = ItemType.Rom,
Name = reader.Entry.Key, Name = reader.Entry.Key,
Machine = new Machine Machine = new Machine
{ {
@@ -620,7 +620,7 @@ namespace SabreTools.Helper
Rom rom = new Rom Rom rom = new Rom
{ {
Type = "rom", Type = ItemType.Rom,
Machine = new Machine Machine = new Machine
{ {
Name = Path.GetFileNameWithoutExtension(input).ToLowerInvariant(), Name = Path.GetFileNameWithoutExtension(input).ToLowerInvariant(),

View File

@@ -177,7 +177,7 @@ namespace SabreTools.Helper
Name = gamename, Name = gamename,
Description = gamedesc, Description = gamedesc,
}, },
Type = (line.Trim().StartsWith("disk (") ? "disk" : "rom"), Type = (line.Trim().StartsWith("disk (") ? ItemType.Disk : ItemType.Rom),
Metadata = new SourceMetadata { SystemID = sysid, SourceID = srcid }, Metadata = new SourceMetadata { SystemID = sysid, SourceID = srcid },
}; };
@@ -300,7 +300,7 @@ namespace SabreTools.Helper
rom.HashData.SHA1 = RomTools.CleanHashData(rom.HashData.SHA1, Constants.SHA1Length); rom.HashData.SHA1 = RomTools.CleanHashData(rom.HashData.SHA1, Constants.SHA1Length);
// If we have a rom and it's missing size AND the hashes match a 0-byte file, fill in the rest of the info // If we have a rom and it's missing size AND the hashes match a 0-byte file, fill in the rest of the info
if (rom.Type == "rom" && (rom.HashData.Size == 0 || rom.HashData.Size == -1) && ((rom.HashData.CRC == Constants.CRCZero || rom.HashData.CRC == "") || rom.HashData.MD5 == Constants.MD5Zero || rom.HashData.SHA1 == Constants.SHA1Zero)) if (rom.Type == ItemType.Rom && (rom.HashData.Size == 0 || rom.HashData.Size == -1) && ((rom.HashData.CRC == Constants.CRCZero || rom.HashData.CRC == "") || rom.HashData.MD5 == Constants.MD5Zero || rom.HashData.SHA1 == Constants.SHA1Zero))
{ {
rom.HashData.Size = Constants.SizeZero; rom.HashData.Size = Constants.SizeZero;
rom.HashData.CRC = Constants.CRCZero; rom.HashData.CRC = Constants.CRCZero;
@@ -308,14 +308,14 @@ namespace SabreTools.Helper
rom.HashData.SHA1 = Constants.SHA1Zero; rom.HashData.SHA1 = Constants.SHA1Zero;
} }
// If the file has no size and it's not the above case, skip and log // If the file has no size and it's not the above case, skip and log
else if (rom.Type == "rom" && (rom.HashData.Size == 0 || rom.HashData.Size == -1)) else if (rom.Type == ItemType.Rom && (rom.HashData.Size == 0 || rom.HashData.Size == -1))
{ {
logger.Warning("Incomplete entry for \"" + rom.Name + "\" will be output as nodump"); logger.Warning("Incomplete entry for \"" + rom.Name + "\" will be output as nodump");
rom.Nodump = true; rom.Nodump = true;
} }
// If we have a disk, make sure that the value for size is -1 // If we have a disk, make sure that the value for size is -1
if (rom.Type == "disk") if (rom.Type == ItemType.Disk)
{ {
rom.HashData.Size = -1; rom.HashData.Size = -1;
} }
@@ -334,8 +334,8 @@ namespace SabreTools.Helper
} }
// Add statistical data // Add statistical data
datdata.RomCount += (rom.Type == "rom" ? 1 : 0); datdata.RomCount += (rom.Type == ItemType.Rom ? 1 : 0);
datdata.DiskCount += (rom.Type == "disk" ? 1 : 0); datdata.DiskCount += (rom.Type == ItemType.Disk ? 1 : 0);
datdata.TotalSize += (rom.Nodump ? 0 : rom.HashData.Size); datdata.TotalSize += (rom.Nodump ? 0 : rom.HashData.Size);
datdata.CRCCount += (String.IsNullOrEmpty(rom.HashData.CRC) ? 0 : 1); datdata.CRCCount += (String.IsNullOrEmpty(rom.HashData.CRC) ? 0 : 1);
datdata.MD5Count += (String.IsNullOrEmpty(rom.HashData.MD5) ? 0 : 1); datdata.MD5Count += (String.IsNullOrEmpty(rom.HashData.MD5) ? 0 : 1);
@@ -588,7 +588,7 @@ namespace SabreTools.Helper
rom.HashData.SHA1 = RomTools.CleanHashData(rom.HashData.SHA1, Constants.SHA1Length); rom.HashData.SHA1 = RomTools.CleanHashData(rom.HashData.SHA1, Constants.SHA1Length);
// If we have a rom and it's missing size AND the hashes match a 0-byte file, fill in the rest of the info // If we have a rom and it's missing size AND the hashes match a 0-byte file, fill in the rest of the info
if (rom.Type == "rom" && (rom.HashData.Size == 0 || rom.HashData.Size == -1) && ((rom.HashData.CRC == Constants.CRCZero || rom.HashData.CRC == "") || rom.HashData.MD5 == Constants.MD5Zero || rom.HashData.SHA1 == Constants.SHA1Zero)) if (rom.Type == ItemType.Rom && (rom.HashData.Size == 0 || rom.HashData.Size == -1) && ((rom.HashData.CRC == Constants.CRCZero || rom.HashData.CRC == "") || rom.HashData.MD5 == Constants.MD5Zero || rom.HashData.SHA1 == Constants.SHA1Zero))
{ {
rom.HashData.Size = Constants.SizeZero; rom.HashData.Size = Constants.SizeZero;
rom.HashData.CRC = Constants.CRCZero; rom.HashData.CRC = Constants.CRCZero;
@@ -596,14 +596,14 @@ namespace SabreTools.Helper
rom.HashData.SHA1 = Constants.SHA1Zero; rom.HashData.SHA1 = Constants.SHA1Zero;
} }
// If the file has no size and it's not the above case, skip and log // If the file has no size and it's not the above case, skip and log
else if (rom.Type == "rom" && (rom.HashData.Size == 0 || rom.HashData.Size == -1)) else if (rom.Type == ItemType.Rom && (rom.HashData.Size == 0 || rom.HashData.Size == -1))
{ {
logger.Warning("Incomplete entry for \"" + rom.Name + "\" will be output as nodump"); logger.Warning("Incomplete entry for \"" + rom.Name + "\" will be output as nodump");
rom.Nodump = true; rom.Nodump = true;
} }
// If we have a disk, make sure that the value for size is -1 // If we have a disk, make sure that the value for size is -1
if (rom.Type == "disk") if (rom.Type == ItemType.Disk)
{ {
rom.HashData.Size = -1; rom.HashData.Size = -1;
} }
@@ -622,8 +622,8 @@ namespace SabreTools.Helper
} }
// Add statistical data // Add statistical data
datdata.RomCount += (rom.Type == "rom" ? 1 : 0); datdata.RomCount += (rom.Type == ItemType.Rom ? 1 : 0);
datdata.DiskCount += (rom.Type == "disk" ? 1 : 0); datdata.DiskCount += (rom.Type == ItemType.Disk ? 1 : 0);
datdata.TotalSize += (rom.Nodump ? 0 : rom.HashData.Size); datdata.TotalSize += (rom.Nodump ? 0 : rom.HashData.Size);
datdata.CRCCount += (String.IsNullOrEmpty(rom.HashData.CRC) ? 0 : 1); datdata.CRCCount += (String.IsNullOrEmpty(rom.HashData.CRC) ? 0 : 1);
datdata.MD5Count += (String.IsNullOrEmpty(rom.HashData.MD5) ? 0 : 1); datdata.MD5Count += (String.IsNullOrEmpty(rom.HashData.MD5) ? 0 : 1);
@@ -679,7 +679,7 @@ namespace SabreTools.Helper
Rom rom = new Rom Rom rom = new Rom
{ {
Type = "rom", Type = ItemType.Rom,
Name = "null", Name = "null",
Machine = new Machine Machine = new Machine
{ {
@@ -708,8 +708,8 @@ namespace SabreTools.Helper
} }
// Add statistical data // Add statistical data
datdata.RomCount += (rom.Type == "rom" ? 1 : 0); datdata.RomCount += (rom.Type == ItemType.Rom ? 1 : 0);
datdata.DiskCount += (rom.Type == "disk" ? 1 : 0); datdata.DiskCount += (rom.Type == ItemType.Disk ? 1 : 0);
datdata.TotalSize += (rom.Nodump ? 0 : rom.HashData.Size); datdata.TotalSize += (rom.Nodump ? 0 : rom.HashData.Size);
datdata.CRCCount += (String.IsNullOrEmpty(rom.HashData.CRC) ? 0 : 1); datdata.CRCCount += (String.IsNullOrEmpty(rom.HashData.CRC) ? 0 : 1);
datdata.MD5Count += (String.IsNullOrEmpty(rom.HashData.MD5) ? 0 : 1); datdata.MD5Count += (String.IsNullOrEmpty(rom.HashData.MD5) ? 0 : 1);
@@ -1135,7 +1135,7 @@ namespace SabreTools.Helper
Description = gamedesc, Description = gamedesc,
}, },
Name = subreader.GetAttribute("name"), Name = subreader.GetAttribute("name"),
Type = subreader.Name, Type = (subreader.Name.ToLowerInvariant() == "disk" ? ItemType.Disk : ItemType.Rom),
HashData = new HashData HashData = new HashData
{ {
Size = size, Size = size,
@@ -1160,8 +1160,8 @@ namespace SabreTools.Helper
} }
// Add statistical data // Add statistical data
datdata.RomCount += (rom.Type == "rom" ? 1 : 0); datdata.RomCount += (rom.Type == ItemType.Rom ? 1 : 0);
datdata.DiskCount += (rom.Type == "disk" ? 1 : 0); datdata.DiskCount += (rom.Type == ItemType.Disk ? 1 : 0);
datdata.TotalSize += (rom.Nodump ? 0 : rom.HashData.Size); datdata.TotalSize += (rom.Nodump ? 0 : rom.HashData.Size);
datdata.CRCCount += (String.IsNullOrEmpty(rom.HashData.CRC) ? 0 : 1); datdata.CRCCount += (String.IsNullOrEmpty(rom.HashData.CRC) ? 0 : 1);
datdata.MD5Count += (String.IsNullOrEmpty(rom.HashData.MD5) ? 0 : 1); datdata.MD5Count += (String.IsNullOrEmpty(rom.HashData.MD5) ? 0 : 1);
@@ -1188,7 +1188,7 @@ namespace SabreTools.Helper
Rom rom = new Rom Rom rom = new Rom
{ {
Type = "rom", Type = ItemType.Rom,
Name = "null", Name = "null",
Machine = new Machine Machine = new Machine
{ {
@@ -1217,8 +1217,8 @@ namespace SabreTools.Helper
} }
// Add statistical data // Add statistical data
datdata.RomCount += (rom.Type == "rom" ? 1 : 0); datdata.RomCount += (rom.Type == ItemType.Rom ? 1 : 0);
datdata.DiskCount += (rom.Type == "disk" ? 1 : 0); datdata.DiskCount += (rom.Type == ItemType.Disk ? 1 : 0);
datdata.TotalSize += (rom.Nodump ? 0 : rom.HashData.Size); datdata.TotalSize += (rom.Nodump ? 0 : rom.HashData.Size);
datdata.CRCCount += (String.IsNullOrEmpty(rom.HashData.CRC) ? 0 : 1); datdata.CRCCount += (String.IsNullOrEmpty(rom.HashData.CRC) ? 0 : 1);
datdata.MD5Count += (String.IsNullOrEmpty(rom.HashData.MD5) ? 0 : 1); datdata.MD5Count += (String.IsNullOrEmpty(rom.HashData.MD5) ? 0 : 1);
@@ -1374,7 +1374,7 @@ namespace SabreTools.Helper
Name = tempname, Name = tempname,
}, },
Name = xtr.GetAttribute("name"), Name = xtr.GetAttribute("name"),
Type = xtr.GetAttribute("type"), Type = (xtr.GetAttribute("type").ToLowerInvariant() == "disk" ? ItemType.Disk : ItemType.Rom),
HashData = new HashData HashData = new HashData
{ {
Size = size, Size = size,
@@ -1399,8 +1399,8 @@ namespace SabreTools.Helper
} }
// Add statistical data // Add statistical data
datdata.RomCount += (rom.Type == "rom" ? 1 : 0); datdata.RomCount += (rom.Type == ItemType.Rom ? 1 : 0);
datdata.DiskCount += (rom.Type == "disk" ? 1 : 0); datdata.DiskCount += (rom.Type == ItemType.Disk ? 1 : 0);
datdata.TotalSize += (rom.Nodump ? 0 : rom.HashData.Size); datdata.TotalSize += (rom.Nodump ? 0 : rom.HashData.Size);
datdata.CRCCount += (String.IsNullOrEmpty(rom.HashData.CRC) ? 0 : 1); datdata.CRCCount += (String.IsNullOrEmpty(rom.HashData.CRC) ? 0 : 1);
datdata.MD5Count += (String.IsNullOrEmpty(rom.HashData.MD5) ? 0 : 1); datdata.MD5Count += (String.IsNullOrEmpty(rom.HashData.MD5) ? 0 : 1);
@@ -1864,7 +1864,7 @@ namespace SabreTools.Helper
} }
// Filter on rom type // Filter on rom type
if (romtype != "" && rom.Type.ToLowerInvariant() != romtype.ToLowerInvariant()) if (romtype != "" && rom.Type.ToString().ToLowerInvariant() != romtype.ToLowerInvariant())
{ {
continue; continue;
} }

View File

@@ -421,7 +421,7 @@ namespace SabreTools.Helper
switch (datdata.OutputFormat) switch (datdata.OutputFormat)
{ {
case OutputFormat.ClrMamePro: case OutputFormat.ClrMamePro:
state += "\t" + rom.Type + " ( name \"" + rom.Name + "\"" + state += "\t" + rom.Type.ToString().ToLowerInvariant() + " ( name \"" + rom.Name + "\"" +
(rom.HashData.Size != -1 ? " size " + rom.HashData.Size : "") + (rom.HashData.Size != -1 ? " size " + rom.HashData.Size : "") +
(!String.IsNullOrEmpty(rom.HashData.CRC) ? " crc " + rom.HashData.CRC.ToLowerInvariant() : "") + (!String.IsNullOrEmpty(rom.HashData.CRC) ? " crc " + rom.HashData.CRC.ToLowerInvariant() : "") +
(!String.IsNullOrEmpty(rom.HashData.MD5) ? " md5 " + rom.HashData.MD5.ToLowerInvariant() : "") + (!String.IsNullOrEmpty(rom.HashData.MD5) ? " md5 " + rom.HashData.MD5.ToLowerInvariant() : "") +
@@ -453,7 +453,7 @@ namespace SabreTools.Helper
else if (datdata.TSV == true) else if (datdata.TSV == true)
{ {
string inline = "\"" + datdata.FileName + "\"\t\"" + datdata.Name + "\"\t\"" + datdata.Description + "\"\t\"" + rom.Machine + "\"\t\"" + rom.Machine + "\"\t\"" + string inline = "\"" + datdata.FileName + "\"\t\"" + datdata.Name + "\"\t\"" + datdata.Description + "\"\t\"" + rom.Machine + "\"\t\"" + rom.Machine + "\"\t\"" +
rom.Type + "\"\t\"" + (rom.Type == "rom" ? rom.Name : "") + "\"\t\"" + (rom.Type == "disk" ? rom.Name : "") + "\"\t\"" + rom.HashData.Size + "\"\t\"" + rom.Type.ToString().ToLowerInvariant() + "\"\t\"" + (rom.Type == ItemType.Rom ? rom.Name : "") + "\"\t\"" + (rom.Type == ItemType.Disk ? rom.Name : "") + "\"\t\"" + rom.HashData.Size + "\"\t\"" +
rom.HashData.CRC + "\"\t\"" + rom.HashData.MD5 + "\"\t\"" + rom.HashData.SHA1 + "\"\t" + (rom.Nodump ? "\"Nodump\"" : "\"\""); rom.HashData.CRC + "\"\t\"" + rom.HashData.MD5 + "\"\t\"" + rom.HashData.SHA1 + "\"\t" + (rom.Nodump ? "\"Nodump\"" : "\"\"");
state += pre + inline + post + "\n"; state += pre + inline + post + "\n";
} }
@@ -461,7 +461,7 @@ namespace SabreTools.Helper
else if (datdata.TSV == false) else if (datdata.TSV == false)
{ {
string inline = "\"" + datdata.FileName + "\",\"" + datdata.Name + "\",\"" + datdata.Description + "\",\"" + rom.Machine + "\",\"" + rom.Machine + "\",\"" + string inline = "\"" + datdata.FileName + "\",\"" + datdata.Name + "\",\"" + datdata.Description + "\",\"" + rom.Machine + "\",\"" + rom.Machine + "\",\"" +
rom.Type + "\",\"" + (rom.Type == "rom" ? rom.Name : "") + "\",\"" + (rom.Type == "disk" ? rom.Name : "") + "\",\"" + rom.HashData.Size + "\",\"" + rom.Type.ToString().ToLowerInvariant() + "\",\"" + (rom.Type == ItemType.Rom ? rom.Name : "") + "\",\"" + (rom.Type == ItemType.Disk ? rom.Name : "") + "\",\"" + rom.HashData.Size + "\",\"" +
rom.HashData.CRC + "\",\"" + rom.HashData.MD5 + "\",\"" + rom.HashData.SHA1 + "\"," + (rom.Nodump ? "\"Nodump\"" : "\"\""); rom.HashData.CRC + "\",\"" + rom.HashData.MD5 + "\",\"" + rom.HashData.SHA1 + "\"," + (rom.Nodump ? "\"Nodump\"" : "\"\"");
state += pre + inline + post + "\n"; state += pre + inline + post + "\n";
} }
@@ -510,7 +510,7 @@ namespace SabreTools.Helper
} }
state += prefix; state += prefix;
state += "<file type=\"" + rom.Type + "\" name=\"" + HttpUtility.HtmlEncode(rom.Name) + "\"" + state += "<file type=\"" + rom.Type.ToString().ToLowerInvariant() + "\" name=\"" + HttpUtility.HtmlEncode(rom.Name) + "\"" +
(rom.HashData.Size != -1 ? " size=\"" + rom.HashData.Size + "\"" : "") + (rom.HashData.Size != -1 ? " size=\"" + rom.HashData.Size + "\"" : "") +
(!String.IsNullOrEmpty(rom.HashData.CRC) ? " crc=\"" + rom.HashData.CRC.ToLowerInvariant() + "\"" : "") + (!String.IsNullOrEmpty(rom.HashData.CRC) ? " crc=\"" + rom.HashData.CRC.ToLowerInvariant() + "\"" : "") +
(!String.IsNullOrEmpty(rom.HashData.MD5) ? " md5=\"" + rom.HashData.MD5.ToLowerInvariant() + "\"" : "") + (!String.IsNullOrEmpty(rom.HashData.MD5) ? " md5=\"" + rom.HashData.MD5.ToLowerInvariant() + "\"" : "") +
@@ -523,7 +523,7 @@ namespace SabreTools.Helper
"/>\n"); "/>\n");
break; break;
case OutputFormat.Xml: case OutputFormat.Xml:
state += "\t\t<" + rom.Type + " name=\"" + HttpUtility.HtmlEncode(rom.Name) + "\"" + state += "\t\t<" + rom.Type.ToString().ToLowerInvariant() + " name=\"" + HttpUtility.HtmlEncode(rom.Name) + "\"" +
(rom.HashData.Size != -1 ? " size=\"" + rom.HashData.Size + "\"" : "") + (rom.HashData.Size != -1 ? " size=\"" + rom.HashData.Size + "\"" : "") +
(!String.IsNullOrEmpty(rom.HashData.CRC) ? " crc=\"" + rom.HashData.CRC.ToLowerInvariant() + "\"" : "") + (!String.IsNullOrEmpty(rom.HashData.CRC) ? " crc=\"" + rom.HashData.CRC.ToLowerInvariant() + "\"" : "") +
(!String.IsNullOrEmpty(rom.HashData.MD5) ? " md5=\"" + rom.HashData.MD5.ToLowerInvariant() + "\"" : "") + (!String.IsNullOrEmpty(rom.HashData.MD5) ? " md5=\"" + rom.HashData.MD5.ToLowerInvariant() + "\"" : "") +

View File

@@ -29,7 +29,7 @@ namespace SabreTools.Helper
Rom rom = new Rom Rom rom = new Rom
{ {
Name = Path.GetFileName(input), Name = Path.GetFileName(input),
Type = "rom", Type = ItemType.Rom,
HashData = new HashData HashData = new HashData
{ {
Size = (new FileInfo(input)).Length, Size = (new FileInfo(input)).Length,
@@ -249,11 +249,11 @@ namespace SabreTools.Helper
return dupefound; return dupefound;
} }
if (rom.Type == "rom" && lastrom.Type == "rom") if (rom.Type == ItemType.Rom && lastrom.Type == ItemType.Rom)
{ {
dupefound = rom.HashData.Equals(lastrom.HashData, false); dupefound = rom.HashData.Equals(lastrom.HashData, false);
} }
else if (rom.Type == "disk" && lastrom.Type == "disk") else if (rom.Type == ItemType.Disk && lastrom.Type == ItemType.Disk)
{ {
dupefound = rom.HashData.Equals(lastrom.HashData, true); dupefound = rom.HashData.Equals(lastrom.HashData, true);
} }

View File

@@ -120,8 +120,8 @@ Please check the log folder if the stats scrolled offscreen");
{ {
foreach (Rom rom in roms) foreach (Rom rom in roms)
{ {
datdata.RomCount += (rom.Type == "rom" ? 1 : 0); datdata.RomCount += (rom.Type == ItemType.Rom ? 1 : 0);
datdata.DiskCount += (rom.Type == "disk" ? 1 : 0); datdata.DiskCount += (rom.Type == ItemType.Disk ? 1 : 0);
datdata.TotalSize += (rom.Nodump ? 0 : rom.HashData.Size); datdata.TotalSize += (rom.Nodump ? 0 : rom.HashData.Size);
datdata.CRCCount += (String.IsNullOrEmpty(rom.HashData.CRC) ? 0 : 1); datdata.CRCCount += (String.IsNullOrEmpty(rom.HashData.CRC) ? 0 : 1);
datdata.MD5Count += (String.IsNullOrEmpty(rom.HashData.MD5) ? 0 : 1); datdata.MD5Count += (String.IsNullOrEmpty(rom.HashData.MD5) ? 0 : 1);

View File

@@ -267,7 +267,7 @@ namespace SabreTools
// If we're in a mode that doesn't allow for actual empty folders, add the blank info // If we're in a mode that doesn't allow for actual empty folders, add the blank info
if (_datdata.OutputFormat != OutputFormat.SabreDat && _datdata.OutputFormat != OutputFormat.MissFile) if (_datdata.OutputFormat != OutputFormat.SabreDat && _datdata.OutputFormat != OutputFormat.MissFile)
{ {
rom.Type = "rom"; rom.Type = ItemType.Rom;
rom.Name = "-"; rom.Name = "-";
rom.HashData.Size = Constants.SizeZero; rom.HashData.Size = Constants.SizeZero;
rom.HashData.CRC = Constants.CRCZero; rom.HashData.CRC = Constants.CRCZero;