cleanup code, added version to commandline interface, updated MSTest nuget packages.

This commit is contained in:
2018-05-18 10:38:59 +02:00
parent cf4cc2cd93
commit 17e12093f8
10 changed files with 79 additions and 37 deletions

View File

@ -10,6 +10,7 @@ namespace KattekerCreator
private string _outputDir;
private string _programFile;
private string _publishDir;
private string _version;
[DisplayName("Program")]
[Description("Path to the program file")]
@ -51,6 +52,14 @@ namespace KattekerCreator
set => SetPropertyIfNotDefault(ref _publishDir, value);
}
[DisplayName("Version")]
[Description("Override version number of the application.")]
public string Version
{
get => _version;
set => SetPropertyIfNotDefault(ref _version, value);
}
private static bool SetPropertyIfNotDefault<T>(ref T field, T value)
{
if (Equals(value, field)) return false;

View File

@ -15,17 +15,17 @@ namespace KattekerCreator
private readonly string _description;
private readonly string _productName;
public AssemblyFileInfo(string fileName, string tempDir)
public AssemblyFileInfo(ApplicationArguments appArguments, string tempDir)
{
FileInfo = new FileInfo(fileName);
FileInfo = new FileInfo(appArguments.ProgramFile);
using (var resourceInfo = new ResourceInfo())
{
resourceInfo.Load(fileName);
resourceInfo.Load(appArguments.ProgramFile);
if (resourceInfo.ResourceTypes.All(x => x.ResourceType != Kernel32.ResourceTypes.RT_VERSION)) return;
var versionResource = (VersionResource) resourceInfo[Kernel32.ResourceTypes.RT_VERSION].First();
var stringFileInfo = ((StringFileInfo) versionResource[nameof(StringFileInfo)]).Strings
.FirstOrDefault().Value;
AssemblyIconPath = GetAssemblyIcon(fileName, tempDir);
AssemblyIconPath = GetAssemblyIcon(appArguments.ProgramFile, tempDir);
if (stringFileInfo.Strings.ContainsKey("CompanyName"))
_company = stringFileInfo.Strings["CompanyName"].StringValue.TrimEnd('\0');
if (stringFileInfo.Strings.ContainsKey("FileDescription"))
@ -35,14 +35,13 @@ namespace KattekerCreator
if (stringFileInfo.Strings.ContainsKey("ProductName"))
_productName = stringFileInfo.Strings["ProductName"].StringValue.TrimEnd('\0');
if (!stringFileInfo.Strings.ContainsKey("ProductVersion")) return;
AssemblyVersion =
GetSemanticVersion(stringFileInfo.Strings["ProductVersion"].StringValue.TrimEnd('\0'));
AssemblyVersion = appArguments.Version != null ? GetSemanticVersion(appArguments.Version) : GetSemanticVersion(stringFileInfo.Strings["ProductVersion"].StringValue.TrimEnd('\0'));
}
}
public string AssemblyIconPath { get; }
public SemVersion AssemblyVersion { get; private set; }
public SemVersion AssemblyVersion { get; }
public string Company => _company ?? string.Empty;

View File

@ -1,4 +1,5 @@
using System;
using System.Threading;
namespace KattekerCreator.Helper
{
@ -9,17 +10,17 @@ namespace KattekerCreator.Helper
public static void WriteInfoLine(string text)
{
using (var c = new ConsoleWithOtherColor())
using (new ConsoleWithOtherColor())
{
c.WriteLine($"{Info} [{DateTime.Now:G}] {text}");
ConsoleWithOtherColor.WriteLine($"{Info} [{DateTime.Now:G}] {text}");
}
}
public static void WriteErrorLine(string text)
{
using (var c = new ConsoleWithOtherColor(ConsoleColor.DarkRed))
using (new ConsoleWithOtherColor(ConsoleColor.DarkRed))
{
c.WriteLine($"{Error} [{DateTime.Now:G}] {text}");
ConsoleWithOtherColor.WriteLine($"{Error} [{DateTime.Now:G}] {text}");
}
}
}
@ -38,13 +39,20 @@ namespace KattekerCreator.Helper
Console.ForegroundColor = color;
}
public void WriteLine(string text)
public static void WriteLine(string text)
{
Console.WriteLine(text);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (!disposing) return;
if (_defaultColor != null) Console.ForegroundColor = _defaultColor.Value;
}
}

View File

@ -56,7 +56,7 @@ namespace KattekerCreator
//Modify AppStub
var appStubFile = ModifyAppStub();
//Acquire infos from Executable.
_assemblyFileInfo = new AssemblyFileInfo(_appArguments.ProgramFile, _tempDir);
_assemblyFileInfo = new AssemblyFileInfo(_appArguments, _tempDir);
var configFile = CreateConfigFile();
//Generate NSIS-Script