From 212527233e69a00050bfaa157deb1b2f15e10c8b Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 21 Jun 2016 11:08:13 -0700 Subject: [PATCH] [DATFromDir] Refactor to allow for easier writing from Rom data --- SabreTools/DATFromDir.cs | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/SabreTools/DATFromDir.cs b/SabreTools/DATFromDir.cs index cb3ca0c9..56c0b488 100644 --- a/SabreTools/DATFromDir.cs +++ b/SabreTools/DATFromDir.cs @@ -328,21 +328,10 @@ namespace SabreTools List extracted = ArchiveTools.GetArchiveFileInfo(item, _logger); foreach (Rom rom in extracted) { - int last = 0; - if (lastparent != null && lastparent.ToLowerInvariant() != rom.Game.ToLowerInvariant()) - { - Output.WriteEndGame(sw, rom, new List(), new List(), lastparent, _datdata, 0, out last, _logger); - } - - // If we have a new game, output the beginning of the new item - if (lastparent == null || lastparent.ToLowerInvariant() != rom.Game.ToLowerInvariant()) - { - Output.WriteStartGame(sw, rom, new List(), lastparent, _datdata, 0, last, _logger); - } - - // Write out the rom data - Output.WriteRomData(sw, rom, lastparent, _datdata, 0, _logger); - _logger.User("File added: " + rom.Name + Environment.NewLine); + lastparent = ProcessFileHelper(item, rom, sw, _basePath, + Path.Combine((Path.GetDirectoryName(Path.GetFullPath(item)) + Path.DirectorySeparatorChar).Remove(0, _basePath.Length) + + Path.GetFileNameWithoutExtension(item) + ), _datdata, lastparent); } } // Otherwise, just get the info on the file itself @@ -351,7 +340,7 @@ namespace SabreTools lastparent = ProcessFile(item, sw, _basePath, "", _datdata, lastparent); } } - // Otherwise, ttempt to extract the files to the temporary directory + // Otherwise, attempt to extract the files to the temporary directory else { bool encounteredErrors = !ArchiveTools.ExtractArchive(item, @@ -405,6 +394,22 @@ namespace SabreTools _logger.Log(Path.GetFileName(item) + " treated like a file"); Rom rom = RomTools.GetSingleFileInfo(item, _noMD5, _noSHA1); + return ProcessFileHelper(item, rom, sw, basepath, parent, datdata, lastparent); + } + + /// + /// Process a single file as a file (with found Rom data) + /// + /// File to be added + /// Rom data to be used to write to file + /// StreamWriter representing the output file + /// Path the represents the parent directory + /// Parent game to be used + /// DatData object with output information + /// Last known parent game name + /// New last known parent game name + private string ProcessFileHelper(string item, Rom rom, StreamWriter sw, string basepath, string parent, Dat datdata, string lastparent) + { try { if (basepath.EndsWith(Path.DirectorySeparatorChar.ToString()))