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

21
ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs

@ -117,9 +117,9 @@ Examples:
_env = env; _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; TextWriter output = System.Console.Out;
string outputDirectory = ResolveOutputDirectory(OutputDirectory); string outputDirectory = ResolveOutputDirectory(OutputDirectory);
@ -137,7 +137,7 @@ Examples:
{ {
string projectFileName = Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(InputAssemblyNames[0]) + ".csproj"); string projectFileName = Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(InputAssemblyNames[0]) + ".csproj");
DecompileAsProject(InputAssemblyNames[0], projectFileName); DecompileAsProject(InputAssemblyNames[0], projectFileName);
return Task.FromResult(0); return 0;
} }
var projects = new List<ProjectItem>(); var projects = new List<ProjectItem>();
foreach (var file in InputAssemblyNames) foreach (var file in InputAssemblyNames)
@ -148,7 +148,7 @@ Examples:
projects.Add(new ProjectItem(projectFileName, projectId.PlatformName, projectId.Guid, projectId.TypeGuid)); projects.Add(new ProjectItem(projectFileName, projectId.PlatformName, projectId.Guid, projectId.TypeGuid));
} }
SolutionCreator.WriteSolutionFile(Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(outputDirectory) + ".sln"), projects); SolutionCreator.WriteSolutionFile(Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(outputDirectory) + ".sln"), projects);
return Task.FromResult(0); return 0;
} }
else else
{ {
@ -156,19 +156,26 @@ Examples:
{ {
int result = PerformPerFileAction(file); int result = PerformPerFileAction(file);
if (result != 0) if (result != 0)
return Task.FromResult(result); return result;
} }
return Task.FromResult(0); return 0;
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
app.Error.WriteLine(ex.ToString()); app.Error.WriteLine(ex.ToString());
return Task.FromResult(ProgramExitCodes.EX_SOFTWARE); return ProgramExitCodes.EX_SOFTWARE;
} }
finally finally
{ {
output.Close(); 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) int PerformPerFileAction(string fileName)

Loading…
Cancel
Save