Browse Source

Activate update check in finally of OnExecuteAsync

pull/3035/head
Christoph Wille 2 years ago
parent
commit
35a3d97066
  1. 7
      ICSharpCode.ILSpyCmd/DotNetToolUpdateChecker.cs
  2. 21
      ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs

7
ICSharpCode.ILSpyCmd/DotNetToolUpdateChecker.cs

@ -20,7 +20,7 @@ namespace ICSharpCode.ILSpyCmd @@ -20,7 +20,7 @@ namespace ICSharpCode.ILSpyCmd
.InformationalVersion);
}
public static async Task CheckForPackageUpdateAsync(string packageId)
public static async Task<NuGetVersion> CheckForPackageUpdateAsync(string packageId)
{
try
{
@ -37,8 +37,7 @@ namespace ICSharpCode.ILSpyCmd @@ -37,8 +37,7 @@ namespace ICSharpCode.ILSpyCmd
var latestVersion = versions.Where(v => v.Release == "").MaxBy(v => v);
if (latestVersion > CurrentPackageVersion())
{
Console.WriteLine("You are not using the latest version of the tool, please update.");
Console.WriteLine($"Latest version is '{latestVersion}'");
return latestVersion;
}
}
#pragma warning disable RCS1075 // Avoid empty catch clause that catches System.Exception.
@ -46,6 +45,8 @@ namespace ICSharpCode.ILSpyCmd @@ -46,6 +45,8 @@ namespace ICSharpCode.ILSpyCmd
{
}
#pragma warning restore RCS1075 // Avoid empty catch clause that catches System.Exception.
return null;
}
}
}

21
ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs

@ -117,9 +117,9 @@ Examples: @@ -117,9 +117,9 @@ Examples:
_env = env;
}
private Task<int> OnExecuteAsync(CommandLineApplication app)
private async Task<int> OnExecuteAsync(CommandLineApplication app)
{
// await DotNetToolUpdateChecker.CheckForPackageUpdateAsync("ilspycmd");
var updateCheckTask = DotNetToolUpdateChecker.CheckForPackageUpdateAsync("ilspycmd");
TextWriter output = System.Console.Out;
string outputDirectory = ResolveOutputDirectory(OutputDirectory);
@ -137,7 +137,7 @@ Examples: @@ -137,7 +137,7 @@ Examples:
{
string projectFileName = Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(InputAssemblyNames[0]) + ".csproj");
DecompileAsProject(InputAssemblyNames[0], projectFileName);
return Task.FromResult(0);
return 0;
}
var projects = new List<ProjectItem>();
foreach (var file in InputAssemblyNames)
@ -148,7 +148,7 @@ Examples: @@ -148,7 +148,7 @@ Examples:
projects.Add(new ProjectItem(projectFileName, projectId.PlatformName, projectId.Guid, projectId.TypeGuid));
}
SolutionCreator.WriteSolutionFile(Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(outputDirectory) + ".sln"), projects);
return Task.FromResult(0);
return 0;
}
else
{
@ -156,19 +156,26 @@ Examples: @@ -156,19 +156,26 @@ Examples:
{
int result = PerformPerFileAction(file);
if (result != 0)
return Task.FromResult(result);
return result;
}
return Task.FromResult(0);
return 0;
}
}
catch (Exception ex)
{
app.Error.WriteLine(ex.ToString());
return Task.FromResult(ProgramExitCodes.EX_SOFTWARE);
return ProgramExitCodes.EX_SOFTWARE;
}
finally
{
output.Close();
var latestVersion = await updateCheckTask;
if (null != latestVersion)
{
Console.WriteLine("You are not using the latest version of the tool, please update.");
Console.WriteLine($"Latest version is '{latestVersion}'");
}
}
int PerformPerFileAction(string fileName)

Loading…
Cancel
Save