diff --git a/FoliCon/Modules/Extension/StreamExtension.cs b/FoliCon/Modules/Extension/StreamExtension.cs index 351ed27..2bf3550 100644 --- a/FoliCon/Modules/Extension/StreamExtension.cs +++ b/FoliCon/Modules/Extension/StreamExtension.cs @@ -30,8 +30,7 @@ public static void ExtractPngAndIcoToDirectory(this Stream archiveStream, string IProgress progressCallback) { using var reader = ArchiveFactory.Open(archiveStream, ReaderOptions); - var pngAndIcoEntries = reader.Entries.Where(entry => - (!entry.IsDirectory && !IsUnwantedDirectoryOrFileType(entry)) && FileUtils.IsPngOrIco(entry.Key)); + var pngAndIcoEntries = reader.Entries.Where(IsValidFile); var pngAndIcoFiles = pngAndIcoEntries.GroupBy(entry => Path.GetFileNameWithoutExtension(entry.Key)) .Select(group => @@ -51,14 +50,9 @@ public static void ExtractPngAndIcoToDirectory(this Stream archiveStream, string progressCallback.Report(extractionProgress); } } - - private static bool IsUnwantedDirectoryOrFileType(IEntry entry) + + private static bool IsValidFile(IEntry entry) { - return entry.Key != null && (entry.IsDirectory || - entry.Key.Contains("ResourceForks") || - entry.Key.Contains("__MACOSX") || - entry.Key.StartsWith("._") || - entry.Key.Equals(".DS_Store") || - entry.Key.Equals("Thumbs.db")); + return !entry.IsDirectory && !FileUtils.isExcludedFileIdentifier(entry.Key) && FileUtils.IsPngOrIco(entry.Key); } } \ No newline at end of file diff --git a/FoliCon/Modules/utils/FileUtils.cs b/FoliCon/Modules/utils/FileUtils.cs index 49e4f79..023a3eb 100644 --- a/FoliCon/Modules/utils/FileUtils.cs +++ b/FoliCon/Modules/utils/FileUtils.cs @@ -23,7 +23,15 @@ public static class FileUtils ".7z", ".tar" ]; - + private static readonly HashSet ExcludedFileIdentifiers = + [ + "ResourceForks", + "__MACOSX", + "._", + ".DS_Store", + "Thumbs.db" + ]; + /// /// Determines whether a given string value ends with any string within a collection of file extensions. /// @@ -39,6 +47,9 @@ private static bool EndsIn(string value, IEnumerable fileExtensions) public static bool IsPngOrIco(string fileName) => fileName != null && EndsIn(fileName, new[] { ".png", ".ico" }); + public static bool isExcludedFileIdentifier(string fileName) => + fileName != null && ExcludedFileIdentifiers.Any(fileName.Contains); + /// /// Deletes Icons (.ico and Desktop.ini files) from all subfolders of given path. ///