Configure CA2007 and add ConfigureAwait(false) to every await in SquirrelLib

This commit is contained in:
Caelan Sayler
2021-12-31 20:23:51 +00:00
parent ab6315ce0d
commit 0b8bcc19d6
14 changed files with 75 additions and 68 deletions

View File

@@ -57,6 +57,7 @@ dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_
dotnet_naming_symbols.constant_fields.applicable_kinds = field dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.applicable_accessibilities = * dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
dotnet_naming_symbols.constant_fields.required_modifiers = const dotnet_naming_symbols.constant_fields.required_modifiers = const
dotnet_diagnostic.CA2007.severity=warning
############################### ###############################
# C# Coding Conventions # # C# Coding Conventions #
############################### ###############################
@@ -117,6 +118,10 @@ csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_preserve_single_line_statements = true csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true csharp_preserve_single_line_blocks = true
insert_final_newline=false insert_final_newline=false
dotnet_diagnostic.IL3000.severity=error
dotnet_diagnostic.IL3001.severity=error
dotnet_diagnostic.IL3002.severity=error
dotnet_diagnostic.IL3003.severity=error
############################### ###############################
# VB Coding Conventions # # VB Coding Conventions #
############################### ###############################

View File

@@ -57,10 +57,10 @@ namespace Squirrel
await this.WarnIfThrows( await this.WarnIfThrows(
async () => { async () => {
await wc.DownloadFileTaskAsync(failedUrl ?? url, targetFile); await wc.DownloadFileTaskAsync(failedUrl ?? url, targetFile).ConfigureAwait(false);
progress(100); progress(100);
}, },
"Failed downloading URL: " + (failedUrl ?? url)); "Failed downloading URL: " + (failedUrl ?? url)).ConfigureAwait(false);
} catch (Exception) { } catch (Exception) {
// NB: Some super brain-dead services are case-sensitive yet // NB: Some super brain-dead services are case-sensitive yet
// corrupt case on upload. I can't even. // corrupt case on upload. I can't even.
@@ -84,7 +84,7 @@ namespace Squirrel
this.Log().Info("Downloading url: " + (failedUrl ?? url)); this.Log().Info("Downloading url: " + (failedUrl ?? url));
return await this.WarnIfThrows(() => wc.DownloadDataTaskAsync(failedUrl ?? url), return await this.WarnIfThrows(() => wc.DownloadDataTaskAsync(failedUrl ?? url),
"Failed to download url: " + (failedUrl ?? url)); "Failed to download url: " + (failedUrl ?? url)).ConfigureAwait(false);
} catch (Exception) { } catch (Exception) {
// NB: Some super brain-dead services are case-sensitive yet // NB: Some super brain-dead services are case-sensitive yet
// corrupt case on upload. I can't even. // corrupt case on upload. I can't even.

View File

@@ -203,19 +203,19 @@ namespace Squirrel
try { try {
updateInfo = await This.ErrorIfThrows(() => This.CheckForUpdate(ignoreDeltaUpdates, x => progress(x / 3)), updateInfo = await This.ErrorIfThrows(() => This.CheckForUpdate(ignoreDeltaUpdates, x => progress(x / 3)),
"Failed to check for updates"); "Failed to check for updates").ConfigureAwait(false);
await This.ErrorIfThrows(() => await This.ErrorIfThrows(() =>
This.DownloadReleases(updateInfo.ReleasesToApply, x => progress(x / 3 + 33)), This.DownloadReleases(updateInfo.ReleasesToApply, x => progress(x / 3 + 33)),
"Failed to download updates"); "Failed to download updates").ConfigureAwait(false);
await This.ErrorIfThrows(() => await This.ErrorIfThrows(() =>
This.ApplyReleases(updateInfo, x => progress(x / 3 + 66)), This.ApplyReleases(updateInfo, x => progress(x / 3 + 66)),
"Failed to apply updates"); "Failed to apply updates").ConfigureAwait(false);
await This.ErrorIfThrows(() => await This.ErrorIfThrows(() =>
This.CreateUninstallerRegistryEntry(), This.CreateUninstallerRegistryEntry(),
"Failed to set up uninstaller"); "Failed to set up uninstaller").ConfigureAwait(false);
} catch { } catch {
if (ignoreDeltaUpdates == false) { if (ignoreDeltaUpdates == false) {
ignoreDeltaUpdates = true; ignoreDeltaUpdates = true;

View File

@@ -89,7 +89,7 @@ namespace Squirrel
try { try {
// Candle reprocesses and compiles WiX source files into object files (.wixobj). // Candle reprocesses and compiles WiX source files into object files (.wixobj).
var candleParams = new string[] { "-nologo", "-ext", "WixNetFxExtension", "-out", objFile, wxsTarget }; var candleParams = new string[] { "-nologo", "-ext", "WixNetFxExtension", "-out", objFile, wxsTarget };
var processResult = await Utility.InvokeProcessAsync(WixCandlePath, candleParams, CancellationToken.None, workingDir); var processResult = await Utility.InvokeProcessAsync(WixCandlePath, candleParams, CancellationToken.None, workingDir).ConfigureAwait(false);
if (processResult.Item1 != 0) { if (processResult.Item1 != 0) {
var msg = String.Format( var msg = String.Format(
@@ -101,7 +101,7 @@ namespace Squirrel
// Light links and binds one or more .wixobj files and creates a Windows Installer database (.msi or .msm). // Light links and binds one or more .wixobj files and creates a Windows Installer database (.msi or .msm).
var lightParams = new string[] { "-ext", "WixNetFxExtension", "-spdb", "-sval", "-out", outputFile, objFile }; var lightParams = new string[] { "-ext", "WixNetFxExtension", "-spdb", "-sval", "-out", outputFile, objFile };
processResult = await Utility.InvokeProcessAsync(WixLightPath, lightParams, CancellationToken.None, workingDir); processResult = await Utility.InvokeProcessAsync(WixLightPath, lightParams, CancellationToken.None, workingDir).ConfigureAwait(false);
if (processResult.Item1 != 0) { if (processResult.Item1 != 0) {
var msg = String.Format( var msg = String.Format(
@@ -118,7 +118,7 @@ namespace Squirrel
public static async Task SetExeIcon(string exePath, string iconPath) public static async Task SetExeIcon(string exePath, string iconPath)
{ {
var args = new[] { Path.GetFullPath(exePath), "--set-icon", iconPath }; var args = new[] { Path.GetFullPath(exePath), "--set-icon", iconPath };
var processResult = await Utility.InvokeProcessAsync(RceditPath, args, CancellationToken.None); var processResult = await Utility.InvokeProcessAsync(RceditPath, args, CancellationToken.None).ConfigureAwait(false);
if (processResult.ExitCode != 0) { if (processResult.ExitCode != 0) {
var msg = String.Format( var msg = String.Format(
@@ -151,7 +151,7 @@ namespace Squirrel
args.Add(Path.GetFullPath(iconPath)); args.Add(Path.GetFullPath(iconPath));
} }
var processResult = await Utility.InvokeProcessAsync(RceditPath, args, CancellationToken.None); var processResult = await Utility.InvokeProcessAsync(RceditPath, args, CancellationToken.None).ConfigureAwait(false);
if (processResult.ExitCode != 0) { if (processResult.ExitCode != 0) {
var msg = String.Format( var msg = String.Format(
@@ -183,7 +183,7 @@ namespace Squirrel
Log.Info("About to sign {0}", exePath); Log.Info("About to sign {0}", exePath);
var psi = Utility.CreateProcessStartInfo(SignToolPath, $"sign {signingOpts} \"{exePath}\""); var psi = Utility.CreateProcessStartInfo(SignToolPath, $"sign {signingOpts} \"{exePath}\"");
var processResult = await Utility.InvokeProcessUnsafeAsync(psi, CancellationToken.None); var processResult = await Utility.InvokeProcessUnsafeAsync(psi, CancellationToken.None).ConfigureAwait(false);
if (processResult.ExitCode != 0) { if (processResult.ExitCode != 0) {
var optsWithPasswordHidden = new Regex(@"/p\s+\w+").Replace(signingOpts, "/p ********"); var optsWithPasswordHidden = new Regex(@"/p\s+\w+").Replace(signingOpts, "/p ********");
@@ -200,7 +200,7 @@ namespace Squirrel
var args = new string[] { "pack", nuspecPath, "-BasePath", baseDirectory, "-OutputDirectory", outputDirectory }; var args = new string[] { "pack", nuspecPath, "-BasePath", baseDirectory, "-OutputDirectory", outputDirectory };
Log.Info($"Packing '{baseDirectory}' into nupkg."); Log.Info($"Packing '{baseDirectory}' into nupkg.");
var res = await Utility.InvokeProcessAsync(NugetPath, args, CancellationToken.None); var res = await Utility.InvokeProcessAsync(NugetPath, args, CancellationToken.None).ConfigureAwait(false);
if (res.ExitCode != 0) if (res.ExitCode != 0)
throw new Exception($"Failed nuget pack (exit {res.ExitCode}): \r\n " + res.StdOutput); throw new Exception($"Failed nuget pack (exit {res.ExitCode}): \r\n " + res.StdOutput);
@@ -220,7 +220,7 @@ namespace Squirrel
var psi = Utility.CreateProcessStartInfo(cmd, args); var psi = Utility.CreateProcessStartInfo(cmd, args);
var result = await Utility.InvokeProcessUnsafeAsync(psi, CancellationToken.None); var result = await Utility.InvokeProcessUnsafeAsync(psi, CancellationToken.None).ConfigureAwait(false);
if (result.ExitCode != 0) throw new Exception(result.StdOutput); if (result.ExitCode != 0) throw new Exception(result.StdOutput);
} catch (Exception ex) { } catch (Exception ex) {
Log.Error($"Failed to extract file {zipFilePath} to {outFolder}\n{ex.Message}"); Log.Error($"Failed to extract file {zipFilePath} to {outFolder}\n{ex.Message}");
@@ -242,7 +242,7 @@ namespace Squirrel
var psi = Utility.CreateProcessStartInfo(cmd, args, inFolder); var psi = Utility.CreateProcessStartInfo(cmd, args, inFolder);
var result = await Utility.InvokeProcessUnsafeAsync(psi, CancellationToken.None); var result = await Utility.InvokeProcessUnsafeAsync(psi, CancellationToken.None).ConfigureAwait(false);
if (result.ExitCode != 0) throw new Exception(result.StdOutput); if (result.ExitCode != 0) throw new Exception(result.StdOutput);
} catch (Exception ex) { } catch (Exception ex) {
Log.Error($"Failed to extract file {zipFilePath} to {inFolder}\n{ex.Message}"); Log.Error($"Failed to extract file {zipFilePath} to {inFolder}\n{ex.Message}");

View File

@@ -142,7 +142,7 @@ namespace Squirrel
} }
// XXX: SafeCopy // XXX: SafeCopy
await Task.Run(() => File.Copy(from, to, true)); await Task.Run(() => File.Copy(from, to, true)).ConfigureAwait(false);
} }
public static void Retry(this Action block, int retries = 2, int retryDelay = 250) public static void Retry(this Action block, int retries = 2, int retryDelay = 250)
@@ -270,11 +270,11 @@ namespace Squirrel
pi.Kill(); pi.Kill();
ct.ThrowIfCancellationRequested(); ct.ThrowIfCancellationRequested();
} }
}); }).ConfigureAwait(false);
string textResult = await pi.StandardOutput.ReadToEndAsync(); string textResult = await pi.StandardOutput.ReadToEndAsync().ConfigureAwait(false);
if (String.IsNullOrWhiteSpace(textResult) || pi.ExitCode != 0) { if (String.IsNullOrWhiteSpace(textResult) || pi.ExitCode != 0) {
textResult = (textResult ?? "") + "\n" + await pi.StandardError.ReadToEndAsync(); textResult = (textResult ?? "") + "\n" + await pi.StandardError.ReadToEndAsync().ConfigureAwait(false);
if (String.IsNullOrWhiteSpace(textResult)) { if (String.IsNullOrWhiteSpace(textResult)) {
textResult = String.Empty; textResult = String.Empty;
@@ -296,7 +296,7 @@ namespace Squirrel
select Task.Run(async () => { select Task.Run(async () => {
using (partition) using (partition)
while (partition.MoveNext()) while (partition.MoveNext())
await body(partition.Current); await body(partition.Current).ConfigureAwait(false);
})); }));
} }
@@ -604,7 +604,7 @@ namespace Squirrel
public static async Task LogIfThrows(this IFullLogger This, LogLevel level, string message, Func<Task> block) public static async Task LogIfThrows(this IFullLogger This, LogLevel level, string message, Func<Task> block)
{ {
try { try {
await block(); await block().ConfigureAwait(false);
} catch (Exception ex) { } catch (Exception ex) {
switch (level) { switch (level) {
case LogLevel.Debug: case LogLevel.Debug:
@@ -627,7 +627,7 @@ namespace Squirrel
public static async Task<T> LogIfThrows<T>(this IFullLogger This, LogLevel level, string message, Func<Task<T>> block) public static async Task<T> LogIfThrows<T>(this IFullLogger This, LogLevel level, string message, Func<Task<T>> block)
{ {
try { try {
return await block(); return await block().ConfigureAwait(false);
} catch (Exception ex) { } catch (Exception ex) {
switch (level) { switch (level) {
case LogLevel.Debug: case LogLevel.Debug:

View File

@@ -80,11 +80,11 @@ namespace Squirrel
/// <summary> Download the latest installer for this runtime to the specified file </summary> /// <summary> Download the latest installer for this runtime to the specified file </summary>
public virtual async Task DownloadToFile(string localPath, Action<DownloadProgressChangedEventArgs> progress = null) public virtual async Task DownloadToFile(string localPath, Action<DownloadProgressChangedEventArgs> progress = null)
{ {
var url = await GetDownloadUrl(); var url = await GetDownloadUrl().ConfigureAwait(false);
Log.Info($"Downloading {Id} from {url} to {localPath}"); Log.Info($"Downloading {Id} from {url} to {localPath}");
using var wc = Utility.CreateWebClient(); using var wc = Utility.CreateWebClient();
wc.DownloadProgressChanged += (s, e) => { progress?.Invoke(e); }; wc.DownloadProgressChanged += (s, e) => { progress?.Invoke(e); };
await wc.DownloadFileTaskAsync(url, localPath); await wc.DownloadFileTaskAsync(url, localPath).ConfigureAwait(false);
} }
/// <summary> Execute a runtime installer at a local file path. Typically used after <see cref="DownloadToFile"/> </summary> /// <summary> Execute a runtime installer at a local file path. Typically used after <see cref="DownloadToFile"/> </summary>
@@ -93,7 +93,7 @@ namespace Squirrel
var args = new string[] { "/passive", "/norestart", "/showrmui" }; var args = new string[] { "/passive", "/norestart", "/showrmui" };
var quietArgs = new string[] { "/q", "/norestart" }; var quietArgs = new string[] { "/q", "/norestart" };
Log.Info($"Running {Id} installer '{pathToInstaller} {string.Join(" ", args)}'"); Log.Info($"Running {Id} installer '{pathToInstaller} {string.Join(" ", args)}'");
var p = await Utility.InvokeProcessAsync(pathToInstaller, isQuiet ? quietArgs : args, CancellationToken.None); var p = await Utility.InvokeProcessAsync(pathToInstaller, isQuiet ? quietArgs : args, CancellationToken.None).ConfigureAwait(false);
// https://johnkoerner.com/install/windows-installer-error-codes/ // https://johnkoerner.com/install/windows-installer-error-codes/
@@ -186,7 +186,7 @@ namespace Squirrel
{ {
switch (CpuArchitecture) { switch (CpuArchitecture) {
case RuntimeCpu.X64: return await CheckIsInstalledX64(); case RuntimeCpu.X64: return await CheckIsInstalledX64().ConfigureAwait(false);
case RuntimeCpu.X86: return CheckIsInstalledX86(); case RuntimeCpu.X86: return CheckIsInstalledX86();
default: return false; default: return false;
@@ -234,7 +234,7 @@ namespace Squirrel
// return x64 results, so we can ask it as a last resort // return x64 results, so we can ask it as a last resort
try { try {
var token = new CancellationTokenSource(2000).Token; var token = new CancellationTokenSource(2000).Token;
var output = await Utility.InvokeProcessAsync("dotnet", new[] { "--info" }, token); var output = await Utility.InvokeProcessAsync("dotnet", new[] { "--info" }, token).ConfigureAwait(false);
if (output.ExitCode != 0) return false; if (output.ExitCode != 0) return false;
return output.StdOutput.Contains("Microsoft.WindowsDesktop.App " + RequiredVersion); return output.StdOutput.Contains("Microsoft.WindowsDesktop.App " + RequiredVersion);
} catch (Win32Exception wex) when (wex.HResult == -2147467259) { } catch (Win32Exception wex) when (wex.HResult == -2147467259) {
@@ -261,7 +261,7 @@ namespace Squirrel
/// <inheritdoc/> /// <inheritdoc/>
public override async Task<string> GetDownloadUrl() public override async Task<string> GetDownloadUrl()
{ {
var latest = await GetLatestDotNetVersion(DotnetRuntimeType.WindowsDesktop, RequiredVersion); var latest = await GetLatestDotNetVersion(DotnetRuntimeType.WindowsDesktop, RequiredVersion).ConfigureAwait(false);
var architecture = CpuArchitecture switch { var architecture = CpuArchitecture switch {
RuntimeCpu.X86 => "x86", RuntimeCpu.X86 => "x86",
RuntimeCpu.X64 => "x64", RuntimeCpu.X64 => "x64",
@@ -288,7 +288,7 @@ namespace Squirrel
}; };
using var wc = Utility.CreateWebClient(); using var wc = Utility.CreateWebClient();
return await wc.DownloadStringTaskAsync(new Uri($"{UncachedDotNetFeed}/{runtime}/{channel}/latest.version")); return await wc.DownloadStringTaskAsync(new Uri($"{UncachedDotNetFeed}/{runtime}/{channel}/latest.version")).ConfigureAwait(false);
} }
/// <summary> /// <summary>

View File

@@ -34,14 +34,14 @@ namespace Squirrel
progress(0); progress(0);
// Progress range: 00 -> 40 // Progress range: 00 -> 40
var release = await createFullPackagesFromDeltas(updateInfo.ReleasesToApply, updateInfo.CurrentlyInstalledVersion, new ApplyReleasesProgress(updateInfo.ReleasesToApply.Count, x => progress(CalculateProgress(x, 0, 40)))); var release = await createFullPackagesFromDeltas(updateInfo.ReleasesToApply, updateInfo.CurrentlyInstalledVersion, new ApplyReleasesProgress(updateInfo.ReleasesToApply.Count, x => progress(CalculateProgress(x, 0, 40)))).ConfigureAwait(false);
progress(40); progress(40);
if (release == null) { if (release == null) {
if (attemptingFullInstall) { if (attemptingFullInstall) {
this.Log().Info("No release to install, running the app"); this.Log().Info("No release to install, running the app");
await invokePostInstall(updateInfo.CurrentlyInstalledVersion.Version, false, true, silentInstall); await invokePostInstall(updateInfo.CurrentlyInstalledVersion.Version, false, true, silentInstall).ConfigureAwait(false);
} }
progress(100); progress(100);
@@ -50,12 +50,12 @@ namespace Squirrel
// Progress range: 40 -> 80 // Progress range: 40 -> 80
var ret = await this.ErrorIfThrows(() => installPackageToAppDir(updateInfo, release, x => progress(CalculateProgress(x, 40, 80))), var ret = await this.ErrorIfThrows(() => installPackageToAppDir(updateInfo, release, x => progress(CalculateProgress(x, 40, 80))),
"Failed to install package to app dir"); "Failed to install package to app dir").ConfigureAwait(false);
progress(80); progress(80);
var currentReleases = await this.ErrorIfThrows(() => updateLocalReleasesFile(), var currentReleases = await this.ErrorIfThrows(() => updateLocalReleasesFile(),
"Failed to update local releases file"); "Failed to update local releases file").ConfigureAwait(false);
progress(85); progress(85);
@@ -65,7 +65,7 @@ namespace Squirrel
progress(90); progress(90);
await this.ErrorIfThrows(() => invokePostInstall(newVersion, attemptingFullInstall, false, silentInstall), await this.ErrorIfThrows(() => invokePostInstall(newVersion, attemptingFullInstall, false, silentInstall),
"Failed to invoke post-install"); "Failed to invoke post-install").ConfigureAwait(false);
progress(95); progress(95);
@@ -93,7 +93,7 @@ namespace Squirrel
var currentVersion = updateInfo.CurrentlyInstalledVersion != null ? var currentVersion = updateInfo.CurrentlyInstalledVersion != null ?
updateInfo.CurrentlyInstalledVersion.Version : null; updateInfo.CurrentlyInstalledVersion.Version : null;
await cleanDeadVersions(currentVersion, newVersion); await cleanDeadVersions(currentVersion, newVersion).ConfigureAwait(false);
} catch (Exception ex) { } catch (Exception ex) {
this.Log().WarnException("Failed to clean dead versions, continuing anyways", ex); this.Log().WarnException("Failed to clean dead versions, continuing anyways", ex);
} }
@@ -131,12 +131,12 @@ namespace Squirrel
cts.CancelAfter(10 * 1000); cts.CancelAfter(10 * 1000);
try { try {
await Utility.InvokeProcessAsync(exe, new string[] { "--squirrel-uninstall", version.ToString() }, cts.Token); await Utility.InvokeProcessAsync(exe, new string[] { "--squirrel-uninstall", version.ToString() }, cts.Token).ConfigureAwait(false);
} catch (Exception ex) { } catch (Exception ex) {
this.Log().ErrorException("Failed to run cleanup hook, continuing: " + exe, ex); this.Log().ErrorException("Failed to run cleanup hook, continuing: " + exe, ex);
} }
} }
}, 1 /*at a time*/); }, 1 /*at a time*/).ConfigureAwait(false);
} else { } else {
allApps.ForEach(x => RemoveShortcutsForExecutable(x.Name, ShortcutLocation.StartMenu | ShortcutLocation.Desktop)); allApps.ForEach(x => RemoveShortcutsForExecutable(x.Name, ShortcutLocation.StartMenu | ShortcutLocation.Desktop));
} }
@@ -317,7 +317,7 @@ namespace Squirrel
Path.Combine(updateInfo.PackageDirectory, release.Filename), Path.Combine(updateInfo.PackageDirectory, release.Filename),
target.FullName, target.FullName,
rootAppDirectory, rootAppDirectory,
progressCallback); progressCallback).ConfigureAwait(false);
return target.FullName; return target.FullName;
}); });
@@ -358,12 +358,12 @@ namespace Squirrel
var basePkg = new ReleasePackage(Path.Combine(rootAppDirectory, "packages", currentVersion.Filename)); var basePkg = new ReleasePackage(Path.Combine(rootAppDirectory, "packages", currentVersion.Filename));
var deltaPkg = new ReleasePackage(Path.Combine(rootAppDirectory, "packages", releasesToApply.First().Filename)); var deltaPkg = new ReleasePackage(Path.Combine(rootAppDirectory, "packages", releasesToApply.First().Filename));
var deltaBuilder = new DeltaPackageBuilder(Directory.GetParent(this.rootAppDirectory).FullName); var deltaBuilder = new DeltaPackageBuilder(Directory.GetParent(rootAppDirectory).FullName);
return deltaBuilder.ApplyDeltaPackage(basePkg, deltaPkg, return deltaBuilder.ApplyDeltaPackage(basePkg, deltaPkg,
Regex.Replace(deltaPkg.InputPackageFile, @"-delta.nupkg$", ".nupkg", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant), Regex.Replace(deltaPkg.InputPackageFile, @"-delta.nupkg$", ".nupkg", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant),
x => progress.ReportReleaseProgress(x)); x => progress.ReportReleaseProgress(x));
}); }).ConfigureAwait(false);
progress.FinishRelease(); progress.FinishRelease();
@@ -375,7 +375,7 @@ namespace Squirrel
var entry = ReleaseEntry.GenerateFromFile(fi.OpenRead(), fi.Name); var entry = ReleaseEntry.GenerateFromFile(fi.OpenRead(), fi.Name);
// Recursively combine the rest of them // Recursively combine the rest of them
return await createFullPackagesFromDeltas(releasesToApply.Skip(1), entry, progress); return await createFullPackagesFromDeltas(releasesToApply.Skip(1), entry, progress).ConfigureAwait(false);
} }
void executeSelfUpdate(SemanticVersion currentVersion) void executeSelfUpdate(SemanticVersion currentVersion)
@@ -418,12 +418,12 @@ namespace Squirrel
cts.CancelAfter(15 * 1000); cts.CancelAfter(15 * 1000);
try { try {
await Utility.InvokeProcessAsync(exe, args, cts.Token); await Utility.InvokeProcessAsync(exe, args, cts.Token).ConfigureAwait(false);
} catch (Exception ex) { } catch (Exception ex) {
this.Log().ErrorException("Couldn't run Squirrel hook, continuing: " + exe, ex); this.Log().ErrorException("Couldn't run Squirrel hook, continuing: " + exe, ex);
} }
} }
}, 1 /* at a time */); }, 1 /* at a time */).ConfigureAwait(false);
// If this is the first run, we run the apps with first-run and // If this is the first run, we run the apps with first-run and
// *don't* wait for them, since they're probably the main EXE // *don't* wait for them, since they're probably the main EXE
@@ -612,14 +612,14 @@ namespace Squirrel
cts.CancelAfter(10 * 1000); cts.CancelAfter(10 * 1000);
try { try {
await Utility.InvokeProcessAsync(exe, args, cts.Token); await Utility.InvokeProcessAsync(exe, args, cts.Token).ConfigureAwait(false);
} catch (Exception ex) { } catch (Exception ex) {
this.Log().ErrorException("Coudln't run Squirrel hook, continuing: " + exe, ex); this.Log().ErrorException("Coudln't run Squirrel hook, continuing: " + exe, ex);
} }
} }
}, 1 /* at a time */); }, 1 /* at a time */).ConfigureAwait(false);
} }
}); }).ConfigureAwait(false);
} }
// Include dead folders in folders to :fire: // Include dead folders in folders to :fire:
@@ -650,7 +650,7 @@ namespace Squirrel
// NB: Same deal as above // NB: Same deal as above
markAppFolderAsDead(x.FullName); markAppFolderAsDead(x.FullName);
} }
}); }).ConfigureAwait(false);
// Clean up the packages directory too // Clean up the packages directory too
var releasesFile = Utility.LocalReleaseFileForAppDir(rootAppDirectory); var releasesFile = Utility.LocalReleaseFileForAppDir(rootAppDirectory);
@@ -682,7 +682,7 @@ namespace Squirrel
internal async Task<List<ReleaseEntry>> updateLocalReleasesFile() internal async Task<List<ReleaseEntry>> updateLocalReleasesFile()
{ {
return await Task.Run(() => ReleaseEntry.BuildReleasesFile(Utility.PackageDirectoryForAppDir(rootAppDirectory))); return await Task.Run(() => ReleaseEntry.BuildReleasesFile(Utility.PackageDirectoryForAppDir(rootAppDirectory))).ConfigureAwait(false);
} }
IEnumerable<DirectoryInfo> getReleases() IEnumerable<DirectoryInfo> getReleases()

