Compare commits

..

No commits in common. "e68f256d801e15e3472568e57db04e35215bdea7" and "3da9846ae3cd75076efa366641131c8cabdca282" have entirely different histories.

15 changed files with 54 additions and 93 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7"/>
</startup> </startup>
<runtime> <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

View File

@ -10,7 +10,6 @@ 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")]
@ -21,11 +20,11 @@ namespace KattekerCreator
} }
[DisplayName("Changelog")] [DisplayName("Changelog")]
[Description("Path of the changelog file")] [Description("Filename of the changelog file")]
public string ChangeLog public string ChangeLog
{ {
get => _changeLog; get => _changeLog;
set => SetPropertyIfNotDefault(ref _changeLog, Path.GetFullPath(value)); set => SetPropertyIfNotDefault(ref _changeLog, value);
} }
[DisplayName("Channel")] [DisplayName("Channel")]
@ -52,14 +51,6 @@ 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

@ -2,6 +2,7 @@
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Katteker;
using Semver; using Semver;
using TsudaKageyu; using TsudaKageyu;
using Vestris.ResourceLib; using Vestris.ResourceLib;
@ -15,17 +16,17 @@ namespace KattekerCreator
private readonly string _description; private readonly string _description;
private readonly string _productName; private readonly string _productName;
public AssemblyFileInfo(ApplicationArguments appArguments, string tempDir) public AssemblyFileInfo(string fileName, string tempDir)
{ {
FileInfo = new FileInfo(appArguments.ProgramFile); FileInfo = new FileInfo(fileName);
using (var resourceInfo = new ResourceInfo()) using (var resourceInfo = new ResourceInfo())
{ {
resourceInfo.Load(appArguments.ProgramFile); resourceInfo.Load(fileName);
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(appArguments.ProgramFile, tempDir); AssemblyIconPath = GetAssemblyIcon(fileName, 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,13 +36,14 @@ 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 = appArguments.Version != null ? GetSemanticVersion(appArguments.Version) : GetSemanticVersion(stringFileInfo.Strings["ProductVersion"].StringValue.TrimEnd('\0')); AssemblyVersion =
GetSemanticVersion(stringFileInfo.Strings["ProductVersion"].StringValue.TrimEnd('\0'));
} }
} }
public string AssemblyIconPath { get; } public string AssemblyIconPath { get; }
public SemVersion AssemblyVersion { get; } public SemVersion AssemblyVersion { get; private set; }
public string Company => _company ?? string.Empty; public string Company => _company ?? string.Empty;

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Threading;
namespace KattekerCreator.Helper namespace KattekerCreator.Helper
{ {
@ -10,17 +9,17 @@ namespace KattekerCreator.Helper
public static void WriteInfoLine(string text) public static void WriteInfoLine(string text)
{ {
using (new ConsoleWithOtherColor()) using (var c = new ConsoleWithOtherColor())
{ {
ConsoleWithOtherColor.WriteLine($"{Info} [{DateTime.Now:G}] {text}"); c.WriteLine($"{Info} [{DateTime.Now:G}] {text}");
} }
} }
public static void WriteErrorLine(string text) public static void WriteErrorLine(string text)
{ {
using (new ConsoleWithOtherColor(ConsoleColor.DarkRed)) using (var c = new ConsoleWithOtherColor(ConsoleColor.DarkRed))
{ {
ConsoleWithOtherColor.WriteLine($"{Error} [{DateTime.Now:G}] {text}"); c.WriteLine($"{Error} [{DateTime.Now:G}] {text}");
} }
} }
} }
@ -39,20 +38,13 @@ namespace KattekerCreator.Helper
Console.ForegroundColor = color; Console.ForegroundColor = color;
} }
public static void WriteLine(string text) public 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

