From cf4cc2cd93ba4533306846e69270d05603cc925b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20B=C3=B6rchers?= Date: Fri, 18 May 2018 08:58:12 +0200 Subject: [PATCH] filehash over the whole file. --- Creator/App.config | 2 +- Creator/ApplicationArguments.cs | 4 ++-- Creator/AssemblyFileInfo.cs | 1 - Creator/KattekerCreator.csproj | 2 +- Creator/Program.cs | 9 +++++---- Katteker.Test/KattekerLibTest.cs | 2 +- Katteker/Utility.cs | 9 +++------ 7 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Creator/App.config b/Creator/App.config index a28c49f..ba6b45f 100644 --- a/Creator/App.config +++ b/Creator/App.config @@ -1,7 +1,7 @@ - + diff --git a/Creator/ApplicationArguments.cs b/Creator/ApplicationArguments.cs index fac204d..8c26902 100644 --- a/Creator/ApplicationArguments.cs +++ b/Creator/ApplicationArguments.cs @@ -20,11 +20,11 @@ namespace KattekerCreator } [DisplayName("Changelog")] - [Description("Filename of the changelog file")] + [Description("Path of the changelog file")] public string ChangeLog { get => _changeLog; - set => SetPropertyIfNotDefault(ref _changeLog, value); + set => SetPropertyIfNotDefault(ref _changeLog, Path.GetFullPath(value)); } [DisplayName("Channel")] diff --git a/Creator/AssemblyFileInfo.cs b/Creator/AssemblyFileInfo.cs index 011f104..67488f4 100644 --- a/Creator/AssemblyFileInfo.cs +++ b/Creator/AssemblyFileInfo.cs @@ -2,7 +2,6 @@ using System.Drawing; using System.IO; using System.Linq; -using Katteker; using Semver; using TsudaKageyu; using Vestris.ResourceLib; diff --git a/Creator/KattekerCreator.csproj b/Creator/KattekerCreator.csproj index d9e03e2..e300511 100644 --- a/Creator/KattekerCreator.csproj +++ b/Creator/KattekerCreator.csproj @@ -9,7 +9,7 @@ Properties KattekerCreator KattekerCreator - v4.7 + v4.6.2 512 ..\ true diff --git a/Creator/Program.cs b/Creator/Program.cs index 1596123..7fa248d 100644 --- a/Creator/Program.cs +++ b/Creator/Program.cs @@ -109,9 +109,10 @@ namespace KattekerCreator if (!Directory.Exists(_appArguments.OutputDir)) Directory.CreateDirectory(_appArguments.OutputDir); if (!string.IsNullOrEmpty(_appArguments.ChangeLog)) { - var changeLogPath = Path.Combine(Path.GetDirectoryName(_appArguments.ProgramFile), _appArguments.ChangeLog); - if (!File.Exists(changeLogPath)) throw new FileNotFoundException(changeLogPath); - File.Copy(changeLogPath, Path.Combine(_appArguments.OutputDir, _appArguments.ChangeLog), true); + var changeLogFilename = Path.GetFileName(_appArguments.ChangeLog); + + if (!File.Exists(_appArguments.ChangeLog)) throw new FileNotFoundException(_appArguments.ChangeLog); + File.Copy(_appArguments.ChangeLog, Path.Combine(_appArguments.OutputDir, changeLogFilename), true); } File.Copy(setupFilePath, Path.Combine(_appArguments.OutputDir, setupFile), true); } @@ -145,7 +146,7 @@ namespace KattekerCreator var kattekerConfig = new KattekerConfig { Publish = _appArguments.PublishDir ?? _appArguments.OutputDir, - Changelog = _appArguments.ChangeLog + Changelog = Path.GetFileName(_appArguments.ChangeLog) }; kattekerConfig.WriteToFile(pathToFile); return pathToFile; diff --git a/Katteker.Test/KattekerLibTest.cs b/Katteker.Test/KattekerLibTest.cs index 18775a7..fe6caa9 100644 --- a/Katteker.Test/KattekerLibTest.cs +++ b/Katteker.Test/KattekerLibTest.cs @@ -15,7 +15,7 @@ namespace Katteker.Test public void Sha1ChecksumOfFile() { var actual = Utility.ComputeFileHash(ExampleFile); - const string expected = "0zgDmFuotnldZIyADoWrpiSDUx4="; + const string expected = "maFpV7FK3EtnU2G5+q2nZ1E3YKY="; Assert.AreEqual(expected, actual); } diff --git a/Katteker/Utility.cs b/Katteker/Utility.cs index 29ffbaf..1b8f16a 100644 --- a/Katteker/Utility.cs +++ b/Katteker/Utility.cs @@ -30,21 +30,18 @@ namespace Katteker /// /// Compute file hash with SHA1. - /// If the file is greater than 5 MB, the hash will only computed with the first 5 MB. /// /// - /// + /// Returns the hash as base64 string internal static string ComputeFileHash(string filename) { string sha1; var fileInfo = new FileInfo(filename); + using (var sha1Managed = new SHA1Managed()) using (var fileStream = fileInfo.OpenRead()) { - var buffer = new byte[5242880]; - fileStream.Read(buffer, 0, buffer.Length); - var sha1Managed = new SHA1Managed(); - sha1 = Convert.ToBase64String(sha1Managed.ComputeHash(buffer)); + sha1 = Convert.ToBase64String(sha1Managed.ComputeHash(fileStream)); } return sha1; }