Skip to content

Commit

Permalink
Activate update check in finally of OnExecuteAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwille committed Jul 12, 2023
1 parent bf91f46 commit 35a3d97
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
7 changes: 4 additions & 3 deletions ICSharpCode.ILSpyCmd/DotNetToolUpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static NuGetVersion CurrentPackageVersion()
.InformationalVersion);
}

public static async Task CheckForPackageUpdateAsync(string packageId)
public static async Task<NuGetVersion> CheckForPackageUpdateAsync(string packageId)
{
try
{
Expand All @@ -37,15 +37,16 @@ public static async Task CheckForPackageUpdateAsync(string packageId)
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.
catch (Exception)
{
}
#pragma warning restore RCS1075 // Avoid empty catch clause that catches System.Exception.

return null;
}
}
}
21 changes: 14 additions & 7 deletions ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ public ILSpyCmdProgram(IHostEnvironment 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;
string outputDirectory = ResolveOutputDirectory(OutputDirectory);
Expand All @@ -137,7 +137,7 @@ private Task<int> OnExecuteAsync(CommandLineApplication app)
{
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)
Expand All @@ -148,27 +148,34 @@ private Task<int> OnExecuteAsync(CommandLineApplication app)
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
{
foreach (var file in InputAssemblyNames)
{
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)
Expand Down

0 comments on commit 35a3d97

Please sign in to comment.