mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Allow for a different output directory on convert; preserve file structure if in a folder
This commit is contained in:
@@ -375,7 +375,7 @@ namespace SabreTools
|
|||||||
{
|
{
|
||||||
foreach (string input in inputs)
|
foreach (string input in inputs)
|
||||||
{
|
{
|
||||||
InitConvert(input, OutputFormat.ClrMamePro);
|
InitConvert(input, OutputFormat.ClrMamePro, outdir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,7 +384,7 @@ namespace SabreTools
|
|||||||
{
|
{
|
||||||
foreach (string input in inputs)
|
foreach (string input in inputs)
|
||||||
{
|
{
|
||||||
InitConvert(input, OutputFormat.RomCenter);
|
InitConvert(input, OutputFormat.RomCenter, outdir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,7 +393,7 @@ namespace SabreTools
|
|||||||
{
|
{
|
||||||
foreach (string input in inputs)
|
foreach (string input in inputs)
|
||||||
{
|
{
|
||||||
InitConvert(input, OutputFormat.Xml);
|
InitConvert(input, OutputFormat.Xml, outdir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -651,13 +651,11 @@ Make a selection:
|
|||||||
===========================
|
===========================
|
||||||
Make a selection:
|
Make a selection:
|
||||||
|
|
||||||
1) Convert DAT to ClrMamePro
|
1) Convert or clean DAT or folder of DATs
|
||||||
2) Convert DAT to RomCenter
|
3) Convert DAT to missfile
|
||||||
3) Convert DAT to XML
|
4) Trim all entries in DAT and merge into a single game
|
||||||
4) Convert DAT to missfile
|
5) Merge, diff, and/or dedup 2 or more DAT files
|
||||||
5) Trim all entries in DAT and merge into a single game
|
6) Split DAT using 2 extensions
|
||||||
6) Merge, diff, and/or dedup 2 or more DAT files
|
|
||||||
7) Split DAT using 2 extensions
|
|
||||||
B) Go back to the previous menu
|
B) Go back to the previous menu
|
||||||
");
|
");
|
||||||
Console.Write("Enter selection: ");
|
Console.Write("Enter selection: ");
|
||||||
@@ -665,24 +663,18 @@ Make a selection:
|
|||||||
switch (selection)
|
switch (selection)
|
||||||
{
|
{
|
||||||
case "1":
|
case "1":
|
||||||
ConvertCMPMenu();
|
ConvertMenu();
|
||||||
break;
|
break;
|
||||||
case "2":
|
case "2":
|
||||||
ConvertRCMenu();
|
|
||||||
break;
|
|
||||||
case "3":
|
|
||||||
ConvertXMLMenu();
|
|
||||||
break;
|
|
||||||
case "4":
|
|
||||||
ConvertMissMenu();
|
ConvertMissMenu();
|
||||||
break;
|
break;
|
||||||
case "5":
|
case "3":
|
||||||
TrimMergeMenu();
|
TrimMergeMenu();
|
||||||
break;
|
break;
|
||||||
case "6":
|
case "4":
|
||||||
MergeDiffMenu();
|
MergeDiffMenu();
|
||||||
break;
|
break;
|
||||||
case "7":
|
case "5":
|
||||||
ExtSplitMenu();
|
ExtSplitMenu();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -690,84 +682,78 @@ Make a selection:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Show the text-based any to CMP conversion menu
|
/// Show the text-based any to any conversion menu
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static void ConvertCMPMenu()
|
private static void ConvertMenu()
|
||||||
{
|
{
|
||||||
string selection = "";
|
string selection = "", input = "", outdir = "";
|
||||||
|
OutputFormat outputFormat = OutputFormat.Xml;
|
||||||
while (selection.ToLowerInvariant() != "b")
|
while (selection.ToLowerInvariant() != "b")
|
||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Build.Start("DATabase");
|
Build.Start("DATabase");
|
||||||
Console.WriteLine(@"ANY -> CMP CONVERT MENU
|
Console.WriteLine(@"DAT CONVERSION MENU
|
||||||
===========================
|
===========================
|
||||||
Enter the name of a DAT file to convert to CMP
|
Make a selection:
|
||||||
or 'b' to go back to the previous menu:
|
|
||||||
");
|
|
||||||
selection = Console.ReadLine();
|
|
||||||
if (selection.ToLowerInvariant() != "b")
|
|
||||||
{
|
|
||||||
Console.Clear();
|
|
||||||
InitConvert(selection, OutputFormat.ClrMamePro);
|
|
||||||
Console.Write("\nPress any key to continue...");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
1) File or folder to convert" + (input == "" ? "" : ":\n" + input) + @"
|
||||||
/// Show the text-based any to RomCenter conversion menu
|
2) New output folder" + (outdir == "" ? " (blank means source directory)" : ":\n" + outdir) + @"
|
||||||
/// </summary>
|
3) Current output type: " + (outputFormat.ToString()) + @"
|
||||||
private static void ConvertRCMenu()
|
4) Process file or folder
|
||||||
{
|
B) Go back to the previous menu
|
||||||
string selection = "";
|
|
||||||
while (selection.ToLowerInvariant() != "b")
|
|
||||||
{
|
|
||||||
Console.Clear();
|
|
||||||
Build.Start("DATabase");
|
|
||||||
Console.WriteLine(@"ANY -> RC CONVERT MENU
|
|
||||||
===========================
|
|
||||||
Enter the name of a DAT file to convert to RomCenter
|
|
||||||
or 'b' to go back to the previous menu:
|
|
||||||
");
|
");
|
||||||
|
Console.Write("Enter selection: ");
|
||||||
selection = Console.ReadLine();
|
selection = Console.ReadLine();
|
||||||
if (selection.ToLowerInvariant() != "b")
|
switch (selection)
|
||||||
|
{
|
||||||
|
case "1":
|
||||||
|
Console.Clear();
|
||||||
|
Console.Write("Please enter a file or folder name: ");
|
||||||
|
input = Console.ReadLine();
|
||||||
|
break;
|
||||||
|
case "2":
|
||||||
|
Console.Clear();
|
||||||
|
Console.Write("Please enter a folder name: ");
|
||||||
|
input = Console.ReadLine();
|
||||||
|
break;
|
||||||
|
case "3":
|
||||||
|
string subsel = "";
|
||||||
|
while (subsel == "")
|
||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
InitConvert(selection, OutputFormat.RomCenter);
|
Console.WriteLine(@"Possible output formats:
|
||||||
Console.Write("\nPress any key to continue...");
|
1) Xml
|
||||||
Console.ReadKey();
|
2) ClrMamePro
|
||||||
}
|
3) RomCenter
|
||||||
}
|
");
|
||||||
return;
|
Console.Write("Please enter your selection: ");
|
||||||
}
|
subsel = Console.ReadLine();
|
||||||
|
|
||||||
/// <summary>
|
switch (subsel)
|
||||||
/// Show the text-based CMP to XML conversion menu
|
|
||||||
/// </summary>
|
|
||||||
private static void ConvertXMLMenu()
|
|
||||||
{
|
|
||||||
string selection = "";
|
|
||||||
while (selection.ToLowerInvariant() != "b")
|
|
||||||
{
|
{
|
||||||
|
case "1":
|
||||||
|
outputFormat = OutputFormat.Xml;
|
||||||
|
break;
|
||||||
|
case "2":
|
||||||
|
outputFormat = OutputFormat.ClrMamePro;
|
||||||
|
break;
|
||||||
|
case "3":
|
||||||
|
outputFormat = OutputFormat.RomCenter;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
subsel = "";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "4":
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Build.Start("DATabase");
|
InitConvert(input, outputFormat, outdir);
|
||||||
Console.WriteLine(@"ANY -> XML CONVERT MENU
|
|
||||||
===========================
|
|
||||||
Enter the name of a DAT file to convert to XML
|
|
||||||
or 'b' to go back to the previous menu:
|
|
||||||
");
|
|
||||||
selection = Console.ReadLine();
|
|
||||||
if (selection.ToLowerInvariant() != "b")
|
|
||||||
{
|
|
||||||
Console.Clear();
|
|
||||||
InitConvert(selection, OutputFormat.Xml);
|
|
||||||
Console.Write("\nPress any key to continue...");
|
Console.Write("\nPress any key to continue...");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1311,9 +1297,17 @@ Make a selection:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename"></param>
|
/// <param name="filename"></param>
|
||||||
/// <param name="outputFormat"></param>
|
/// <param name="outputFormat"></param>
|
||||||
private static void InitConvert(string filename, OutputFormat outputFormat)
|
private static void InitConvert(string filename, OutputFormat outputFormat, string outdir = "")
|
||||||
{
|
{
|
||||||
|
// Clean the input strings
|
||||||
|
outdir = outdir.Replace("\"", "");
|
||||||
|
if (outdir != "")
|
||||||
|
{
|
||||||
|
outdir = Path.GetFullPath(outdir);
|
||||||
|
}
|
||||||
|
Console.WriteLine(outdir);
|
||||||
filename = filename.Replace("\"", "");
|
filename = filename.Replace("\"", "");
|
||||||
|
|
||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
{
|
{
|
||||||
logger.User("Converting " + filename);
|
logger.User("Converting " + filename);
|
||||||
@@ -1342,15 +1336,17 @@ Make a selection:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the extension matches, append ".new" to the filename
|
// If the extension matches, append ".new" to the filename
|
||||||
if (Path.GetExtension(filename) == (datdata.OutputFormat == OutputFormat.Xml ? ".xml" : ".dat"))
|
if (outdir == "" && Path.GetExtension(filename) == (datdata.OutputFormat == OutputFormat.Xml ? ".xml" : ".dat"))
|
||||||
{
|
{
|
||||||
datdata.Description += ".new";
|
datdata.Description += ".new";
|
||||||
}
|
}
|
||||||
|
|
||||||
Output.WriteDatfile(datdata, Path.GetDirectoryName(filename), logger);
|
Output.WriteDatfile(datdata, (outdir == "" ? Path.GetDirectoryName(filename) : outdir), logger);
|
||||||
}
|
}
|
||||||
else if (Directory.Exists(filename))
|
else if (Directory.Exists(filename))
|
||||||
{
|
{
|
||||||
|
filename = Path.GetFullPath(filename);
|
||||||
|
|
||||||
foreach (string file in Directory.EnumerateFiles(filename, "*", SearchOption.AllDirectories))
|
foreach (string file in Directory.EnumerateFiles(filename, "*", SearchOption.AllDirectories))
|
||||||
{
|
{
|
||||||
logger.User("Converting " + file);
|
logger.User("Converting " + file);
|
||||||
@@ -1379,12 +1375,12 @@ Make a selection:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the extension matches, append ".new" to the filename
|
// If the extension matches, append ".new" to the filename
|
||||||
if (Path.GetExtension(file) == (datdata.OutputFormat == OutputFormat.Xml ? ".xml" : ".dat"))
|
if (outdir == "" && Path.GetExtension(file) == (datdata.OutputFormat == OutputFormat.Xml ? ".xml" : ".dat"))
|
||||||
{
|
{
|
||||||
datdata.Description += ".new";
|
datdata.Description += ".new";
|
||||||
}
|
}
|
||||||
|
|
||||||
Output.WriteDatfile(datdata, Path.GetDirectoryName(file), logger);
|
Output.WriteDatfile(datdata, (outdir == "" ? Path.GetDirectoryName(file) : outdir + Path.DirectorySeparatorChar + Path.GetDirectoryName(file).Remove(0, filename.Length)), logger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ namespace SabreTools.Helper
|
|||||||
outDir += Path.DirectorySeparatorChar;
|
outDir += Path.DirectorySeparatorChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create the output directory if it doesn't already exist
|
||||||
|
Directory.CreateDirectory(outDir);
|
||||||
|
|
||||||
// (currently uses current time, change to "last updated time")
|
// (currently uses current time, change to "last updated time")
|
||||||
logger.User("Opening file for writing: " + outDir + datdata.Description + (datdata.OutputFormat == OutputFormat.Xml ? ".xml" : ".dat"));
|
logger.User("Opening file for writing: " + outDir + datdata.Description + (datdata.OutputFormat == OutputFormat.Xml ? ".xml" : ".dat"));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user