Merge lp:~wwahammy-deactivatedaccount/coapp-toolkit/developing into lp:coapp-toolkit

Proposed by Eric Schultz
Status: Merged
Approved by: Garrett Serack
Approved revision: no longer in the source branch.
Merged at revision: 35
Proposed branch: lp:~wwahammy-deactivatedaccount/coapp-toolkit/developing
Merge into: lp:coapp-toolkit
Diff against target: 87 lines (+13/-38)
2 files modified
Utility/NativeMethods.cs (+0/-12)
Utility/ProgramFinder.cs (+13/-26)
To merge this branch: bzr merge lp:~wwahammy-deactivatedaccount/coapp-toolkit/developing
Reviewer Review Type Date Requested Status
Garrett Serack Pending
Review via email: mp+44159@code.launchpad.net

Description of the change

The current version of ProgramFinder.GetToolVersion fails when the application using the library is built for x64 or is built for AnyCPU but is running on x64. The last call to NativeMethods.VerQueryValue in GetToolVersion crashes because it expects versionInfo to have a 32-bit address, not a 64-bit one. I really don't know why this is going on but in order to fix it, I've removed the unsafe code with managed code that performs the same purpose.

Also because of this change we're not using any of the methods in NativeMethods anymore so I removed that class.

To post a comment you must log in.
35. By Garrett Serack

Fixed Garrett's Insanity

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Utility/NativeMethods.cs'
2--- Utility/NativeMethods.cs 2010-07-13 19:45:09 +0000
3+++ Utility/NativeMethods.cs 2010-12-19 05:21:14 +0000
4@@ -17,18 +17,6 @@
5 using System;
6 using System.Runtime.InteropServices;
7
8- class NativeMethods
9- {
10- [DllImport("version.dll")]
11- public static extern int GetFileVersionInfoSize(string sFileName, out int handle);
12- [DllImport("version.dll")]
13- public static extern bool GetFileVersionInfo(string sFileName, int handle, int size, byte[] infoBuffer);
14- [DllImport("version.dll")]
15- unsafe public static extern bool VerQueryValue(byte[] pBlock, string pSubBlock, out string pValue, out uint len);
16- [DllImport("version.dll")]
17- unsafe public static extern bool VerQueryValue(byte[] pBlock, string pSubBlock, out short* pValue, out uint len);
18- }
19-
20 public enum MachineType
21 {
22 Native = 0,
23
24=== modified file 'Utility/ProgramFinder.cs'
25--- Utility/ProgramFinder.cs 2010-11-19 20:29:47 +0000
26+++ Utility/ProgramFinder.cs 2010-12-19 05:21:14 +0000
27@@ -1,7 +1,7 @@
28 //-----------------------------------------------------------------------
29 // <copyright company="CoApp Project">
30 // Original Copyright (c) 2009 Microsoft Corporation. All rights reserved.
31-// Changes Copyright (c) 2010 Garrett Serack. All rights reserved.
32+// Changes Copyright (c) 2010 Eric Schultz, Garrett Serack. All rights reserved.
33 // </copyright>
34 //-----------------------------------------------------------------------
35
36@@ -18,6 +18,7 @@
37 using System;
38 using System.Collections.Generic;
39 using System.IO;
40+ using System.Diagnostics;
41
42 public class ProgramFinder
43 {
44@@ -287,32 +288,18 @@
45
46 }
47
48- unsafe public virtual string GetToolVersion(string FileName)
49+ public virtual string GetToolVersion(string FileName)
50 {
51- int handle;
52- // Figure out how much version info there is:
53- int size = NativeMethods.GetFileVersionInfoSize(FileName, out handle);
54-
55- if (0 == size)
56- return null;
57-
58- byte[] buffer = new byte[size];
59-
60- if (!NativeMethods.GetFileVersionInfo(FileName, handle, size, buffer))
61- return null;
62-
63- short* subBlock;
64- uint len;
65- // Get the locale info from the version info:
66- if (!NativeMethods.VerQueryValue(buffer, @"\VarFileInfo\Translation", out subBlock, out len))
67- return null;
68-
69- string spv = @"\StringFileInfo\" + subBlock[0].ToString("X4") + subBlock[1].ToString("X4") + @"\ProductVersion";
70-
71- // Get the ProductVersion value for this program:
72- string versionInfo;
73-
74- return !NativeMethods.VerQueryValue(buffer, spv, out versionInfo, out len) ? null : versionInfo;
75+
76+ try
77+ {
78+ FileVersionInfo info = FileVersionInfo.GetVersionInfo(FileName);
79+ return info.FileVersion;
80+ }
81+ catch
82+ {
83+ return null;
84+ }
85 }
86
87 public static ExecutableInfo GetExeType(string filename)

Subscribers

People subscribed via source and target branches

to all changes: