Create a more extensible system for DAT creation for future additions

This commit is contained in:
Matt Nadareski
2016-05-15 14:34:06 -07:00
parent d753b796fe
commit ff48cddc9a
6 changed files with 211 additions and 42 deletions

View File

@@ -140,7 +140,18 @@ namespace SabreTools
post = " (No Duplicates)"; post = " (No Duplicates)";
// Output the difflist (a-b)+(b-a) diff // Output the difflist (a-b)+(b-a) diff
Output.WriteToDatFromDict(_name + post, _desc + post, _version, _date, _cat, _author, _forceunpack, _old, _dedup, "", diffed, _logger); DatData outerDiffData = new DatData
{
Name = _name + post,
Description = _desc + post,
Version = _version,
Date = _date,
Category = _cat,
Author = _author,
ForcePacking = (_forceunpack ? ForcePacking.Unzip : ForcePacking.None),
OutputFormat = (_old ? OutputFormat.ClrMamePro : OutputFormat.Xml),
};
Output.WriteToDatFromDict(outerDiffData, _dedup, "", diffed, _logger);
// For the AB mode-style diffs, get all required dictionaries and output with a new name // For the AB mode-style diffs, get all required dictionaries and output with a new name
// Loop through _inputs first and filter from all diffed roms to find the ones that have the same "System" // Loop through _inputs first and filter from all diffed roms to find the ones that have the same "System"
@@ -168,7 +179,19 @@ namespace SabreTools
} }
post = " (" + Path.GetFileNameWithoutExtension(_inputs[j]) + " Only)"; post = " (" + Path.GetFileNameWithoutExtension(_inputs[j]) + " Only)";
Output.WriteToDatFromDict(_name + post, _desc + post, _version, _date, _cat, _author, _forceunpack, _old, _dedup, "", sysDict, _logger);
DatData diffData = new DatData
{
Name = _name + post,
Description = _desc + post,
Version = _version,
Date = _date,
Category = _cat,
Author = _author,
ForcePacking = (_forceunpack ? ForcePacking.Unzip : ForcePacking.None),
OutputFormat = (_old ? OutputFormat.ClrMamePro : OutputFormat.Xml),
};
Output.WriteToDatFromDict(diffData, _dedup, "", sysDict, _logger);
} }
// Get all entries that have External dupes // Get all entries that have External dupes
@@ -196,12 +219,35 @@ namespace SabreTools
} }
} }
} }
Output.WriteToDatFromDict(_name + post, _desc + post, _version, _date, _cat, _author, _forceunpack, _old, _dedup, "", duplicates, _logger);
DatData dupeData = new DatData
{
Name = _name + post,
Description = _desc + post,
Version = _version,
Date = _date,
Category = _cat,
Author = _author,
ForcePacking = (_forceunpack ? ForcePacking.Unzip : ForcePacking.None),
OutputFormat = (_old ? OutputFormat.ClrMamePro : OutputFormat.Xml),
};
Output.WriteToDatFromDict(dupeData, _dedup, "", duplicates, _logger);
} }
// Output all entries with user-defined merge // Output all entries with user-defined merge
else else
{ {
Output.WriteToDatFromDict(_name, _desc, _version, _date, _cat, _author, _forceunpack, _old, _dedup, "", dict, _logger); DatData userData = new DatData
{
Name = _name,
Description = _desc,
Version = _version,
Date = _date,
Category = _cat,
Author = _author,
ForcePacking = (_forceunpack ? ForcePacking.Unzip : ForcePacking.None),
OutputFormat = (_old ? OutputFormat.ClrMamePro : OutputFormat.Xml),
};
Output.WriteToDatFromDict(userData, _dedup, "", dict, _logger);
} }
return true; return true;

View File

@@ -225,7 +225,18 @@ namespace SabreTools
} }
// Then write out the file // Then write out the file
Output.WriteToDatFromDict(name, description, "", date, "SabreTools", "SabreTools", false, _old, true, _outroot, roms, _logger, _norename); DatData datdata = new DatData
{
Name = name,
Description = description,
Version = "",
Date = date,
Category = "SabreTools",
Author = "SabreTools",
ForcePacking = ForcePacking.None,
OutputFormat = (_old ? OutputFormat.ClrMamePro : OutputFormat.Xml),
};
Output.WriteToDatFromDict(datdata, true, _outroot, roms, _logger, _norename);
return true; return true;
} }

View File

