Merge pull request #400 from swurzinger/song-loading-speedup

improve song enumeration performance
This commit is contained in:
Florian Küpper authored and GitHub committed 2018-10-24 09:04:19 +02:00
commit fda7d4acb3
8 files changed
+26 -35

No files matched your search

+1 -1
View File
@@ -157,7 +157,7 @@ namespace Vocaluxe.Base
if (_Initialized)
return;
List<string> soundFiles = CHelper.ListSoundFiles(CSettings.FolderNameBackgroundMusic, true, true);
IEnumerable<string> soundFiles = CHelper.ListSoundFiles(CSettings.FolderNameBackgroundMusic, true, true);
foreach (string path in soundFiles)
_BGMusicFiles.Add(new CPlaylistElement(path));
+2 -2
View File
@@ -174,7 +174,7 @@ namespace Vocaluxe.Base
_CoverThemes.Clear();
string folderPath = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameCover);
List<string> files = CHelper.ListFiles(folderPath, "*.xml");
IEnumerable<string> files = CHelper.ListFiles(folderPath, "*.xml");
var xml = new CXmlDeserializer();
foreach (string file in files)
@@ -207,7 +207,7 @@ namespace Vocaluxe.Base
Debug.Assert(!String.IsNullOrEmpty(coverTheme.Info.Name));
List<string> files = CHelper.ListImageFiles(coverTheme.FolderPath, true, true);
IEnumerable<string> files = CHelper.ListImageFiles(coverTheme.FolderPath, true, true);
lock (_Covers)
{
+5 -6
View File
@@ -339,18 +339,17 @@ namespace Vocaluxe.Base
SongsLoaded = false;
_Songs.Clear();
var files = new List<string>();
var files = Enumerable.Empty<string>();
using (CBenchmark.Time("List Songs"))
{
foreach (string p in CConfig.SongFolders)
foreach (string path in CConfig.SongFolders)
{
if (Directory.Exists(p))
if (Directory.Exists(path))
{
string path = p;
files.AddRange(CHelper.ListFiles(path, "*.txt", true, true));
files.AddRange(CHelper.ListFiles(path, "*.txd", true, true));
files = files.Union(CHelper.ListFiles(path, "*.txt", true, true));
files = files.Union(CHelper.ListFiles(path, "*.txd", true, true));
}
}
}
+1 -1
View File
@@ -86,7 +86,7 @@ namespace Vocaluxe.Base.ThemeSystem
}
string path = Path.Combine(_Folder, Name);
List<string> files = CHelper.ListFiles(path, "*.xml");
IEnumerable<string> files = CHelper.ListFiles(path, "*.xml");
// Load skins, succeed if at least 1 skin was loaded
bool ok = false;
+1 -1
View File
@@ -135,7 +135,7 @@ namespace Vocaluxe.Base.ThemeSystem
public static bool ReadThemesFromFolder(string path, int partyModeID)
{
List<string> files = CHelper.ListFiles(path, "*.xml", false, true);
IEnumerable<string> files = CHelper.ListFiles(path, "*.xml", false, true);
List<CTheme> newThemes = new List<CTheme>();
foreach (string file in files)
+12 -20
View File
@@ -20,6 +20,7 @@ using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using VocaluxeLib.Log;
namespace VocaluxeLib
@@ -165,25 +166,20 @@ namespace VocaluxeLib
/// <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)
public static IEnumerable<string> ListFiles(string path, string searchPattern, bool recursive = false, bool fullpath = false)
{
var files = new List<string>();
IEnumerable<string> files = Enumerable.Empty<string>();
var dir = new DirectoryInfo(path);
if (!dir.Exists)
return files;
if (recursive && !fullpath)
throw new NotSupportedException("recursive file listing with relative path names is not supported");
try
{
// ReSharper disable LoopCanBeConvertedToQuery
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, searchPattern, true, fullpath));
}
files = Directory.EnumerateFiles(dir.FullName, searchPattern, recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
files = files.Select(fullpath ? (Func<string, string>)Path.GetFullPath : Path.GetFileName);
}
catch (Exception) {}
@@ -198,13 +194,9 @@ namespace VocaluxeLib
/// <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, IEnumerable<string> searchPatterns, bool recursive = false, bool fullpath = false)
public static IEnumerable<string> ListFiles(string path, IEnumerable<string> searchPatterns, bool recursive = false, bool fullpath = false)
{
var files = new List<string>();
foreach (string pattern in searchPatterns)
files.AddRange(ListFiles(path, pattern, recursive, fullpath));
return files;
return searchPatterns.SelectMany(pattern => ListFiles(path, pattern, recursive, fullpath));
}
/// <summary>
@@ -214,7 +206,7 @@ namespace VocaluxeLib
/// <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)
public static IEnumerable<string> ListImageFiles(string path, bool recursive = false, bool fullpath = false)
{
return ListFiles(path, _ImageFileTypes, recursive, fullpath);
}
@@ -226,7 +218,7 @@ namespace VocaluxeLib
/// <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> ListSoundFiles(string path, bool recursive = false, bool fullpath = false)
public static IEnumerable<string> ListSoundFiles(string path, bool recursive = false, bool fullpath = false)
{
return ListFiles(path, _SoundFileTypes, recursive, fullpath);
}
+2 -2
View File
@@ -196,10 +196,10 @@ namespace VocaluxeLib.Log
int i = 0;
return theRegex.Replace(template, delegate(Match match)
{
if (propertyValues.Length >= i)
if (i >= propertyValues.Length)
return match.Value;
return propertyValues[i++].ToString();
});
});
}
}
+2 -2
View File
@@ -325,7 +325,7 @@ namespace VocaluxeLib.Songs
{
if (CoverFileName == "")
{
List<string> files = CHelper.ListImageFiles(Folder);
IEnumerable<string> files = CHelper.ListImageFiles(Folder);
foreach (String file in files)
{
if (file.ContainsIgnoreCase("[CO]") &&
@@ -336,7 +336,7 @@ namespace VocaluxeLib.Songs
if (BackgroundFileNames.Count == 0)
{
List<string> files = CHelper.ListImageFiles(Folder);
IEnumerable<string> files = CHelper.ListImageFiles(Folder);
foreach (String file in files)
{
if (file.ContainsIgnoreCase("[BG]") &&