Skip to content

Instantly share code, notes, and snippets.

@jamesrcounts
Created March 19, 2012 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesrcounts/2115876 to your computer and use it in GitHub Desktop.
Save jamesrcounts/2115876 to your computer and use it in GitHub Desktop.
A patch that corrects GetPathInProgramFilesX86 behavior in a process compiled for x86
When the test project is compiled for x86, Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) and Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) both return "C:\Program Files (x86)"
on an x64 machine. As a result, the ternary expression does not end up helping find x64 versions of the utilities ApprovalTests is looking for.
However, Environment.GetEnvironmentVariable("ProgramW6432") returns "C:\Program Files" even when the test assembly is compiled for x86 and ApprovalTests is able to find x64 utilities.
Index: BeyondCompareReporter.cs
===================================================================
--- BeyondCompareReporter.cs (revision 378)
+++ BeyondCompareReporter.cs (working copy)
@@ -20,7 +20,7 @@
public static string GetPathInProgramFilesX86(string path)
{
var x86Path = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + @"\" + path;
- return File.Exists(x86Path) ? x86Path : Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + @"\" + path;
+ return File.Exists(x86Path) ? x86Path : Environment.GetEnvironmentVariable("ProgramW6432") + @"\" + path;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment