Added Prism to example, Added ability to filter files and minor bugfixes
This commit is contained in:
1042
Creator/Helper/Minimatcher.cs
Normal file
1042
Creator/Helper/Minimatcher.cs
Normal file
File diff suppressed because it is too large
Load Diff
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Minimatch;
|
||||
using Vestris.ResourceLib;
|
||||
|
||||
namespace KattekerCreator.Helper
|
||||
@ -73,25 +74,33 @@ namespace KattekerCreator.Helper
|
||||
#endif
|
||||
}
|
||||
|
||||
public static IEnumerable<FileInfo> EnumerateFiles(string programFile, IEnumerable<string> userdefinedFileExclusions = null)
|
||||
public static IList<FileInfo> EnumerateFiles(string path, IEnumerable<string> userdefinedFileExclusions = null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(programFile)) return null;
|
||||
var directoryName = Path.GetDirectoryName(programFile);
|
||||
if (directoryName == null) return null;
|
||||
var files = new DirectoryInfo(directoryName).EnumerateFiles("*.*", SearchOption.AllDirectories);
|
||||
var filter = FileExclusions(userdefinedFileExclusions).ToArray();
|
||||
return files.Where(x => !filter.Any(y => x.Name.EndsWith(y, StringComparison.Ordinal)));
|
||||
if (string.IsNullOrWhiteSpace(path)) throw new ArgumentNullException(nameof(path));
|
||||
var result = new DirectoryInfo(path).EnumerateFiles("*.*", SearchOption.AllDirectories).ToList();
|
||||
var minimatchOptions = new Options {AllowWindowsPaths = true};
|
||||
foreach (var pattern in FileExclusions(userdefinedFileExclusions))
|
||||
{
|
||||
var matcher = new Minimatcher(pattern, minimatchOptions);
|
||||
for (var index = result.Count - 1; index >= 0; index--)
|
||||
{
|
||||
if (matcher.IsMatch(result[index].Name))
|
||||
{
|
||||
result.Remove(result[index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static IEnumerable<string> FileExclusions(IEnumerable<string> userdefinedfileExclusions = null)
|
||||
{
|
||||
yield return ".pdb";
|
||||
yield return ".tmp";
|
||||
yield return ".obj";
|
||||
yield return ".pch";
|
||||
yield return ".vshost.exe";
|
||||
yield return ".vshost.exe.config";
|
||||
yield return ".vshost.exe.manifest";
|
||||
yield return "*.pdb";
|
||||
yield return "*.tmp";
|
||||
yield return "*.obj";
|
||||
yield return "*.pch";
|
||||
yield return "*.vshost.exe*";
|
||||
yield return "squirrelHelperInfo.json";
|
||||
yield return "Katteker.config";
|
||||
|
||||
|
Reference in New Issue
Block a user