@@ -382,10 +382,55 @@ namespace SabreTools
} }
// Finally, output all of the files // Finally, output all of the files
Output.WriteToDatFromDict("Net New", "Net New", "", DateTime.Now.ToString("yyyy-MM-dd"), "", "SabreTools", false, false, true, "", netNew, _logger); DatData netNewData = new DatData
Output.WriteToDatFromDict("Unneeded", "Unneeded", "", DateTime.Now.ToString("yyyy-MM-dd"), "", "SabreTools", false, false, true, "", unneeded, _logger); {
Output.WriteToDatFromDict("New Missing", "New Missing", "", DateTime.Now.ToString("yyyy-MM-dd"), "", "SabreTools", false, false, true, "", newMissing, _logger); Name = "Net New",
Output.WriteToDatFromDict("Have", "Have", "", DateTime.Now.ToString("yyyy-MM-dd"), "", "SabreTools", false, false, true, "", have, _logger); Description = "Net New",
Version = "",
Date = DateTime.Now.ToString("yyyy-MM-dd"),
Category = "",
Author = "SabreTools",
ForcePacking = ForcePacking.None,
OutputFormat = OutputFormat.Xml,
};
DatData unneededData = new DatData
{
Name = "Unneeded",
Description = "Unneeded",
Version = "",
Date = DateTime.Now.ToString("yyyy-MM-dd"),
Category = "",
Author = "SabreTools",
ForcePacking = ForcePacking.None,
OutputFormat = OutputFormat.Xml,
};
DatData newMissingData = new DatData
{
Name = "New Missing",
Description = "New Missing",
Version = "",
Date = DateTime.Now.ToString("yyyy-MM-dd"),
Category = "",
Author = "SabreTools",
ForcePacking = ForcePacking.None,
OutputFormat = OutputFormat.Xml,
};
DatData haveData = new DatData
{
Name = "Have",
Description = "Have",
Version = "",
Date = DateTime.Now.ToString("yyyy-MM-dd"),
Category = "",
Author = "SabreTools",
ForcePacking = ForcePacking.None,
OutputFormat = OutputFormat.Xml,
};
Output.WriteToDatFromDict(netNewData, true, "", netNew, _logger);
Output.WriteToDatFromDict(unneededData, true, "", unneeded, _logger);
Output.WriteToDatFromDict(newMissingData, true, "", newMissing, _logger);
Output.WriteToDatFromDict(haveData, true, "", have, _logger);
return true; return true;
} }
@@ -442,7 +487,18 @@ namespace SabreTools
} }
} }
Output.WriteToDatFromDict("Have", "Have", "", DateTime.Now.ToString("yyyy-MM-dd"), "", "SabreTools", false, false, true, "", have, _logger); DatData haveData = new DatData
{
Name = "Have",
Description = "Have",
Version = "",
Date = DateTime.Now.ToString("yyyy-MM-dd"),
Category = "",
Author = "SabreTools",
ForcePacking = ForcePacking.None,
OutputFormat = OutputFormat.Xml,
};
Output.WriteToDatFromDict(haveData, true, "", have, _logger);
return true; return true;
} }
@@ -499,7 +555,18 @@ namespace SabreTools
} }
} }
Output.WriteToDatFromDict("Have", "Have", "", DateTime.Now.ToString("yyyy-MM-dd"), "", "SabreTools", false, false, true, "", have, _logger); DatData haveData = new DatData
{
Name = "Have",
Description = "Have",
Version = "",
Date = DateTime.Now.ToString("yyyy-MM-dd"),
Category = "",
Author = "SabreTools",
ForcePacking = ForcePacking.None,
OutputFormat = OutputFormat.Xml,
};
Output.WriteToDatFromDict(haveData, true, "", have, _logger);
return true; return true;
} }

View File

@@ -62,4 +62,35 @@ namespace SabreTools.Helper
ExternalHash, ExternalHash,
ExternalAll, ExternalAll,
} }
public enum ForceMerging
{
None = 0,
Split,
Full,
}
public enum ForceNodump
{
None = 0,
Obsolete,
Required,
Ignore,
}
public enum ForcePacking
{
None = 0,
Zip,
Unzip,
}
public enum OutputFormat
{
Xml = 0,
ClrMamePro,
RomCenter,
DOSCenter,
MissFile,
}
} }

View File

