Skip to content

Commit f695842

Browse files
committed
Add excluded extension support
1 parent ee3c9b9 commit f695842

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

QuickList/Application/Configuration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ internal sealed class Configuration
6464
/// </summary>
6565
internal int FileReaderParallelism { get; set; }
6666

67+
/// <summary>
68+
/// Excluded extensions
69+
/// </summary>
70+
internal List<string> ExcludedExtensions { get; set; }
71+
6772

6873
internal static Configuration Parse(string iniFile)
6974
{

QuickList/Application/FileReader.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Diagnostics;
55
using System.IO;
66
using System.Linq;
7+
using System.Runtime.CompilerServices;
78
using System.Runtime.InteropServices;
89
using Sander.QuickList.Application.Enums;
910
using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
@@ -87,9 +88,20 @@ private List<Entry> ListFiles()
8788
_configuration.Status = Status.Get("Gathering files", percentage);
8889
}
8990

91+
92+
if (_configuration.ExcludedExtensions?.Count > 0)
93+
ExcludeByExtension(fileList);
94+
9095
return fileList;
9196
}
9297

98+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
99+
private void ExcludeByExtension(List<Entry> fileList)
100+
{
101+
foreach (var extension in _configuration.ExcludedExtensions)
102+
fileList.RemoveAll(x => string.Compare(Utils.GetExtension(x.Fullname), extension, StringComparison.OrdinalIgnoreCase) == 0);
103+
}
104+
93105

94106
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
95107
private static extern bool FindNextFile(IntPtr hFindFile, out WIN32_FIND_DATAW lpFindFileData);
@@ -221,6 +233,7 @@ private List<Entry> ParallelFindNextFile(string path)
221233
}
222234

223235
if (findHandle != INVALID_HANDLE_VALUE) FindClose(findHandle);
236+
224237
return fileList.ToList();
225238
}
226239

QuickList/Application/MediaInfoProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ internal Task AddMediaInfo(List<Entry> entries)
7070

7171
percentage += step;
7272

73-
var extension = Path.GetExtension(entry.Fullname) ?? string.Empty;
73+
var extension = $".{Utils.GetExtension(entry.Fullname) ?? string.Empty}";
7474

7575
if (!_configuration.ForceShellMedia && _tagSharpFormats.Contains(extension))
7676
{

QuickList/Application/Utils.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,18 @@ internal static string ReadableSize(long size, string numberFormat = "0.##")
5757

5858
return FormattableString.Invariant($"{(readable / 1024).ToString(numberFormat, CultureInfo.InvariantCulture)}{suffix}");
5959
}
60+
61+
/// <summary>
62+
/// Return extension. Should be slightly faster than inbuild method
63+
/// </summary>
64+
/// <returns></returns>
65+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
66+
internal static string GetExtension(string filename)
67+
{
68+
var lastDot = filename.LastIndexOf(".", StringComparison.Ordinal);
69+
if (lastDot == -1)
70+
return null;
71+
return filename.Substring(lastDot + 1);
72+
}
6073
}
6174
}

QuickList/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ private static void Main(params string[] parameters)
6060
IniFile = @"c:\temp\out\testaudio.ini",
6161
ShowUi = true,
6262
ForceShellMedia = false,
63-
FileReaderParallelism = 1
63+
FileReaderParallelism = 1,
64+
ExcludedExtensions = new List<string> { "txt", "json", "xml", "dll", "pdb"}
6465
};
6566
#endif
6667
configuration.Validate();

0 commit comments

Comments
 (0)