Skip to content

Commit

Permalink
Add support for language neutral VersionInfo in target .exes
Browse files Browse the repository at this point in the history
  • Loading branch information
mungojam committed Dec 27, 2020
1 parent 76c87af commit 3cc10f1
Show file tree
Hide file tree
Showing 4 changed files with 26 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
11 changes: 11 additions & 0 deletions test/SquirrelAwareExecutableDetectorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ public void SquirrelAwareViaVersionBlock()
Assert.Equal(1, ret.Value);
}

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

var ret = SquirrelAwareExecutableDetector.GetPESquirrelAwareVersion(target);
Assert.Equal(1, ret.Value);
}


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

0 comments on commit 3cc10f1

Please sign in to comment.