From c8e31248643484d8c346be369906bb76456fc769 Mon Sep 17 00:00:00 2001 From: Caelan Sayler Date: Fri, 8 Mar 2024 14:28:56 +0000 Subject: [PATCH] Minor changes to spelling, comments, code style --- .../Commands/WindowsPackCommandRunner.cs | 6 ++--- src/Velopack.Packaging.Windows/SetupBundle.cs | 20 ++++++++--------- .../Abstractions/ICommand.cs | 2 +- .../Abstractions/IConsole.cs | 5 +++++ .../Abstractions/IFancyConsole.cs | 4 +--- .../Abstractions/IPlatformOptions.cs | 2 +- src/Velopack/Internal/SimpleJson.cs | 2 +- src/Velopack/Internal/Utility.cs | 3 +-- src/Velopack/Sources/GitBase.cs | 4 ++-- src/Velopack/Sources/GithubSource.cs | 2 +- src/Velopack/Sources/GitlabSource.cs | 2 +- src/Velopack/Sources/IFileDownloader.cs | 2 +- src/Velopack/Sources/IUpdateSource.cs | 2 +- src/Velopack/Sources/SimpleFileSource.cs | 2 +- src/Velopack/VelopackRuntimeInfo.cs | 4 ++-- .../Divergic.Logging.Xunit.csproj | 4 ++-- .../WindowsPackTests.cs | 22 +++++++++---------- test/Velopack.Tests/Velopack.Tests.csproj | 4 ++-- 18 files changed, 47 insertions(+), 45 deletions(-) create mode 100644 src/Velopack.Packaging/Abstractions/IConsole.cs diff --git a/src/Velopack.Packaging.Windows/Commands/WindowsPackCommandRunner.cs b/src/Velopack.Packaging.Windows/Commands/WindowsPackCommandRunner.cs index 06708923..66f65dcf 100644 --- a/src/Velopack.Packaging.Windows/Commands/WindowsPackCommandRunner.cs +++ b/src/Velopack.Packaging.Windows/Commands/WindowsPackCommandRunner.cs @@ -135,13 +135,13 @@ public class WindowsPackCommandRunner : PackageBuilder protected override Task CreateSetupPackage(Action progress, string releasePkg, string packDir, string targetSetupExe) { - var bundledzp = new ZipPackage(releasePkg); + var bundledZip = new ZipPackage(releasePkg); Utility.Retry(() => File.Copy(HelperFile.SetupPath, targetSetupExe, true)); progress(10); if (VelopackRuntimeInfo.IsWindows) { - Rcedit.SetPEVersionBlockFromPackageInfo(targetSetupExe, bundledzp, Options.Icon); + Rcedit.SetPEVersionBlockFromPackageInfo(targetSetupExe, bundledZip, Options.Icon); } else { - Log.Warn("Unable to set Setup.exe icon (only supported on windows)"); + Log.Warn("Unable to set PE Version on Setup.exe (only supported on windows)"); } progress(25); Log.Debug($"Creating Setup bundle"); diff --git a/src/Velopack.Packaging.Windows/SetupBundle.cs b/src/Velopack.Packaging.Windows/SetupBundle.cs index fd39ed5f..eed496b8 100644 --- a/src/Velopack.Packaging.Windows/SetupBundle.cs +++ b/src/Velopack.Packaging.Windows/SetupBundle.cs @@ -21,16 +21,16 @@ public static class SetupBundle void FindBundleHeader() { - using (var memoryMappedFile = MemoryMappedFile.CreateFromFile(setupPath, FileMode.Open, null, 0, MemoryMappedFileAccess.Read)) - using (MemoryMappedViewAccessor accessor = memoryMappedFile.CreateViewAccessor(0, 0, MemoryMappedFileAccess.Read)) { - int position = BinaryUtils.SearchInFile(accessor, bundleSignature); - if (position == -1) { - throw new PlaceHolderNotFoundInAppHostException(bundleSignature); - } + using var memoryMappedFile = MemoryMappedFile.CreateFromFile(setupPath, FileMode.Open, null, 0, MemoryMappedFileAccess.Read); + using MemoryMappedViewAccessor accessor = memoryMappedFile.CreateViewAccessor(0, 0, MemoryMappedFileAccess.Read); - offset = accessor.ReadInt64(position - 16); - length = accessor.ReadInt64(position - 8); + int position = BinaryUtils.SearchInFile(accessor, bundleSignature); + if (position == -1) { + throw new PlaceHolderNotFoundInAppHostException(bundleSignature); } + + offset = accessor.ReadInt64(position - 16); + length = accessor.ReadInt64(position - 8); } Utility.Retry(FindBundleHeader); @@ -53,8 +53,8 @@ public static class SetupBundle bundleLength = pkgStream.Length; pkgStream.CopyTo(setupStream); } finally { - if (pkgStream != null) pkgStream.Dispose(); - if (setupStream != null) setupStream.Dispose(); + pkgStream?.Dispose(); + setupStream?.Dispose(); } byte[] placeholder = { diff --git a/src/Velopack.Packaging/Abstractions/ICommand.cs b/src/Velopack.Packaging/Abstractions/ICommand.cs index 3bef20ea..3ecc7877 100644 --- a/src/Velopack.Packaging/Abstractions/ICommand.cs +++ b/src/Velopack.Packaging/Abstractions/ICommand.cs @@ -1,4 +1,4 @@ -namespace Velopack.Packaging.Abstractions; +namespace Velopack.Packaging.Abstractions; public interface ICommand where TOpt : class { diff --git a/src/Velopack.Packaging/Abstractions/IConsole.cs b/src/Velopack.Packaging/Abstractions/IConsole.cs new file mode 100644 index 00000000..b2749626 --- /dev/null +++ b/src/Velopack.Packaging/Abstractions/IConsole.cs @@ -0,0 +1,5 @@ +namespace Velopack.Packaging.Abstractions; +public interface IConsole +{ + void WriteLine(string message = ""); +} diff --git a/src/Velopack.Packaging/Abstractions/IFancyConsole.cs b/src/Velopack.Packaging/Abstractions/IFancyConsole.cs index 16940341..c938aafc 100644 --- a/src/Velopack.Packaging/Abstractions/IFancyConsole.cs +++ b/src/Velopack.Packaging/Abstractions/IFancyConsole.cs @@ -1,12 +1,10 @@ namespace Velopack.Packaging.Abstractions; -public interface IFancyConsole +public interface IFancyConsole : IConsole { Task ExecuteProgressAsync(Func action); void WriteTable(string tableName, IEnumerable> rows, bool hasHeaderRow = true); Task PromptYesNo(string prompt, bool? defaultValue = null, TimeSpan? timeout = null); - - void WriteLine(string text = ""); } diff --git a/src/Velopack.Packaging/Abstractions/IPlatformOptions.cs b/src/Velopack.Packaging/Abstractions/IPlatformOptions.cs index cf1bc36f..6875bd58 100644 --- a/src/Velopack.Packaging/Abstractions/IPlatformOptions.cs +++ b/src/Velopack.Packaging/Abstractions/IPlatformOptions.cs @@ -1,4 +1,4 @@ -namespace Velopack.Packaging.Abstractions; +namespace Velopack.Packaging.Abstractions; public interface IPlatformOptions : IOutputOptions { diff --git a/src/Velopack/Internal/SimpleJson.cs b/src/Velopack/Internal/SimpleJson.cs index 9c461156..778457af 100644 --- a/src/Velopack/Internal/SimpleJson.cs +++ b/src/Velopack/Internal/SimpleJson.cs @@ -1,4 +1,4 @@ -using System; +using System; using NuGet.Versioning; #if NET5_0_OR_GREATER diff --git a/src/Velopack/Internal/Utility.cs b/src/Velopack/Internal/Utility.cs index 1a7af3bb..d3f89eb7 100644 --- a/src/Velopack/Internal/Utility.cs +++ b/src/Velopack/Internal/Utility.cs @@ -486,8 +486,7 @@ namespace Velopack public static bool IsHttpUrl(string urlOrPath) { - var uri = default(Uri); - if (!Uri.TryCreate(urlOrPath, UriKind.Absolute, out uri)) { + if (!Uri.TryCreate(urlOrPath, UriKind.Absolute, out Uri? uri)) { return false; } diff --git a/src/Velopack/Sources/GitBase.cs b/src/Velopack/Sources/GitBase.cs index 315dfd2e..f159204a 100644 --- a/src/Velopack/Sources/GitBase.cs +++ b/src/Velopack/Sources/GitBase.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -64,7 +64,7 @@ namespace Velopack.Sources public virtual async Task GetReleaseFeed(ILogger logger, string channel, Guid? stagingId = null, VelopackAsset? latestLocalRelease = null) { var releases = await GetReleases(Prerelease).ConfigureAwait(false); - if (releases == null || releases.Count() == 0) { + if (releases == null || releases.Length == 0) { logger.Warn($"No releases found at '{RepoUri}'."); return new VelopackAssetFeed(); } diff --git a/src/Velopack/Sources/GithubSource.cs b/src/Velopack/Sources/GithubSource.cs index af20b1ed..0c0224c5 100644 --- a/src/Velopack/Sources/GithubSource.cs +++ b/src/Velopack/Sources/GithubSource.cs @@ -18,7 +18,7 @@ namespace Velopack.Sources [JsonPropertyName("prerelease")] public bool Prerelease { get; set; } - /// The date which this release was published publically. + /// The date which this release was published publicly. [JsonPropertyName("published_at")] public DateTime? PublishedAt { get; set; } diff --git a/src/Velopack/Sources/GitlabSource.cs b/src/Velopack/Sources/GitlabSource.cs index 182638e8..1fa8af19 100644 --- a/src/Velopack/Sources/GitlabSource.cs +++ b/src/Velopack/Sources/GitlabSource.cs @@ -25,7 +25,7 @@ namespace Velopack.Sources public bool UpcomingRelease { get; set; } /// - /// The date which this release was published publically. + /// The date which this release was published publicly. /// [JsonPropertyName("released_at")] public DateTime? ReleasedAt { get; set; } diff --git a/src/Velopack/Sources/IFileDownloader.cs b/src/Velopack/Sources/IFileDownloader.cs index 4198a315..756a67ab 100644 --- a/src/Velopack/Sources/IFileDownloader.cs +++ b/src/Velopack/Sources/IFileDownloader.cs @@ -15,7 +15,7 @@ namespace Velopack.Sources /// The url which will be downloaded. /// /// The local path where the file will be stored - /// If a file exists at this path, it will be overritten. + /// If a file exists at this path, it will be overwritten. /// /// A delegate for reporting download progress, with expected values from 0-100. /// diff --git a/src/Velopack/Sources/IUpdateSource.cs b/src/Velopack/Sources/IUpdateSource.cs index 9c1674c2..77ddd21c 100644 --- a/src/Velopack/Sources/IUpdateSource.cs +++ b/src/Velopack/Sources/IUpdateSource.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; diff --git a/src/Velopack/Sources/SimpleFileSource.cs b/src/Velopack/Sources/SimpleFileSource.cs index 833b50ab..14ddaf8d 100644 --- a/src/Velopack/Sources/SimpleFileSource.cs +++ b/src/Velopack/Sources/SimpleFileSource.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Threading; diff --git a/src/Velopack/VelopackRuntimeInfo.cs b/src/Velopack/VelopackRuntimeInfo.cs index 8ff55fe2..99d65aef 100644 --- a/src/Velopack/VelopackRuntimeInfo.cs +++ b/src/Velopack/VelopackRuntimeInfo.cs @@ -142,7 +142,7 @@ namespace Velopack VelopackDisplayVersion = VelopackNugetVersion.ToNormalizedString() + (VelopackNugetVersion.IsPrerelease ? " (prerelease)" : ""); #pragma warning restore CS0612 - // get real cpu architecture, even when virtualised by Wow64 + // get real cpu architecture, even when virtualized by Wow64 #if NETFRAMEWORK CheckArchitectureWindows(); #else @@ -216,7 +216,7 @@ namespace Velopack SystemOs = RuntimeOs.Windows; // find the actual OS architecture. We can't rely on the framework alone for this on Windows - // because Wow64 virtualisation is good enough to trick us to believing we're running natively + // because Wow64 virtualization is good enough to trick us to believing we're running natively // in some cases unless we use functions that are not virtualized (such as IsWow64Process2) try { diff --git a/test/Divergic.Logging.Xunit/Divergic.Logging.Xunit.csproj b/test/Divergic.Logging.Xunit/Divergic.Logging.Xunit.csproj index a02c6c46..69756f88 100644 --- a/test/Divergic.Logging.Xunit/Divergic.Logging.Xunit.csproj +++ b/test/Divergic.Logging.Xunit/Divergic.Logging.Xunit.csproj @@ -10,8 +10,8 @@ - - + + diff --git a/test/Velopack.Packaging.Tests/WindowsPackTests.cs b/test/Velopack.Packaging.Tests/WindowsPackTests.cs index b8b49279..eb200b35 100644 --- a/test/Velopack.Packaging.Tests/WindowsPackTests.cs +++ b/test/Velopack.Packaging.Tests/WindowsPackTests.cs @@ -346,7 +346,7 @@ public class WindowsPackTests new DeltaPatchCommandRunner(logger, new BasicConsole(logger, new DefaultPromptValueFactory(false))).Run(new DeltaPatchOptions { BasePackage = Path.Combine(releaseDir, $"{id}-1.0.0-full.nupkg"), OutputFile = output, - PatchFiles = new[] { new FileInfo(deltaPath), new FileInfo(deltav3) }, + PatchFiles = [new FileInfo(deltaPath), new FileInfo(deltav3)], }).GetAwaiterResult(); // are the packages the same? @@ -373,7 +373,7 @@ public class WindowsPackTests // install app var setupPath1 = Path.Combine(releaseDir, $"{id}-win-Setup.exe"); - RunNoCoverage(setupPath1, new string[] { "--nocolor", "--installto", installDir }, + RunNoCoverage(setupPath1, ["--nocolor", "--installto", installDir], Environment.GetFolderPath(Environment.SpecialFolder.Desktop), logger); var argsPath = Path.Combine(installDir, "args.txt"); @@ -388,8 +388,8 @@ public class WindowsPackTests PackTestApp(id, "2.0.0", "version 2 test", releaseDir, logger); // install v2 - RunCoveredDotnet(appPath, new string[] { "download", releaseDir }, installDir, logger); - RunCoveredDotnet(appPath, new string[] { "apply", releaseDir }, installDir, logger, exitCode: null); + RunCoveredDotnet(appPath, ["download", releaseDir], installDir, logger); + RunCoveredDotnet(appPath, ["apply", releaseDir], installDir, logger, exitCode: null); Thread.Sleep(2000); @@ -404,7 +404,7 @@ public class WindowsPackTests Assert.Equal("2.0.0,test,args !!", File.ReadAllText(restartedPath).Trim()); var updatePath = Path.Combine(installDir, "Update.exe"); - RunNoCoverage(updatePath, new string[] { "--nocolor", "--silent", "--uninstall" }, Environment.CurrentDirectory, logger); + RunNoCoverage(updatePath, ["--nocolor", "--silent", "--uninstall"], Environment.CurrentDirectory, logger); } [SkippableFact] @@ -550,7 +550,7 @@ public class WindowsPackTests //private string RunCoveredRust(string binName, string[] args, string workingDir, ILogger logger, int? exitCode = 0) //{ - // var outputfile = GetPath($"coverage.runrust.{RandomString(8)}.xml"); + // var outputFile = GetPath($"coverage.runrust.{RandomString(8)}.xml"); // var manifestFile = GetPath("..", "src", "Rust", "Cargo.toml"); // var psi = new ProcessStartInfo("cargo"); @@ -565,7 +565,7 @@ public class WindowsPackTests // psi.ArgumentList.Add("--manifest-path"); // psi.ArgumentList.Add(manifestFile); // psi.ArgumentList.Add("--output"); - // psi.ArgumentList.Add(outputfile); + // psi.ArgumentList.Add(outputFile); // psi.ArgumentList.Add("--bin"); // psi.ArgumentList.Add(binName); // psi.ArgumentList.Add("--"); @@ -579,7 +579,7 @@ public class WindowsPackTests //logger.Info($"TEST: Running {psi.FileName} {psi.ArgumentList.Aggregate((a, b) => $"{a} {b}")}"); //using var p = Process.Start(psi); - var outputfile = PathHelper.GetTestRootPath($"run.{RandomString(8)}.log"); + var outputFile = PathHelper.GetTestRootPath($"run.{RandomString(8)}.log"); try { // this is a huge hack, but WaitForProcess hangs in the test runner when the output is redirected @@ -591,7 +591,7 @@ public class WindowsPackTests var fix = new ProcessStartInfo("cmd.exe"); fix.CreateNoWindow = true; fix.WorkingDirectory = psi.WorkingDirectory; - fix.Arguments = $"/c \"{psi.FileName}\" {debug} > {outputfile} 2>&1"; + fix.Arguments = $"/c \"{psi.FileName}\" {debug} > {outputFile} 2>&1"; Stopwatch sw = new Stopwatch(); sw.Start(); @@ -609,7 +609,7 @@ public class WindowsPackTests logger.Info($"TEST: Process exited with code {p.ExitCode} in {elapsed.TotalSeconds}s"); using var fs = Utility.Retry(() => { - return File.Open(outputfile, FileMode.Open, FileAccess.ReadWrite, FileShare.None); + return File.Open(outputFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None); }, 10, 1000, logger); using var reader = new StreamReader(fs); @@ -633,7 +633,7 @@ public class WindowsPackTests ).Trim(); } finally { try { - File.Delete(outputfile); + File.Delete(outputFile); } catch { } } } diff --git a/test/Velopack.Tests/Velopack.Tests.csproj b/test/Velopack.Tests/Velopack.Tests.csproj index 14a858cb..087c1d32 100644 --- a/test/Velopack.Tests/Velopack.Tests.csproj +++ b/test/Velopack.Tests/Velopack.Tests.csproj @@ -1,4 +1,4 @@ - + @@ -16,7 +16,7 @@ - +