From 17e12093f88034d37675bbdfbec12116e9dc1366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20B=C3=B6rchers?= Date: Fri, 18 May 2018 10:38:59 +0200 Subject: [PATCH] cleanup code, added version to commandline interface, updated MSTest nuget packages. --- Creator/ApplicationArguments.cs | 9 +++++++++ Creator/AssemblyFileInfo.cs | 13 ++++++------- Creator/Helper/Log.cs | 18 +++++++++++++----- Creator/Program.cs | 2 +- Katteker.Gui/Katteker.Gui.csproj | 1 + Katteker.Gui/NativeMethods.cs | 30 ++++++++++++++++++++++++++++++ Katteker.Gui/UpdateWindow.cs | 15 +++------------ Katteker.Test/Katteker.Test.csproj | 20 ++++++++++---------- Katteker.Test/packages.config | 4 ++-- Katteker/UpdateManager.cs | 4 ++++ 10 files changed, 79 insertions(+), 37 deletions(-) create mode 100644 Katteker.Gui/NativeMethods.cs diff --git a/Creator/ApplicationArguments.cs b/Creator/ApplicationArguments.cs index 8c26902..eec0663 100644 --- a/Creator/ApplicationArguments.cs +++ b/Creator/ApplicationArguments.cs @@ -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(ref T field, T value) { if (Equals(value, field)) return false; diff --git a/Creator/AssemblyFileInfo.cs b/Creator/AssemblyFileInfo.cs index 67488f4..9c826e7 100644 --- a/Creator/AssemblyFileInfo.cs +++ b/Creator/AssemblyFileInfo.cs @@ -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; diff --git a/Creator/Helper/Log.cs b/Creator/Helper/Log.cs index 07647e4..1c253ac 100644 --- a/Creator/Helper/Log.cs +++ b/Creator/Helper/Log.cs @@ -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; } } diff --git a/Creator/Program.cs b/Creator/Program.cs index 7fa248d..a6e36a2 100644 --- a/Creator/Program.cs +++ b/Creator/Program.cs @@ -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 diff --git a/Katteker.Gui/Katteker.Gui.csproj b/Katteker.Gui/Katteker.Gui.csproj index a4c1fe1..6e9b001 100644 --- a/Katteker.Gui/Katteker.Gui.csproj +++ b/Katteker.Gui/Katteker.Gui.csproj @@ -42,6 +42,7 @@ + diff --git a/Katteker.Gui/NativeMethods.cs b/Katteker.Gui/NativeMethods.cs new file mode 100644 index 0000000..b4d395f --- /dev/null +++ b/Katteker.Gui/NativeMethods.cs @@ -0,0 +1,30 @@ +using System; +using System.Runtime.InteropServices; + +namespace Katteker.Gui +{ + /// + /// Native methods. + /// + public static class NativeMethods + { + /// + /// Release the capture + /// + [DllImport("User32.dll")] + public static extern bool ReleaseCapture(); + + /// + /// Send message + /// + [DllImport("User32.dll")] + public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); + + /// + /// Set Process API aware + /// + [DllImport("user32.dll")] + public static extern bool SetProcessDPIAware(); + + } +} \ No newline at end of file diff --git a/Katteker.Gui/UpdateWindow.cs b/Katteker.Gui/UpdateWindow.cs index d7087fc..1c03690 100644 --- a/Katteker.Gui/UpdateWindow.cs +++ b/Katteker.Gui/UpdateWindow.cs @@ -1,7 +1,6 @@ using System; using System.Drawing; using System.IO; -using System.Runtime.InteropServices; using System.Windows.Forms; using Katteker.Gui.Properties; @@ -24,7 +23,7 @@ namespace Katteker.Gui Font = SystemFonts.MessageBoxFont; Application.EnableVisualStyles(); if (Environment.OSVersion.Version.Major >= 6) - SetProcessDPIAware(); + NativeMethods.SetProcessDPIAware(); InitializeComponent(); } @@ -46,14 +45,6 @@ namespace Katteker.Gui 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) { Close(); @@ -77,8 +68,8 @@ namespace Katteker.Gui return; } if (e.Button != MouseButtons.Left) return; - ReleaseCapture(); - SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0); + NativeMethods.ReleaseCapture(); + NativeMethods.SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0); } diff --git a/Katteker.Test/Katteker.Test.csproj b/Katteker.Test/Katteker.Test.csproj index 8dea54e..09478c9 100644 --- a/Katteker.Test/Katteker.Test.csproj +++ b/Katteker.Test/Katteker.Test.csproj @@ -1,6 +1,6 @@  - + Debug AnyCPU @@ -39,10 +39,10 @@ - ..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + ..\packages\MSTest.TestFramework.1.3.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll - ..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + ..\packages\MSTest.TestFramework.1.3.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll @@ -51,9 +51,6 @@ - - - PreserveNewest @@ -65,14 +62,17 @@ Katteker + + + - 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}". + 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}. - - + + - + \ No newline at end of file diff --git a/Katteker.Test/packages.config b/Katteker.Test/packages.config index cf2d094..6b79fc9 100644 --- a/Katteker.Test/packages.config +++ b/Katteker.Test/packages.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file diff --git a/Katteker/UpdateManager.cs b/Katteker/UpdateManager.cs index a4961a9..18d2963 100644 --- a/Katteker/UpdateManager.cs +++ b/Katteker/UpdateManager.cs @@ -81,6 +81,10 @@ namespace Katteker } } + /// + /// Check for updates + /// + /// public async Task> CheckForUpdateAsync() { _releases = Utility.IsWebUrl(_urlOrPath) ? await DownloadIndexAsync(_urlOrPath).ConfigureAwait(false) : GetFromFilesystem(_urlOrPath);