@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>KattekerCreator</RootNamespace> <RootNamespace>KattekerCreator</RootNamespace>
<AssemblyName>KattekerCreator</AssemblyName> <AssemblyName>KattekerCreator</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion> <TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir> <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages> <RestorePackages>true</RestorePackages>

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, _tempDir); _assemblyFileInfo = new AssemblyFileInfo(_appArguments.ProgramFile, _tempDir);
var configFile = CreateConfigFile(); var configFile = CreateConfigFile();
//Generate NSIS-Script //Generate NSIS-Script
@ -109,10 +109,9 @@ namespace KattekerCreator
if (!Directory.Exists(_appArguments.OutputDir)) Directory.CreateDirectory(_appArguments.OutputDir); if (!Directory.Exists(_appArguments.OutputDir)) Directory.CreateDirectory(_appArguments.OutputDir);
if (!string.IsNullOrEmpty(_appArguments.ChangeLog)) if (!string.IsNullOrEmpty(_appArguments.ChangeLog))
{ {
var changeLogFilename = Path.GetFileName(_appArguments.ChangeLog); var changeLogPath = Path.Combine(Path.GetDirectoryName(_appArguments.ProgramFile), _appArguments.ChangeLog);
if (!File.Exists(changeLogPath)) throw new FileNotFoundException(changeLogPath);
if (!File.Exists(_appArguments.ChangeLog)) throw new FileNotFoundException(_appArguments.ChangeLog); File.Copy(changeLogPath, Path.Combine(_appArguments.OutputDir, _appArguments.ChangeLog), true);
File.Copy(_appArguments.ChangeLog, Path.Combine(_appArguments.OutputDir, changeLogFilename), true);
} }
File.Copy(setupFilePath, Path.Combine(_appArguments.OutputDir, setupFile), true); File.Copy(setupFilePath, Path.Combine(_appArguments.OutputDir, setupFile), true);
} }
@ -146,7 +145,7 @@ namespace KattekerCreator
var kattekerConfig = new KattekerConfig var kattekerConfig = new KattekerConfig
{ {
Publish = _appArguments.PublishDir ?? _appArguments.OutputDir, Publish = _appArguments.PublishDir ?? _appArguments.OutputDir,
Changelog = Path.GetFileName(_appArguments.ChangeLog) Changelog = _appArguments.ChangeLog
}; };
kattekerConfig.WriteToFile(pathToFile); kattekerConfig.WriteToFile(pathToFile);
return pathToFile; return pathToFile;

View File

@ -42,7 +42,6 @@
<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

@ -1,30 +0,0 @@
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,6 +1,7 @@
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;
@ -23,7 +24,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)
NativeMethods.SetProcessDPIAware(); SetProcessDPIAware();
InitializeComponent(); InitializeComponent();
} }
@ -45,6 +46,14 @@ 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();
@ -68,8 +77,8 @@ namespace Katteker.Gui
return; return;
} }
if (e.Button != MouseButtons.Left) return; if (e.Button != MouseButtons.Left) return;
NativeMethods.ReleaseCapture(); ReleaseCapture();
NativeMethods.SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0); 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.3.0\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.0\build\net45\MSTest.TestAdapter.props')" /> <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')" />
<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.3.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath> <HintPath>..\packages\MSTest.TestFramework.1.2.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.3.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath> <HintPath>..\packages\MSTest.TestFramework.1.2.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,6 +51,9 @@
<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>
@ -62,17 +65,14 @@
<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>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> <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>
</PropertyGroup> </PropertyGroup>
<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.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.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.0\build\net45\MSTest.TestAdapter.targets'))" /> <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'))" />
</Target> </Target>
<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')" /> <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')" />
</Project> </Project>

View File

@ -15,7 +15,7 @@ namespace Katteker.Test
public void Sha1ChecksumOfFile() public void Sha1ChecksumOfFile()
{ {
var actual = Utility.ComputeFileHash(ExampleFile); var actual = Utility.ComputeFileHash(ExampleFile);
const string expected = "maFpV7FK3EtnU2G5+q2nZ1E3YKY="; const string expected = "0zgDmFuotnldZIyADoWrpiSDUx4=";
Assert.AreEqual(expected, actual); Assert.AreEqual(expected, actual);
} }

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.3.0" targetFramework="net461" /> <package id="MSTest.TestAdapter" version="1.2.0" targetFramework="net461" />
<package id="MSTest.TestFramework" version="1.3.0" targetFramework="net461" /> <package id="MSTest.TestFramework" version="1.2.0" targetFramework="net461" />
</packages> </packages>

View File

@ -81,10 +81,6 @@ 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);

View File

@ -30,18 +30,21 @@ namespace Katteker
/// <summary> /// <summary>
/// Compute file hash with SHA1. /// Compute file hash with SHA1.
/// If the file is greater than 5 MB, the hash will only computed with the first 5 MB.
/// </summary> /// </summary>
/// <param name="filename"></param> /// <param name="filename"></param>
/// <returns>Returns the hash as base64 string</returns> /// <returns></returns>
internal static string ComputeFileHash(string filename) internal static string ComputeFileHash(string filename)
{ {
string sha1; string sha1;
var fileInfo = new FileInfo(filename); var fileInfo = new FileInfo(filename);
using (var sha1Managed = new SHA1Managed())
using (var fileStream = fileInfo.OpenRead()) using (var fileStream = fileInfo.OpenRead())
{ {
sha1 = Convert.ToBase64String(sha1Managed.ComputeHash(fileStream)); var buffer = new byte[5242880];
fileStream.Read(buffer, 0, buffer.Length);
var sha1Managed = new SHA1Managed();
sha1 = Convert.ToBase64String(sha1Managed.ComputeHash(buffer));
} }
return sha1; return sha1;
} }

View File

@ -1,4 +1,4 @@
Katteker SquirrelKiller (aka Wombat)
============= =============
Ziele: Ziele: