[RombaSharp] Add export to RombaSharp

This commit is contained in:
Matt Nadareski
2016-10-12 16:51:42 -07:00
parent 8c7a60d89e
commit 9eded53d6e
3 changed files with 49 additions and 2 deletions

View File

@@ -295,6 +295,42 @@ namespace SabreTools
_logger.User("User Processor Time: " + proc.UserProcessorTime);
}
/// <summary>
/// Export the current database to CSV
/// </summary>
private static void ExportDatabase()
{
SqliteConnection dbc = new SqliteConnection(_connectionString);
dbc.Open();
StreamWriter sw = new StreamWriter(File.Open("export.csv", FileMode.Create, FileAccess.Write));
sw.WriteLine("\"ID\",\"Size\",\"CRC\",\"MD5\",\"SHA-1\",\"In Depot\",\"DAT Hash\"");
string query = "SELECT dats.id, size, crc, md5, sha1, indepot, hash FROM data JOIN dats ON data.id=dats.id";
SqliteCommand slc = new SqliteCommand(query, dbc);
SqliteDataReader sldr = slc.ExecuteReader();
if (sldr.HasRows)
{
while (sldr.Read())
{
string line = "\"" + sldr.GetInt32(0) + "\","
+ "\"" + sldr.GetInt64(1) + "\","
+ "\"" + sldr.GetString(2) + "\","
+ "\"" + sldr.GetString(3) + "\","
+ "\"" + sldr.GetString(4) + "\","
+ "\"" + sldr.GetInt32(5) + "\","
+ "\"" + sldr.GetString(6) + "\"";
sw.WriteLine(line);
}
}
sldr.Dispose();
slc.Dispose();
sw.Dispose();
dbc.Dispose();
}
/// <summary>
/// Moves DAT index entries for orphaned DATs to backup folder
/// </summary>

View File

@@ -75,6 +75,7 @@ namespace SabreTools
dbstats = false,
diffdat = false,
dir2dat = false,
export = false,
fixdat = false,
lookup = false,
memstats = false,
@@ -117,6 +118,9 @@ namespace SabreTools
case "dir2dat":
dir2dat = true;
break;
case "export":
export = true;
break;
case "fixdat":
fixdat = true;
break;
@@ -176,8 +180,8 @@ namespace SabreTools
}
// If more than one switch is enabled, show the help screen
if (!(archive ^ build ^ dbstats ^ diffdat ^ dir2dat ^ fixdat ^ lookup ^ memstats ^ miss ^
progress ^ purgeBackup ^ purgeDelete ^ refreshDats ^ shutdown))
if (!(archive ^ build ^ dbstats ^ diffdat ^ dir2dat ^ export ^ fixdat ^ lookup ^ memstats ^
miss ^ progress ^ purgeBackup ^ purgeDelete ^ refreshDats ^ shutdown))
{
_logger.Error("Only one feature switch is allowed at a time");
Build.Help();
@@ -226,6 +230,12 @@ namespace SabreTools
InitDir2Dat(inputs);
}
// Export the database to file
else if (export)
{
ExportDatabase();
}
// For each specified DAT file it creates a fix DAT
else if (fixdat)
{

View File

@@ -89,6 +89,7 @@ namespace SabreTools.Helper
helptext.Add(" -new= DAT to compare to");
helptext.Add(" dir2dat Creates a DAT file for the specified input directory");
helptext.Add(" -out= Filename to save out to");
helptext.Add(" export Exports db to export.csv");
helptext.Add(" fixdat For each specified DAT file it creates a fix DAT");
helptext.Add(" lookup For each specified hash, look up available information");
helptext.Add(" memstats Prints memory stats");