Minor changes to spelling, comments, code style

This commit is contained in:
Caelan Sayler
2024-03-08 14:28:56 +00:00
parent 55fbec5ac2
commit c8e3124864
18 changed files with 47 additions and 45 deletions

View File

@@ -135,13 +135,13 @@ public class WindowsPackCommandRunner : PackageBuilder<WindowsPackOptions>
protected override Task CreateSetupPackage(Action<int> progress, string releasePkg, string packDir, string targetSetupExe) protected override Task CreateSetupPackage(Action<int> 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)); Utility.Retry(() => File.Copy(HelperFile.SetupPath, targetSetupExe, true));
progress(10); progress(10);
if (VelopackRuntimeInfo.IsWindows) { if (VelopackRuntimeInfo.IsWindows) {
Rcedit.SetPEVersionBlockFromPackageInfo(targetSetupExe, bundledzp, Options.Icon); Rcedit.SetPEVersionBlockFromPackageInfo(targetSetupExe, bundledZip, Options.Icon);
} else { } 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); progress(25);
Log.Debug($"Creating Setup bundle"); Log.Debug($"Creating Setup bundle");

View File

@@ -21,16 +21,16 @@ public static class SetupBundle
void FindBundleHeader() void FindBundleHeader()
{ {
using (var memoryMappedFile = MemoryMappedFile.CreateFromFile(setupPath, FileMode.Open, null, 0, MemoryMappedFileAccess.Read)) using var memoryMappedFile = MemoryMappedFile.CreateFromFile(setupPath, FileMode.Open, null, 0, MemoryMappedFileAccess.Read);
using (MemoryMappedViewAccessor accessor = memoryMappedFile.CreateViewAccessor(0, 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);
}
offset = accessor.ReadInt64(position - 16); int position = BinaryUtils.SearchInFile(accessor, bundleSignature);
length = accessor.ReadInt64(position - 8); if (position == -1) {
throw new PlaceHolderNotFoundInAppHostException(bundleSignature);
} }
offset = accessor.ReadInt64(position - 16);
length = accessor.ReadInt64(position - 8);
} }
Utility.Retry(FindBundleHeader); Utility.Retry(FindBundleHeader);
@@ -53,8 +53,8 @@ public static class SetupBundle
bundleLength = pkgStream.Length; bundleLength = pkgStream.Length;
pkgStream.CopyTo(setupStream); pkgStream.CopyTo(setupStream);
} finally { } finally {
if (pkgStream != null) pkgStream.Dispose(); pkgStream?.Dispose();
if (setupStream != null) setupStream.Dispose(); setupStream?.Dispose();
} }
byte[] placeholder = { byte[] placeholder = {

View File

@@ -1,4 +1,4 @@
namespace Velopack.Packaging.Abstractions; namespace Velopack.Packaging.Abstractions;
public interface ICommand<TOpt> where TOpt : class public interface ICommand<TOpt> where TOpt : class
{ {

View File

@@ -0,0 +1,5 @@
namespace Velopack.Packaging.Abstractions;
public interface IConsole
{
void WriteLine(string message = "");
}

View File

@@ -1,12 +1,10 @@
namespace Velopack.Packaging.Abstractions; namespace Velopack.Packaging.Abstractions;
public interface IFancyConsole public interface IFancyConsole : IConsole
{ {
Task ExecuteProgressAsync(Func<IFancyConsoleProgress, Task> action); Task ExecuteProgressAsync(Func<IFancyConsoleProgress, Task> action);
void WriteTable(string tableName, IEnumerable<IEnumerable<string>> rows, bool hasHeaderRow = true); void WriteTable(string tableName, IEnumerable<IEnumerable<string>> rows, bool hasHeaderRow = true);
Task<bool> PromptYesNo(string prompt, bool? defaultValue = null, TimeSpan? timeout = null); Task<bool> PromptYesNo(string prompt, bool? defaultValue = null, TimeSpan? timeout = null);
void WriteLine(string text = "");
} }

View File

@@ -1,4 +1,4 @@
namespace Velopack.Packaging.Abstractions; namespace Velopack.Packaging.Abstractions;
public interface IPlatformOptions : IOutputOptions public interface IPlatformOptions : IOutputOptions
{ {

View File

@@ -1,4 +1,4 @@
using System; using System;
using NuGet.Versioning; using NuGet.Versioning;
#if NET5_0_OR_GREATER #if NET5_0_OR_GREATER

View File

@@ -486,8 +486,7 @@ namespace Velopack
public static bool IsHttpUrl(string urlOrPath) public static bool IsHttpUrl(string urlOrPath)
{ {
var uri = default(Uri); if (!Uri.TryCreate(urlOrPath, UriKind.Absolute, out Uri? uri)) {
if (!Uri.TryCreate(urlOrPath, UriKind.Absolute, out uri)) {
return false; return false;
} }

View File

@@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
@@ -64,7 +64,7 @@ namespace Velopack.Sources
public virtual async Task<VelopackAssetFeed> GetReleaseFeed(ILogger logger, string channel, Guid? stagingId = null, VelopackAsset? latestLocalRelease = null) public virtual async Task<VelopackAssetFeed> GetReleaseFeed(ILogger logger, string channel, Guid? stagingId = null, VelopackAsset? latestLocalRelease = null)
{ {
var releases = await GetReleases(Prerelease).ConfigureAwait(false); 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}'."); logger.Warn($"No releases found at '{RepoUri}'.");
return new VelopackAssetFeed(); return new VelopackAssetFeed();
} }

View File

@@ -18,7 +18,7 @@ namespace Velopack.Sources
[JsonPropertyName("prerelease")] [JsonPropertyName("prerelease")]
public bool Prerelease { get; set; } public bool Prerelease { get; set; }
/// <summary> The date which this release was published publically. </summary> /// <summary> The date which this release was published publicly. </summary>
[JsonPropertyName("published_at")] [JsonPropertyName("published_at")]
public DateTime? PublishedAt { get; set; } public DateTime? PublishedAt { get; set; }

View File

@@ -25,7 +25,7 @@ namespace Velopack.Sources
public bool UpcomingRelease { get; set; } public bool UpcomingRelease { get; set; }
/// <summary> /// <summary>
/// The date which this release was published publically. /// The date which this release was published publicly.
/// </summary> /// </summary>
[JsonPropertyName("released_at")] [JsonPropertyName("released_at")]
public DateTime? ReleasedAt { get; set; } public DateTime? ReleasedAt { get; set; }

View File

@@ -15,7 +15,7 @@ namespace Velopack.Sources
/// <param name="url">The url which will be downloaded.</param> /// <param name="url">The url which will be downloaded.</param>
/// <param name="targetFile"> /// <param name="targetFile">
/// The local path where the file will be stored /// The local path where the file will be stored
/// If a file exists at this path, it will be overritten.</param> /// If a file exists at this path, it will be overwritten.</param>
/// <param name="progress"> /// <param name="progress">
/// A delegate for reporting download progress, with expected values from 0-100. /// A delegate for reporting download progress, with expected values from 0-100.
/// </param> /// </param>

View File

@@ -1,4 +1,4 @@
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View File

@@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Threading; using System.Threading;

View File

@@ -142,7 +142,7 @@ namespace Velopack
VelopackDisplayVersion = VelopackNugetVersion.ToNormalizedString() + (VelopackNugetVersion.IsPrerelease ? " (prerelease)" : ""); VelopackDisplayVersion = VelopackNugetVersion.ToNormalizedString() + (VelopackNugetVersion.IsPrerelease ? " (prerelease)" : "");
#pragma warning restore CS0612 #pragma warning restore CS0612
// get real cpu architecture, even when virtualised by Wow64 // get real cpu architecture, even when virtualized by Wow64
#if NETFRAMEWORK #if NETFRAMEWORK
CheckArchitectureWindows(); CheckArchitectureWindows();
#else #else
@@ -216,7 +216,7 @@ namespace Velopack
SystemOs = RuntimeOs.Windows; SystemOs = RuntimeOs.Windows;
// find the actual OS architecture. We can't rely on the framework alone for this on 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) // in some cases unless we use functions that are not virtualized (such as IsWow64Process2)
try { try {

View File

@@ -10,8 +10,8 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="7.0.0" /> <PackageReference Include="System.Text.Json" Version="8.0.2" />
<PackageReference Include="Xunit.Abstractions" Version="2.0.3" /> <PackageReference Include="Xunit.Abstractions" Version="2.0.3" />
</ItemGroup> </ItemGroup>

View File

@@ -346,7 +346,7 @@ public class WindowsPackTests
new DeltaPatchCommandRunner(logger, new BasicConsole(logger, new DefaultPromptValueFactory(false))).Run(new DeltaPatchOptions { new DeltaPatchCommandRunner(logger, new BasicConsole(logger, new DefaultPromptValueFactory(false))).Run(new DeltaPatchOptions {
BasePackage = Path.Combine(releaseDir, $"{id}-1.0.0-full.nupkg"), BasePackage = Path.Combine(releaseDir, $"{id}-1.0.0-full.nupkg"),
OutputFile = output, OutputFile = output,
PatchFiles = new[] { new FileInfo(deltaPath), new FileInfo(deltav3) }, PatchFiles = [new FileInfo(deltaPath), new FileInfo(deltav3)],
}).GetAwaiterResult(); }).GetAwaiterResult();
// are the packages the same? // are the packages the same?
@@ -373,7 +373,7 @@ public class WindowsPackTests
// install app // install app
var setupPath1 = Path.Combine(releaseDir, $"{id}-win-Setup.exe"); 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); Environment.GetFolderPath(Environment.SpecialFolder.Desktop), logger);
var argsPath = Path.Combine(installDir, "args.txt"); var argsPath = Path.Combine(installDir, "args.txt");
@@ -388,8 +388,8 @@ public class WindowsPackTests
PackTestApp(id, "2.0.0", "version 2 test", releaseDir, logger); PackTestApp(id, "2.0.0", "version 2 test", releaseDir, logger);
// install v2 // install v2
RunCoveredDotnet(appPath, new string[] { "download", releaseDir }, installDir, logger); RunCoveredDotnet(appPath, ["download", releaseDir], installDir, logger);
RunCoveredDotnet(appPath, new string[] { "apply", releaseDir }, installDir, logger, exitCode: null); RunCoveredDotnet(appPath, ["apply", releaseDir], installDir, logger, exitCode: null);
Thread.Sleep(2000); Thread.Sleep(2000);
@@ -404,7 +404,7 @@ public class WindowsPackTests
Assert.Equal("2.0.0,test,args !!", File.ReadAllText(restartedPath).Trim()); Assert.Equal("2.0.0,test,args !!", File.ReadAllText(restartedPath).Trim());
var updatePath = Path.Combine(installDir, "Update.exe"); 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] [SkippableFact]
@@ -550,7 +550,7 @@ public class WindowsPackTests
//private string RunCoveredRust(string binName, string[] args, string workingDir, ILogger logger, int? exitCode = 0) //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 manifestFile = GetPath("..", "src", "Rust", "Cargo.toml");
// var psi = new ProcessStartInfo("cargo"); // var psi = new ProcessStartInfo("cargo");
@@ -565,7 +565,7 @@ public class WindowsPackTests
// psi.ArgumentList.Add("--manifest-path"); // psi.ArgumentList.Add("--manifest-path");
// psi.ArgumentList.Add(manifestFile); // psi.ArgumentList.Add(manifestFile);
// psi.ArgumentList.Add("--output"); // psi.ArgumentList.Add("--output");
// psi.ArgumentList.Add(outputfile); // psi.ArgumentList.Add(outputFile);
// psi.ArgumentList.Add("--bin"); // psi.ArgumentList.Add("--bin");
// psi.ArgumentList.Add(binName); // psi.ArgumentList.Add(binName);
// psi.ArgumentList.Add("--"); // psi.ArgumentList.Add("--");
@@ -579,7 +579,7 @@ public class WindowsPackTests
//logger.Info($"TEST: Running {psi.FileName} {psi.ArgumentList.Aggregate((a, b) => $"{a} {b}")}"); //logger.Info($"TEST: Running {psi.FileName} {psi.ArgumentList.Aggregate((a, b) => $"{a} {b}")}");
//using var p = Process.Start(psi); //using var p = Process.Start(psi);
var outputfile = PathHelper.GetTestRootPath($"run.{RandomString(8)}.log"); var outputFile = PathHelper.GetTestRootPath($"run.{RandomString(8)}.log");
try { try {
// this is a huge hack, but WaitForProcess hangs in the test runner when the output is redirected // 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"); var fix = new ProcessStartInfo("cmd.exe");
fix.CreateNoWindow = true; fix.CreateNoWindow = true;
fix.WorkingDirectory = psi.WorkingDirectory; 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(); Stopwatch sw = new Stopwatch();
sw.Start(); sw.Start();
@@ -609,7 +609,7 @@ public class WindowsPackTests
logger.Info($"TEST: Process exited with code {p.ExitCode} in {elapsed.TotalSeconds}s"); logger.Info($"TEST: Process exited with code {p.ExitCode} in {elapsed.TotalSeconds}s");
using var fs = Utility.Retry(() => { 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); }, 10, 1000, logger);
using var reader = new StreamReader(fs); using var reader = new StreamReader(fs);
@@ -633,7 +633,7 @@ public class WindowsPackTests
).Trim(); ).Trim();
} finally { } finally {
try { try {
File.Delete(outputfile); File.Delete(outputFile);
} catch { } } catch { }
} }
} }

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<Choose> <Choose>
@@ -16,7 +16,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="System.IO.Packaging" Version="8.0.0" /> <PackageReference Include="System.IO.Packaging" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.0" /> <PackageReference Include="System.Text.Json" Version="8.0.2" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) "> <ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) ">