From f2951a41ca44f05d75ae7726858a6e9a715a61bc Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Fri, 18 Sep 2020 15:18:12 -0700 Subject: [PATCH] Separate all blank finding for DFD --- SabreTools.Library/DatFiles/DatFile.cs | 60 +++++++++++++++----------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs index a4df3a20..34d870d9 100644 --- a/SabreTools.Library/DatFiles/DatFile.cs +++ b/SabreTools.Library/DatFiles/DatFile.cs @@ -1973,7 +1973,6 @@ namespace SabreTools.Library.DatFiles /// TreatAsFiles representing CHD and Archive scanning /// Type of files that should be skipped /// True if blank items should be created for empty folders, false otherwise - /// Output directory to /// True if archive header should be used, false otherwise public bool PopulateFromDir( string basePath, @@ -1999,7 +1998,7 @@ namespace SabreTools.Library.DatFiles // Now find all folders that are empty, if we are supposed to if (addBlanks) - ProcessBlanks(basePath); + ProcessDirectoryBlanks(basePath); } else if (File.Exists(basePath)) { @@ -2052,7 +2051,11 @@ namespace SabreTools.Library.DatFiles else if (!asFiles.HasFlag(TreatAsFile.Archive)) { var extracted = archive.GetChildren(); - ProcessArchive(item, basePath, addBlanks, archive, extracted); + ProcessArchive(item, basePath, extracted); + + // Now find all folders that are empty, if we are supposed to + if (addBlanks) + ProcessArchiveBlanks(item, basePath, archive); } // Process as file if we're treating archives as files @@ -2112,11 +2115,8 @@ namespace SabreTools.Library.DatFiles /// /// File to be added /// Path the represents the parent directory - /// True if blank items should be created for empty folders, false otherwise - /// BaseArchive to get blank folders from, if necessary /// List of BaseFiles representing the internal files - /// True if only information from file headers should be used, false otherwise - private void ProcessArchive(string item, string basePath, bool addBlanks, BaseArchive archive, List extracted) + private void ProcessArchive(string item, string basePath, List extracted) { // Get the parent path for all items string parent = (Path.GetDirectoryName(Path.GetFullPath(item)) + Path.DirectorySeparatorChar).Remove(0, basePath.Length) + Path.GetFileNameWithoutExtension(item); @@ -2127,30 +2127,38 @@ namespace SabreTools.Library.DatFiles DatItem datItem = DatItem.Create(baseFile); ProcessFileHelper(item, datItem, basePath, parent); }); - - // Then, if we're looking for blanks, get all of the blank folders and add them - if (addBlanks) - { - List empties = new List(); - - // Now get all blank folders from the archive - if (archive != null) - empties = archive.GetEmptyFolders(); - - // Add add all of the found empties to the DAT - Parallel.ForEach(empties, Globals.ParallelOptions, empty => - { - Rom emptyRom = new Rom(Path.Combine(empty, "_"), item); - ProcessFileHelper(item, emptyRom, basePath, parent); - }); - } } /// - /// Process blank folders + /// Process blank folders in an archive + /// + /// File containing the blanks + /// Path the represents the parent directory + /// BaseArchive to get blanks from + private void ProcessArchiveBlanks(string item, string basePath, BaseArchive archive) + { + List empties = new List(); + + // Get the parent path for all items + string parent = (Path.GetDirectoryName(Path.GetFullPath(item)) + Path.DirectorySeparatorChar).Remove(0, basePath.Length) + Path.GetFileNameWithoutExtension(item); + + // Now get all blank folders from the archive + if (archive != null) + empties = archive.GetEmptyFolders(); + + // Add add all of the found empties to the DAT + Parallel.ForEach(empties, Globals.ParallelOptions, empty => + { + Rom emptyRom = new Rom(Path.Combine(empty, "_"), item); + ProcessFileHelper(item, emptyRom, basePath, parent); + }); + } + + /// + /// Process blank folders in a directory /// /// Path the represents the parent directory - private void ProcessBlanks(string basePath) + private void ProcessDirectoryBlanks(string basePath) { // If we're in depot mode, we don't process blanks if (Header.OutputDepot?.IsActive == true)