[SabreTools, Output] Add CSV output mode

This commit is contained in:
Matt Nadareski
2016-08-23 15:18:37 -07:00
parent 12f1c3aa90
commit 23634d0d58
5 changed files with 30 additions and 12 deletions

View File

@@ -137,6 +137,7 @@ Options:
-re=, --rep-ext= Replace all extensions with specified
-ro, --romba Output in Romba format (requires SHA-1)
-tsv, --tsv Output in Tab-Separated Value format
-csv, --csv Output in Comma-Separated Value format
-or, --output-rc Output in RomCenter format
-os, --output-sd Output in SabreDAT format
-ox, --output-xml Output in Logiqx XML format

View File

@@ -110,7 +110,7 @@ namespace SabreTools.Helper
public string AddExt;
public bool GameName;
public bool Romba;
public bool TSV; // tab-deliminated output
public bool? TSV; // true for tab-deliminated output, false for comma-deliminated output
// Statistical data related to the DAT
public long RomCount;

View File

@@ -159,11 +159,16 @@ namespace SabreTools.Helper
")\n";
break;
case OutputFormat.MissFile:
if (datdata.TSV)
if (datdata.TSV == true)
{
header = "File Name\tInternal Name\tDescription\tGame Name\tGame Description\tType\t" +
"Rom Name\tDisk Name\tSize\tCRC\tMD5\tSHA1\tNodump\n";
}
else if (datdata.TSV == false)
{
header = "\"File Name\",\"Internal Name\",\"Description\",\"Game Name\",\"Game Description\",\"Type\",\"" +
"Rom Name\",\"Disk Name\",\"Size\",\"CRC\",\"MD5\",\"SHA1\",\"Nodump\n";
}
break;
case OutputFormat.RomCenter:
header = "[CREDITS]\n" +
@@ -392,8 +397,8 @@ namespace SabreTools.Helper
" )\n";
break;
case OutputFormat.MissFile:
string pre = datdata.Prefix + (datdata.Quotes || datdata.TSV ? "\"" : "");
string post = (datdata.Quotes || datdata.TSV ? "\"" : "") + datdata.Postfix;
string pre = datdata.Prefix + (datdata.Quotes ? "\"" : "");
string post = (datdata.Quotes ? "\"" : "") + datdata.Postfix;
// Check for special strings in prefix and postfix
pre = pre.Replace("%crc%", rom.CRC).Replace("%md5%", rom.MD5).Replace("%sha1%", rom.SHA1).Replace("%size%", rom.Size.ToString());
@@ -411,13 +416,21 @@ namespace SabreTools.Helper
}
}
// If we're in TSV mode, similarly the state is consistent
else if (datdata.TSV)
else if (datdata.TSV == true)
{
string inline = datdata.FileName + "\t" + datdata.Name + "\t" + datdata.Description + "\t" + rom.Game + "\t" + rom.Game + "\t" +
rom.Type + "\t" + (rom.Type == "rom" ? rom.Name : "") + "\t" + (rom.Type == "disk" ? rom.Name : "") + "\t" + rom.Size + "\t" +
rom.CRC + "\t" + rom.MD5 + "\t" + rom.SHA1 + "\t" + (rom.Nodump ? "Nodump" : "");
state += pre + inline + post + "\n";
}
// If we're in CSV mode, similarly the state is consistent
else if (datdata.TSV == false)
{
string inline = "\"" + datdata.FileName + "\",\"" + datdata.Name + "\",\"" + datdata.Description + "\",\"" + rom.Game + "\",\"" + rom.Game + "\",\"" +
rom.Type + "\",\"" + (rom.Type == "rom" ? rom.Name : "") + "\",\"" + (rom.Type == "disk" ? rom.Name : "") + "\",\"" + rom.Size + "\",\"" +
rom.CRC + "\",\"" + rom.MD5 + "\",\"" + rom.SHA1 + "\"," + (rom.Nodump ? "\"Nodump\"" : "\"\"");
state += pre + inline + post + "\n";
}
// Otherwise, use any flags
else
{

View File

@@ -107,7 +107,7 @@ namespace SabreTools
/// <param name="addext">Add an extension to all items</param>
/// <param name="datprefix">Add the dat name as a directory prefix</param>
/// <param name="romba">Output files in romba format</param>
/// <param name="tsv">Output files in TSV format</param>
/// <param name="tsv">True to output files in TSV format, false to output files in CSV format, null otherwise</param>
/// /* Merging and Diffing info */
/// <param name="merge">True if input files should be merged into a single file, false otherwise</param>
/// <param name="diff">True if the input files should be diffed with each other, false otherwise</param>
@@ -169,7 +169,7 @@ namespace SabreTools
string addext,
bool datprefix,
bool romba,
bool tsv,
bool? tsv,
/* Merging and Diffing info */
bool merge,

View File

@@ -117,12 +117,12 @@ namespace SabreTools
stats = false,
superdat = false,
trim = false,
tsv = false,
skip = false,
update = false,
usegame = true;
bool? cascade = null,
nodump = null;
nodump = null,
tsv = null;
long sgt = -1,
slt = -1,
seq = -1;
@@ -203,6 +203,10 @@ namespace SabreTools
case "--convert-sd":
outputSD = true;
break;
case "-csv":
case "--csv":
tsv = false;
break;
case "-cx":
case "--convert-xml":
outputXML = true;
@@ -588,7 +592,7 @@ namespace SabreTools
// If more than one switch is enabled, show the help screen
if (!(add ^ datfromdir ^ extsplit ^ generate ^ genall ^ hashsplit ^ import ^ listsrc ^ listsys ^
(merge || diff || update || outputCMP || outputRC || outputSD || outputXML || outputMiss || tsv || trim) ^
(merge || diff || update || outputCMP || outputRC || outputSD || outputXML || outputMiss || tsv != null|| trim) ^
offlineMerge ^ rem ^ stats))
{
_logger.Error("Only one feature switch is allowed at a time");
@@ -598,7 +602,7 @@ namespace SabreTools
}
// If a switch that requires a filename is set and no file is, show the help screen
if (inputs.Count == 0 && (update || (outputMiss || tsv) || outputCMP || outputRC || outputSD
if (inputs.Count == 0 && (update || (outputMiss || tsv != null) || outputCMP || outputRC || outputSD
|| outputXML || extsplit || hashsplit || datfromdir || (merge || diff) || stats || trim))
{
_logger.Error("This feature requires at least one input");
@@ -642,7 +646,7 @@ namespace SabreTools
}
// Convert, update, merge, diff, and filter a DAT or folder of DATs
else if (update || outputCMP || outputMiss || tsv || outputRC || outputSD || outputXML || merge || diff)
else if (update || outputCMP || outputMiss || tsv != null || outputRC || outputSD || outputXML || merge || diff)
{
InitUpdate(inputs, filename, name, description, rootdir, category, version, date, author, email, homepage, url, comment, header,
superdat, forcemerge, forcend, forcepack, outputCMP, outputMiss, outputRC, outputSD, outputXML, usegame, prefix,