14 private string fileName;
16 private string companyName;
18 private string fileDescription;
20 private string fileVersion;
22 private string internalName;
24 private string legalCopyright;
26 private string originalFilename;
28 private string productName;
30 private string productVersion;
32 private string comments;
34 private string legalTrademarks;
36 private string privateBuild;
38 private string specialBuild;
40 private string language;
42 private int fileMajor;
44 private int fileMinor;
46 private int fileBuild;
48 private int filePrivate;
50 private int productMajor;
52 private int productMinor;
54 private int productBuild;
56 private int productPrivate;
58 private int fileFlags;
182 this.fileName = fileName;
185 private static string ConvertTo8DigitHex(
int value)
189 if (text.Length == 8)
194 for (
int i = text.Length; i < 8; i++)
196 stringBuilder.
Append(
"0");
198 stringBuilder.
Append(text);
202 private static Microsoft.Win32.NativeMethods.VS_FIXEDFILEINFO GetFixedFileInfo(IntPtr memPtr)
204 IntPtr lplpBuffer = IntPtr.Zero;
205 if (Microsoft.Win32.UnsafeNativeMethods.VerQueryValue(
new HandleRef(
null, memPtr),
"\\", ref lplpBuffer, out
int _))
207 Microsoft.Win32.NativeMethods.VS_FIXEDFILEINFO vS_FIXEDFILEINFO =
new Microsoft.Win32.NativeMethods.VS_FIXEDFILEINFO();
209 return vS_FIXEDFILEINFO;
211 return new Microsoft.Win32.NativeMethods.VS_FIXEDFILEINFO();
214 private static string GetFileVersionLanguage(IntPtr memPtr)
216 int langID = GetVarEntry(memPtr) >> 16;
218 Microsoft.Win32.UnsafeNativeMethods.VerLanguageName(langID, stringBuilder, stringBuilder.
Capacity);
222 private static string GetFileVersionString(IntPtr memPtr,
string name)
225 IntPtr lplpBuffer = IntPtr.Zero;
226 if (Microsoft.Win32.UnsafeNativeMethods.VerQueryValue(
new HandleRef(
null, memPtr), name, ref lplpBuffer, out
int _) && lplpBuffer != IntPtr.Zero)
233 private static int GetVarEntry(IntPtr memPtr)
235 IntPtr lplpBuffer = IntPtr.Zero;
236 if (Microsoft.Win32.UnsafeNativeMethods.VerQueryValue(
new HandleRef(
null, memPtr),
"\\VarFileInfo\\Translation", ref lplpBuffer, out
int _))
243 private bool GetVersionInfoForCodePage(IntPtr memIntPtr,
string codepage)
245 string format =
"\\\\StringFileInfo\\\\{0}\\\\{1}";
306 language = GetFileVersionLanguage(memIntPtr);
307 Microsoft.Win32.NativeMethods.VS_FIXEDFILEINFO fixedFileInfo = GetFixedFileInfo(memIntPtr);
308 fileMajor = HIWORD(fixedFileInfo.dwFileVersionMS);
309 fileMinor = LOWORD(fixedFileInfo.dwFileVersionMS);
310 fileBuild = HIWORD(fixedFileInfo.dwFileVersionLS);
311 filePrivate = LOWORD(fixedFileInfo.dwFileVersionLS);
312 productMajor = HIWORD(fixedFileInfo.dwProductVersionMS);
313 productMinor = LOWORD(fixedFileInfo.dwProductVersionMS);
314 productBuild = HIWORD(fixedFileInfo.dwProductVersionLS);
315 productPrivate = LOWORD(fixedFileInfo.dwProductVersionLS);
316 fileFlags = fixedFileInfo.dwFileFlags;
317 return fileVersion !=
string.Empty;
321 private static string GetFullPathWithAssert(
string fileName)
334 string fullPathWithAssert = GetFullPathWithAssert(fileName);
339 int fileVersionInfoSize = Microsoft.Win32.UnsafeNativeMethods.GetFileVersionInfoSize(fileName, out handle);
341 if (fileVersionInfoSize != 0)
343 byte[] array =
new byte[fileVersionInfoSize];
344 byte[] array2 = array;
345 fixed (
byte* value = array2)
348 if (Microsoft.Win32.UnsafeNativeMethods.GetFileVersionInfo(fileName, 0, fileVersionInfoSize,
new HandleRef(
null, intPtr)))
350 int varEntry = GetVarEntry(intPtr);
351 if (!fileVersionInfo.GetVersionInfoForCodePage(intPtr, ConvertTo8DigitHex(varEntry)))
353 int[] array3 =
new int[3]
359 int[] array4 = array3;
360 foreach (
int num
in array4)
362 if (num != varEntry && fileVersionInfo.GetVersionInfoForCodePage(intPtr, ConvertTo8DigitHex(num)))
371 return fileVersionInfo;
374 private static int HIWORD(
int dword)
376 return Microsoft.Win32.NativeMethods.Util.HIWORD(dword);
379 private static int LOWORD(
int dword)
381 return Microsoft.Win32.NativeMethods.Util.LOWORD(dword);
391 string value =
"\r\n";
392 stringBuilder.
Append(
"File: ");
394 stringBuilder.
Append(value);
395 stringBuilder.
Append(
"InternalName: ");
397 stringBuilder.
Append(value);
398 stringBuilder.
Append(
"OriginalFilename: ");
400 stringBuilder.
Append(value);
401 stringBuilder.
Append(
"FileVersion: ");
403 stringBuilder.
Append(value);
404 stringBuilder.
Append(
"FileDescription: ");
406 stringBuilder.
Append(value);
407 stringBuilder.
Append(
"Product: ");
409 stringBuilder.
Append(value);
410 stringBuilder.
Append(
"ProductVersion: ");
412 stringBuilder.
Append(value);
413 stringBuilder.
Append(
"Debug: ");
415 stringBuilder.
Append(value);
416 stringBuilder.
Append(
"Patched: ");
418 stringBuilder.
Append(value);
419 stringBuilder.
Append(
"PreRelease: ");
421 stringBuilder.
Append(value);
422 stringBuilder.
Append(
"PrivateBuild: ");
424 stringBuilder.
Append(value);
425 stringBuilder.
Append(
"SpecialBuild: ");
427 stringBuilder.
Append(value);
428 stringBuilder.
Append(
"Language: ");
430 stringBuilder.
Append(value);
Converts a base data type to another base data type.
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
bool IsPreRelease
Gets a value that specifies whether the file is a development version, rather than a commercially rel...
string FileDescription
Gets the description of the file.
string InternalName
Gets the internal name of the file, if one exists.
FileIOPermissionAccess
Specifies the type of file access requested.
string FileName
Gets the name of the file that this instance of T:System.Diagnostics.FileVersionInfo describes.
static bool Exists(string path)
Determines whether the specified file exists.
int ProductMajorPart
Gets the major part of the version number for the product this file is associated with.
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
int ProductPrivatePart
Gets the private part number of the product this file is associated with.
string PrivateBuild
Gets information about a private version of the file.
Wraps a managed object holding a handle to a resource that is passed to unmanaged code using platform...
string LegalCopyright
Gets all copyright notices that apply to the specified file.
string CompanyName
Gets the name of the company that produced the file.
int FileMinorPart
Gets the minor part of the version number of the file.
string LegalTrademarks
Gets the trademarks and registered trademarks that apply to the file.
string ProductVersion
Gets the version of the product this file is distributed with.
int FileMajorPart
Gets the major part of the version number.
string FileVersion
Gets the file version number.
SecurityAction
Specifies the security actions that can be performed using declarative security.
string OriginalFilename
Gets the name the file was created with.
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
int ProductBuildPart
Gets the build number of the product this file is associated with.
int FilePrivatePart
Gets the file private part number.
A platform-specific type that is used to represent a pointer or a handle.
static string PtrToStringAuto(IntPtr ptr, int len)
Allocates a managed T:System.String and copies the specified number of characters from a string store...
static unsafe FileVersionInfo GetVersionInfo(string fileName)
Returns a T:System.Diagnostics.FileVersionInfo representing the version information associated with t...
string Language
Gets the default language string for the version info block.
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
static string GetFullPath(string path)
Returns the absolute path for the specified path string.
bool IsPatched
Gets a value that specifies whether the file has been modified and is not identical to the original s...
bool IsSpecialBuild
Gets a value that specifies whether the file is a special build.
Provides version information for a physical file on disk.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
bool IsDebug
Gets a value that specifies whether the file contains debugging information or is compiled with debug...
The exception that is thrown when an attempt to access a file that does not exist on disk fails.
int Capacity
Gets or sets the maximum number of characters that can be contained in the memory allocated by the cu...
static void PtrToStructure(IntPtr ptr, object structure)
Marshals data from an unmanaged block of memory to a managed object.
string Comments
Gets the comments associated with the file.
string ProductName
Gets the name of the product this file is distributed with.
string SpecialBuild
Gets the special build information for the file.
override string ToString()
Returns a partial list of properties in the T:System.Diagnostics.FileVersionInfo and their values.
static short ReadInt16([In] [MarshalAs(UnmanagedType.AsAny)] object ptr, int ofs)
Reads a 16-bit signed integer at a given offset from unmanaged memory.
static string ToString(object value)
Converts the value of the specified object to its equivalent string representation.
int FileBuildPart
Gets the build number of the file.
Provides static methods for the creation, copying, deletion, moving, and opening of a single file,...
Provides information about a specific culture (called a locale for unmanaged code development)....
Controls the ability to access files and folders. This class cannot be inherited.
bool IsPrivateBuild
Gets a value that specifies whether the file was built using standard release procedures.
int ProductMinorPart
Gets the minor part of the version number for the product the file is associated with.
Performs operations on T:System.String instances that contain file or directory path information....