diff --git a/DATabase/DATabase.cs b/DATabase/DATabase.cs index 9dbdd9a7..d317ccf6 100644 --- a/DATabase/DATabase.cs +++ b/DATabase/DATabase.cs @@ -24,7 +24,7 @@ namespace SabreTools /// + This requires implementing a "last updated" data point for all DATs and tracking for "last generate" somewhere /// - Impelement a ToSort folder for DATs that will place DATs in the correct subfolder on Import /// - public class DATabase + public partial class DATabase { // Private required variables private static string _datroot = "DATS"; @@ -73,11 +73,6 @@ namespace SabreTools bare = false, cascade = false, clean = false, - convertMiss = false, - convertCMP = false, - convertRC = false, - convertSD = false, - convertXml = false, dedup = false, diff = false, gamename = false, @@ -95,6 +90,11 @@ namespace SabreTools merge = false, norename = false, old = false, + outputCMP = false, + outputMiss = false, + outputRC = false, + outputSD = false, + outputXML = false, quotes = false, rem = false, romba = false, @@ -104,13 +104,23 @@ namespace SabreTools trim = false, tsv = false, skip = false, + update = false, usegame = true; string addext = "", author = "", - cat = "", - desc = "", + category = "", + comment = "", + date = "", + description = "", + email = "", exta = "", extb = "", + filename = "", + forcemerge = "", + forcend = "", + forcepack = "", + header = "", + homepage = "", name = "", manu = "", outdir = "", @@ -146,30 +156,10 @@ namespace SabreTools case "--cascade": cascade = true; break; - case "-cc": - case "--convert-cmp": - convertCMP = true; - break; case "-clean": case "--clean": clean = true; break; - case "-cm": - case "--convert-miss": - convertMiss = true; - break; - case "-cr": - case "--convert-rc": - convertRC = true; - break; - case "-cs": - case "--convert-sd": - convertSD = true; - break; - case "-cx": - case "--convert-xml": - convertXml = true; - break; case "-dd": case "--dedup": dedup = true; @@ -234,6 +224,26 @@ namespace SabreTools case "--old": old = true; break; + case "-oc": + case "--output-cmp": + outputCMP = true; + break; + case "-om": + case "--output-miss": + outputMiss = true; + break; + case "-or": + case "--output-rc": + outputRC = true; + break; + case "-os": + case "--output-sd": + outputSD = true; + break; + case "-ox": + case "--output-xml": + outputXML = true; + break; case "-q": case "--quotes": quotes = true; @@ -277,6 +287,10 @@ namespace SabreTools case "--unzip": forceunpack = true; break; + case "-ud": + case "--update": + update = true; + break; default: if (arg.StartsWith("-ae=") || arg.StartsWith("--add-ext=")) { @@ -286,13 +300,25 @@ namespace SabreTools { author = arg.Split('=')[1]; } - else if (arg.StartsWith("-c=") || arg.StartsWith("--cat=")) + else if (arg.StartsWith("-ca=") || arg.StartsWith("--category=")) { - cat = arg.Split('=')[1]; + category = arg.Split('=')[1]; } - else if (arg.StartsWith("-d=") || arg.StartsWith("--desc=")) + else if (arg.StartsWith("-co=") || arg.StartsWith("--comment=")) { - desc = arg.Split('=')[1]; + comment = arg.Split('=')[1]; + } + else if (arg.StartsWith("-da=") || arg.StartsWith("--date=")) + { + date = arg.Split('=')[1]; + } + else if (arg.StartsWith("-de=") || arg.StartsWith("--desc=")) + { + description = arg.Split('=')[1]; + } + else if (arg.StartsWith("-em=") || arg.StartsWith("--email=")) + { + email = arg.Split('=')[1]; } else if (arg.StartsWith("-exta=")) { @@ -302,6 +328,30 @@ namespace SabreTools { extb = arg.Split('=')[1]; } + else if (arg.StartsWith("-f=") || arg.StartsWith("--filename=")) + { + filename = arg.Split('=')[1]; + } + else if (arg.StartsWith("-fm=") || arg.StartsWith("--forcemerge=")) + { + forcemerge = arg.Split('=')[1]; + } + else if (arg.StartsWith("-fn=") || arg.StartsWith("--forcend=")) + { + forcend = arg.Split('=')[1]; + } + else if (arg.StartsWith("-fp=") || arg.StartsWith("--forcepack=")) + { + forcepack = arg.Split('=')[1]; + } + else if (arg.StartsWith("-h=") || arg.StartsWith("--header=")) + { + header = arg.Split('=')[1]; + } + else if (arg.StartsWith("-hp=") || arg.StartsWith("--homepage=")) + { + homepage = arg.Split('=')[1]; + } else if (arg.StartsWith("-input=")) { inputs.Add(arg.Split('=')[1].Replace("\"", "")); @@ -342,6 +392,10 @@ namespace SabreTools { repext = arg.Split('=')[1]; } + else if (arg.StartsWith("-u=") || arg.StartsWith("--url=")) + { + url = arg.Split('=')[1]; + } else if (arg.StartsWith("-url=") && url == "") { url = arg.Split('=')[1]; @@ -373,8 +427,8 @@ namespace SabreTools } // If more than one switch is enabled or help is set, show the help screen - if (help || !(add ^ (convertMiss || romba) ^ convertCMP ^ convertRC ^ convertSD ^ convertXml ^ extsplit ^ generate ^ - genall ^ hashsplit ^ import ^ listsrc ^ listsys ^ (merge || diff) ^ rem ^ stats ^ trim)) + if (help || !(add ^ extsplit ^ generate ^ genall ^ hashsplit ^ import ^ listsrc ^ listsys ^ (merge || diff) ^ + (update || outputCMP || outputRC || outputSD || outputXML || outputMiss || romba) ^ rem ^ stats ^ trim)) { _logger.Error("Only one feature switch is allowed at a time"); Build.Help(); @@ -383,8 +437,8 @@ namespace SabreTools } // If a switch that requires a filename is set and no file is, show the help screen - if (inputs.Count == 0 && ((convertMiss || romba) || convertCMP || convertRC || convertSD - || convertXml || extsplit || hashsplit || (merge || diff) || stats || trim)) + if (inputs.Count == 0 && (update || (outputMiss || romba) || outputCMP || outputRC || outputSD + || outputXML || extsplit || hashsplit || (merge || diff) || stats || trim)) { _logger.Error("This feature requires at least one input"); Build.Help(); @@ -426,48 +480,14 @@ namespace SabreTools ListSystems(); } - // Convert DAT to missfile - else if (convertMiss || romba) + // Convert or update a DAT or folder of DATs + else if (update || outputCMP || outputMiss || outputRC || outputSD || outputXML || romba) { foreach (string input in inputs) { - InitConvertMiss(input, usegame, prefix, postfix, quotes, repext, addext, gamename, romba, tsv); - } - } - - // Convert any DAT to CMP DAT - else if (convertCMP) - { - foreach (string input in inputs) - { - InitConvert(input, OutputFormat.ClrMamePro, outdir, clean); - } - } - - // Convert any DAT to RC DAT - else if (convertRC) - { - foreach (string input in inputs) - { - InitConvert(input, OutputFormat.RomCenter, outdir, clean); - } - } - - // Convert any DAT to SabreDAT - else if (convertSD) - { - foreach (string input in inputs) - { - InitConvert(input, OutputFormat.SabreDat, outdir, clean); - } - } - - // Convert any DAT to XML DAT - else if (convertXml) - { - foreach (string input in inputs) - { - InitConvert(input, OutputFormat.Xml, outdir, clean); + InitUpdate(input, filename, name, description, category, version, date, author, email, homepage, url, comment, header, + superdat, forcemerge, forcend, forcepack, outputCMP, outputMiss, outputRC, outputSD, outputXML, usegame, prefix, + postfix, quotes, repext, addext, gamename, romba, tsv, outdir, clean); } } @@ -526,7 +546,7 @@ namespace SabreTools // Merge, diff, and dedupe at least 2 DATs else if (merge || diff) { - InitMergeDiff(inputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, superdat, cascade, inplace, outdir, clean); + InitMergeDiff(inputs, name, description, category, version, author, diff, dedup, bare, forceunpack, old, superdat, cascade, inplace, outdir, clean); } // Split a DAT by available hashes @@ -542,7 +562,10 @@ namespace SabreTools } // If nothing is set, show the help - Build.Help(); + else + { + Build.Help(); + } _logger.Close(); return; @@ -1333,185 +1356,6 @@ Make a selection: imp.UpdateDatabase(); } - /// - /// Wrap generating a DAT from the library - /// - /// System ID to be used in the DAT (blank means all) - /// True if files should not be renamed with system and/or source in merged mode (default false) - /// True if the output file should be in ClrMamePro format (default false) - private static void InitGenerate(string systemid, bool norename, bool old) - { - IGenerate gen = new GenerateTwo(systemid, "" /* sourceid */, _datroot, _outroot, _connectionString, _logger, norename, old); - gen.Export(); - } - - /// - /// Wrap generating all standard DATs from the library - /// - private static void InitGenerateAll(bool norename, bool old) - { - List systems = new List(); - using (SqliteConnection dbc = new SqliteConnection(_connectionString)) - { - dbc.Open(); - - string query = "SELECT id FROM system"; - using (SqliteCommand slc = new SqliteCommand(query, dbc)) - { - using (SqliteDataReader sldr = slc.ExecuteReader()) - { - // If nothing is found, tell the user and exit - if (!sldr.HasRows) - { - _logger.Warning("No systems found! Please add a system and then try again."); - return; - } - - while (sldr.Read()) - { - systems.Add(sldr.GetInt32(0).ToString()); - } - } - } - - // Loop through the inputs - foreach (string system in systems) - { - _logger.User("Generating DAT for system id " + system); - InitGenerate(system, norename, old); - } - } - } - - /// - /// Wrap converting DAT file from any format to any format - /// - /// - /// - /// Optional param for output directory - /// True to clean the game names to WoD standard, false otherwise (default) - private static void InitConvert(string filename, OutputFormat outputFormat, string outdir, bool clean) - { - // Clean the input strings - outdir = outdir.Replace("\"", ""); - if (outdir != "") - { - outdir = Path.GetFullPath(outdir) + Path.DirectorySeparatorChar; - } - filename = filename.Replace("\"", ""); - - if (File.Exists(filename)) - { - _logger.User("Converting \"" + Path.GetFileName(filename) + "\""); - DatData datdata = new DatData - { - OutputFormat = outputFormat, - MergeRoms = false, - }; - datdata = RomManipulation.Parse(filename, 0, 0, datdata, _logger, true, clean); - - // If the extension matches, append ".new" to the filename - string extension = (datdata.OutputFormat == OutputFormat.Xml || datdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat"); - if (outdir == "" && Path.GetExtension(filename) == extension) - { - datdata.FileName += ".new"; - } - - Output.WriteDatfile(datdata, (outdir == "" ? Path.GetDirectoryName(filename) : outdir), _logger); - } - else if (Directory.Exists(filename)) - { - filename = Path.GetFullPath(filename) + Path.DirectorySeparatorChar; - - foreach (string file in Directory.EnumerateFiles(filename, "*", SearchOption.AllDirectories)) - { - _logger.User("Converting \"" + Path.GetFullPath(file).Remove(0, filename.Length) + "\""); - DatData datdata = new DatData - { - OutputFormat = outputFormat, - MergeRoms = false, - }; - datdata = RomManipulation.Parse(file, 0, 0, datdata, _logger, true, clean); - - // If the extension matches, append ".new" to the filename - string extension = (datdata.OutputFormat == OutputFormat.Xml || datdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat"); - if (outdir == "" && Path.GetExtension(file) == extension) - { - datdata.FileName += ".new"; - } - - Output.WriteDatfile(datdata, (outdir == "" ? Path.GetDirectoryName(file) : outdir + Path.GetDirectoryName(file).Remove(0, filename.Length - 1)), _logger); - } - } - else - { - _logger.Error("I'm sorry but " + filename + " doesn't exist!"); - } - return; - } - - /// - /// Wrap converting a DAT to missfile - /// - /// File to be converted - /// True if games are to be used in output, false if roms are - /// Generic prefix to be added to each line - /// Generic postfix to be added to each line - /// Add quotes to each item - /// Replace all extensions with another - /// Add an extension to all items - /// Add the dat name as a directory prefix - /// Output files in romba format - /// Output files in TSV format - private static void InitConvertMiss(string input, bool usegame, string prefix, string postfix, bool quotes, - string repext, string addext, bool gamename, bool romba, bool tsv) - { - // Strip any quotations from the name - input = input.Replace("\"", ""); - - if (input != "" && File.Exists(input)) - { - // Get the full input name - input = Path.GetFullPath(input); - - // Get the output name - string name = Path.GetFileNameWithoutExtension(input) + "-miss"; - - // Read in the roms from the DAT and then write them to the file - _logger.User("Converting " + input); - DatData datdata = new DatData - { - OutputFormat = OutputFormat.MissFile, - - UseGame = usegame, - Prefix = prefix, - Postfix = postfix, - AddExt = addext, - RepExt = repext, - Quotes = quotes, - GameName = gamename, - Romba = romba, - TSV = tsv, - }; - datdata = RomManipulation.Parse(input, 0, 0, datdata, _logger); - datdata.FileName += "-miss"; - datdata.Name += "-miss"; - datdata.Description += "-miss"; - - // Normalize the extensions - addext = (addext == "" || addext.StartsWith(".") ? addext : "." + addext); - repext = (repext == "" || repext.StartsWith(".") ? repext : "." + repext); - - Output.WriteDatfile(datdata, Path.GetDirectoryName(input), _logger); - _logger.User(input + " converted to: " + name); - return; - } - else - { - _logger.Error("I'm sorry but " + input + "doesn't exist!"); - } - } - /// /// Wrap trimming and merging a single DAT /// diff --git a/DATabase/DATabase.csproj b/DATabase/DATabase.csproj index b138ca68..93e0e042 100644 --- a/DATabase/DATabase.csproj +++ b/DATabase/DATabase.csproj @@ -112,9 +112,11 @@ + + diff --git a/DATabase/Partials/DATabase_InitGenerate.cs b/DATabase/Partials/DATabase_InitGenerate.cs new file mode 100644 index 00000000..a262f578 --- /dev/null +++ b/DATabase/Partials/DATabase_InitGenerate.cs @@ -0,0 +1,60 @@ +using System.Collections.Generic; +using Mono.Data.Sqlite; + +using SabreTools.Helper; + +namespace SabreTools +{ + public partial class DATabase + { + /// + /// Wrap generating a DAT from the library + /// + /// System ID to be used in the DAT (blank means all) + /// True if files should not be renamed with system and/or source in merged mode (default false) + /// True if the output file should be in ClrMamePro format (default false) + private static void InitGenerate(string systemid, bool norename, bool old) + { + IGenerate gen = new GenerateTwo(systemid, "" /* sourceid */, _datroot, _outroot, _connectionString, _logger, norename, old); + gen.Export(); + } + + /// + /// Wrap generating all standard DATs from the library + /// + private static void InitGenerateAll(bool norename, bool old) + { + List systems = new List(); + using (SqliteConnection dbc = new SqliteConnection(_connectionString)) + { + dbc.Open(); + + string query = "SELECT id FROM system"; + using (SqliteCommand slc = new SqliteCommand(query, dbc)) + { + using (SqliteDataReader sldr = slc.ExecuteReader()) + { + // If nothing is found, tell the user and exit + if (!sldr.HasRows) + { + _logger.Warning("No systems found! Please add a system and then try again."); + return; + } + + while (sldr.Read()) + { + systems.Add(sldr.GetInt32(0).ToString()); + } + } + } + + // Loop through the inputs + foreach (string system in systems) + { + _logger.User("Generating DAT for system id " + system); + InitGenerate(system, norename, old); + } + } + } + } +} diff --git a/DATabase/Partials/DATabase_InitUpdate.cs b/DATabase/Partials/DATabase_InitUpdate.cs new file mode 100644 index 00000000..a8e8f560 --- /dev/null +++ b/DATabase/Partials/DATabase_InitUpdate.cs @@ -0,0 +1,386 @@ +using System.IO; +using SabreTools.Helper; + +namespace SabreTools +{ + public partial class DATabase + { + /// + /// Wrap converting and updating DAT file from any format to any format + /// + /// Input filename + /// New filename + /// New name + /// New description + /// New category + /// New version + /// New date + /// New author + /// New email + /// New homepage + /// New URL + /// New comment + /// New header + /// True to set SuperDAT type, false otherwise + /// None, Split, Full + /// None, Obsolete, Required, Ignore + /// None, Zip, Unzip + /// True to output to ClrMamePro format + /// True to output to Missfile format + /// True to output to RomCenter format + /// True to output to SabreDAT format + /// True to output to Logiqx XML format + /// True if games are to be used in output, false if roms are + /// Generic prefix to be added to each line + /// Generic postfix to be added to each line + /// Add quotes to each item + /// Replace all extensions with another + /// Add an extension to all items + /// Add the dat name as a directory prefix + /// Output files in romba format + /// Output files in TSV format + /// Optional param for output directory + /// True to clean the game names to WoD standard, false otherwise (default) + public static void InitUpdate(string input, + string filename, + string name, + string description, + string category, + string version, + string date, + string author, + string email, + string homepage, + string url, + string comment, + string header, + bool superdat, + string forcemerge, + string forcend, + string forcepack, + bool outputCMP, + bool outputMiss, + bool outputRC, + bool outputSD, + bool outputXML, + bool usegame, + string prefix, + string postfix, + bool quotes, + string repext, + string addext, + bool gamename, + bool romba, + bool tsv, + string outdir, + bool clean) + { + // Set the special flags + ForceMerging fm = ForceMerging.None; + switch (forcemerge.ToLowerInvariant()) + { + case "none": + default: + fm = ForceMerging.None; + break; + case "split": + fm = ForceMerging.Split; + break; + case "full": + fm = ForceMerging.Full; + break; + } + + ForceNodump fn = ForceNodump.None; + switch (forcend.ToLowerInvariant()) + { + case "none": + default: + fn = ForceNodump.None; + break; + case "obsolete": + fn = ForceNodump.Obsolete; + break; + case "required": + fn = ForceNodump.Required; + break; + case "ignore": + fn = ForceNodump.Ignore; + break; + } + + ForcePacking fp = ForcePacking.None; + switch (forcepack.ToLowerInvariant()) + { + case "none": + default: + fp = ForcePacking.None; + break; + case "zip": + fp = ForcePacking.Zip; + break; + case "unzip": + fp = ForcePacking.Unzip; + break; + } + + // Normalize the extensions + addext = (addext == "" || addext.StartsWith(".") ? addext : "." + addext); + repext = (repext == "" || repext.StartsWith(".") ? repext : "." + repext); + + // Populate the DatData object + DatData userInputDat = new DatData + { + FileName = filename, + Name = name, + Description = description, + Category = category, + Version = version, + Date = date, + Author = author, + Email = email, + Homepage = homepage, + Url = url, + Comment = comment, + Header = header, + Type = (superdat ? "SuperDAT" : null), + ForceMerging = fm, + ForceNodump = fn, + ForcePacking = fp, + MergeRoms = false, + + UseGame = usegame, + Prefix = prefix, + Postfix = postfix, + Quotes = quotes, + RepExt = repext, + AddExt = addext, + GameName = gamename, + Romba = romba, + TSV = tsv, + }; + + if (outputCMP) + { + userInputDat.OutputFormat = OutputFormat.ClrMamePro; + InitUpdate(input, userInputDat, outdir, clean); + } + if (outputMiss || romba) + { + userInputDat.OutputFormat = OutputFormat.MissFile; + InitUpdate(input, userInputDat, outdir, clean); + } + if (outputRC) + { + userInputDat.OutputFormat = OutputFormat.RomCenter; + InitUpdate(input, userInputDat, outdir, clean); + } + if (outputSD) + { + userInputDat.OutputFormat = OutputFormat.SabreDat; + InitUpdate(input, userInputDat, outdir, clean); + } + if (outputXML) + { + userInputDat.OutputFormat = OutputFormat.Xml; + InitUpdate(input, userInputDat, outdir, clean); + } + if (!outputCMP && !(outputMiss || romba) && !outputRC && !outputSD && !outputXML) + { + InitUpdate(input, userInputDat, outdir, clean); + } + } + + /// + /// Wrap converting and updating DAT file from any format to any format + /// + /// Name of the input file or folder + /// User specified inputs contained in a DatData object + /// Optional param for output directory + /// True to clean the game names to WoD standard, false otherwise (default) + public static void InitUpdate(string inputFileName, DatData datdata, string outputDirectory, bool clean = false) + { + // Clean the input strings + outputDirectory = outputDirectory.Replace("\"", ""); + if (outputDirectory != "") + { + outputDirectory = Path.GetFullPath(outputDirectory) + Path.DirectorySeparatorChar; + } + inputFileName = inputFileName.Replace("\"", ""); + + if (File.Exists(inputFileName)) + { + _logger.User("Converting \"" + Path.GetFileName(inputFileName) + "\""); + datdata = RomManipulation.Parse(inputFileName, 0, 0, datdata, _logger, true, clean); + + // If the extension matches, append ".new" to the filename + string extension = (datdata.OutputFormat == OutputFormat.Xml || datdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat"); + if (outputDirectory == "" && Path.GetExtension(inputFileName) == extension) + { + datdata.FileName += ".new"; + } + + Output.WriteDatfile(datdata, (outputDirectory == "" ? Path.GetDirectoryName(inputFileName) : outputDirectory), _logger); + } + else if (Directory.Exists(inputFileName)) + { + inputFileName = Path.GetFullPath(inputFileName) + Path.DirectorySeparatorChar; + + foreach (string file in Directory.EnumerateFiles(inputFileName, "*", SearchOption.AllDirectories)) + { + _logger.User("Converting \"" + Path.GetFullPath(file).Remove(0, inputFileName.Length) + "\""); + DatData innerDatdata = (DatData)datdata.Clone(); + innerDatdata.Roms = null; + innerDatdata = RomManipulation.Parse(file, 0, 0, innerDatdata, _logger, true, clean); + + // If the extension matches, append ".new" to the filename + string extension = (innerDatdata.OutputFormat == OutputFormat.Xml || innerDatdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat"); + if (outputDirectory == "" && Path.GetExtension(file) == extension) + { + innerDatdata.FileName += ".new"; + } + + Output.WriteDatfile(innerDatdata, (outputDirectory == "" ? Path.GetDirectoryName(file) : outputDirectory + Path.GetDirectoryName(file).Remove(0, inputFileName.Length - 1)), _logger); + } + } + else + { + _logger.Error("I'm sorry but " + inputFileName + " doesn't exist!"); + } + return; + } + + #region OBSOLETE + + /// + /// Wrap converting DAT file from any format to any format + /// + /// + /// + /// Optional param for output directory + /// True to clean the game names to WoD standard, false otherwise (default) + private static void InitConvert(string filename, OutputFormat outputFormat, string outdir, bool clean) + { + // Clean the input strings + outdir = outdir.Replace("\"", ""); + if (outdir != "") + { + outdir = Path.GetFullPath(outdir) + Path.DirectorySeparatorChar; + } + filename = filename.Replace("\"", ""); + + if (File.Exists(filename)) + { + _logger.User("Converting \"" + Path.GetFileName(filename) + "\""); + DatData datdata = new DatData + { + OutputFormat = outputFormat, + MergeRoms = false, + }; + datdata = RomManipulation.Parse(filename, 0, 0, datdata, _logger, true, clean); + + // If the extension matches, append ".new" to the filename + string extension = (datdata.OutputFormat == OutputFormat.Xml || datdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat"); + if (outdir == "" && Path.GetExtension(filename) == extension) + { + datdata.FileName += ".new"; + } + + Output.WriteDatfile(datdata, (outdir == "" ? Path.GetDirectoryName(filename) : outdir), _logger); + } + else if (Directory.Exists(filename)) + { + filename = Path.GetFullPath(filename) + Path.DirectorySeparatorChar; + + foreach (string file in Directory.EnumerateFiles(filename, "*", SearchOption.AllDirectories)) + { + _logger.User("Converting \"" + Path.GetFullPath(file).Remove(0, filename.Length) + "\""); + DatData datdata = new DatData + { + OutputFormat = outputFormat, + MergeRoms = false, + }; + datdata = RomManipulation.Parse(file, 0, 0, datdata, _logger, true, clean); + + // If the extension matches, append ".new" to the filename + string extension = (datdata.OutputFormat == OutputFormat.Xml || datdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat"); + if (outdir == "" && Path.GetExtension(file) == extension) + { + datdata.FileName += ".new"; + } + + Output.WriteDatfile(datdata, (outdir == "" ? Path.GetDirectoryName(file) : outdir + Path.GetDirectoryName(file).Remove(0, filename.Length - 1)), _logger); + } + } + else + { + _logger.Error("I'm sorry but " + filename + " doesn't exist!"); + } + return; + } + + /// + /// Wrap converting a DAT to missfile + /// + /// File to be converted + /// True if games are to be used in output, false if roms are + /// Generic prefix to be added to each line + /// Generic postfix to be added to each line + /// Add quotes to each item + /// Replace all extensions with another + /// Add an extension to all items + /// Add the dat name as a directory prefix + /// Output files in romba format + /// Output files in TSV format + private static void InitConvertMiss(string input, bool usegame, string prefix, string postfix, bool quotes, + string repext, string addext, bool gamename, bool romba, bool tsv) + { + // Strip any quotations from the name + input = input.Replace("\"", ""); + + if (input != "" && File.Exists(input)) + { + // Get the full input name + input = Path.GetFullPath(input); + + // Get the output name + string name = Path.GetFileNameWithoutExtension(input) + "-miss"; + + // Read in the roms from the DAT and then write them to the file + _logger.User("Converting " + input); + DatData datdata = new DatData + { + OutputFormat = OutputFormat.MissFile, + + UseGame = usegame, + Prefix = prefix, + Postfix = postfix, + AddExt = addext, + RepExt = repext, + Quotes = quotes, + GameName = gamename, + Romba = romba, + TSV = tsv, + }; + datdata = RomManipulation.Parse(input, 0, 0, datdata, _logger); + datdata.FileName += "-miss"; + datdata.Name += "-miss"; + datdata.Description += "-miss"; + + // Normalize the extensions + addext = (addext == "" || addext.StartsWith(".") ? addext : "." + addext); + repext = (repext == "" || repext.StartsWith(".") ? repext : "." + repext); + + Output.WriteDatfile(datdata, Path.GetDirectoryName(input), _logger); + _logger.User(input + " converted to: " + name); + return; + } + else + { + _logger.Error("I'm sorry but " + input + "doesn't exist!"); + } + } + + #endregion + } +} diff --git a/SabreHelper/Data/Build.cs b/SabreHelper/Data/Build.cs index caeb92cb..779c392c 100644 --- a/SabreHelper/Data/Build.cs +++ b/SabreHelper/Data/Build.cs @@ -25,31 +25,35 @@ namespace SabreTools.Helper string mid = name + " " + Constants.Version; mid = "|" + mid.PadLeft(((77 - mid.Length) / 2) + mid.Length).PadRight(77) + "|"; - // Set the console to ready state - ConsoleColor formertext = ConsoleColor.White; - ConsoleColor formerback = ConsoleColor.Black; - if (!MonoEnvironment) + // If we're outputting to console, do fancy things + if (!Console.IsOutputRedirected) { - Console.SetBufferSize(Console.BufferWidth, 999); - formertext = Console.ForegroundColor; - formerback = Console.BackgroundColor; - Console.ForegroundColor = ConsoleColor.Yellow; - Console.BackgroundColor = ConsoleColor.Blue; - } + // Set the console to ready state + ConsoleColor formertext = ConsoleColor.White; + ConsoleColor formerback = ConsoleColor.Black; + if (!MonoEnvironment) + { + Console.SetBufferSize(Console.BufferWidth, 999); + formertext = Console.ForegroundColor; + formerback = Console.BackgroundColor; + Console.ForegroundColor = ConsoleColor.Yellow; + Console.BackgroundColor = ConsoleColor.Blue; + } - Console.Title = "SabreTools-" + name + " " + Constants.Version; + Console.Title = "SabreTools-" + name + " " + Constants.Version; - // Output the header - Console.WriteLine(border); - Console.WriteLine(mid); - Console.WriteLine(border); - Console.WriteLine(); + // Output the header + Console.WriteLine(border); + Console.WriteLine(mid); + Console.WriteLine(border); + Console.WriteLine(); - // Return the console to the original text and background colors - if (!MonoEnvironment) - { - Console.ForegroundColor = formertext; - Console.BackgroundColor = formerback; + // Return the console to the original text and background colors + if (!MonoEnvironment) + { + Console.ForegroundColor = formertext; + Console.BackgroundColor = formerback; + } } } @@ -77,28 +81,6 @@ Options: -system= System name (system only) -source= Source name (source only) -url= URL (source only) - -cc, --convert-cmp Convert any DAT to CMP - -clean Clean game names according to WoD standards - -out= Output directory - -cm, --convert-miss Convert from DAT to miss - -r, --roms Output roms to miss instead of sets - -gp, --game-prefix Add game name as a prefix to each item - -pre=, --prefix= Set prefix to be printed in front of all lines - -post=, --postfix= Set postfix to be printed behind all lines - -q, --quotes Put double-quotes around each item - -ae=, --add-ext= Add an extension to each item - -re=, --rep-ext= Replace all extensions with specified - -ro, --romba Output roms in Romba format (requires SHA-1) - -tsv, --tsv Output roms in Tab-Separated Value format - -cs, --convert-sd Convert any DAT to SabreDAT - -clean Clean game names according to WoD standards - -out= Output directory - -cr, --convert-rc Convert any DAT to RomCenter - -clean Clean game names according to WoD standards - -out= Output directory - -cx, --convert-xml Convert any DAT to XML - -clean Clean game names according to WoD standards - -out= Output directory -es, --ext-split Split a DAT by two file extensions -exta= First extension to split by -extb= Second extension to split by @@ -128,8 +110,8 @@ Options: -out= Output directory (overridden by --inplace) -sd, --superdat Enable SuperDAT creation -n=, --name= Set the internal name of the DAT - -d=, --desc= Set the filename and description of the DAT - -c=, --cat= Set the category of the DAT + -de=, --desc= Set the filename and description of the DAT + -ca=, --category= Set the category of the DAT -v=, --version= Set the version of the DAT -au=, --author= Set the author of the DAT -rm, --remove Remove a system or source from the database @@ -141,6 +123,52 @@ Options: -rd=, --root-dir= Set the root directory for trimming calculation -nr, --no-rename Keep game names instead of using '!' -df, --disable-force Disable forceunzipping + -ud, --update Update a DAT file + -oc, --output-cmp Output in CMP format + -om, --output-miss Output in Missfile format + -r, --roms Output roms to miss instead of sets + -gp, --game-prefix Add game name as a prefix to each item + -pre=, --prefix= Set prefix to be printed in front of all lines + -post=, --postfix= Set postfix to be printed behind all lines + -q, --quotes Put double-quotes around each item + -ae=, --add-ext= Add an extension to each item + -re=, --rep-ext= Replace all extensions with specified + -ro, --romba Output roms in Romba format (requires SHA-1) + -tsv, --tsv Output roms in Tab-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 + -f=, --filename= Set a new filename + -n=, --name= Set a new internal name + -de=, --desc= Set a new description + -ca=, --category= Set a new category + -v=, --version= Set a new version + -da=, --date= Set a new date + -au=, --author= Set a new author + -em=, --email= Set a new email + -hp=, --homepage= Set a new homepage + -u=, --url= Set a new URL + -co=, --comment= Set a new comment + -h=, --header= Set a new header skipper + -sd=, --superdat Set SuperDAT type + -fm=, --forcemerge= Set force merging + Supported values are: + - None + - Split + - Full + -fn=, --forcend= Set force nodump + Supported values are: + - None + - Obsolete + - Required + - Ignore + -fp=, --forcepack= Set force packing + Supported values are: + - None + - Zip + - Unzip + -clean Clean game names according to WoD standards + -out= Output directory Filenames and directories can't start with a reserved string unless prefixed by 'input=' diff --git a/SabreHelper/Data/Structs.cs b/SabreHelper/Data/Structs.cs index 5b3309df..3c1e2b46 100644 --- a/SabreHelper/Data/Structs.cs +++ b/SabreHelper/Data/Structs.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace SabreTools.Helper { @@ -28,7 +29,7 @@ namespace SabreTools.Helper /// /// Intermediate struct for holding DAT information /// - public struct DatData + public struct DatData : ICloneable { // Data common to most DAT types public string FileName; @@ -70,5 +71,47 @@ namespace SabreTools.Helper public long MD5Count; public long SHA1Count; public long NodumpCount; + + public object Clone() + { + return new DatData + { + FileName = this.FileName, + Name = this.Name, + Description = this.Description, + Category = this.Category, + Version = this.Version, + Date = this.Date, + Author = this.Author, + Email = this.Email, + Homepage = this.Homepage, + Url = this.Url, + Comment = this.Comment, + Header = this.Header, + Type = this.Type, + ForceMerging = this.ForceMerging, + ForceNodump = this.ForceNodump, + ForcePacking = this.ForcePacking, + OutputFormat = this.OutputFormat, + MergeRoms = this.MergeRoms, + Roms = this.Roms, + UseGame = this.UseGame, + Prefix = this.Prefix, + Postfix = this.Postfix, + Quotes = this.Quotes, + RepExt = this.RepExt, + AddExt = this.AddExt, + GameName = this.GameName, + Romba = this.Romba, + TSV = this.TSV, + RomCount = this.RomCount, + DiskCount = this.DiskCount, + TotalSize = this.TotalSize, + CRCCount = this.CRCCount, + MD5Count = this.MD5Count, + SHA1Count = this.SHA1Count, + NodumpCount = this.NodumpCount, + }; + } } }