Added Prism to example, Added ability to filter files and minor bugfixes
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
|
||||
@ -11,6 +12,7 @@ namespace KattekerCreator
|
||||
private string _programFile;
|
||||
private string _publishDir;
|
||||
private string _version;
|
||||
private string _filterAsString;
|
||||
|
||||
[DisplayName("Program")]
|
||||
[Description("Path to the program file")]
|
||||
@ -60,6 +62,14 @@ namespace KattekerCreator
|
||||
set => SetPropertyIfNotDefault(ref _version, value);
|
||||
}
|
||||
|
||||
[DisplayName("Filter")]
|
||||
[Description("Filter parameter. Use minimatch pattern.")]
|
||||
public string FilterAsString
|
||||
{
|
||||
get => _filterAsString;
|
||||
set => SetPropertyIfNotDefault(ref _filterAsString, value);
|
||||
}
|
||||
|
||||
private static bool SetPropertyIfNotDefault<T>(ref T field, T value)
|
||||
{
|
||||
if (Equals(value, field)) return false;
|
||||
@ -67,5 +77,7 @@ namespace KattekerCreator
|
||||
field = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
public string[] Filter => string.IsNullOrWhiteSpace(FilterAsString) ? new string[0] : FilterAsString.Split(';');
|
||||
}
|
||||
}
|
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";
|
||||
|
||||
|
@ -55,6 +55,7 @@
|
||||
<Compile Include="IconExtractor\IconExtractor.cs" />
|
||||
<Compile Include="IconExtractor\IconUtil.cs" />
|
||||
<Compile Include="IconExtractor\NativeMethods.cs" />
|
||||
<Compile Include="Helper\Minimatcher.cs" />
|
||||
<Compile Include="PathFragments.cs" />
|
||||
<Compile Include="PhysicalFile.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
|
@ -183,7 +183,7 @@ namespace KattekerCreator
|
||||
};
|
||||
var path = Path.GetDirectoryName(_appArguments.ProgramFile) ?? string.Empty;
|
||||
setupTmpl.Files.AddRange(additionalFiles);
|
||||
var files = Utils.EnumerateFiles(_appArguments.ProgramFile).ToArray();
|
||||
var files = Utils.EnumerateFiles(path, _appArguments.Filter).ToArray();
|
||||
setupTmpl.InstallSize = (long) Math.Floor(files.Sum(x => x.Length) / 1024f);
|
||||
setupTmpl.Files.AddRange(files.Select(x => new PhysicalFile(x.FullName, x.FullName.Replace(path, $"app-{_assemblyFileInfo.AssemblyVersion}"))));
|
||||
var transformText = setupTmpl.TransformText();
|
||||
|
Reference in New Issue
Block a user