Browse Source

Make update check explicit, see #3101

pull/3111/head
Christoph Wille 2 years ago
parent
commit
6e3b9ecc57
  1. 12
      ICSharpCode.ILSpyCmd/DotNetToolUpdateChecker.cs
  2. 8
      ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs

12
ICSharpCode.ILSpyCmd/DotNetToolUpdateChecker.cs

@ -11,6 +11,8 @@ using NuGet.Versioning;
namespace ICSharpCode.ILSpyCmd namespace ICSharpCode.ILSpyCmd
{ {
internal record PackageCheckResult(NuGetVersion RunningVersion, NuGetVersion LatestVersion, bool UpdateRecommendation);
// Idea from https://github.com/ErikEJ/EFCorePowerTools/blob/master/src/GUI/efcpt/Services/PackageService.cs // Idea from https://github.com/ErikEJ/EFCorePowerTools/blob/master/src/GUI/efcpt/Services/PackageService.cs
internal static class DotNetToolUpdateChecker internal static class DotNetToolUpdateChecker
{ {
@ -20,7 +22,7 @@ namespace ICSharpCode.ILSpyCmd
.InformationalVersion); .InformationalVersion);
} }
public static async Task<NuGetVersion> CheckForPackageUpdateAsync(string packageId) public static async Task<PackageCheckResult> CheckForPackageUpdateAsync(string packageId)
{ {
try try
{ {
@ -35,10 +37,10 @@ namespace ICSharpCode.ILSpyCmd
CancellationToken.None).ConfigureAwait(false); CancellationToken.None).ConfigureAwait(false);
var latestVersion = versions.Where(v => v.Release == "").MaxBy(v => v); var latestVersion = versions.Where(v => v.Release == "").MaxBy(v => v);
if (latestVersion > CurrentPackageVersion()) var runningVersion = CurrentPackageVersion();
{ int comparisonResult = latestVersion.CompareTo(runningVersion, VersionComparison.Version);
return latestVersion;
} return new PackageCheckResult(runningVersion, latestVersion, comparisonResult > 0);
} }
#pragma warning disable RCS1075 // Avoid empty catch clause that catches System.Exception. #pragma warning disable RCS1075 // Avoid empty catch clause that catches System.Exception.
catch (Exception) catch (Exception)

8
ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs

@ -124,7 +124,7 @@ Examples:
private async Task<int> OnExecuteAsync(CommandLineApplication app) private async Task<int> OnExecuteAsync(CommandLineApplication app)
{ {
Task<NuGetVersion> updateCheckTask = null; Task<PackageCheckResult> updateCheckTask = null;
if (!DisableUpdateCheck) if (!DisableUpdateCheck)
{ {
updateCheckTask = DotNetToolUpdateChecker.CheckForPackageUpdateAsync("ilspycmd"); updateCheckTask = DotNetToolUpdateChecker.CheckForPackageUpdateAsync("ilspycmd");
@ -181,11 +181,11 @@ Examples:
if (null != updateCheckTask) if (null != updateCheckTask)
{ {
var latestVersion = await updateCheckTask; var checkResult = await updateCheckTask;
if (null != latestVersion) if (null != checkResult && checkResult.UpdateRecommendation)
{ {
Console.WriteLine("You are not using the latest version of the tool, please update."); Console.WriteLine("You are not using the latest version of the tool, please update.");
Console.WriteLine($"Latest version is '{latestVersion}'"); Console.WriteLine($"Latest version is '{checkResult.LatestVersion}' (yours is '{checkResult.RunningVersion}')");
} }
} }
} }

Loading…
Cancel
Save