From ba5581af63790eaf44be7f601808067d17dfaf19 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 27 Apr 2016 18:29:29 -0700 Subject: [PATCH] Fix AB output from new database --- DATabase/MergeDiff.cs | 2 +- SabreHelper/Output.cs | 39 ++++++++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/DATabase/MergeDiff.cs b/DATabase/MergeDiff.cs index 44ad1398..6b7d4516 100644 --- a/DATabase/MergeDiff.cs +++ b/DATabase/MergeDiff.cs @@ -131,7 +131,7 @@ 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, _ad, "", dbc, _logger); + Output.WriteToDatFromDb(_name + "-db", _desc + "-db", _version, _date, _cat, _author, _forceunpack, _old, _diff, _ad, "", dbc, _logger); dbc.Close(); diff --git a/SabreHelper/Output.cs b/SabreHelper/Output.cs index 391dc93b..f4a821d3 100644 --- a/SabreHelper/Output.cs +++ b/SabreHelper/Output.cs @@ -130,7 +130,7 @@ namespace SabreTools.Helper } /// - /// Create and open an output file for writing + /// Create and open an output file for writing direct from a database /// /// Internal name of the DAT /// Description and external name of the DAT @@ -146,7 +146,7 @@ namespace SabreTools.Helper /// Database connection representing the roms to be written /// Logger object for console and/or file output /// Tru if the DAT was written correctly, false otherwise - public static bool WriteToDat2(string name, string description, string version, string date, string category, string author, + public static bool WriteToDatFromDb(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 @@ -166,7 +166,7 @@ namespace SabreTools.Helper inputs.Add(""); if (diff) { - inputs.Add("WHERE dupe<>'true'"); + inputs.Add("<>"); } if (ab) { @@ -176,23 +176,42 @@ namespace SabreTools.Helper { while (sldr.Read()) { - inputs.Add("WHERE dupe='" + inputs + "'"); + inputs.Add(sldr.GetString(0)); } } } } - int i = 0; - foreach (string input in inputs) + for (int i = 0; i < inputs.Count; i++) { + // Set strings to be used internally + string input = inputs[i]; + string where = ""; string tempname = name; string tempdesc = description; + // Get the right value from the input + if (input == "<>") + { + where = "WHERE dupe<>'true'"; + input = "diff"; + } + else if (input == "true") + { + where = "WHERE dupe='true'"; + input = "diff"; + } + else if (input != "") + { + where = "WHERE dupe='" + input + "'"; + input = Path.GetFileNameWithoutExtension(input); + } + // If we have special outputs, append the right things if (i != 0) { - tempname += " (" + i + ")"; - tempdesc += " (" + i + ")"; + tempname += " (" + input + ")"; + tempdesc += " (" + input + ")"; } // (currently uses current time, change to "last updated time") @@ -231,7 +250,7 @@ namespace SabreTools.Helper // Write out each of the machines and roms string lastgame = ""; - string query = "SELECT * FROM roms " + input + " ORDER BY game, name"; + string query = "SELECT * FROM roms " + where + " ORDER BY game, name"; using (SqliteDataReader sldr = (new SqliteCommand(query, dbc).ExecuteReader())) { while (sldr.Read()) @@ -285,8 +304,6 @@ namespace SabreTools.Helper logger.Error(ex.ToString()); return false; } - - i++; } return true;