mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add output folder as an optoin
This commit is contained in:
@@ -19,6 +19,7 @@ namespace SabreTools
|
|||||||
// Private instance variables
|
// Private instance variables
|
||||||
private string _systems;
|
private string _systems;
|
||||||
private string _sources;
|
private string _sources;
|
||||||
|
private string _outdir;
|
||||||
private string _connectionString;
|
private string _connectionString;
|
||||||
private bool _norename;
|
private bool _norename;
|
||||||
private bool _old;
|
private bool _old;
|
||||||
@@ -32,11 +33,12 @@ namespace SabreTools
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="systems">Comma-separated list of systems to be included in the DAT (blank means all)</param>
|
/// <param name="systems">Comma-separated list of systems to be included in the DAT (blank means all)</param>
|
||||||
/// <param name="sources">Comma-separated list of sources to be included in the DAT (blank means all)</param>
|
/// <param name="sources">Comma-separated list of sources to be included in the DAT (blank means all)</param>
|
||||||
|
/// <param name="outdir">The output folder where the generated DAT will be put; blank means the current directory</param>
|
||||||
/// <param name="connectionString">Connection string for SQLite</param>
|
/// <param name="connectionString">Connection string for SQLite</param>
|
||||||
/// <param name="logger">Logger object for file or console output</param>
|
/// <param name="logger">Logger object for file or console output</param>
|
||||||
/// <param name="norename">True if files should not be renamed with system and/or source in merged mode (default false)</param>
|
/// <param name="norename">True if files should not be renamed with system and/or source in merged mode (default false)</param>
|
||||||
/// <param name="old">True if the output file should be in RomVault format (default false)</param>
|
/// <param name="old">True if the output file should be in RomVault format (default false)</param>
|
||||||
public Generate(string systems, string sources, string connectionString, Logger logger, bool norename = false, bool old = false)
|
public Generate(string systems, string sources, string outdir, string connectionString, Logger logger, bool norename = false, bool old = false)
|
||||||
{
|
{
|
||||||
_systems = systems;
|
_systems = systems;
|
||||||
_sources = sources;
|
_sources = sources;
|
||||||
@@ -45,6 +47,13 @@ namespace SabreTools
|
|||||||
_old = old;
|
_old = old;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
|
// Take care of special outfolder cases
|
||||||
|
_outdir = (outdir == "" ? outdir :
|
||||||
|
(outdir.Contains("/") && !outdir.EndsWith("/") ? outdir + "/" :
|
||||||
|
(outdir.Contains("\\") && !outdir.EndsWith("\\") ? outdir + "\\" : outdir)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
_headers = new Dictionary<int, string>();
|
_headers = new Dictionary<int, string>();
|
||||||
_headers.Add(25, "a7800.xml");
|
_headers.Add(25, "a7800.xml");
|
||||||
_headers.Add(228, "fds.xml");
|
_headers.Add(228, "fds.xml");
|
||||||
@@ -168,11 +177,11 @@ namespace SabreTools
|
|||||||
string datname = systemname + " (" + sourcename + " " + version + ")";
|
string datname = systemname + " (" + sourcename + " " + version + ")";
|
||||||
|
|
||||||
// Create and open an output file for writing (currently uses current time, change to "last updated time"
|
// Create and open an output file for writing (currently uses current time, change to "last updated time"
|
||||||
_logger.Log("Opening file for writing: " + datname + (_old ? ".dat" : ".xml"));
|
_logger.Log("Opening file for writing: " + _outdir + datname + (_old ? ".dat" : ".xml"));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FileStream fs = File.Create(datname + (_old ? ".dat" : ".xml"));
|
FileStream fs = File.Create(_outdir + datname + (_old ? ".dat" : ".xml"));
|
||||||
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
|
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
|
||||||
|
|
||||||
// Temporarilly set _system if we're in MEGAMERGED mode to get the right header skip XML
|
// Temporarilly set _system if we're in MEGAMERGED mode to get the right header skip XML
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ namespace SabreTools
|
|||||||
bool help = false, import = false, generate = false, convert = false,
|
bool help = false, import = false, generate = false, convert = false,
|
||||||
listsys = false, listsrc = false, norename = false, old = false,
|
listsys = false, listsrc = false, norename = false, old = false,
|
||||||
log = false, genall = false, add = false, rem = false, skip = false;
|
log = false, genall = false, add = false, rem = false, skip = false;
|
||||||
string systems = "", sources = "", input = "", manu = "", url = "";
|
string systems = "", sources = "", input = "", manu = "", url = "", outdir = "";
|
||||||
foreach (string arg in args)
|
foreach (string arg in args)
|
||||||
{
|
{
|
||||||
// Main functions
|
// Main functions
|
||||||
@@ -76,6 +76,7 @@ namespace SabreTools
|
|||||||
// User input strings
|
// User input strings
|
||||||
systems = (arg.StartsWith("system=") && systems == "" ? arg.Split('=')[1] : systems);
|
systems = (arg.StartsWith("system=") && systems == "" ? arg.Split('=')[1] : systems);
|
||||||
sources = (arg.StartsWith("source=") && sources == "" ? arg.Split('=')[1] : sources);
|
sources = (arg.StartsWith("source=") && sources == "" ? arg.Split('=')[1] : sources);
|
||||||
|
outdir = (arg.StartsWith("out=") && outdir == "" ? arg.Split('=')[1] : outdir);
|
||||||
manu = (arg.StartsWith("manu=") && manu == "" ? arg.Split('=')[1] : manu);
|
manu = (arg.StartsWith("manu=") && manu == "" ? arg.Split('=')[1] : manu);
|
||||||
url = (arg.StartsWith("url=") && url == "" ? arg.Split('=')[1] : url);
|
url = (arg.StartsWith("url=") && url == "" ? arg.Split('=')[1] : url);
|
||||||
|
|
||||||
@@ -84,6 +85,7 @@ namespace SabreTools
|
|||||||
input = (!arg.StartsWith("-") &&
|
input = (!arg.StartsWith("-") &&
|
||||||
!arg.StartsWith("source=") &&
|
!arg.StartsWith("source=") &&
|
||||||
!arg.StartsWith("system=") &&
|
!arg.StartsWith("system=") &&
|
||||||
|
!arg.StartsWith("out=") &&
|
||||||
!arg.StartsWith("manu=") &&
|
!arg.StartsWith("manu=") &&
|
||||||
!arg.StartsWith("url=") &&
|
!arg.StartsWith("url=") &&
|
||||||
!arg.StartsWith("input=") &&
|
!arg.StartsWith("input=") &&
|
||||||
@@ -118,13 +120,13 @@ namespace SabreTools
|
|||||||
// Generate a DAT
|
// Generate a DAT
|
||||||
else if (generate)
|
else if (generate)
|
||||||
{
|
{
|
||||||
InitGenerate(systems, sources, norename, old);
|
InitGenerate(systems, sources, outdir, norename, old);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate all DATs
|
// Generate all DATs
|
||||||
else if (genall)
|
else if (genall)
|
||||||
{
|
{
|
||||||
InitGenerateAll(norename, old);
|
InitGenerateAll(outdir, norename, old);
|
||||||
}
|
}
|
||||||
|
|
||||||
// List all available sources
|
// List all available sources
|
||||||
@@ -382,7 +384,7 @@ or 'b' to go back to the previous menu:");
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static void GenerateMenu()
|
private static void GenerateMenu()
|
||||||
{
|
{
|
||||||
string selection = "", systems = "", sources = "";
|
string selection = "", systems = "", sources = "", outdir = "";
|
||||||
bool norename = false, old = false;
|
bool norename = false, old = false;
|
||||||
while (selection.ToLowerInvariant() != "b")
|
while (selection.ToLowerInvariant() != "b")
|
||||||
{
|
{
|
||||||
@@ -396,7 +398,8 @@ Make a selection:
|
|||||||
2) " + (old ? "Enable XML output" : "Enable RomVault output") + @"
|
2) " + (old ? "Enable XML output" : "Enable RomVault output") + @"
|
||||||
3) Enter a list of systems to generate from
|
3) Enter a list of systems to generate from
|
||||||
4) Enter a list of sources to generate from
|
4) Enter a list of sources to generate from
|
||||||
5) Generate the DAT file
|
5) Enter an output folder
|
||||||
|
6) Generate the DAT file
|
||||||
B) Go back to the previous menu
|
B) Go back to the previous menu
|
||||||
");
|
");
|
||||||
Console.Write("Enter selection: ");
|
Console.Write("Enter selection: ");
|
||||||
@@ -423,7 +426,12 @@ Make a selection:
|
|||||||
break;
|
break;
|
||||||
case "5":
|
case "5":
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
InitGenerate(systems, sources, norename, old);
|
Console.Write("Please enter a folder name: ");
|
||||||
|
outdir = Console.ReadLine();
|
||||||
|
break;
|
||||||
|
case "6":
|
||||||
|
Console.Clear();
|
||||||
|
InitGenerate(systems, sources, outdir, norename, old);
|
||||||
Console.Write("\nPress any key to continue...");
|
Console.Write("\nPress any key to continue...");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
break;
|
break;
|
||||||
@@ -439,9 +447,9 @@ Make a selection:
|
|||||||
/// <param name="sources">Comma-separated list of sources to be included in the DAT (blank means all)</param>
|
/// <param name="sources">Comma-separated list of sources to be included in the DAT (blank means all)</param>
|
||||||
/// <param name="norename">True if files should not be renamed with system and/or source in merged mode (default false)</param>
|
/// <param name="norename">True if files should not be renamed with system and/or source in merged mode (default false)</param>
|
||||||
/// <param name="old">True if the output file should be in RomVault format (default false)</param>
|
/// <param name="old">True if the output file should be in RomVault format (default false)</param>
|
||||||
private static void InitGenerate(string systems, string sources, bool norename, bool old)
|
private static void InitGenerate(string systems, string sources, string outdir, bool norename, bool old)
|
||||||
{
|
{
|
||||||
Generate gen = new Generate(systems, sources, _connectionString, logger, norename, old);
|
Generate gen = new Generate(systems, sources, outdir, _connectionString, logger, norename, old);
|
||||||
gen.Export();
|
gen.Export();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -451,7 +459,7 @@ Make a selection:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static void GenerateAllMenu()
|
private static void GenerateAllMenu()
|
||||||
{
|
{
|
||||||
string selection = "";
|
string selection = "", outdir = "";
|
||||||
bool norename = false, old = false;
|
bool norename = false, old = false;
|
||||||
while (selection.ToLowerInvariant() != "b")
|
while (selection.ToLowerInvariant() != "b")
|
||||||
{
|
{
|
||||||
@@ -463,7 +471,8 @@ Make a selection:
|
|||||||
|
|
||||||
1) " + (norename ? "Enable game renaming" : "Disable game renaming") + @"
|
1) " + (norename ? "Enable game renaming" : "Disable game renaming") + @"
|
||||||
2) " + (old ? "Enable XML output" : "Enable RomVault output") + @"
|
2) " + (old ? "Enable XML output" : "Enable RomVault output") + @"
|
||||||
3) Generate all DAT files
|
3) Enter an output folder
|
||||||
|
4) Generate all DAT files
|
||||||
B) Go back to the previous menu
|
B) Go back to the previous menu
|
||||||
");
|
");
|
||||||
Console.Write("Enter selection: ");
|
Console.Write("Enter selection: ");
|
||||||
@@ -478,7 +487,12 @@ Make a selection:
|
|||||||
break;
|
break;
|
||||||
case "3":
|
case "3":
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
InitGenerateAll(norename, old);
|
Console.Write("Please enter a folder name: ");
|
||||||
|
outdir = Console.ReadLine();
|
||||||
|
break;
|
||||||
|
case "4":
|
||||||
|
Console.Clear();
|
||||||
|
InitGenerateAll(outdir, norename, old);
|
||||||
Console.Write("\nPress any key to continue...");
|
Console.Write("\nPress any key to continue...");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
break;
|
break;
|
||||||
@@ -492,7 +506,7 @@ Make a selection:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="norename">True if files should not be renamed with system and/or source in merged mode (default false)</param>
|
/// <param name="norename">True if files should not be renamed with system and/or source in merged mode (default false)</param>
|
||||||
/// <param name="old">True if the output file should be in RomVault format (default false)</param>
|
/// <param name="old">True if the output file should be in RomVault format (default false)</param>
|
||||||
private static void InitGenerateAll(bool norename, bool old)
|
private static void InitGenerateAll(string outdir, bool norename, bool old)
|
||||||
{
|
{
|
||||||
// Generate system-merged
|
// Generate system-merged
|
||||||
string query = @"SELECT DISTINCT systems.id
|
string query = @"SELECT DISTINCT systems.id
|
||||||
@@ -516,7 +530,7 @@ Make a selection:
|
|||||||
|
|
||||||
while (sldr.Read())
|
while (sldr.Read())
|
||||||
{
|
{
|
||||||
InitGenerate(sldr.GetInt32(0).ToString(), "", norename, old);
|
InitGenerate(sldr.GetInt32(0).ToString(), "", outdir, norename, old);
|
||||||
|
|
||||||
// Generate custom
|
// Generate custom
|
||||||
string squery = @"SELECT DISTINCT sources.id
|
string squery = @"SELECT DISTINCT sources.id
|
||||||
@@ -541,7 +555,7 @@ Make a selection:
|
|||||||
|
|
||||||
while (ssldr.Read())
|
while (ssldr.Read())
|
||||||
{
|
{
|
||||||
InitGenerate(sldr.GetInt32(0).ToString(), ssldr.GetInt32(0).ToString(), norename, old);
|
InitGenerate(sldr.GetInt32(0).ToString(), ssldr.GetInt32(0).ToString(), outdir, norename, old);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -569,14 +583,14 @@ Make a selection:
|
|||||||
|
|
||||||
while (sldr.Read())
|
while (sldr.Read())
|
||||||
{
|
{
|
||||||
InitGenerate("", sldr.GetInt32(0).ToString(), norename, old);
|
InitGenerate("", sldr.GetInt32(0).ToString(), outdir, norename, old);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate MEGAMERGED
|
// Generate MEGAMERGED
|
||||||
InitGenerate("", "", norename, old);
|
InitGenerate("", "", outdir, norename, old);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user