View File

@@ -77,7 +77,7 @@ namespace Squirrel
}); });
} }
var data = await urlDownloader.DownloadUrl(uri.ToString()); var data = await urlDownloader.DownloadUrl(uri.ToString()).ConfigureAwait(false);
releaseFile = Encoding.UTF8.GetString(data); releaseFile = Encoding.UTF8.GetString(data);
} catch (WebException ex) { } catch (WebException ex) {
this.Log().InfoException("Download resulted in WebException (returning blank release list)", ex); this.Log().InfoException("Download resulted in WebException (returning blank release list)", ex);

View File

@@ -39,10 +39,10 @@ namespace Squirrel
component = toIncrement / 100.0 * p; component = toIncrement / 100.0 * p;
progress((int) Math.Round(current += component)); progress((int) Math.Round(current += component));
} }
}); }).ConfigureAwait(false);
checksumPackage(x); checksumPackage(x);
}); }).ConfigureAwait(false);
} else { } else {
// From Disk // From Disk
await releasesToDownload.ForEachAsync(x => { await releasesToDownload.ForEachAsync(x => {
@@ -55,7 +55,7 @@ namespace Squirrel
lock (progress) progress((int) Math.Round(current += toIncrement)); lock (progress) progress((int) Math.Round(current += toIncrement));
checksumPackage(x); checksumPackage(x);
}); }).ConfigureAwait(false);
} }
} }

