Add helper function for listing image files (common task)
This commit is contained in:
1 parent
8ea9698e2d
commit
658a3068b0
4 files changed
+33
-23
No files matched your search
@@ -175,13 +175,9 @@ namespace Vocaluxe.Base
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var ignoreList = new List<string>();
|
var ignoreList = new List<string>();
|
||||||
var files = new List<string>();
|
|
||||||
|
|
||||||
string coverPath = Path.Combine(CSettings.FolderCover, coverTheme.Folder);
|
string coverPath = Path.Combine(CSettings.FolderCover, coverTheme.Folder);
|
||||||
files.AddRange(CHelper.ListFiles(coverPath, "*.png", true, true));
|
List<string> files = CHelper.ListImageFiles(coverPath, 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));
|
|
||||||
|
|
||||||
CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(CSettings.FolderCover, coverTheme.File));
|
CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(CSettings.FolderCover, coverTheme.File));
|
||||||
lock (_Covers)
|
lock (_Covers)
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using VocaluxeLib;
|
using VocaluxeLib;
|
||||||
using VocaluxeLib.Profile;
|
|
||||||
using VocaluxeLib.Draw;
|
using VocaluxeLib.Draw;
|
||||||
|
using VocaluxeLib.Profile;
|
||||||
|
|
||||||
namespace Vocaluxe.Base
|
namespace Vocaluxe.Base
|
||||||
{
|
{
|
||||||
@@ -578,12 +578,7 @@ namespace Vocaluxe.Base
|
|||||||
|
|
||||||
var files = new List<string>();
|
var files = new List<string>();
|
||||||
foreach (string path in CSettings.FoldersProfiles)
|
foreach (string path in CSettings.FoldersProfiles)
|
||||||
{
|
files.AddRange(CHelper.ListImageFiles(path, true, true));
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (string file in files)
|
foreach (string file in files)
|
||||||
{
|
{
|
||||||
|
|||||||
+28
-3
@@ -145,7 +145,15 @@ namespace VocaluxeLib
|
|||||||
rect = new RectangleF(left, upper, scaledWidth, scaledHeight);
|
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 files = new List<string>();
|
||||||
var dir = new DirectoryInfo(path);
|
var dir = new DirectoryInfo(path);
|
||||||
@@ -155,14 +163,14 @@ namespace VocaluxeLib
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// ReSharper disable LoopCanBeConvertedToQuery
|
// ReSharper disable LoopCanBeConvertedToQuery
|
||||||
foreach (FileInfo file in dir.GetFiles(cast))
|
foreach (FileInfo file in dir.GetFiles(searchPattern))
|
||||||
// ReSharper restore LoopCanBeConvertedToQuery
|
// ReSharper restore LoopCanBeConvertedToQuery
|
||||||
files.Add(!fullpath ? file.Name : file.FullName);
|
files.Add(!fullpath ? file.Name : file.FullName);
|
||||||
|
|
||||||
if (recursive)
|
if (recursive)
|
||||||
{
|
{
|
||||||
foreach (DirectoryInfo di in dir.GetDirectories())
|
foreach (DirectoryInfo di in dir.GetDirectories())
|
||||||
files.AddRange(ListFiles(di.FullName, cast, true, fullpath));
|
files.AddRange(ListFiles(di.FullName, searchPattern, true, fullpath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception) {}
|
catch (Exception) {}
|
||||||
@@ -170,6 +178,23 @@ namespace VocaluxeLib
|
|||||||
return files;
|
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)
|
public static bool TryParse<T>(string value, out T result, bool ignoreCase = false)
|
||||||
where T : struct
|
where T : struct
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -318,10 +318,7 @@ namespace VocaluxeLib.Songs
|
|||||||
{
|
{
|
||||||
if (CoverFileName == "")
|
if (CoverFileName == "")
|
||||||
{
|
{
|
||||||
List<string> files = CHelper.ListFiles(Folder, "*.jpg");
|
List<string> files = CHelper.ListImageFiles(Folder);
|
||||||
files.AddRange(CHelper.ListFiles(Folder, "*.jpeg"));
|
|
||||||
files.AddRange(CHelper.ListFiles(Folder, "*.png"));
|
|
||||||
files.AddRange(CHelper.ListFiles(Folder, "*.gif"));
|
|
||||||
foreach (String file in files)
|
foreach (String file in files)
|
||||||
{
|
{
|
||||||
if (file.ContainsIgnoreCase("[CO]") &&
|
if (file.ContainsIgnoreCase("[CO]") &&
|
||||||
@@ -332,10 +329,7 @@ namespace VocaluxeLib.Songs
|
|||||||
|
|
||||||
if (BackgroundFileNames.Count == 0)
|
if (BackgroundFileNames.Count == 0)
|
||||||
{
|
{
|
||||||
List<string> files = CHelper.ListFiles(Folder, "*.jpg");
|
List<string> files = CHelper.ListImageFiles(Folder);
|
||||||
files.AddRange(CHelper.ListFiles(Folder, "*.jpeg"));
|
|
||||||
files.AddRange(CHelper.ListFiles(Folder, "*.png"));
|
|
||||||
files.AddRange(CHelper.ListFiles(Folder, "*.gif"));
|
|
||||||
foreach (String file in files)
|
foreach (String file in files)
|
||||||
{
|
{
|
||||||
if (file.ContainsIgnoreCase("[BG]") &&
|
if (file.ContainsIgnoreCase("[BG]") &&
|
||||||
|
|||||||
Reference in new issue
Block a user