diff --git a/DATabase/DATabase.cs b/DATabase/DATabase.cs index 47aed4ad..d970696b 100644 --- a/DATabase/DATabase.cs +++ b/DATabase/DATabase.cs @@ -315,6 +315,8 @@ namespace SabreTools } } + // Split a DAT by extension + logger.Close(); return; } @@ -740,7 +742,7 @@ or 'b' to go back to the previous menu: { if (File.Exists(filename)) { - Console.WriteLine("Converting " + filename); + logger.Log("Converting " + filename); XmlDocument doc = new XmlDocument(); try { @@ -751,7 +753,7 @@ or 'b' to go back to the previous menu: sw.Write(conv); sw.Close(); fs.Close(); - Console.WriteLine("Converted file: " + Path.GetFileNameWithoutExtension(filename) + ".new.dat"); + logger.Log("Converted file: " + Path.GetFileNameWithoutExtension(filename) + ".new.dat"); } catch (XmlException) { @@ -760,7 +762,7 @@ or 'b' to go back to the previous menu: } else { - Console.WriteLine("I'm sorry but " + filename + " doesn't exist!"); + logger.Error("I'm sorry but " + filename + " doesn't exist!"); } return; } @@ -800,7 +802,7 @@ or 'b' to go back to the previous menu: { if (File.Exists(filename)) { - Console.WriteLine("Converting " + filename); + logger.Log("Converting " + filename); XElement conv = Converters.RomVaultToXML(File.ReadAllLines(filename)); FileStream fs = File.OpenWrite(Path.GetFileNameWithoutExtension(filename) + ".new.xml"); StreamWriter sw = new StreamWriter(fs); @@ -809,11 +811,11 @@ or 'b' to go back to the previous menu: sw.Write(conv); sw.Close(); fs.Close(); - Console.WriteLine("Converted file: " + Path.GetFileNameWithoutExtension(filename) + ".new.xml"); + logger.Log("Converted file: " + Path.GetFileNameWithoutExtension(filename) + ".new.xml"); } else { - Console.WriteLine("I'm sorry but " + filename + "doesn't exist!"); + logger.Error("I'm sorry but " + filename + "doesn't exist!"); } return; } @@ -937,7 +939,7 @@ Make a selection: break; case "5": Console.Clear(); - InitTrimMerge(input, root, rename, forceunzip); + InitExtSplit(input, exta, extb, outdir); Console.Write("\nPress any key to continue..."); Console.ReadKey(); break; @@ -946,23 +948,35 @@ Make a selection: } /// - /// Wrap trimming and merging a single DAT + /// Wrap splitting a DAT by 2 extensions /// /// Input file or folder to be converted - /// Root directory to base path lengths on + /// Root directory to base path lengths on /// True is games should not be renamed /// True if forcepacking="unzip" should be included - 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("\"", ""); + 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); - sg.Process(); + if (exta == "" || extb == "") + { + logger.Warning("Two extension are needed to split a DAT!"); + return; + } + ExtSplit es = new ExtSplit(input, exta, extb, outdir, logger); + es.Split(); return; } + else + { + logger.Log("I'm sorry but " + input + "doesn't exist!"); + } } /// diff --git a/DATabase/ExtSplit.cs b/DATabase/ExtSplit.cs index 7e33bc37..6ea3d934 100644 --- a/DATabase/ExtSplit.cs +++ b/DATabase/ExtSplit.cs @@ -6,7 +6,7 @@ using SabreTools.Helper; namespace SabreTools { - public class DatSplit + public class ExtSplit { // Instance variables private string _extA; @@ -22,7 +22,7 @@ namespace SabreTools /// First extension to split on /// Second extension to split on /// Logger object for console and file writing - 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("\"", ""); _extA = (extA.StartsWith(".") ? extA : "." + extA).ToUpperInvariant(); @@ -82,9 +82,9 @@ namespace SabreTools // Then write out both files 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, - "", "", "", "", false, !RomManipulation.IsXmlDat(_filename), "", romsB, _logger); + "", "", "", "", false, !RomManipulation.IsXmlDat(_filename), _outdir, romsB, _logger); return success; }