From 905f11758a670e8e77c462282bae7b3ed31ced9b Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sat, 4 Jun 2016 23:07:58 -0700 Subject: [PATCH] [DATFromDir] Romba ignores all empty folders --- DATFromDir/DATFromDir.cs | 74 ++++++++++++++++++---------------- SabreHelper/RomManipulation.cs | 1 + 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/DATFromDir/DATFromDir.cs b/DATFromDir/DATFromDir.cs index 028dc3fb..b75bf14b 100644 --- a/DATFromDir/DATFromDir.cs +++ b/DATFromDir/DATFromDir.cs @@ -305,43 +305,13 @@ namespace SabreTools lastparent = ProcessFile(subitem, sw, lastparent); } - // If there were no subitems, add a "blank" game to to the set - if (!items) + // In romba mode we ignore empty folders completely + if (!_datdata.Romba) { - string actualroot = item.Remove(0, basePathBackup.Length); - RomData rom = new RomData + // If there were no subitems, add a "blank" game to to the set (if not in Romba mode) + if (!items) { - Name = "null", - Game = (_datdata.Type == "SuperDAT" ? - _datdata.Name + (actualroot != "" && !actualroot.StartsWith(Path.DirectorySeparatorChar.ToString()) ? - Path.DirectorySeparatorChar.ToString() : - "") + actualroot : - actualroot), - Size = -1, - CRC = "null", - MD5 = "null", - SHA1 = "null", - }; - - string key = rom.Size + "-" + rom.CRC; - if (_datdata.Roms.ContainsKey(key)) - { - _datdata.Roms[key].Add(rom); - } - else - { - List temp = new List(); - temp.Add(rom); - _datdata.Roms.Add(key, temp); - } - } - - // Now scour subdirectories for empties and add those as well - foreach (string subdir in Directory.EnumerateDirectories(item, "*", SearchOption.AllDirectories)) - { - if (Directory.EnumerateFiles(subdir, "*", SearchOption.AllDirectories).Count() == 0) - { - string actualroot = subdir.Remove(0, basePathBackup.Length); + string actualroot = item.Remove(0, basePathBackup.Length); RomData rom = new RomData { Name = "null", @@ -368,6 +338,40 @@ namespace SabreTools _datdata.Roms.Add(key, temp); } } + + // Now scour subdirectories for empties and add those as well (if not in Romba mode) + foreach (string subdir in Directory.EnumerateDirectories(item, "*", SearchOption.AllDirectories)) + { + if (Directory.EnumerateFiles(subdir, "*", SearchOption.AllDirectories).Count() == 0) + { + string actualroot = subdir.Remove(0, basePathBackup.Length); + RomData rom = new RomData + { + Name = "null", + Game = (_datdata.Type == "SuperDAT" ? + _datdata.Name + (actualroot != "" && !actualroot.StartsWith(Path.DirectorySeparatorChar.ToString()) ? + Path.DirectorySeparatorChar.ToString() : + "") + actualroot : + actualroot), + Size = -1, + CRC = "null", + MD5 = "null", + SHA1 = "null", + }; + + string key = rom.Size + "-" + rom.CRC; + if (_datdata.Roms.ContainsKey(key)) + { + _datdata.Roms[key].Add(rom); + } + else + { + List temp = new List(); + temp.Add(rom); + _datdata.Roms.Add(key, temp); + } + } + } } } _basePath = basePathBackup; diff --git a/SabreHelper/RomManipulation.cs b/SabreHelper/RomManipulation.cs index 8a400632..27572515 100644 --- a/SabreHelper/RomManipulation.cs +++ b/SabreHelper/RomManipulation.cs @@ -207,6 +207,7 @@ namespace SabreTools.Helper rom.Name = gc[i].Replace("\"", ""); break; case "size": + Int64.TryParse(gc[i].Replace("\"", ""), out rom.Size); break; case "crc":