diff --git a/Vocaluxe/Base/CCover.cs b/Vocaluxe/Base/CCover.cs index 241ec0d8..fddf06d2 100644 --- a/Vocaluxe/Base/CCover.cs +++ b/Vocaluxe/Base/CCover.cs @@ -175,13 +175,9 @@ namespace Vocaluxe.Base return; var ignoreList = new List(); - var files = new List(); string coverPath = Path.Combine(CSettings.FolderCover, coverTheme.Folder); - files.AddRange(CHelper.ListFiles(coverPath, "*.png", true, true)); - files.AddRange(CHelper.ListFiles(coverPath, "*.jpg", true, true)); - files.AddRange(CHelper.ListFiles(coverPath, "*.jpeg", true, true)); - files.AddRange(CHelper.ListFiles(coverPath, "*.bmp", true, true)); + List files = CHelper.ListImageFiles(coverPath, true, true); CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(CSettings.FolderCover, coverTheme.File)); lock (_Covers) diff --git a/Vocaluxe/Base/CProfiles.cs b/Vocaluxe/Base/CProfiles.cs index b4f4ae50..124cebdd 100644 --- a/Vocaluxe/Base/CProfiles.cs +++ b/Vocaluxe/Base/CProfiles.cs @@ -19,8 +19,8 @@ using System; using System.Collections.Generic; using System.IO; using VocaluxeLib; -using VocaluxeLib.Profile; using VocaluxeLib.Draw; +using VocaluxeLib.Profile; namespace Vocaluxe.Base { @@ -578,12 +578,7 @@ namespace Vocaluxe.Base var files = new List(); foreach (string path in CSettings.FoldersProfiles) - { - files.AddRange(CHelper.ListFiles(path, "*.png", true, true)); - files.AddRange(CHelper.ListFiles(path, "*.jpg", true, true)); - files.AddRange(CHelper.ListFiles(path, "*.jpeg", true, true)); - files.AddRange(CHelper.ListFiles(path, "*.bmp", true, true)); - } + files.AddRange(CHelper.ListImageFiles(path, true, true)); foreach (string file in files) { diff --git a/VocaluxeLib/CHelper.cs b/VocaluxeLib/CHelper.cs index a03b1ad9..b10cdb74 100644 --- a/VocaluxeLib/CHelper.cs +++ b/VocaluxeLib/CHelper.cs @@ -145,7 +145,15 @@ namespace VocaluxeLib rect = new RectangleF(left, upper, scaledWidth, scaledHeight); } - public static List ListFiles(string path, string cast, bool recursive = false, bool fullpath = false) + /// + /// Returns a list with all files in the given path that match a given pattern + /// + /// Path to search for + /// Pattern to match (e.g. "*.jpg") + /// Search directories recursively + /// False for just file names, True for full path + /// List of file names + public static List ListFiles(string path, string searchPattern, bool recursive = false, bool fullpath = false) { var files = new List(); var dir = new DirectoryInfo(path); @@ -155,14 +163,14 @@ namespace VocaluxeLib try { // ReSharper disable LoopCanBeConvertedToQuery - foreach (FileInfo file in dir.GetFiles(cast)) + foreach (FileInfo file in dir.GetFiles(searchPattern)) // ReSharper restore LoopCanBeConvertedToQuery files.Add(!fullpath ? file.Name : file.FullName); if (recursive) { foreach (DirectoryInfo di in dir.GetDirectories()) - files.AddRange(ListFiles(di.FullName, cast, true, fullpath)); + files.AddRange(ListFiles(di.FullName, searchPattern, true, fullpath)); } } catch (Exception) {} @@ -170,6 +178,23 @@ namespace VocaluxeLib return files; } + /// + /// Returns a list with all image files in the given path + /// Searches for: jpg, jpeg, png, gif + /// + /// Path to search for + /// Search directories recursively + /// False for just file names, True for full path + /// List of image file names + public static List ListImageFiles(string path, bool recursive = false, bool fullpath = false) + { + List files = ListFiles(path, "*.jpg", recursive, fullpath); + files.AddRange(ListFiles(path, "*.jpeg", recursive, fullpath)); + files.AddRange(ListFiles(path, "*.png", recursive, fullpath)); + files.AddRange(ListFiles(path, "*.gif", recursive, fullpath)); + return files; + } + public static bool TryParse(string value, out T result, bool ignoreCase = false) where T : struct { diff --git a/VocaluxeLib/Songs/CSong.cs b/VocaluxeLib/Songs/CSong.cs index c16c1874..a1c4ad33 100644 --- a/VocaluxeLib/Songs/CSong.cs +++ b/VocaluxeLib/Songs/CSong.cs @@ -318,10 +318,7 @@ namespace VocaluxeLib.Songs { if (CoverFileName == "") { - List files = CHelper.ListFiles(Folder, "*.jpg"); - files.AddRange(CHelper.ListFiles(Folder, "*.jpeg")); - files.AddRange(CHelper.ListFiles(Folder, "*.png")); - files.AddRange(CHelper.ListFiles(Folder, "*.gif")); + List files = CHelper.ListImageFiles(Folder); foreach (String file in files) { if (file.ContainsIgnoreCase("[CO]") && @@ -332,10 +329,7 @@ namespace VocaluxeLib.Songs if (BackgroundFileNames.Count == 0) { - List files = CHelper.ListFiles(Folder, "*.jpg"); - files.AddRange(CHelper.ListFiles(Folder, "*.jpeg")); - files.AddRange(CHelper.ListFiles(Folder, "*.png")); - files.AddRange(CHelper.ListFiles(Folder, "*.gif")); + List files = CHelper.ListImageFiles(Folder); foreach (String file in files) { if (file.ContainsIgnoreCase("[BG]") &&