Skip to content

Commit

Permalink
Merge pull request #1732 from mungojam/dotnet-core-initial-support
Browse files Browse the repository at this point in the history
Add support for language neutral VersionInfo in target .exes
  • Loading branch information
anaisbetts authored Sep 3, 2021
2 parents 76c87af + 9f26070 commit 64b0f86
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Squirrel/SquirrelAwareExecutableDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,21 @@ public static List<string> GetAllSquirrelAwareApps(string directory, int minimum
var buf = new byte[size];
if (!NativeMethods.GetFileVersionInfo(executable, 0, size, buf)) return null;

IntPtr result; int resultSize;
if (!NativeMethods.VerQueryValue(buf, "\\StringFileInfo\\040904B0\\SquirrelAwareVersion", out result, out resultSize)) {
const string englishUS = "040904B0";
const string neutral = "000004B0";
var supportedLanguageCodes = new[] {englishUS, neutral};

IntPtr result;
int resultSize;
if (!supportedLanguageCodes.Any(
languageCode =>
NativeMethods.VerQueryValue(
buf,
$"\\StringFileInfo\\{languageCode}\\SquirrelAwareVersion",
out result, out resultSize
)
))
{
return null;
}

Expand Down
13 changes: 13 additions & 0 deletions test/SquirrelAwareExecutableDetectorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ public void SquirrelAwareViaVersionBlock()
Assert.Equal(1, ret.Value);
}

[Fact]
public void SquirrelAwareViaLanguageNeutralVersionBlock()
{
var target = IntegrationTestHelper.GetPath("fixtures", "SquirrelAwareTweakedNetCoreApp.exe");
Assert.True(File.Exists(target));

var ret = SquirrelAwareExecutableDetector.GetPESquirrelAwareVersion(target);

Assert.NotNull(ret);
Assert.Equal(1, ret.Value);
}


[Fact]
public void SquirrelAwareViaAssemblyAttribute()
{
Expand Down
Binary file added test/fixtures/SquirrelAwareTweakedNetCoreApp.exe
Binary file not shown.

0 comments on commit 64b0f86

Please sign in to comment.