mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
More code changes to accustom diff and AB
This commit is contained in:
@@ -131,10 +131,11 @@ namespace SabreTools
|
||||
{
|
||||
_logger.Log("Total number of lines in database: " + slc.ExecuteScalar());
|
||||
}
|
||||
Output.WriteToDat2(_name + "-db", _desc + "-db", _version, _date, _cat, _author, _forceunpack, _old, _diff, "", dbc, _logger);
|
||||
Output.WriteToDat2(_name + "-db", _desc + "-db", _version, _date, _cat, _author, _forceunpack, _old, _diff, _ad, "", dbc, _logger);
|
||||
|
||||
dbc.Close();
|
||||
|
||||
/*
|
||||
// If we're in Alldiff mode, we can only use the first 2 inputs
|
||||
if (_ad)
|
||||
{
|
||||
@@ -152,6 +153,7 @@ namespace SabreTools
|
||||
Output.WriteToDat(_name + "-" + input1 + "-only", _desc + "-" + input1 + "-only", _version, _date, _cat, _author, _forceunpack, _old, "", OnlyB, _logger);
|
||||
Output.WriteToDat(_name + "-inboth", _desc + "-inboth", _version, _date, _cat, _author, _forceunpack, _old, "", BothAB, _logger);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// If we want a merged list, send it for merging before outputting
|
||||
|
||||
@@ -24,7 +24,8 @@ namespace SabreTools.Helper
|
||||
/// <param name="roms">List of RomData objects representing the games to be written out</param>
|
||||
/// <param name="logger">Logger object for console and/or file output</param>
|
||||
/// <returns>Tru if the DAT was written correctly, false otherwise</returns>
|
||||
public static bool WriteToDat(string name, string description, string version, string date, string category, string author, bool forceunpack, bool old, string outDir, List<RomData> roms, Logger logger)
|
||||
public static bool WriteToDat(string name, string description, string version, string date, string category, string author,
|
||||
bool forceunpack, bool old, string outDir, List<RomData> roms, Logger logger)
|
||||
{
|
||||
// If it's empty, use the current folder
|
||||
if (outDir.Trim() == "")
|
||||
@@ -140,12 +141,13 @@ namespace SabreTools.Helper
|
||||
/// <param name="forceunpack">Force all sets to be unzipped</param>
|
||||
/// <param name="old">Set output mode to old-style DAT</param>
|
||||
/// <param name="diff">Only output files that don't have dupes</param>
|
||||
/// <param name="ab">Enable output of files just in each DAT and also just duped. Best if combined with diff=true.</param>
|
||||
/// <param name="outDir">Set the output directory</param>
|
||||
/// <param name="dbc">Database connection representing the roms to be written</param>
|
||||
/// <param name="logger">Logger object for console and/or file output</param>
|
||||
/// <returns>Tru if the DAT was written correctly, false otherwise</returns>
|
||||
public static bool WriteToDat2(string name, string description, string version, string date, string category,
|
||||
string author, bool forceunpack, bool old, bool diff, string outDir, SqliteConnection dbc, Logger logger)
|
||||
public static bool WriteToDat2(string name, string description, string version, string date, string category, string author,
|
||||
bool forceunpack, bool old, bool diff, bool ab, string outDir, SqliteConnection dbc, Logger logger)
|
||||
{
|
||||
// If it's empty, use the current folder
|
||||
if (outDir.Trim() == "")
|
||||
@@ -159,17 +161,51 @@ namespace SabreTools.Helper
|
||||
outDir += Path.DirectorySeparatorChar;
|
||||
}
|
||||
|
||||
// Get all query strings to use
|
||||
List<string> inputs = new List<string>();
|
||||
inputs.Add("");
|
||||
if (diff)
|
||||
{
|
||||
inputs.Add("WHERE dupe<>'true'");
|
||||
}
|
||||
if (ab)
|
||||
{
|
||||
using (SqliteDataReader sldr = (new SqliteCommand("SELECT DISTINCT dupe FROM roms", dbc).ExecuteReader()))
|
||||
{
|
||||
if (sldr.HasRows)
|
||||
{
|
||||
while (sldr.Read())
|
||||
{
|
||||
inputs.Add("WHERE dupe='" + inputs + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
foreach (string input in inputs)
|
||||
{
|
||||
string tempname = name;
|
||||
string tempdesc = description;
|
||||
|
||||
// If we have special outputs, append the right things
|
||||
if (i != 0)
|
||||
{
|
||||
tempname += " (" + i + ")";
|
||||
tempdesc += " (" + i + ")";
|
||||
}
|
||||
|
||||
// (currently uses current time, change to "last updated time")
|
||||
logger.Log("Opening file for writing: " + outDir + description + (old ? ".dat" : ".xml"));
|
||||
logger.Log("Opening file for writing: " + outDir + tempdesc + (old ? ".dat" : ".xml"));
|
||||
|
||||
try
|
||||
{
|
||||
FileStream fs = File.Create(outDir + description + (old ? ".dat" : ".xml"));
|
||||
FileStream fs = File.Create(outDir + tempdesc + (old ? ".dat" : ".xml"));
|
||||
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
|
||||
|
||||
string header_old = "clrmamepro (\n" +
|
||||
"\tname \"" + HttpUtility.HtmlEncode(name) + "\"\n" +
|
||||
"\tdescription \"" + HttpUtility.HtmlEncode(description) + "\"\n" +
|
||||
"\tname \"" + HttpUtility.HtmlEncode(tempname) + "\"\n" +
|
||||
"\tdescription \"" + HttpUtility.HtmlEncode(tempdesc) + "\"\n" +
|
||||
"\tcategory \"" + HttpUtility.HtmlEncode(category) + "\"\n" +
|
||||
"\tversion \"" + HttpUtility.HtmlEncode(version) + "\"\n" +
|
||||
"\tdate \"" + HttpUtility.HtmlEncode(date) + "\"\n" +
|
||||
@@ -181,8 +217,8 @@ namespace SabreTools.Helper
|
||||
"<!DOCTYPE datafile PUBLIC \"-//Logiqx//DTD ROM Management Datafile//EN\" \"http://www.logiqx.com/Dats/datafile.dtd\">\n\n" +
|
||||
"\t<datafile>\n" +
|
||||
"\t\t<header>\n" +
|
||||
"\t\t\t<name>" + HttpUtility.HtmlEncode(name) + "</name>\n" +
|
||||
"\t\t\t<description>" + HttpUtility.HtmlEncode(description) + "</description>\n" +
|
||||
"\t\t\t<name>" + HttpUtility.HtmlEncode(tempname) + "</name>\n" +
|
||||
"\t\t\t<description>" + HttpUtility.HtmlEncode(tempdesc) + "</description>\n" +
|
||||
"\t\t\t<category>" + HttpUtility.HtmlEncode(category) + "</category>\n" +
|
||||
"\t\t\t<version>" + HttpUtility.HtmlEncode(version) + "</version>\n" +
|
||||
"\t\t\t<date>" + HttpUtility.HtmlEncode(date) + "</date>\n" +
|
||||
@@ -195,7 +231,7 @@ namespace SabreTools.Helper
|
||||
|
||||
// Write out each of the machines and roms
|
||||
string lastgame = "";
|
||||
string query = "SELECT * FROM roms" + (diff ? " WHERE dupe='false'" : "") + " ORDER BY game, name";
|
||||
string query = "SELECT * FROM roms " + input + " ORDER BY game, name";
|
||||
using (SqliteDataReader sldr = (new SqliteCommand(query, dbc).ExecuteReader()))
|
||||
{
|
||||
while (sldr.Read())
|
||||
@@ -250,6 +286,9 @@ namespace SabreTools.Helper
|
||||
return false;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -468,7 +468,7 @@ namespace SabreTools.Helper
|
||||
if (!sldr.HasRows)
|
||||
{
|
||||
query = @"INSERT INTO roms
|
||||
(game, name, type, sysid, srcid, size, crc, md5, sha1)
|
||||
(game, name, type, sysid, srcid, size, crc, md5, sha1, dupe)
|
||||
VALUES ('" + tempname.Replace("'", "''") + "', '" +
|
||||
xtr.GetAttribute("name").Replace("'", "''") + "', '" +
|
||||
xtr.Name + "', " +
|
||||
@@ -478,6 +478,7 @@ VALUES ('" + tempname.Replace("'", "''") + "', '" +
|
||||
(xtr.GetAttribute("crc") != null ? ", '" + xtr.GetAttribute("crc").ToLowerInvariant().Trim() + "'" : ", ''") +
|
||||
(xtr.GetAttribute("md5") != null ? ", '" + xtr.GetAttribute("md5").ToLowerInvariant().Trim() + "'" : ", ''") +
|
||||
(xtr.GetAttribute("sha1") != null ? ", '" + xtr.GetAttribute("sha1").ToLowerInvariant().Trim() + "'" : ", ''") +
|
||||
", '" + filename + "'" +
|
||||
")";
|
||||
using (SqliteCommand sslc = new SqliteCommand(query, dbc))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user