Enable multiple source/system merging

This commit is contained in:
Matt Nadareski
2016-03-24 17:38:08 -07:00
parent 4fc30158f3
commit b1df50aab9
2 changed files with 43 additions and 73 deletions

View File

@@ -11,10 +11,8 @@ namespace DATabase
class Generate class Generate
{ {
// Private instance variables // Private instance variables
private int _systems; private string _systems;
//private string _systems; private string _sources;
private int _sources;
//private string _sources;
private string _connectionString; private string _connectionString;
private bool _norename; private bool _norename;
private bool _old; private bool _old;
@@ -22,8 +20,7 @@ namespace DATabase
// Private required variables // Private required variables
private Dictionary<int, string> _headers; private Dictionary<int, string> _headers;
//public Generate(string systems, string sources, string connectionString, bool norename = false, bool old = false) public Generate(string systems, string sources, string connectionString, bool norename = false, bool old = false)
public Generate(int systems, int sources, string connectionString, bool norename = false, bool old = false)
{ {
_systems = systems; _systems = systems;
_sources = sources; _sources = sources;
@@ -44,12 +41,10 @@ namespace DATabase
public bool Export() public bool Export()
{ {
// Get the system name, if applicable // Get the system name, if applicable
string systemname = "ALL"; string systemname = "";
//if (_systems != "") if (_systems != "")
if (_systems != -1)
{ {
//string query = "SELECT manufacturer, system FROM systems WHERE id in (" + _systems + ")"; string query = "SELECT manufacturer, system FROM systems WHERE id in (" + _systems + ")";
string query = "SELECT manufacturer, system FROM systems WHERE id=" + _systems;
using (SQLiteConnection dbc = new SQLiteConnection(_connectionString)) using (SQLiteConnection dbc = new SQLiteConnection(_connectionString))
{ {
dbc.Open(); dbc.Open();
@@ -60,42 +55,38 @@ namespace DATabase
// If there are no games for this combination, return nothing // If there are no games for this combination, return nothing
if (!sldr.HasRows) if (!sldr.HasRows)
{ {
//Console.WriteLine("No system could be found with id in \"" + _systems + "\". Please check and try again."); Console.WriteLine("No system could be found with id in \"" + _systems + "\". Please check and try again.");
Console.WriteLine("No system could be found with id " + _systems + ". Please check and try again.");
return false; return false;
} }
// Retieve and build the system name
sldr.Read();
systemname = sldr.GetString(0) + " - " + sldr.GetString(1);
/*
// Retrieve and build the system name from all retrieved // Retrieve and build the system name from all retrieved
int tempsize = 0; int tempsize = 0;
while (sldr.Read() && tempsize < 3) while (sldr.Read() && tempsize < 3)
{ {
systemname += (tempsize == 0 ? systemname += (tempsize == 0 ?
sldr.GetString(0) + " - " + sldr.GetString(1) : sldr.GetString(0) + " - " + sldr.GetString(1) :
", " + sldr.GetString(0) + " - " + sldr.GetString(1)); "; " + sldr.GetString(0) + " - " + sldr.GetString(1));
tempsize++; tempsize++;
} }
// If there are more than 3 systems, just put "etc." on the end // If there are more than 3 systems, just put "etc." on the end
if (sldr.Read()) if (sldr.Read())
{ {
systemname += ", etc."; systemname += "; etc.";
}
*/
} }
} }
} }
} }
}
else
{
systemname = "ALL";
}
string sourcename = "Merged"; string sourcename = "";
// if (_sources != "") if (_sources != "")
if (_sources != -1)
{ {
//string query = "SELECT name FROM sources WHERE id in (" + _sources + ")"; string query = "SELECT name FROM sources WHERE id in (" + _sources + ")";
string query = "SELECT name FROM sources WHERE id=" + _sources;
using (SQLiteConnection dbc = new SQLiteConnection(_connectionString)) using (SQLiteConnection dbc = new SQLiteConnection(_connectionString))
{ {
dbc.Open(); dbc.Open();
@@ -106,33 +97,31 @@ namespace DATabase
// If there are no games for this combination, return nothing // If there are no games for this combination, return nothing
if (!sldr.HasRows) if (!sldr.HasRows)
{ {
//Console.WriteLine("No source could be found with id in \"" + _sources + "\". Please check and try again."); Console.WriteLine("No source could be found with id in \"" + _sources + "\". Please check and try again.");
Console.WriteLine("No source could be found with id " + _sources + ". Please check and try again.");
return false; return false;
} }
// Retieve and build the system name
sldr.Read();
sourcename = sldr.GetString(0);
/*
// Retrieve and build the source name from all retrieved // Retrieve and build the source name from all retrieved
int tempsize = 0; int tempsize = 0;
while (sldr.Read() && tempsize < 3) while (sldr.Read() && tempsize < 3)
{ {
sourcename += (tempsize == 0 ? sldr.GetString(0) : ", " + sldr.GetString(0)); sourcename += (tempsize == 0 ? sldr.GetString(0) : "; " + sldr.GetString(0));
tempsize++; tempsize++;
} }
// If there are more than 3 systems, just put "etc." on the end // If there are more than 3 systems, just put "etc." on the end
if (sldr.Read()) if (sldr.Read())
{ {
sourcename += ", etc."; sourcename += "; etc.";
}
*/
} }
} }
} }
} }
}
else
{
sourcename = "Merged";
}
// Retrieve the list of processed roms // Retrieve the list of processed roms
List<RomData> roms = ProcessRoms(); List<RomData> roms = ProcessRoms();
@@ -156,19 +145,16 @@ namespace DATabase
StreamWriter sw = new StreamWriter(fs); StreamWriter sw = new StreamWriter(fs);
// Temporarilly set _system if we're in MEGAMERGED mode to get the right header skip XML // Temporarilly set _system if we're in MEGAMERGED mode to get the right header skip XML
//if (_systems == "" && _sources == "") if (_systems == "" && _sources == "")
if (_systems == -1 && _sources == -1)
{ {
//_systems == "0"; _systems = "0";
_systems = 0;
} }
string header_old = "clrmamepro (\n" + string header_old = "clrmamepro (\n" +
"\tname \"" + HttpUtility.HtmlEncode(datname) + "\"\n" + "\tname \"" + HttpUtility.HtmlEncode(datname) + "\"\n" +
"\tdescription \"" + HttpUtility.HtmlEncode(datname) + "\"\n" + "\tdescription \"" + HttpUtility.HtmlEncode(datname) + "\"\n" +
"\tversion \"" + version + "\"\n" + "\tversion \"" + version + "\"\n" +
//(_systems != "" && _systems.Count(c => c == ',') == 0 && _headers.ContainsKey(Int32.Parse(_systems)) ? " header \"" + _headers[Int32.Parse(_systems)] + "\"\n" : "") + (_systems != "" && _systems.Split(',').Length == 1 && _headers.ContainsKey(Int32.Parse(_systems)) ? " header \"" + _headers[Int32.Parse(_systems)] + "\"\n" : "") +
(_systems >= 0 && _headers.ContainsKey(_systems) ? " header \"" + _headers[_systems] + "\"\n" : "") +
"\tcomment \"\"\n" + "\tcomment \"\"\n" +
"\tauthor \"The Wizard of DATz\"\n" + "\tauthor \"The Wizard of DATz\"\n" +
")\n"; ")\n";
@@ -183,16 +169,14 @@ namespace DATabase
"\t\t\t<version>" + version + "</version>\n" + "\t\t\t<version>" + version + "</version>\n" +
"\t\t\t<date>" + version + "</date>\n" + "\t\t\t<date>" + version + "</date>\n" +
"\t\t\t<author>The Wizard of DATz</author>\n" + "\t\t\t<author>The Wizard of DATz</author>\n" +
//(_systems != "" && _systems.Count(c => c == ',') == 0 && _headers.ContainsKey(Int32.Parse(_systems)) ? " header=\"" + _headers[Int32.Parse(_systems)] + "\"\n" : "") + "\t\t\t<clrmamepro" +
"\t\t\t<clrmamepro" + (_systems >= 0 && _headers.ContainsKey(_systems) ? " header=\"" + _headers[_systems] + "\"" : "") + "/>\n" + (_systems != "" && _systems.Split(',').Length == 1 && _headers.ContainsKey(Int32.Parse(_systems)) ? " header=\"" + _headers[Int32.Parse(_systems)] + "\"\n" : "") + "/>\n" +
"\t\t</header>\n"; "\t\t</header>\n";
// Unset _system again if we're in MEGAMERGED mode // Unset _system again if we're in MEGAMERGED mode
//if (_systems == "0" && _sources == "") if (_systems == "0" && _sources == "")
if (_systems == 0 && _sources == -1)
{ {
//_systems = ""; _systems = "";
_systems = -1;
} }
// Write the header out // Write the header out
@@ -257,9 +241,9 @@ namespace DATabase
{ {
List<RomData> roms = new List<RomData>(); List<RomData> roms = new List<RomData>();
// Check if we're in a merged mode // Check if we have listed sources or systems
bool sysmerged = (_systems == -1); bool sysmerged = (_systems != "" && _systems.Split(',').Length > 1);
bool srcmerged = (_sources == -1); bool srcmerged = (_sources != "" && _sources.Split(',').Length > 1);
bool merged = sysmerged || srcmerged; bool merged = sysmerged || srcmerged;
string query = @" string query = @"
@@ -276,12 +260,10 @@ JOIN files
ON games.id=files.setid ON games.id=files.setid
JOIN checksums JOIN checksums
ON files.id=checksums.file" + ON files.id=checksums.file" +
(!sysmerged || !srcmerged ? "\nWHERE" : "") + (_systems != "" || _sources != "" ? "\nWHERE" : "") +
//(!srcmerged ? " sources.id in (" + _sources + ")" : "") + (_sources != "" ? " sources.id in (" + _sources + ")" : "") +
(!srcmerged ? " sources.id=" + _sources : "") + (_systems != "" && _sources != "" ? " AND" : "") +
(!srcmerged && !sysmerged ? " AND" : "") + (_systems != "" ? " systems.id in (" + _systems + ")" : "") +
//(!sysmerged ? " systems.id in (" + _systems + ")" : "") + "\n" +
(!sysmerged ? " systems.id=" + _systems : "") + "\n" +
"\nORDER BY " + "\nORDER BY " +
(merged ? "checksums.size, checksums.crc, checksums.md5, checksums.sha1" (merged ? "checksums.size, checksums.crc, checksums.md5, checksums.sha1"
: "systems.id, sources.id, games.name, files.name"); : "systems.id, sources.id, games.name, files.name");

View File

@@ -88,19 +88,7 @@ namespace DATabase
// Generate a DAT // Generate a DAT
else if (generate) else if (generate)
{ {
int sysid = -1, srcid = -1; Generate gen = new Generate(systems, sources, _connectionString, norename, old);
if (systems != "")
{
Int32.TryParse(systems, out sysid);
}
if (sources != "")
{
Int32.TryParse(sources, out srcid);
}
//Generate gen = new Generate(systems, sources, _connectionString, norename, old);
Generate gen = new Generate(sysid, srcid, _connectionString, norename, old);
gen.Export(); gen.Export();
} }
@@ -195,16 +183,16 @@ ORDER BY systems.manufacturer, systems.system";
Console.Write(@" Console.Write(@"
DATabase - Import and Generate DAT files DATabase - Import and Generate DAT files
----------------------------------------- -----------------------------------------
Usage: DATabase [option] [filename|dirname|<system=sy> <source=so>] Usage: DATabase [option] [filename|dirname|<system=sy,...> <source=so,...>]
Options: Options:
-h, -?, --help Show this help -h, -?, --help Show this help
-i, --import Start tool in import mode -i, --import Start tool in import mode
A filename or folder is required to run A filename or folder is required to run
-g, --generate Start tool in generate mode -g, --generate Start tool in generate mode
system=sy Filter by system ID 'sy' system=sy,... List of system IDs
source=so Filter by source ID 'so' source=so,... List of source IDs
-nr, --no-rename don't rename games -nr, --no-rename Don't auto-rename games
-old produces a DAT in RV format -old produces a DAT in RV format
-lso, --list-sources List all sources (id <= name) -lso, --list-sources List all sources (id <= name)
-lsy, --list-systems List all systems (id <= name) -lsy, --list-systems List all systems (id <= name)