@@ -141,14 +141,7 @@ namespace SabreTools.Helper
/// <summary> /// <summary>
/// Create and open an output file for writing direct from a dictionary /// Create and open an output file for writing direct from a dictionary
/// </summary> /// </summary>
/// <param name="name">Internal name of the DAT</param> /// <param name="datdata">All information for creating the datfile header</param>
/// <param name="description">Description and external name of the DAT</param>
/// <param name="version">Version or iteration of the DAT</param>
/// <param name="date">Usually the DAT creation date</param>
/// <param name="category">Category of the DAT</param>
/// <param name="author">DAT author</param>
/// <param name="forceunpack">Force all sets to be unzipped</param>
/// <param name="old">Set output mode to old-style DAT</param>
/// <param name="merge">Enable output in merged mode (one game per hash)</param> /// <param name="merge">Enable output in merged mode (one game per hash)</param>
/// <param name="outDir">Set the output directory</param> /// <param name="outDir">Set the output directory</param>
/// <param name="dict">Dictionary containing all the roms to be written</param> /// <param name="dict">Dictionary containing all the roms to be written</param>
@@ -161,8 +154,7 @@ namespace SabreTools.Helper
/// - Have the ability to strip special (non-ASCII) characters from rom information /// - Have the ability to strip special (non-ASCII) characters from rom information
/// - Add a flag for ignoring roms with blank sizes /// - Add a flag for ignoring roms with blank sizes
/// </remarks> /// </remarks>
public static bool WriteToDatFromDict(string name, string description, string version, string date, string category, string author, public static bool WriteToDatFromDict(DatData datdata, bool merge, string outDir, Dictionary<string, List<RomData>> dict, Logger logger, bool norename = true)
bool forceunpack, bool old, bool merge, string outDir, Dictionary<string, List<RomData>> dict, Logger logger, bool norename = true)
{ {
// Get all values in the dictionary and write out // Get all values in the dictionary and write out
SortedDictionary<string, List<RomData>> sortable = new SortedDictionary<string, List<RomData>>(); SortedDictionary<string, List<RomData>> sortable = new SortedDictionary<string, List<RomData>>();
@@ -208,38 +200,38 @@ namespace SabreTools.Helper
} }
// (currently uses current time, change to "last updated time") // (currently uses current time, change to "last updated time")
logger.User("Opening file for writing: " + outDir + description + (old ? ".dat" : ".xml")); logger.User("Opening file for writing: " + outDir + datdata.Description + (datdata.OutputFormat == OutputFormat.ClrMamePro ? ".dat" : ".xml"));
try try
{ {
FileStream fs = File.Create(outDir + description + (old ? ".dat" : ".xml")); FileStream fs = File.Create(outDir + datdata.Description + (datdata.OutputFormat == OutputFormat.ClrMamePro ? ".dat" : ".xml"));
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8); StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
string header_old = "clrmamepro (\n" + string header_old = "clrmamepro (\n" +
"\tname \"" + HttpUtility.HtmlEncode(name) + "\"\n" + "\tname \"" + HttpUtility.HtmlEncode(datdata.Name) + "\"\n" +
"\tdescription \"" + HttpUtility.HtmlEncode(description) + "\"\n" + "\tdescription \"" + HttpUtility.HtmlEncode(datdata.Description) + "\"\n" +
"\tcategory \"" + HttpUtility.HtmlEncode(category) + "\"\n" + "\tcategory \"" + HttpUtility.HtmlEncode(datdata.Category) + "\"\n" +
"\tversion \"" + HttpUtility.HtmlEncode(version) + "\"\n" + "\tversion \"" + HttpUtility.HtmlEncode(datdata.Version) + "\"\n" +
"\tdate \"" + HttpUtility.HtmlEncode(date) + "\"\n" + "\tdate \"" + HttpUtility.HtmlEncode(datdata.Date) + "\"\n" +
"\tauthor \"" + HttpUtility.HtmlEncode(author) + "\"\n" + "\tauthor \"" + HttpUtility.HtmlEncode(datdata.Author) + "\"\n" +
(forceunpack ? "\tforcezipping no\n" : "") + (datdata.ForcePacking == ForcePacking.Unzip ? "\tforcezipping no\n" : "") +
")\n"; ")\n";
string header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + string header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!DOCTYPE datafile PUBLIC \"-//Logiqx//DTD ROM Management Datafile//EN\" \"http://www.logiqx.com/Dats/datafile.dtd\">\n\n" + "<!DOCTYPE datafile PUBLIC \"-//Logiqx//DTD ROM Management Datafile//EN\" \"http://www.logiqx.com/Dats/datafile.dtd\">\n\n" +
"<datafile>\n" + "<datafile>\n" +
"\t<header>\n" + "\t<header>\n" +
"\t\t<name>" + HttpUtility.HtmlEncode(name) + "</name>\n" + "\t\t<name>" + HttpUtility.HtmlEncode(datdata.Name) + "</name>\n" +
"\t\t<description>" + HttpUtility.HtmlEncode(description) + "</description>\n" + "\t\t<description>" + HttpUtility.HtmlEncode(datdata.Description) + "</description>\n" +
"\t\t<category>" + HttpUtility.HtmlEncode(category) + "</category>\n" + "\t\t<category>" + HttpUtility.HtmlEncode(datdata.Category) + "</category>\n" +
"\t\t<version>" + HttpUtility.HtmlEncode(version) + "</version>\n" + "\t\t<version>" + HttpUtility.HtmlEncode(datdata.Version) + "</version>\n" +
"\t\t<date>" + HttpUtility.HtmlEncode(date) + "</date>\n" + "\t\t<date>" + HttpUtility.HtmlEncode(datdata.Date) + "</date>\n" +
"\t\t<author>" + HttpUtility.HtmlEncode(author) + "</author>\n" + "\t\t<author>" + HttpUtility.HtmlEncode(datdata.Author) + "</author>\n" +
(forceunpack ? "\t\t<clrmamepro forcepacking=\"unzip\" />\n" : "") + (datdata.ForcePacking == ForcePacking.Unzip ? "\t\t<clrmamepro forcepacking=\"unzip\" />\n" : "") +
"\t</header>\n"; "\t</header>\n";
// Write the header out // Write the header out
sw.Write((old ? header_old : header)); sw.Write((datdata.OutputFormat == OutputFormat.ClrMamePro ? header_old : header));
// Write out each of the machines and roms // Write out each of the machines and roms
string lastgame = null; string lastgame = null;
@@ -250,18 +242,18 @@ namespace SabreTools.Helper
string state = ""; string state = "";
if (lastgame != null && lastgame.ToLowerInvariant() != rom.Game.ToLowerInvariant()) if (lastgame != null && lastgame.ToLowerInvariant() != rom.Game.ToLowerInvariant())
{ {
state += (old ? ")\n" : "\t</machine>\n"); state += (datdata.OutputFormat == OutputFormat.ClrMamePro ? ")\n" : "\t</machine>\n");
} }
if (lastgame == null || lastgame.ToLowerInvariant() != rom.Game.ToLowerInvariant()) if (lastgame == null || lastgame.ToLowerInvariant() != rom.Game.ToLowerInvariant())
{ {
state += (old ? "game (\n\tname \"" + rom.Game + "\"\n" + state += (datdata.OutputFormat == OutputFormat.ClrMamePro ? "game (\n\tname \"" + rom.Game + "\"\n" +
"\tdescription \"" + rom.Game + "\"\n" : "\tdescription \"" + rom.Game + "\"\n" :
"\t<machine name=\"" + HttpUtility.HtmlEncode(rom.Game) + "\">\n" + "\t<machine name=\"" + HttpUtility.HtmlEncode(rom.Game) + "\">\n" +
"\t\t<description>" + HttpUtility.HtmlEncode(rom.Game) + "</description>\n"); "\t\t<description>" + HttpUtility.HtmlEncode(rom.Game) + "</description>\n");
} }
if (old) if (datdata.OutputFormat == OutputFormat.ClrMamePro)
{ {
state += "\t" + rom.Type + " ( name \"" + rom.Name + "\"" + state += "\t" + rom.Type + " ( name \"" + rom.Name + "\"" +
(rom.Size != 0 ? " size " + rom.Size : "") + (rom.Size != 0 ? " size " + rom.Size : "") +
@@ -286,7 +278,7 @@ namespace SabreTools.Helper
} }
} }
sw.Write((old ? ")" : "\t</machine>\n</datafile>")); sw.Write((datdata.OutputFormat == OutputFormat.ClrMamePro ? ")" : "\t</machine>\n</datafile>"));
logger.User("File written!" + Environment.NewLine); logger.User("File written!" + Environment.NewLine);
sw.Close(); sw.Close();
fs.Close(); fs.Close();

View File

@@ -20,4 +20,26 @@
public string SHA1; public string SHA1;
public DupeType Dupe; public DupeType Dupe;
} }
/// <summary>
/// Intermediate struct for holding DAT information
/// </summary>
public struct DatData
{
public string Name;
public string Description;
public string Category;
public string Version;
public string Date;
public string Author;
public string Email;
public string Homepage;
public string Url;
public string Comment;
public string Header;
public ForceMerging ForceMerging;
public ForceNodump ForceNodump;
public ForcePacking ForcePacking;
public OutputFormat OutputFormat;
}
} }