mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Use DatData for everything; read header elements
Reading the header elements will come in handy for when built-in parse and generate code will take care of converting from any format to any format.
This commit is contained in:
@@ -144,16 +144,19 @@ namespace SabreTools
|
||||
{
|
||||
// First get the combination Dictionary of currentAllMerged and currentNewMerged
|
||||
_logger.User("Adding Current and New Merged DATs to the dictionary");
|
||||
Dictionary<string, List<RomData>> completeDats = new Dictionary<string, List<RomData>>();
|
||||
DatData completeDats = new DatData
|
||||
{
|
||||
Roms = new Dictionary<string, List<RomData>>(),
|
||||
};
|
||||
completeDats = RomManipulation.ParseDict(_currentAllMerged, 0, 0, completeDats, _logger);
|
||||
completeDats = RomManipulation.ParseDict(_currentNewMerged, 0, 0, completeDats, _logger);
|
||||
|
||||
// Now get Net New output dictionary [(currentNewMerged)-(currentAllMerged)]
|
||||
_logger.User("Creating and populating Net New dictionary");
|
||||
Dictionary<string, List<RomData>> netNew = new Dictionary<string, List<RomData>>();
|
||||
foreach (string key in completeDats.Keys)
|
||||
foreach (string key in completeDats.Roms.Keys)
|
||||
{
|
||||
List<RomData> templist = RomManipulation.Merge(completeDats[key]);
|
||||
List<RomData> templist = RomManipulation.Merge(completeDats.Roms[key]);
|
||||
foreach (RomData rom in templist)
|
||||
{
|
||||
if (rom.Dupe == DupeType.None && rom.System == _currentNewMerged)
|
||||
@@ -175,9 +178,9 @@ namespace SabreTools
|
||||
// Now create the Unneeded dictionary [(currentAllMerged)-(currentNewMerged)]
|
||||
_logger.User("Creating and populating Uneeded dictionary");
|
||||
Dictionary<string, List<RomData>> unneeded = new Dictionary<string, List<RomData>>();
|
||||
foreach (string key in completeDats.Keys)
|
||||
foreach (string key in completeDats.Roms.Keys)
|
||||
{
|
||||
List<RomData> templist = RomManipulation.Merge(completeDats[key]);
|
||||
List<RomData> templist = RomManipulation.Merge(completeDats.Roms[key]);
|
||||
foreach (RomData rom in templist)
|
||||
{
|
||||
if (rom.Dupe == DupeType.None && rom.System == _currentAllMerged)
|
||||
@@ -198,23 +201,26 @@ namespace SabreTools
|
||||
|
||||
// Now create the New Missing dictionary [(Net New)+(currentMissingMerged-(Unneeded))]
|
||||
_logger.User("Creating and populating New Missing dictionary");
|
||||
Dictionary<string, List<RomData>> midMissing = new Dictionary<string, List<RomData>>();
|
||||
DatData midMissing = new DatData
|
||||
{
|
||||
Roms = new Dictionary<string, List<RomData>>(),
|
||||
};
|
||||
midMissing = RomManipulation.ParseDict(_currentMissingMerged, 0, 0, midMissing, _logger);
|
||||
foreach (string key in unneeded.Keys)
|
||||
{
|
||||
if (midMissing.ContainsKey(key))
|
||||
if (midMissing.Roms.ContainsKey(key))
|
||||
{
|
||||
midMissing[key].AddRange(unneeded[key]);
|
||||
midMissing.Roms[key].AddRange(unneeded[key]);
|
||||
}
|
||||
else
|
||||
{
|
||||
midMissing.Add(key, unneeded[key]);
|
||||
midMissing.Roms.Add(key, unneeded[key]);
|
||||
}
|
||||
}
|
||||
Dictionary<string, List<RomData>> newMissing = new Dictionary<string, List<RomData>>();
|
||||
foreach (string key in midMissing.Keys)
|
||||
foreach (string key in midMissing.Roms.Keys)
|
||||
{
|
||||
List<RomData> templist = RomManipulation.Merge(midMissing[key]);
|
||||
List<RomData> templist = RomManipulation.Merge(midMissing.Roms[key]);
|
||||
foreach (RomData rom in templist)
|
||||
{
|
||||
if (rom.Dupe == DupeType.None && rom.System == _currentMissingMerged)
|
||||
@@ -258,11 +264,11 @@ namespace SabreTools
|
||||
midHave.Add(key, newMissing[key]);
|
||||
}
|
||||
}
|
||||
foreach (string key in completeDats.Keys)
|
||||
foreach (string key in completeDats.Roms.Keys)
|
||||
{
|
||||
if (midHave.ContainsKey(key))
|
||||
{
|
||||
foreach (RomData rom in completeDats[key])
|
||||
foreach (RomData rom in completeDats.Roms[key])
|
||||
{
|
||||
if (rom.System == _currentNewMerged)
|
||||
{
|
||||
@@ -273,7 +279,7 @@ namespace SabreTools
|
||||
else
|
||||
{
|
||||
List<RomData> roms = new List<RomData>();
|
||||
foreach (RomData rom in completeDats[key])
|
||||
foreach (RomData rom in completeDats.Roms[key])
|
||||
{
|
||||
if (rom.System == _currentNewMerged)
|
||||
{
|
||||
@@ -448,13 +454,16 @@ namespace SabreTools
|
||||
{
|
||||
// Now create the Have dictionary [(currentAllMerged)-(currentMissingMerged)]
|
||||
_logger.User("Creating and populating Have dictionary");
|
||||
Dictionary<string, List<RomData>> midHave = new Dictionary<string, List<RomData>>();
|
||||
DatData midHave = new DatData
|
||||
{
|
||||
Roms = new Dictionary<string, List<RomData>>(),
|
||||
};
|
||||
midHave = RomManipulation.ParseDict(_currentMissingMerged, 0, 0, midHave, _logger);
|
||||
midHave = RomManipulation.ParseDict(_currentAllMerged, 0, 0, midHave, _logger);
|
||||
Dictionary<string, List<RomData>> have = new Dictionary<string, List<RomData>>();
|
||||
foreach (string key in midHave.Keys)
|
||||
foreach (string key in midHave.Roms.Keys)
|
||||
{
|
||||
List<RomData> templist = RomManipulation.Merge(midHave[key]);
|
||||
List<RomData> templist = RomManipulation.Merge(midHave.Roms[key]);
|
||||
foreach (RomData rom in templist)
|
||||
{
|
||||
if (rom.Dupe == DupeType.None && rom.System == _currentAllMerged)
|
||||
@@ -518,13 +527,16 @@ namespace SabreTools
|
||||
{
|
||||
// Now create the Have dictionary [(currentNewMerged)-(currentMissingMerged)]
|
||||
_logger.User("Creating and populating Have dictionary");
|
||||
Dictionary<string, List<RomData>> midHave = new Dictionary<string, List<RomData>>();
|
||||
DatData midHave = new DatData
|
||||
{
|
||||
Roms = new Dictionary<string, List<RomData>>(),
|
||||
};
|
||||
midHave = RomManipulation.ParseDict(_currentMissingMerged, 0, 0, midHave, _logger);
|
||||
midHave = RomManipulation.ParseDict(_currentNewMerged, 0, 0, midHave, _logger);
|
||||
Dictionary<string, List<RomData>> have = new Dictionary<string, List<RomData>>();
|
||||
foreach (string key in midHave.Keys)
|
||||
foreach (string key in midHave.Roms.Keys)
|
||||
{
|
||||
List<RomData> templist = RomManipulation.Merge(midHave[key]);
|
||||
List<RomData> templist = RomManipulation.Merge(midHave.Roms[key]);
|
||||
foreach (RomData rom in templist)
|
||||
{
|
||||
if (rom.Dupe == DupeType.None && rom.System == _currentNewMerged)
|
||||
|
||||
@@ -375,22 +375,6 @@ namespace SabreTools.Helper
|
||||
/// <param name="logger">Logger object for console and/or file output</param>
|
||||
/// <returns>DatData object representing the read-in data</returns>
|
||||
public static DatData ParseDict(string filename, int sysid, int srcid, DatData datdata, Logger logger)
|
||||
{
|
||||
Dictionary<string, List<RomData>> roms = ParseDict(filename, sysid, srcid, datdata.Roms, logger);
|
||||
datdata.Roms = roms;
|
||||
return datdata;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a DAT and return all found games and roms within
|
||||
/// </summary>
|
||||
/// <param name="filename">Name of the file to be parsed</param>
|
||||
/// <param name="sysid">System ID for the DAT</param>
|
||||
/// <param name="srcid">Source ID for the DAT</param>
|
||||
/// <param name="dict">The dictionary to add found roms to</param>
|
||||
/// <param name="logger">Logger object for console and/or file output</param>
|
||||
/// <returns>Dictionary with "size-crc" key and List of RomData objects value representing the found data</returns>
|
||||
public static Dictionary<string, List<RomData>> ParseDict(string filename, int sysid, int srcid, Dictionary<string, List<RomData>> dict, Logger logger)
|
||||
{
|
||||
XmlTextReader xtr = GetXmlTextReader(filename, logger);
|
||||
bool superdat = false, shouldbreak = false;
|
||||
@@ -415,14 +399,104 @@ namespace SabreTools.Helper
|
||||
xtr.Read();
|
||||
break;
|
||||
case "header":
|
||||
xtr.ReadToDescendant("name");
|
||||
string content = xtr.ReadElementContentAsString();
|
||||
superdat = (content != null ? content.Contains(" - SuperDAT") : false);
|
||||
while (xtr.Name != "header")
|
||||
// We want to process the entire subtree of the header
|
||||
XmlReader headreader = xtr.ReadSubtree();
|
||||
|
||||
if (headreader != null)
|
||||
{
|
||||
xtr.Read();
|
||||
while (headreader.Read())
|
||||
{
|
||||
// We only want elements
|
||||
if (headreader.NodeType != XmlNodeType.Element)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get all header items (ONLY OVERWRITE IF THERE'S NO DATA)
|
||||
switch (xtr.Name)
|
||||
{
|
||||
case "name":
|
||||
string readname = headreader.ReadElementContentAsString();
|
||||
datdata.Name = (datdata.Name == "" ? readname : "");
|
||||
superdat = superdat || readname.Contains(" - SuperDAT");
|
||||
break;
|
||||
case "description":
|
||||
datdata.Description = (datdata.Description == "" ? headreader.ReadElementContentAsString() : datdata.Description);
|
||||
break;
|
||||
case "category":
|
||||
datdata.Category = (datdata.Category == "" ? headreader.ReadElementContentAsString() : datdata.Category);
|
||||
break;
|
||||
case "version":
|
||||
datdata.Version = (datdata.Version == "" ? headreader.ReadElementContentAsString() : datdata.Version);
|
||||
break;
|
||||
case "date":
|
||||
datdata.Date = (datdata.Date == "" ? headreader.ReadElementContentAsString() : datdata.Date);
|
||||
break;
|
||||
case "author":
|
||||
datdata.Author = (datdata.Author == "" ? headreader.ReadElementContentAsString() : datdata.Author);
|
||||
break;
|
||||
case "email":
|
||||
datdata.Email = (datdata.Email == "" ? headreader.ReadElementContentAsString() : datdata.Email);
|
||||
break;
|
||||
case "homepage":
|
||||
datdata.Homepage = (datdata.Homepage == "" ? headreader.ReadElementContentAsString() : datdata.Homepage);
|
||||
break;
|
||||
case "url":
|
||||
datdata.Url = (datdata.Url == "" ? headreader.ReadElementContentAsString() : datdata.Url);
|
||||
break;
|
||||
case "comment":
|
||||
datdata.Comment = (datdata.Comment == "" ? headreader.ReadElementContentAsString() : datdata.Comment);
|
||||
break;
|
||||
case "clrmamepro":
|
||||
if (headreader.GetAttribute("forcemerging") != null)
|
||||
{
|
||||
switch (headreader.GetAttribute("forcemerging"))
|
||||
{
|
||||
case "split":
|
||||
datdata.ForceMerging = ForceMerging.Split;
|
||||
break;
|
||||
case "none":
|
||||
datdata.ForceMerging = ForceMerging.None;
|
||||
break;
|
||||
case "full":
|
||||
datdata.ForceMerging = ForceMerging.Full;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (headreader.GetAttribute("forcenodump") != null)
|
||||
{
|
||||
switch (headreader.GetAttribute("forcenodump"))
|
||||
{
|
||||
case "obsolete":
|
||||
datdata.ForceNodump = ForceNodump.Obsolete;
|
||||
break;
|
||||
case "required":
|
||||
datdata.ForceNodump = ForceNodump.Required;
|
||||
break;
|
||||
case "ignore":
|
||||
datdata.ForceNodump = ForceNodump.Ignore;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (headreader.GetAttribute("forcepacking") != null)
|
||||
{
|
||||
switch (headreader.GetAttribute("forcepacking"))
|
||||
{
|
||||
case "zip":
|
||||
datdata.ForcePacking = ForcePacking.Zip;
|
||||
break;
|
||||
case "unzip":
|
||||
datdata.ForcePacking = ForcePacking.Unzip;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
xtr.Read();
|
||||
|
||||
// Skip the header node now that we've processed it
|
||||
xtr.Skip();
|
||||
break;
|
||||
case "machine":
|
||||
case "game":
|
||||
@@ -491,11 +565,11 @@ namespace SabreTools.Helper
|
||||
// If the rom is continue or ignore, add the size to the previous rom
|
||||
if (xtr.GetAttribute("loadflag") == "continue" || xtr.GetAttribute("loadflag") == "ignore")
|
||||
{
|
||||
int index = dict[key].Count() - 1;
|
||||
RomData lastrom = dict[key][index];
|
||||
int index = datdata.Roms[key].Count() - 1;
|
||||
RomData lastrom = datdata.Roms[key][index];
|
||||
lastrom.Size += size;
|
||||
dict[key].RemoveAt(index);
|
||||
dict[key].Add(lastrom);
|
||||
datdata.Roms[key].RemoveAt(index);
|
||||
datdata.Roms[key].Add(lastrom);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -548,15 +622,15 @@ namespace SabreTools.Helper
|
||||
System = filename,
|
||||
};
|
||||
|
||||
if (dict.ContainsKey(key))
|
||||
if (datdata.Roms.ContainsKey(key))
|
||||
{
|
||||
dict[key].Add(value);
|
||||
datdata.Roms[key].Add(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<RomData> newvalue = new List<RomData>();
|
||||
newvalue.Add(value);
|
||||
dict.Add(key, newvalue);
|
||||
datdata.Roms.Add(key, newvalue);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -583,7 +657,7 @@ namespace SabreTools.Helper
|
||||
}
|
||||
}
|
||||
|
||||
return dict;
|
||||
return datdata;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -34,9 +34,12 @@ namespace SabreTools
|
||||
long size = 0;
|
||||
foreach (string filename in inputs)
|
||||
{
|
||||
Dictionary<string, List<RomData>> roms = new Dictionary<string, List<RomData>>();
|
||||
roms = RomManipulation.ParseDict(filename, 0, 0, roms, logger);
|
||||
foreach (List<RomData> romlist in roms.Values)
|
||||
DatData datdata = new DatData
|
||||
{
|
||||
Roms = new Dictionary<string, List<RomData>>(),
|
||||
};
|
||||
datdata = RomManipulation.ParseDict(filename, 0, 0, datdata, logger);
|
||||
foreach (List<RomData> romlist in datdata.Roms.Values)
|
||||
{
|
||||
foreach (RomData rom in romlist)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user