Add new features requested by Obiwantje

This commit is contained in:
Matt Nadareski
2016-04-20 13:20:50 -07:00
parent dc0cd4f153
commit ec54249ab6
3 changed files with 31 additions and 6 deletions

View File

@@ -33,7 +33,7 @@ namespace SabreTools
// Output the title // Output the title
Build.Start("DatToMiss"); Build.Start("DatToMiss");
string prefix = "", postfix = "", input = ""; string prefix = "", postfix = "", input = "", addext = "", repext = "";
bool tofile = false, help = false, usegame = true, quotes = false; bool tofile = false, help = false, usegame = true, quotes = false;
foreach (string arg in args) foreach (string arg in args)
{ {
@@ -57,14 +57,22 @@ namespace SabreTools
quotes = true; quotes = true;
break; break;
default: default:
if ((arg.StartsWith("-pre=") || arg.StartsWith("--prefix=")) && prefix == "") if (arg.StartsWith("-pre=") || arg.StartsWith("--prefix="))
{ {
prefix = arg.Split('=')[1]; prefix = arg.Split('=')[1];
} }
else if ((arg.StartsWith("-post=") || arg.StartsWith("--postfix=")) && postfix == "") else if (arg.StartsWith("-post=") || arg.StartsWith("--postfix="))
{ {
postfix = arg.Split('=')[1]; postfix = arg.Split('=')[1];
} }
else if (arg.StartsWith("-ae=") || arg.StartsWith("-add-ext="))
{
addext = arg.Split('=')[1];
}
else if (arg.StartsWith("-re=") || arg.StartsWith("-rep-ext="))
{
repext = arg.Split('=')[1];
}
else if (input == "" && File.Exists(arg.Replace("\"", ""))) else if (input == "" && File.Exists(arg.Replace("\"", "")))
{ {
input = arg.Replace("\"", ""); input = arg.Replace("\"", "");
@@ -93,7 +101,7 @@ namespace SabreTools
name += Path.GetFileNameWithoutExtension(input) + "-miss.txt"; name += Path.GetFileNameWithoutExtension(input) + "-miss.txt";
// Read in the roms from the DAT and then write them to the file // Read in the roms from the DAT and then write them to the file
Output.WriteToText(name, Path.GetDirectoryName(input), RomManipulation.Parse(input, 0, 0, logger), logger, usegame, prefix, postfix, quotes); Output.WriteToText(name, Path.GetDirectoryName(input), RomManipulation.Parse(input, 0, 0, logger), logger, usegame, prefix, postfix, addext, repext, quotes);
} }
} }
} }

View File

@@ -170,7 +170,9 @@ Options:
-r, --roms Output roms to miss instead of sets -r, --roms Output roms to miss instead of sets
-pre=, --prefix= Set prefix to be printed in front of all lines -pre=, --prefix= Set prefix to be printed in front of all lines
-post=, --postfix= Set postfix to be printed behind all lines -post=, --postfix= Set postfix to be printed behind all lines
-q, --quotes Put double-quotes around each outputted item (not prefix/postfix)"); -q, --quotes Put double-quotes around each outputted item (not prefix/postfix)
-ae=, --add-ext= Add an extension to each outputted item
-re=, --rep-ext= Replace all extensions with specified");
break; break;
default: default:
Console.Write("This is the default help output"); Console.Write("This is the default help output");

View File

@@ -138,7 +138,8 @@ namespace SabreTools.Helper
/// <param name="postfix">Arbitrary string to postfix each line</param> /// <param name="postfix">Arbitrary string to postfix each line</param>
/// <param name="quotes">True if quotes should be put around the item, false otherwise (default)</param> /// <param name="quotes">True if quotes should be put around the item, false otherwise (default)</param>
/// <returns>True if the file was written, false otherwise</returns> /// <returns>True if the file was written, false otherwise</returns>
public static bool WriteToText(string textfile, string outdir, List<RomData> roms, Logger logger, bool useGame = true, string prefix = "", string postfix = "", bool quotes = false) public static bool WriteToText(string textfile, string outdir, List<RomData> roms, Logger logger, bool useGame = true, string prefix = "",
string postfix = "", string addext = "", string repext = "", bool quotes = false)
{ {
// Normalize the output directory // Normalize the output directory
if (outdir == "") if (outdir == "")
@@ -166,6 +167,20 @@ namespace SabreTools.Helper
string lastgame = ""; string lastgame = "";
foreach (RomData rom in roms) foreach (RomData rom in roms)
{ {
string pre = prefix + (quotes ? "\"" : "");
string post = (quotes ? "\"" : "") + postfix;
string name = (useGame ? rom.Game : rom.Name);
if (repext != "")
{
string dir = Path.GetDirectoryName(name);
dir = (dir.EndsWith(Path.DirectorySeparatorChar.ToString()) ? dir : dir + Path.DirectorySeparatorChar);
name = dir + Path.GetFileNameWithoutExtension(name) + repext;
}
if (addext != "")
{
name += addext;
}
if (useGame && rom.Game != lastgame) if (useGame && rom.Game != lastgame)
{ {
sw.WriteLine(prefix + (quotes ? "\"" : "") + rom.Game + (quotes ? "\"" : "") + postfix); sw.WriteLine(prefix + (quotes ? "\"" : "") + rom.Game + (quotes ? "\"" : "") + postfix);