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

This commit is contained in:
Holger Börchers 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 _outputDir;
private string _programFile; private string _programFile;
private string _publishDir; private string _publishDir;
private string _version;
[DisplayName("Program")] [DisplayName("Program")]
[Description("Path to the program file")] [Description("Path to the program file")]
@ -51,6 +52,14 @@ namespace KattekerCreator
set => SetPropertyIfNotDefault(ref _publishDir, value); 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) private static bool SetPropertyIfNotDefault<T>(ref T field, T value)
{ {
if (Equals(value, field)) return false; if (Equals(value, field)) return false;

View File

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

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Threading;
namespace KattekerCreator.Helper namespace KattekerCreator.Helper
{ {
@ -9,17 +10,17 @@ namespace KattekerCreator.Helper
public static void WriteInfoLine(string text) 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) 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; Console.ForegroundColor = color;
} }
public void WriteLine(string text) public static void WriteLine(string text)
{ {
Console.WriteLine(text); Console.WriteLine(text);
} }
public void Dispose() public void Dispose()
{ {
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (!disposing) return;
if (_defaultColor != null) Console.ForegroundColor = _defaultColor.Value; if (_defaultColor != null) Console.ForegroundColor = _defaultColor.Value;
} }
} }

View File

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

View File

@ -42,6 +42,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="NativeMethods.cs" />
<Compile Include="Wrapper.cs" /> <Compile Include="Wrapper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs"> <Compile Include="Properties\Resources.Designer.cs">

View File

@ -0,0 +1,30 @@
using System;
using System.Runtime.InteropServices;
namespace Katteker.Gui
{
/// <summary>
/// Native methods.
/// </summary>
public static class NativeMethods
{
/// <summary>
/// Release the capture
/// </summary>
[DllImport("User32.dll")]
public static extern bool ReleaseCapture();
/// <summary>
/// Send message
/// </summary>
[DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
/// <summary>
/// Set Process API aware
/// </summary>
[DllImport("user32.dll")]
public static extern bool SetProcessDPIAware();
}
}

View File

@ -1,7 +1,6 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms; using System.Windows.Forms;
using Katteker.Gui.Properties; using Katteker.Gui.Properties;
@ -24,7 +23,7 @@ namespace Katteker.Gui
Font = SystemFonts.MessageBoxFont; Font = SystemFonts.MessageBoxFont;
Application.EnableVisualStyles(); Application.EnableVisualStyles();
if (Environment.OSVersion.Version.Major >= 6) if (Environment.OSVersion.Version.Major >= 6)
SetProcessDPIAware(); NativeMethods.SetProcessDPIAware();
InitializeComponent(); InitializeComponent();
} }
@ -46,14 +45,6 @@ namespace Katteker.Gui
base.Dispose(disposing); base.Dispose(disposing);
} }
[DllImport("User32.dll")]
private static extern bool ReleaseCapture();
[DllImport("User32.dll")]
private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();
private void CloseBtn_Click(object sender, EventArgs e) private void CloseBtn_Click(object sender, EventArgs e)
{ {
Close(); Close();
@ -77,8 +68,8 @@ namespace Katteker.Gui
return; return;
} }
if (e.Button != MouseButtons.Left) return; if (e.Button != MouseButtons.Left) return;
ReleaseCapture(); NativeMethods.ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0); NativeMethods.SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
} }

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.props')" /> <Import Project="..\packages\MSTest.TestAdapter.1.3.0\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.0\build\net45\MSTest.TestAdapter.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -39,10 +39,10 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath> <HintPath>..\packages\MSTest.TestFramework.1.3.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference> </Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath> <HintPath>..\packages\MSTest.TestFramework.1.3.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
@ -51,9 +51,6 @@
<Compile Include="KattekerLibTest.cs" /> <Compile Include="KattekerLibTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="testdata\Example.exe"> <Content Include="testdata\Example.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@ -65,14 +62,17 @@
<Name>Katteker</Name> <Name>Katteker</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" /> <Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup> <PropertyGroup>
<ErrorText>Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}".</ErrorText> <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup> </PropertyGroup>
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.props'))" /> <Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.0\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.0\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.targets'))" /> <Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.0\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.0\build\net45\MSTest.TestAdapter.targets'))" />
</Target> </Target>
<Import Project="..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.targets')" /> <Import Project="..\packages\MSTest.TestAdapter.1.3.0\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.0\build\net45\MSTest.TestAdapter.targets')" />
</Project> </Project>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="MSTest.TestAdapter" version="1.2.0" targetFramework="net461" /> <package id="MSTest.TestAdapter" version="1.3.0" targetFramework="net461" />
<package id="MSTest.TestFramework" version="1.2.0" targetFramework="net461" /> <package id="MSTest.TestFramework" version="1.3.0" targetFramework="net461" />
</packages> </packages>

View File

@ -81,6 +81,10 @@ namespace Katteker
} }
} }
/// <summary>
/// Check for updates
/// </summary>
/// <returns></returns>
public async Task<IEnumerable<ReleaseEntry>> CheckForUpdateAsync() public async Task<IEnumerable<ReleaseEntry>> CheckForUpdateAsync()
{ {
_releases = Utility.IsWebUrl(_urlOrPath) ? await DownloadIndexAsync(_urlOrPath).ConfigureAwait(false) : GetFromFilesystem(_urlOrPath); _releases = Utility.IsWebUrl(_urlOrPath) ? await DownloadIndexAsync(_urlOrPath).ConfigureAwait(false) : GetFromFilesystem(_urlOrPath);