~wwahammy-deactivatedaccount/coapp-toolkit/developing

« back to all changes in this revision

Viewing changes to Utility/ProgramFinder.cs

  • Committer: garretts
  • Date: 2010-12-19 20:15:27 UTC
  • mfrom: (34.1.3 coapp-toolkit)
  • Revision ID: garretts@microsoft.com-20101219201527-queidjsp80w1xlqr
Fixed Garrett's Insanity

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//-----------------------------------------------------------------------
2
2
// <copyright company="CoApp Project">
3
3
//     Original Copyright (c) 2009 Microsoft Corporation. All rights reserved.
4
 
//     Changes Copyright (c) 2010  Garrett Serack. All rights reserved.
 
4
//     Changes Copyright (c) 2010  Eric Schultz, Garrett Serack. All rights reserved.
5
5
// </copyright>
6
6
//-----------------------------------------------------------------------
7
7
 
18
18
    using System;
19
19
    using System.Collections.Generic;
20
20
    using System.IO;
 
21
    using System.Diagnostics;
21
22
 
22
23
    public class ProgramFinder
23
24
    {
287
288
 
288
289
        }
289
290
 
290
 
        unsafe public virtual string GetToolVersion(string FileName)
 
291
        public virtual string GetToolVersion(string FileName)
291
292
        {
292
 
            int handle;
293
 
            // Figure out how much version info there is:
294
 
            int size = NativeMethods.GetFileVersionInfoSize(FileName, out handle);
295
 
 
296
 
            if (0 == size)
297
 
                return null;
298
 
 
299
 
            byte[] buffer = new byte[size];
300
 
 
301
 
            if (!NativeMethods.GetFileVersionInfo(FileName, handle, size, buffer))
302
 
                return null;
303
 
 
304
 
            short* subBlock;
305
 
            uint len;
306
 
            // Get the locale info from the version info:
307
 
            if (!NativeMethods.VerQueryValue(buffer, @"\VarFileInfo\Translation", out subBlock, out len))
308
 
                return null;
309
 
 
310
 
            string spv = @"\StringFileInfo\" + subBlock[0].ToString("X4") + subBlock[1].ToString("X4") + @"\ProductVersion";
311
 
 
312
 
            // Get the ProductVersion value for this program:
313
 
            string versionInfo;
314
 
 
315
 
            return !NativeMethods.VerQueryValue(buffer, spv, out versionInfo, out len) ? null : versionInfo;
 
293
            
 
294
            try
 
295
            {
 
296
                FileVersionInfo info = FileVersionInfo.GetVersionInfo(FileName);
 
297
                return info.FileVersion;
 
298
            }
 
299
            catch
 
300
            {
 
301
                return null;
 
302
            }
316
303
        }
317
304
 
318
305
        public static ExecutableInfo GetExeType(string filename)