mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Miscellaneous cleanup
Updated Help to include new commandline params, clean up naming across classes, further updates to help future merging
This commit is contained in:
@@ -30,10 +30,9 @@ namespace SabreTools
|
||||
private bool _noMD5;
|
||||
private bool _noSHA1;
|
||||
private bool _noDate;
|
||||
private bool _forceunzip;
|
||||
private bool _forceunpack;
|
||||
private bool _archivesAsFiles;
|
||||
private bool _old;
|
||||
private bool _log;
|
||||
private bool _superDat;
|
||||
|
||||
// User specified strings
|
||||
@@ -59,13 +58,13 @@ namespace SabreTools
|
||||
/// <param name="noMD5">True if MD5 hashes should be skipped over, false otherwise</param>
|
||||
/// <param name="noSHA1">True if SHA-1 hashes should be skipped over, false otherwise</param>
|
||||
/// <param name="noDate">True if the date should be omitted from the DAT, false otherwise</param>
|
||||
/// <param name="forceunzip">True if the forcepacking="unzip" tag is to be added, false otherwise</param>
|
||||
/// <param name="forceunpack">True if the forcepacking="unzip" tag is to be added, false otherwise</param>
|
||||
/// <param name="archivesAsFiles">True if all archives should be treated like files, false otherwise</param>
|
||||
/// <param name="old">True if a old-style DAT should be output, false otherwise</param>
|
||||
/// <param name="superDat">True if SuperDAT mode is enabled, false otherwise</param>
|
||||
/// <param name="logger">Logger object for console and file output</param>
|
||||
public DATFromDir(List<String> inputs, string name, string desc, string cat, string version, string author,
|
||||
bool noMD5, bool noSHA1, bool noDate, bool forceunzip, bool archivesAsFiles, bool old, bool superDat, Logger logger)
|
||||
bool noMD5, bool noSHA1, bool noDate, bool forceunpack, bool archivesAsFiles, bool old, bool superDat, Logger logger)
|
||||
{
|
||||
_inputs = inputs;
|
||||
_name = name;
|
||||
@@ -76,7 +75,7 @@ namespace SabreTools
|
||||
_noMD5 = noMD5;
|
||||
_noSHA1 = noSHA1;
|
||||
_noDate = noDate;
|
||||
_forceunzip = forceunzip;
|
||||
_forceunpack = forceunpack;
|
||||
_archivesAsFiles = archivesAsFiles;
|
||||
_old = old;
|
||||
_superDat = superDat;
|
||||
@@ -102,8 +101,8 @@ namespace SabreTools
|
||||
logger.Start();
|
||||
|
||||
// First things first, take care of all of the arguments that this could have
|
||||
bool noMD5 = false, noSHA1 = false, forceunzip = false, allfiles = false, old = false, log = false, superDat = false, noDate = false;
|
||||
string name = "", desc = "", cat = "", version = "", author = "", basePath = "";
|
||||
bool noMD5 = false, noSHA1 = false, forceunpack = false, archivesAsFiles = false, old = false, log = false, superDat = false, noDate = false;
|
||||
string name = "", desc = "", cat = "", version = "", author = "";
|
||||
List<string> inputs = new List<string>();
|
||||
foreach (string arg in args)
|
||||
{
|
||||
@@ -129,11 +128,11 @@ namespace SabreTools
|
||||
break;
|
||||
case "-u":
|
||||
case "--unzip":
|
||||
forceunzip = true;
|
||||
forceunpack = true;
|
||||
break;
|
||||
case "-f":
|
||||
case "--files":
|
||||
allfiles = true;
|
||||
archivesAsFiles = true;
|
||||
break;
|
||||
case "-o":
|
||||
case "--old":
|
||||
@@ -203,7 +202,7 @@ namespace SabreTools
|
||||
}
|
||||
|
||||
// Create a new DATFromDir object and process the inputs
|
||||
DATFromDir dfd = new DATFromDir(inputs, name, desc, cat, version, author, noMD5, noSHA1, noDate, forceunzip, allfiles, old, superDat, logger);
|
||||
DATFromDir dfd = new DATFromDir(inputs, name, desc, cat, version, author, noMD5, noSHA1, noDate, forceunpack, archivesAsFiles, old, superDat, logger);
|
||||
bool success = dfd.Start();
|
||||
|
||||
// If we failed, show the help
|
||||
@@ -313,7 +312,7 @@ namespace SabreTools
|
||||
_desc = (_desc == "" ? _name + (_noDate ? "" : " (" + _date + ")") : _desc);
|
||||
|
||||
// Now write it all out as a DAT
|
||||
Output.WriteToDat(_name, _desc, _version, _date, _cat, _author, _forceunzip, _old, Environment.CurrentDirectory, _roms, _logger);
|
||||
Output.WriteToDat(_name, _desc, _version, _date, _cat, _author, _forceunpack, _old, Environment.CurrentDirectory, _roms, _logger);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -226,10 +226,18 @@ namespace SabreTools
|
||||
{
|
||||
url = arg.Split('=')[1];
|
||||
}
|
||||
else
|
||||
else if (File.Exists(arg) || Directory.Exists(arg))
|
||||
{
|
||||
inputs.Add(arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Warning("Invalid input detected: " + arg);
|
||||
Console.WriteLine();
|
||||
Build.Help();
|
||||
logger.Close();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -995,7 +1003,7 @@ Make a selection:
|
||||
private static void TrimMergeMenu()
|
||||
{
|
||||
string selection = "", input = "", root = "";
|
||||
bool forceunzip = true, rename = true;
|
||||
bool forceunpack = true, rename = true;
|
||||
while (selection.ToLowerInvariant() != "b")
|
||||
{
|
||||
Console.Clear();
|
||||
@@ -1006,7 +1014,7 @@ Make a selection:
|
||||
|
||||
1) File or folder to process" + (input != "" ? ":\n\t" + input : "") + @"
|
||||
2) Root folder for reference" + (root != "" ? ":\n\t" + root : "") + @"
|
||||
3) " + (forceunzip ? "Remove 'forcepacking=\"unzip\"' from output" : "Add 'forcepacking=\"unzip\"' to output") + @"
|
||||
3) " + (forceunpack ? "Remove 'forcepacking=\"unzip\"' from output" : "Add 'forcepacking=\"unzip\"' to output") + @"
|
||||
4) " + (rename ? "Disable game renaming" : "Enable game renaming") + @"
|
||||
5) Process the file or folder
|
||||
B) Go back to the previous menu
|
||||
@@ -1026,14 +1034,14 @@ Make a selection:
|
||||
root = Console.ReadLine();
|
||||
break;
|
||||
case "3":
|
||||
forceunzip = !forceunzip;
|
||||
forceunpack = !forceunpack;
|
||||
break;
|
||||
case "4":
|
||||
rename = !rename;
|
||||
break;
|
||||
case "5":
|
||||
Console.Clear();
|
||||
InitTrimMerge(input, root, rename, forceunzip);
|
||||
InitTrimMerge(input, root, rename, forceunpack);
|
||||
Console.Write("\nPress any key to continue...");
|
||||
Console.ReadKey();
|
||||
break;
|
||||
|
||||
@@ -8,24 +8,47 @@ namespace SabreTools
|
||||
{
|
||||
public class MergeDAT
|
||||
{
|
||||
// Instance variables
|
||||
// Listing related variables
|
||||
private List<RomData> _roms;
|
||||
private List<String> _inputs;
|
||||
|
||||
// User specified flags
|
||||
private bool _diff;
|
||||
private bool _dedup;
|
||||
private List<String> _inputs;
|
||||
private bool _noDate;
|
||||
private bool _forceunpack;
|
||||
private bool _old;
|
||||
|
||||
// User specified strings
|
||||
private string _name;
|
||||
private string _desc;
|
||||
private string _cat;
|
||||
private string _version;
|
||||
private string _author;
|
||||
|
||||
// Other required variables
|
||||
private string _date = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
private Logger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new MergeDAT object
|
||||
/// </summary>
|
||||
/// <param name="inputs">A List of Strings representing the DATs or DAT folders to be merged</param>
|
||||
/// <param name="diff">True if a DiffDat of all inputs is wanted, false otherwise</param>
|
||||
/// <param name="dedup">True if the outputted file should remove duplicates, false otherwise</param>
|
||||
/// <param name="logger">Logger object for console and file output</param>
|
||||
public MergeDAT(List<String> inputs, bool diff, bool dedup, Logger logger)
|
||||
|
||||
public MergeDAT(List<String> inputs, string name, string desc, string cat, string version, string author,
|
||||
bool diff, bool dedup, bool noDate, bool forceunpack, bool old, Logger logger)
|
||||
{
|
||||
_inputs = inputs;
|
||||
_name = name;
|
||||
_desc = desc;
|
||||
_cat = cat;
|
||||
_version = version;
|
||||
_author = author;
|
||||
_diff = diff;
|
||||
_dedup = dedup;
|
||||
_noDate = noDate;
|
||||
_forceunpack = forceunpack;
|
||||
_old = old;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -57,7 +80,8 @@ namespace SabreTools
|
||||
Build.Start("DiffDat");
|
||||
|
||||
List<String> inputs = new List<String>();
|
||||
bool tofile = false, help = false, dedup = false, diff = false;
|
||||
bool help = false, dedup = false, diff = false, forceunpack = false, old = false, log = false, noDate = false;
|
||||
string name = "", desc = "", cat = "", version = "", author = "";
|
||||
foreach (string arg in args)
|
||||
{
|
||||
switch (arg)
|
||||
@@ -65,12 +89,9 @@ namespace SabreTools
|
||||
case "-h":
|
||||
case "-?":
|
||||
case "--help":
|
||||
help = true;
|
||||
break;
|
||||
case "-l":
|
||||
case "--log":
|
||||
tofile = true;
|
||||
break;
|
||||
Build.Help();
|
||||
logger.Close();
|
||||
return;
|
||||
case "-di":
|
||||
case "--diff":
|
||||
diff = true;
|
||||
@@ -79,9 +100,45 @@ namespace SabreTools
|
||||
case "--dedup":
|
||||
dedup = true;
|
||||
break;
|
||||
case "-b":
|
||||
case "--bare":
|
||||
noDate = true;
|
||||
break;
|
||||
case "-u":
|
||||
case "--unzip":
|
||||
forceunpack = true;
|
||||
break;
|
||||
case "-o":
|
||||
case "--old":
|
||||
old = true;
|
||||
break;
|
||||
case "-l":
|
||||
case "--log":
|
||||
log = true;
|
||||
break;
|
||||
default:
|
||||
if (arg.StartsWith("-n=") || arg.StartsWith("--name="))
|
||||
{
|
||||
name = arg.Split('=')[1];
|
||||
}
|
||||
else if (arg.StartsWith("-d=") || arg.StartsWith("--desc="))
|
||||
{
|
||||
desc = arg.Split('=')[1];
|
||||
}
|
||||
else if (arg.StartsWith("-c=") || arg.StartsWith("--cat="))
|
||||
{
|
||||
cat = arg.Split('=')[1];
|
||||
}
|
||||
else if (arg.StartsWith("-a=") || arg.StartsWith("--author="))
|
||||
{
|
||||
author = arg.Split('=')[1];
|
||||
}
|
||||
else if (arg.StartsWith("-v=") || arg.StartsWith("--version="))
|
||||
{
|
||||
version = arg.Split('=')[1];
|
||||
}
|
||||
// Add actual files to the list of inputs
|
||||
if (File.Exists(arg.Replace("\"", "")))
|
||||
else if (File.Exists(arg.Replace("\"", "")))
|
||||
{
|
||||
inputs.Add(Path.GetFullPath(arg.Replace("\"", "")));
|
||||
}
|
||||
@@ -97,7 +154,7 @@ namespace SabreTools
|
||||
}
|
||||
|
||||
// Set the possibly new value for logger
|
||||
logger.ToFile = tofile;
|
||||
logger.ToFile = log;
|
||||
|
||||
// Show help if explicitly asked for it or if not enough files are supplied
|
||||
if (help || inputs.Count < 2)
|
||||
@@ -108,7 +165,7 @@ namespace SabreTools
|
||||
}
|
||||
|
||||
// Otherwise, read in the files, process them and write the result to the file type that the first one is
|
||||
MergeDAT md = new MergeDAT(inputs, diff, dedup, logger);
|
||||
MergeDAT md = new MergeDAT(inputs, name, desc, cat, version, author, diff, dedup, noDate, forceunpack, old, logger);
|
||||
md.MergeDiff();
|
||||
}
|
||||
|
||||
@@ -150,14 +207,30 @@ namespace SabreTools
|
||||
A = RomManipulation.Merge(A);
|
||||
}
|
||||
|
||||
if (_diff)
|
||||
// Get the names that will be used
|
||||
if (_name == "")
|
||||
{
|
||||
Output.WriteToDat("diffdat" + (_dedup ? "-merged" : ""), "diffdat" + (_dedup ? "-merged" : ""), "", "", "DiffDat", "SabreTools", false, !RomManipulation.IsXmlDat(_inputs[0]), "", A, _logger);
|
||||
_name = (_diff ? "diffdat" : "mergedat") + (_dedup ? "-merged" : "");
|
||||
}
|
||||
else
|
||||
if (_desc == "")
|
||||
{
|
||||
Output.WriteToDat("combinedat" + (_dedup ? "-merged" : ""), "combinedat" + (_dedup ? "-merged" : ""), "", "", "", "SabreTools", false, !RomManipulation.IsXmlDat(_inputs[0]), "", A, _logger);
|
||||
_desc = (_diff ? "diffdat" : "mergedat") + (_dedup ? "-merged" : "");
|
||||
if (!_noDate)
|
||||
{
|
||||
_desc += " (" + _date + ")";
|
||||
}
|
||||
}
|
||||
if (_cat == "" && _diff)
|
||||
{
|
||||
_cat = "DiffDAT";
|
||||
}
|
||||
if (_author == "")
|
||||
{
|
||||
_author = "SabreTools";
|
||||
}
|
||||
|
||||
// Now write the file out
|
||||
Output.WriteToDat(_name, _desc, _version, _date, _cat, _author, _forceunpack, _old, "", A, _logger);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -165,7 +165,15 @@ Options:
|
||||
-h, -?, --help Show this help dialog
|
||||
-l, --log Enable log to file
|
||||
-di, --diff Switch to diffdat mode
|
||||
-dd, --dedup Enable deduping in the created DAT");
|
||||
-dd, --dedup Enable deduping in the created DAT
|
||||
-b, --bare Don't include date in file name
|
||||
-u, --unzip Force unzipping in created DAT
|
||||
-o, --old Output DAT in RV format instead of XML
|
||||
-n=, --name= Set the name of the DAT
|
||||
-d=, --desc= Set the description of the DAT
|
||||
-c=, --cat= Set the category of the DAT
|
||||
-v=, --version= Set the version of the DAT
|
||||
-a=, --author= Set the author of the DAT");
|
||||
break;
|
||||
default:
|
||||
Console.Write("This is the default help output");
|
||||
|
||||
@@ -17,13 +17,13 @@ namespace SabreTools.Helper
|
||||
/// <param name="date">Usually the DAT creation date</param>
|
||||
/// <param name="category">Category of the DAT</param>
|
||||
/// <param name="author">DAT author</param>
|
||||
/// <param name="forceunzip">Force all sets to be unzipped</param>
|
||||
/// <param name="forceunpack">Force all sets to be unzipped</param>
|
||||
/// <param name="old">Set output mode to old-style DAT</param>
|
||||
/// <param name="outDir">Set the output directory</param>
|
||||
/// <param name="roms">List of RomData objects representing the games to be written out</param>
|
||||
/// <param name="logger">Logger object for console and/or file output</param>
|
||||
/// <returns>Tru if the DAT was written correctly, false otherwise</returns>
|
||||
public static bool WriteToDat(string name, string description, string version, string date, string category, string author, bool forceunzip, bool old, string outDir, List<RomData> roms, Logger logger)
|
||||
public static bool WriteToDat(string name, string description, string version, string date, string category, string author, bool forceunpack, bool old, string outDir, List<RomData> roms, Logger logger)
|
||||
{
|
||||
// If it's empty, use the current folder
|
||||
if (outDir.Trim() == "")
|
||||
@@ -51,7 +51,7 @@ namespace SabreTools.Helper
|
||||
"\tversion \"" + HttpUtility.HtmlEncode(version) + "\"\n" +
|
||||
"\tcomment \"\"\n" +
|
||||
"\tauthor \"" + HttpUtility.HtmlEncode(author) + "\"\n" +
|
||||
(forceunzip ? "\tforcezipping no\n" : "") +
|
||||
(forceunpack ? "\tforcezipping no\n" : "") +
|
||||
")\n";
|
||||
|
||||
string header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
@@ -64,7 +64,7 @@ namespace SabreTools.Helper
|
||||
"\t\t\t<version>" + HttpUtility.HtmlEncode(version) + "</version>\n" +
|
||||
"\t\t\t<date>" + HttpUtility.HtmlEncode(date) + "</date>\n" +
|
||||
"\t\t\t<author>" + HttpUtility.HtmlEncode(author) + "</author>\n" +
|
||||
(forceunzip ? "\t\t\t<clrmamepro forcepacking=\"unzip\" />\n" : "") +
|
||||
(forceunpack ? "\t\t\t<clrmamepro forcepacking=\"unzip\" />\n" : "") +
|
||||
"\t\t</header>\n";
|
||||
|
||||
// Write the header out
|
||||
|
||||
Reference in New Issue
Block a user