mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[SabreTools, Output] Add CSV output mode
This commit is contained in:
@@ -137,6 +137,7 @@ Options:
|
|||||||
-re=, --rep-ext= Replace all extensions with specified
|
-re=, --rep-ext= Replace all extensions with specified
|
||||||
-ro, --romba Output in Romba format (requires SHA-1)
|
-ro, --romba Output in Romba format (requires SHA-1)
|
||||||
-tsv, --tsv Output in Tab-Separated Value format
|
-tsv, --tsv Output in Tab-Separated Value format
|
||||||
|
-csv, --csv Output in Comma-Separated Value format
|
||||||
-or, --output-rc Output in RomCenter format
|
-or, --output-rc Output in RomCenter format
|
||||||
-os, --output-sd Output in SabreDAT format
|
-os, --output-sd Output in SabreDAT format
|
||||||
-ox, --output-xml Output in Logiqx XML format
|
-ox, --output-xml Output in Logiqx XML format
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ namespace SabreTools.Helper
|
|||||||
public string AddExt;
|
public string AddExt;
|
||||||
public bool GameName;
|
public bool GameName;
|
||||||
public bool Romba;
|
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
|
// Statistical data related to the DAT
|
||||||
public long RomCount;
|
public long RomCount;
|
||||||
|
|||||||
@@ -159,11 +159,16 @@ namespace SabreTools.Helper
|
|||||||
")\n";
|
")\n";
|
||||||
break;
|
break;
|
||||||
case OutputFormat.MissFile:
|
case OutputFormat.MissFile:
|
||||||
if (datdata.TSV)
|
if (datdata.TSV == true)
|
||||||
{
|
{
|
||||||
header = "File Name\tInternal Name\tDescription\tGame Name\tGame Description\tType\t" +
|
header = "File Name\tInternal Name\tDescription\tGame Name\tGame Description\tType\t" +
|
||||||
"Rom Name\tDisk Name\tSize\tCRC\tMD5\tSHA1\tNodump\n";
|
"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;
|
break;
|
||||||
case OutputFormat.RomCenter:
|
case OutputFormat.RomCenter:
|
||||||
header = "[CREDITS]\n" +
|
header = "[CREDITS]\n" +
|
||||||
@@ -392,8 +397,8 @@ namespace SabreTools.Helper
|
|||||||
" )\n";
|
" )\n";
|
||||||
break;
|
break;
|
||||||
case OutputFormat.MissFile:
|
case OutputFormat.MissFile:
|
||||||
string pre = datdata.Prefix + (datdata.Quotes || datdata.TSV ? "\"" : "");
|
string pre = datdata.Prefix + (datdata.Quotes ? "\"" : "");
|
||||||
string post = (datdata.Quotes || datdata.TSV ? "\"" : "") + datdata.Postfix;
|
string post = (datdata.Quotes ? "\"" : "") + datdata.Postfix;
|
||||||
|
|
||||||
// Check for special strings in prefix and 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());
|
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
|
// 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" +
|
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.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" : "");
|
rom.CRC + "\t" + rom.MD5 + "\t" + rom.SHA1 + "\t" + (rom.Nodump ? "Nodump" : "");
|
||||||
state += pre + inline + post + "\n";
|
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
|
// Otherwise, use any flags
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ namespace SabreTools
|
|||||||
/// <param name="addext">Add an extension to all items</param>
|
/// <param name="addext">Add an extension to all items</param>
|
||||||
/// <param name="datprefix">Add the dat name as a directory prefix</param>
|
/// <param name="datprefix">Add the dat name as a directory prefix</param>
|
||||||
/// <param name="romba">Output files in romba format</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 */
|
/// /* Merging and Diffing info */
|
||||||
/// <param name="merge">True if input files should be merged into a single file, false otherwise</param>
|
/// <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>
|
/// <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,
|
string addext,
|
||||||
bool datprefix,
|
bool datprefix,
|
||||||
bool romba,
|
bool romba,
|
||||||
bool tsv,
|
bool? tsv,
|
||||||
|
|
||||||
/* Merging and Diffing info */
|
/* Merging and Diffing info */
|
||||||
bool merge,
|
bool merge,
|
||||||
|
|||||||
@@ -117,12 +117,12 @@ namespace SabreTools
|
|||||||
stats = false,
|
stats = false,
|
||||||
superdat = false,
|
superdat = false,
|
||||||
trim = false,
|
trim = false,
|
||||||
tsv = false,
|
|
||||||
skip = false,
|
skip = false,
|
||||||
update = false,
|
update = false,
|
||||||
usegame = true;
|
usegame = true;
|
||||||
bool? cascade = null,
|
bool? cascade = null,
|
||||||
nodump = null;
|
nodump = null,
|
||||||
|
tsv = null;
|
||||||
long sgt = -1,
|
long sgt = -1,
|
||||||
slt = -1,
|
slt = -1,
|
||||||
seq = -1;
|
seq = -1;
|
||||||
@@ -203,6 +203,10 @@ namespace SabreTools
|
|||||||
case "--convert-sd":
|
case "--convert-sd":
|
||||||
outputSD = true;
|
outputSD = true;
|
||||||
break;
|
break;
|
||||||
|
case "-csv":
|
||||||
|
case "--csv":
|
||||||
|
tsv = false;
|
||||||
|
break;
|
||||||
case "-cx":
|
case "-cx":
|
||||||
case "--convert-xml":
|
case "--convert-xml":
|
||||||
outputXML = true;
|
outputXML = true;
|
||||||
@@ -588,7 +592,7 @@ namespace SabreTools
|
|||||||
|
|
||||||
// If more than one switch is enabled, show the help screen
|
// If more than one switch is enabled, show the help screen
|
||||||
if (!(add ^ datfromdir ^ extsplit ^ generate ^ genall ^ hashsplit ^ import ^ listsrc ^ listsys ^
|
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))
|
offlineMerge ^ rem ^ stats))
|
||||||
{
|
{
|
||||||
_logger.Error("Only one feature switch is allowed at a time");
|
_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 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))
|
|| outputXML || extsplit || hashsplit || datfromdir || (merge || diff) || stats || trim))
|
||||||
{
|
{
|
||||||
_logger.Error("This feature requires at least one input");
|
_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
|
// 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,
|
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,
|
superdat, forcemerge, forcend, forcepack, outputCMP, outputMiss, outputRC, outputSD, outputXML, usegame, prefix,
|
||||||
|
|||||||
Reference in New Issue
Block a user