View File

@@ -65,10 +65,10 @@ namespace Squirrel
using (var client = new HttpClient() { BaseAddress = baseAddress }) { using (var client = new HttpClient() { BaseAddress = baseAddress }) {
client.DefaultRequestHeaders.UserAgent.Add(userAgent); client.DefaultRequestHeaders.UserAgent.Add(userAgent);
var response = await client.GetAsync(releasesApiBuilder.ToString()); var response = await client.GetAsync(releasesApiBuilder.ToString()).ConfigureAwait(false);
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
var releases = SimpleJson.DeserializeObject<List<Release>>(await response.Content.ReadAsStringAsync()); var releases = SimpleJson.DeserializeObject<List<Release>>(await response.Content.ReadAsStringAsync().ConfigureAwait(false));
var latestRelease = releases var latestRelease = releases
.Where(x => prerelease || !x.Prerelease) .Where(x => prerelease || !x.Prerelease)
.OrderByDescending(x => x.PublishedAt) .OrderByDescending(x => x.PublishedAt)

View File

@@ -54,7 +54,7 @@ namespace Squirrel
var targetIco = Path.Combine(rootAppDirectory, "app.ico"); var targetIco = Path.Combine(rootAppDirectory, "app.ico");
using (var iconStream = iconFile.GetStream()) using (var iconStream = iconFile.GetStream())
using (var targetStream = File.Open(targetIco, FileMode.Create, FileAccess.Write)) using (var targetStream = File.Open(targetIco, FileMode.Create, FileAccess.Write))
await iconStream.CopyToAsync(targetStream); await iconStream.CopyToAsync(targetStream).ConfigureAwait(false);
this.Log().Info($"File '{targetIco}' is being used for uninstall icon."); this.Log().Info($"File '{targetIco}' is being used for uninstall icon.");
key.SetValue("DisplayIcon", targetIco, RegistryValueKind.String); key.SetValue("DisplayIcon", targetIco, RegistryValueKind.String);
} catch (Exception ex) { } catch (Exception ex) {

View File

@@ -58,48 +58,48 @@ namespace Squirrel
{ {
var checkForUpdate = new CheckForUpdateImpl(rootAppDirectory); var checkForUpdate = new CheckForUpdateImpl(rootAppDirectory);
await acquireUpdateLock(); await acquireUpdateLock().ConfigureAwait(false);
return await checkForUpdate.CheckForUpdate(intention, Utility.LocalReleaseFileForAppDir(rootAppDirectory), updateUrlOrPath, ignoreDeltaUpdates, progress, urlDownloader); return await checkForUpdate.CheckForUpdate(intention, Utility.LocalReleaseFileForAppDir(rootAppDirectory), updateUrlOrPath, ignoreDeltaUpdates, progress, urlDownloader).ConfigureAwait(false);
} }
/// <inheritdoc/> /// <inheritdoc/>
public async Task DownloadReleases(IEnumerable<ReleaseEntry> releasesToDownload, Action<int> progress = null) public async Task DownloadReleases(IEnumerable<ReleaseEntry> releasesToDownload, Action<int> progress = null)
{ {
var downloadReleases = new DownloadReleasesImpl(rootAppDirectory); var downloadReleases = new DownloadReleasesImpl(rootAppDirectory);
await acquireUpdateLock(); await acquireUpdateLock().ConfigureAwait(false);
await downloadReleases.DownloadReleases(updateUrlOrPath, releasesToDownload, progress, urlDownloader); await downloadReleases.DownloadReleases(updateUrlOrPath, releasesToDownload, progress, urlDownloader).ConfigureAwait(false);
} }
/// <inheritdoc/> /// <inheritdoc/>
public async Task<string> ApplyReleases(UpdateInfo updateInfo, Action<int> progress = null) public async Task<string> ApplyReleases(UpdateInfo updateInfo, Action<int> progress = null)
{ {
var applyReleases = new ApplyReleasesImpl(rootAppDirectory); var applyReleases = new ApplyReleasesImpl(rootAppDirectory);
await acquireUpdateLock(); await acquireUpdateLock().ConfigureAwait(false);
return await applyReleases.ApplyReleases(updateInfo, false, false, progress); return await applyReleases.ApplyReleases(updateInfo, false, false, progress).ConfigureAwait(false);
} }
/// <inheritdoc/> /// <inheritdoc/>
public async Task FullInstall(bool silentInstall = false, Action<int> progress = null) public async Task FullInstall(bool silentInstall = false, Action<int> progress = null)
{ {
var updateInfo = await CheckForUpdate(intention: UpdaterIntention.Install); var updateInfo = await CheckForUpdate(intention: UpdaterIntention.Install).ConfigureAwait(false);
await DownloadReleases(updateInfo.ReleasesToApply); await DownloadReleases(updateInfo.ReleasesToApply).ConfigureAwait(false);
var applyReleases = new ApplyReleasesImpl(rootAppDirectory); var applyReleases = new ApplyReleasesImpl(rootAppDirectory);
await acquireUpdateLock(); await acquireUpdateLock().ConfigureAwait(false);
await applyReleases.ApplyReleases(updateInfo, silentInstall, true, progress); await applyReleases.ApplyReleases(updateInfo, silentInstall, true, progress).ConfigureAwait(false);
} }
/// <inheritdoc/> /// <inheritdoc/>
public async Task FullUninstall() public async Task FullUninstall()
{ {
var applyReleases = new ApplyReleasesImpl(rootAppDirectory); var applyReleases = new ApplyReleasesImpl(rootAppDirectory);
await acquireUpdateLock(); await acquireUpdateLock().ConfigureAwait(false);
this.KillAllExecutablesBelongingToPackage(); this.KillAllExecutablesBelongingToPackage();
await applyReleases.FullUninstall(); await applyReleases.FullUninstall().ConfigureAwait(false);
} }
/// <inheritdoc/> /// <inheritdoc/>
@@ -271,7 +271,7 @@ namespace Squirrel
var updateProcess = Process.Start(getUpdateExe(), String.Format("--processStartAndWait {0} {1}", exeToStart, argsArg)); var updateProcess = Process.Start(getUpdateExe(), String.Format("--processStartAndWait {0} {1}", exeToStart, argsArg));
await Task.Delay(500); await Task.Delay(500).ConfigureAwait(false);
return updateProcess; return updateProcess;
} }

View File

@@ -13,6 +13,7 @@
<BuiltInComInteropSupport>true</BuiltInComInteropSupport> <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile> <EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings> <SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
<NoWarn>CA2007</NoWarn>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -12,6 +12,7 @@
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile> <EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings> <SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
<NoWarn>CA2007</NoWarn>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>