Add helper function for listing image files (common task)

This commit is contained in:
Flamefire committed 2014-03-16 18:58:01 +01:00
1 parent 8ea9698e2d
commit 658a3068b0
4 files changed
+33 -23

No files matched your search

+1 -5
View File
@@ -175,13 +175,9 @@ namespace Vocaluxe.Base
return;
var ignoreList = new List<string>();
var files = new List<string>();
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<string> files = CHelper.ListImageFiles(coverPath, true, true);
CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(CSettings.FolderCover, coverTheme.File));
lock (_Covers)
+2 -7
View File
@@ -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<string>();
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)
{
+28 -3
View File
@@ -145,7 +145,15 @@ namespace VocaluxeLib
rect = new RectangleF(left, upper, scaledWidth, scaledHeight);
}
public static List<string> ListFiles(string path, string cast, bool recursive = false, bool fullpath = false)
/// <summary>
/// Returns a list with all files in the given path that match a given pattern
/// </summary>
/// <param name="path">Path to search for</param>
/// <param name="searchPattern">Pattern to match (e.g. "*.jpg")</param>
/// <param name="recursive">Search directories recursively</param>
/// <param name="fullpath">False for just file names, True for full path</param>
/// <returns>List of file names</returns>
public static List<string> ListFiles(string path, string searchPattern, bool recursive = false, bool fullpath = false)
{
var files = new List<string>();
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;
}
/// <summary>
/// Returns a list with all image files in the given path
/// Searches for: jpg, jpeg, png, gif
/// </summary>
/// <param name="path">Path to search for</param>
/// <param name="recursive">Search directories recursively</param>
/// <param name="fullpath">False for just file names, True for full path</param>
/// <returns>List of image file names</returns>
public static List<string> ListImageFiles(string path, bool recursive = false, bool fullpath = false)
{
List<string> 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<T>(string value, out T result, bool ignoreCase = false)
where T : struct
{
+2 -8
View File
@@ -318,10 +318,7 @@ namespace VocaluxeLib.Songs
{
if (CoverFileName == "")
{
List<string> files = CHelper.ListFiles(Folder, "*.jpg");
files.AddRange(CHelper.ListFiles(Folder, "*.jpeg"));
files.AddRange(CHelper.ListFiles(Folder, "*.png"));
files.AddRange(CHelper.ListFiles(Folder, "*.gif"));
List<string> 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<string> files = CHelper.ListFiles(Folder, "*.jpg");
files.AddRange(CHelper.ListFiles(Folder, "*.jpeg"));
files.AddRange(CHelper.ListFiles(Folder, "*.png"));
files.AddRange(CHelper.ListFiles(Folder, "*.gif"));
List<string> files = CHelper.ListImageFiles(Folder);
foreach (String file in files)
{
if (file.ContainsIgnoreCase("[BG]") &&