diff --git a/SabreTools.Helper/Data/Build.cs b/SabreTools.Helper/Data/Build.cs index 918a779c..35d605bd 100644 --- a/SabreTools.Helper/Data/Build.cs +++ b/SabreTools.Helper/Data/Build.cs @@ -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 diff --git a/SabreTools.Helper/Data/Structs.cs b/SabreTools.Helper/Data/Structs.cs index 32341ef1..2d3b4e5e 100644 --- a/SabreTools.Helper/Data/Structs.cs +++ b/SabreTools.Helper/Data/Structs.cs @@ -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; diff --git a/SabreTools.Helper/Tools/Output.cs b/SabreTools.Helper/Tools/Output.cs index 24ee062d..9ddb8d50 100644 --- a/SabreTools.Helper/Tools/Output.cs +++ b/SabreTools.Helper/Tools/Output.cs @@ -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 { diff --git a/SabreTools/Partials/SabreTools_Inits.cs b/SabreTools/Partials/SabreTools_Inits.cs index a8861d37..7f627c72 100644 --- a/SabreTools/Partials/SabreTools_Inits.cs +++ b/SabreTools/Partials/SabreTools_Inits.cs @@ -107,7 +107,7 @@ namespace SabreTools /// Add an extension to all items /// Add the dat name as a directory prefix /// Output files in romba format - /// Output files in TSV format + /// True to output files in TSV format, false to output files in CSV format, null otherwise /// /* Merging and Diffing info */ /// True if input files should be merged into a single file, false otherwise /// True if the input files should be diffed with each other, false otherwise @@ -169,7 +169,7 @@ namespace SabreTools string addext, bool datprefix, bool romba, - bool tsv, + bool? tsv, /* Merging and Diffing info */ bool merge, diff --git a/SabreTools/SabreTools.cs b/SabreTools/SabreTools.cs index e0b8ce59..3a1ff751 100644 --- a/SabreTools/SabreTools.cs +++ b/SabreTools/SabreTools.cs @@ -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,