Merge DatSplit, part 4

This commit is contained in:
Matt Nadareski
2016-04-20 11:37:20 -07:00
parent 5dfd1db8e2
commit 3dd26574d0
2 changed files with 32 additions and 18 deletions

View File

@@ -315,6 +315,8 @@ namespace SabreTools
} }
} }
// Split a DAT by extension
logger.Close(); logger.Close();
return; return;
} }
@@ -740,7 +742,7 @@ or 'b' to go back to the previous menu:
{ {
if (File.Exists(filename)) if (File.Exists(filename))
{ {
Console.WriteLine("Converting " + filename); logger.Log("Converting " + filename);
XmlDocument doc = new XmlDocument(); XmlDocument doc = new XmlDocument();
try try
{ {
@@ -751,7 +753,7 @@ or 'b' to go back to the previous menu:
sw.Write(conv); sw.Write(conv);
sw.Close(); sw.Close();
fs.Close(); fs.Close();
Console.WriteLine("Converted file: " + Path.GetFileNameWithoutExtension(filename) + ".new.dat"); logger.Log("Converted file: " + Path.GetFileNameWithoutExtension(filename) + ".new.dat");
} }
catch (XmlException) catch (XmlException)
{ {
@@ -760,7 +762,7 @@ or 'b' to go back to the previous menu:
} }
else else
{ {
Console.WriteLine("I'm sorry but " + filename + " doesn't exist!"); logger.Error("I'm sorry but " + filename + " doesn't exist!");
} }
return; return;
} }
@@ -800,7 +802,7 @@ or 'b' to go back to the previous menu:
{ {
if (File.Exists(filename)) if (File.Exists(filename))
{ {
Console.WriteLine("Converting " + filename); logger.Log("Converting " + filename);
XElement conv = Converters.RomVaultToXML(File.ReadAllLines(filename)); XElement conv = Converters.RomVaultToXML(File.ReadAllLines(filename));
FileStream fs = File.OpenWrite(Path.GetFileNameWithoutExtension(filename) + ".new.xml"); FileStream fs = File.OpenWrite(Path.GetFileNameWithoutExtension(filename) + ".new.xml");
StreamWriter sw = new StreamWriter(fs); StreamWriter sw = new StreamWriter(fs);
@@ -809,11 +811,11 @@ or 'b' to go back to the previous menu:
sw.Write(conv); sw.Write(conv);
sw.Close(); sw.Close();
fs.Close(); fs.Close();
Console.WriteLine("Converted file: " + Path.GetFileNameWithoutExtension(filename) + ".new.xml"); logger.Log("Converted file: " + Path.GetFileNameWithoutExtension(filename) + ".new.xml");
} }
else else
{ {
Console.WriteLine("I'm sorry but " + filename + "doesn't exist!"); logger.Error("I'm sorry but " + filename + "doesn't exist!");
} }
return; return;
} }
@@ -937,7 +939,7 @@ Make a selection:
break; break;
case "5": case "5":
Console.Clear(); Console.Clear();
InitTrimMerge(input, root, rename, forceunzip); InitExtSplit(input, exta, extb, outdir);
Console.Write("\nPress any key to continue..."); Console.Write("\nPress any key to continue...");
Console.ReadKey(); Console.ReadKey();
break; break;
@@ -946,23 +948,35 @@ Make a selection:
} }
/// <summary> /// <summary>
/// Wrap trimming and merging a single DAT /// Wrap splitting a DAT by 2 extensions
/// </summary> /// </summary>
/// <param name="input">Input file or folder to be converted</param> /// <param name="input">Input file or folder to be converted</param>
/// <param name="root">Root directory to base path lengths on</param> /// <param name="exta">Root directory to base path lengths on</param>
/// <param name="rename">True is games should not be renamed</param> /// <param name="rename">True is games should not be renamed</param>
/// <param name="force">True if forcepacking="unzip" should be included</param> /// <param name="force">True if forcepacking="unzip" should be included</param>
private static void InitTrimMerge(string input, string root, bool rename, bool force) private static void InitExtSplit(string input, string exta, string extb, string outdir)
{ {
// Strip any quotations from the name // Strip any quotations from the names
input = input.Replace("\"", ""); input = input.Replace("\"", "");
exta = exta.Replace("\"", "");
extb = extb.Replace("\"", "");
outdir = outdir.Replace("\"", "");
if (input != "" && (File.Exists(input) || Directory.Exists(input))) if (input != "" && File.Exists(input))
{ {
TrimMerge sg = new TrimMerge(input, root, rename, force, logger); if (exta == "" || extb == "")
sg.Process(); {
logger.Warning("Two extension are needed to split a DAT!");
return;
}
ExtSplit es = new ExtSplit(input, exta, extb, outdir, logger);
es.Split();
return; return;
} }
else
{
logger.Log("I'm sorry but " + input + "doesn't exist!");
}
} }
/// <summary> /// <summary>

View File

@@ -6,7 +6,7 @@ using SabreTools.Helper;
namespace SabreTools namespace SabreTools
{ {
public class DatSplit public class ExtSplit
{ {
// Instance variables // Instance variables
private string _extA; private string _extA;
@@ -22,7 +22,7 @@ namespace SabreTools
/// <param name="extA">First extension to split on</param> /// <param name="extA">First extension to split on</param>
/// <param name="extB">Second extension to split on</param> /// <param name="extB">Second extension to split on</param>
/// <param name="logger">Logger object for console and file writing</param> /// <param name="logger">Logger object for console and file writing</param>
public DatSplit(string filename, string extA, string extB, string outdir, Logger logger) public ExtSplit(string filename, string extA, string extB, string outdir, Logger logger)
{ {
_filename = filename.Replace("\"", ""); _filename = filename.Replace("\"", "");
_extA = (extA.StartsWith(".") ? extA : "." + extA).ToUpperInvariant(); _extA = (extA.StartsWith(".") ? extA : "." + extA).ToUpperInvariant();
@@ -82,9 +82,9 @@ namespace SabreTools
// Then write out both files // Then write out both files
bool success = Output.WriteToDat(Path.GetFileNameWithoutExtension(_filename) + "." + _extA, Path.GetFileNameWithoutExtension(_filename) + "." + _extA, bool success = Output.WriteToDat(Path.GetFileNameWithoutExtension(_filename) + "." + _extA, Path.GetFileNameWithoutExtension(_filename) + "." + _extA,
"", "", "", "", false, !RomManipulation.IsXmlDat(_filename), "", romsA, _logger); "", "", "", "", false, !RomManipulation.IsXmlDat(_filename), _outdir, romsA, _logger);
success &= Output.WriteToDat(Path.GetFileNameWithoutExtension(_filename) + "." + _extB, Path.GetFileNameWithoutExtension(_filename) + "." + _extB, success &= Output.WriteToDat(Path.GetFileNameWithoutExtension(_filename) + "." + _extB, Path.GetFileNameWithoutExtension(_filename) + "." + _extB,
"", "", "", "", false, !RomManipulation.IsXmlDat(_filename), "", romsB, _logger); "", "", "", "", false, !RomManipulation.IsXmlDat(_filename), _outdir, romsB, _logger);
return success; return success;
} }