提交 462b27a7 编写于 作者: D dotnet-bot

Add System.Diagnostics.FileVersionInfo source


Commit migrated from https://github.com/dotnet/corefx/commit/5e9db2482a100e8343349d77aed9ec83592a2230
上级 71f3a271

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Diagnostics.FileVersionInfo", "System.Diagnostics.FileVersionInfo\src\System.Diagnostics.FileVersionInfo.csproj", "{00EDA5FD-E802-40D3-92D5-56C27612D36D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{00EDA5FD-E802-40D3-92D5-56C27612D36D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00EDA5FD-E802-40D3-92D5-56C27612D36D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00EDA5FD-E802-40D3-92D5-56C27612D36D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00EDA5FD-E802-40D3-92D5-56C27612D36D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
internal partial class Interop
{
internal partial class mincore
{
[DllImport("api-ms-win-core-localization-l1-2-0.dll", CharSet = CharSet.Unicode, EntryPoint = "VerLanguageNameW")]
public static extern int VerLanguageName(uint langID, StringBuilder lpBuffer, uint nSize);
[DllImport("api-ms-win-core-version-l1-1-0.dll", CharSet = CharSet.Unicode, EntryPoint = "VerQueryValueW")]
internal extern static bool VerQueryValue(
IntPtr pBlock,
string lpSubBlock,
out IntPtr lplpBuffer,
out uint puLen);
[DllImport("api-ms-win-core-version-l1-1-0.dll", CharSet = CharSet.Unicode, EntryPoint = "GetFileVersionInfoExW")]
internal extern static bool GetFileVersionInfoEx(
uint dwFlags,
string lpwstrFilename,
uint dwHandle,
uint dwLen,
IntPtr lpData);
[DllImport("api-ms-win-core-version-l1-1-0.dll", CharSet = CharSet.Unicode, EntryPoint = "GetFileVersionInfoSizeExW")]
internal extern static uint GetFileVersionInfoSizeEx(
uint dwFlags,
string lpwstrFilename,
out uint lpdwHandle);
}
internal enum Constants : uint
{
ErrorSuccess = 0x0u,
FileVerGetLocalised = 0x1u,
VS_FF_Debug = 0x1u,
MutexModifyState = 0x1u,
FileVerGetNeutral = 0x2u,
VS_FF_Prerelease = 0x2u,
ErrorFileNotFound = 0x2u,
EventModifyState = 0x2u,
FileTypeChar = 0x2u,
ErrorPathNotFound = 0x3u,
VS_FF_Patched = 0x4u,
ErrorAccessDenied = 0x5u,
ErrorInvalidHandle = 0x6u,
VS_FF_PrivateBuild = 0x8u,
ErrorInvalidDrive = 0xFu,
VS_FF_InfoInferred = 0x10u,
VS_FF_SpecialBuild = 0x20u,
ErrorSharingViolation = 0x20u,
ErrorInvalidParameter = 0x57u,
ErrorInvalidName = 0x7Bu,
ErrorBadPathname = 0xA1u,
ErrorAlreadyExists = 0xB7u,
ErrorFilenameExcedRange = 0xCEu,
Synchronize = 0x100000u,
StdErrorHandle = 0xFFFFFFF4u,
StdOutputHandle = 0xFFFFFFF5u,
StdInputHandle = 0xFFFFFFF6u,
}
[StructLayout(LayoutKind.Sequential)]
internal struct VS_FIXEDFILEINFO
{
public uint dwSignature;
public uint dwStrucVersion;
public uint dwFileVersionMS;
public uint dwFileVersionLS;
public uint dwProductVersionMS;
public uint dwProductVersionLS;
public uint dwFileFlagsMask;
public uint dwFileFlags;
public uint dwFileOS;
public uint dwFileType;
public uint dwFileSubtype;
public uint dwFileDateMS;
public uint dwFileDateLS;
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<!-- Work around known Dev14 bug - see
https://connect.microsoft.com/VisualStudio/feedback/details/1000796/connect-file-uap-props-not-found-cant-build-a-portable-lib-on-vs14
-->
<_WindowsKitBinPath>$(MSBuildProgramFiles32)\Windows Kits\8.1\bin\x86</_WindowsKitBinPath>
<_WindowsPhoneKitBinPath>$(MSBuildProgramFiles32)\Windows Phone Kits\8.1\bin</_WindowsPhoneKitBinPath>
<MakePriExeFullPath>$(_WindowsKitBinPath)\makepri.exe</MakePriExeFullPath>
<MakeAppxExeFullPath>$(_WindowsKitBinPath)\makeappx.exe</MakeAppxExeFullPath>
<SignAppxPackageExeFullPath>$(_WindowsKitBinPath)\signtool.exe</SignAppxPackageExeFullPath>
<MakePriExtensionPath>$(_WindowsPhoneKitBinPath)\x86\MrmEnvironmentExtDl.dll</MakePriExtensionPath>
<MakePriExtensionPath_x64>$(_WindowsPhoneKitBinPath)\x64\MrmEnvironmentExtDl.dll</MakePriExtensionPath_x64>
</PropertyGroup>
<PropertyGroup>
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
<Platform Condition="'$(Platform)' == ''">AnyCPU</Platform>
<ProjectGuid>{00EDA5FD-E802-40D3-92D5-56C27612D36D}</ProjectGuid>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AssemblyName>System.Diagnostics.FileVersionInfo</AssemblyName>
<OutputPath Condition="'$(OutputPath)'==''">$(BaseOutputPath)bin\$(Configuration)\$(AssemblyName)\</OutputPath>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile7</TargetFrameworkProfile>
<ImplicitlyExpandTargetFramework>False</ImplicitlyExpandTargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<PlatformTarget>AnyCPU</PlatformTarget>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<DebugType>full</DebugType>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Optimize>true</Optimize>
<DefineConstants>TRACE</DefineConstants>
<DebugType>pdbonly</DebugType>
<DebugSymbols>true</DebugSymbols>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<!-- Compiled Source Files -->
<ItemGroup>
<Compile Include="System\Diagnostics\FileVersionInfo.cs" />
<Compile Include="Interop\Interop.Manual.cs" />
</ItemGroup>
<!-- Contract references used -->
<ItemGroup>
<Reference Include="System.Collections">
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\System.Collections.4.0.10-beta-22405\lib\portable-wpa80+win80+net45+aspnetcore50\System.Collections.dll</HintPath>
</Reference>
<Reference Include="System.Diagnostics.Debug">
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\System.Diagnostics.Debug.4.0.10-beta-22405\lib\portable-wpa80+win80+net45+aspnetcore50\System.Diagnostics.Debug.dll</HintPath>
</Reference>
<Reference Include="System.Diagnostics.Tools">
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\System.Diagnostics.Tools.4.0.0-beta-22405\lib\portable-wpa80+win80+net45+aspnetcore50\System.Diagnostics.Tools.dll</HintPath>
</Reference>
<Reference Include="System.Globalization">
<Private>True</Private>
<HintPath>..\..\packages\System.Globalization.4.0.10-beta-22412\lib\portable-wpa80+win80+net45+aspnetcore50\System.Globalization.dll</HintPath>
</Reference>
<Reference Include="System.IO">
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\System.IO.4.0.10-beta-22405\lib\portable-wpa80+win80+net45+aspnetcore50\System.IO.dll</HintPath>
</Reference>
<Reference Include="System.IO.FileSystem">
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\System.IO.FileSystem.4.0.0-beta-22412\lib\portable-wpa80+win80+net45+aspnetcore50\System.IO.FileSystem.dll</HintPath>
</Reference>
<Reference Include="System.IO.FileSystem.Primitives">
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\System.IO.FileSystem.Primitives.4.0.0-beta-22412\lib\portable-wpa80+win80+net45+aspnetcore50\System.IO.FileSystem.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Reflection">
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\System.Reflection.4.0.10-beta-22405\lib\portable-wpa80+win80+net45+aspnetcore50\System.Reflection.dll</HintPath>
</Reference>
<Reference Include="System.Reflection.Primitives">
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\System.Reflection.Primitives.4.0.0-beta-22412\lib\portable-wpa80+win80+net45+aspnetcore50\System.Reflection.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Runtime">
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\System.Runtime.4.0.20-beta-22405\lib\portable-wpa80+win80+net45+aspnetcore50\System.Runtime.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Extensions">
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\System.Runtime.Extensions.4.0.10-beta-22405\lib\portable-wpa80+win80+net45+aspnetcore50\System.Runtime.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Handles">
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\System.Runtime.Handles.4.0.0-beta-22412\lib\portable-wpa80+win80+net45+aspnetcore50\System.Runtime.Handles.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.InteropServices">
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\System.Runtime.InteropServices.4.0.20-beta-22412\lib\portable-wpa80+win80+net45+aspnetcore50\System.Runtime.InteropServices.dll</HintPath>
</Reference>
<Reference Include="System.Text.Encoding">
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\System.Text.Encoding.4.0.10-beta-22405\lib\portable-wpa80+win80+net45+aspnetcore50\System.Text.Encoding.dll</HintPath>
</Reference>
<Reference Include="System.Threading">
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\System.Threading.4.0.0-beta-22405\lib\portable-wpa80+win80+net45+aspnetcore50\System.Threading.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks">
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\System.Threading.Tasks.4.0.10-beta-22405\lib\portable-wpa80+win80+net45+aspnetcore50\System.Threading.Tasks.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
</Project>
\ No newline at end of file
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Text;
using System.Runtime.InteropServices;
using System;
using System.IO;
using System.Globalization;
using System.Runtime.Versioning;
namespace System.Diagnostics
{
/// <summary>
/// Provides version information for a physical file on disk.
/// </summary>
public sealed class FileVersionInfo
{
private string _fileName;
private string _companyName;
private string _fileDescription;
private string _fileVersion;
private string _internalName;
private string _legalCopyright;
private string _originalFilename;
private string _productName;
private string _productVersion;
private string _comments;
private string _legalTrademarks;
private string _privateBuild;
private string _specialBuild;
private string _language;
private uint _fileMajor;
private uint _fileMinor;
private uint _fileBuild;
private uint _filePrivate;
private uint _productMajor;
private uint _productMinor;
private uint _productBuild;
private uint _productPrivate;
private uint _fileFlags;
private FileVersionInfo(string fileName)
{
_fileName = fileName;
}
/// <summary>
/// Gets the comments associated with the file.
/// </summary>
public string Comments
{
get
{
return _comments;
}
}
/// <summary>
/// Gets the name of the company that produced the file.
/// </summary>
public string CompanyName
{
get
{
return _companyName;
}
}
/// <summary>
/// Gets the build number of the file.
/// </summary>
public int FileBuildPart
{
get
{
return (int)_fileBuild;
}
}
/// <summary>
/// Gets the description of the file.
/// </summary>
public string FileDescription
{
get
{
return _fileDescription;
}
}
/// <summary>
/// Gets the major part of the version number.
/// </summary>
public int FileMajorPart
{
get
{
return (int)_fileMajor;
}
}
/// <summary>
/// Gets the minor part of the version number of the file.
/// </summary>
public int FileMinorPart
{
get
{
return (int)_fileMinor;
}
}
/// <summary>
/// Gets the name of the file that this instance of System.Windows.Forms.FileVersionInfo describes.
/// </summary>
public string FileName
{
get
{
return _fileName;
}
}
/// <summary>
/// Gets the file private part number.
/// </summary>
public int FilePrivatePart
{
get
{
return (int)_filePrivate;
}
}
/// <summary>
/// Gets the file version number.
/// </summary>
public string FileVersion
{
get
{
return _fileVersion;
}
}
/// <summary>
/// Gets the internal name of the file, if one exists.
/// </summary>
public string InternalName
{
get
{
return _internalName;
}
}
/// <summary>
/// Gets a value that specifies whether the file contains debugging information
/// or is compiled with debugging features enabled.
/// </summary>
public bool IsDebug
{
get
{
return (_fileFlags & (uint)Interop.Constants.VS_FF_Debug) != 0;
}
}
/// <summary>
/// Gets a value that specifies whether the file has been modified and is not identical to
/// the original shipping file of the same version number.
/// </summary>
public bool IsPatched
{
get
{
return (_fileFlags & (uint)Interop.Constants.VS_FF_Patched) != 0;
}
}
/// <summary>
/// Gets a value that specifies whether the file was built using standard release procedures.
/// </summary>
public bool IsPrivateBuild
{
get
{
return (_fileFlags & (uint)Interop.Constants.VS_FF_PrivateBuild) != 0;
}
}
/// <summary>
/// Gets a value that specifies whether the file
/// is a development version, rather than a commercially released product.
/// </summary>
public bool IsPreRelease
{
get
{
return (_fileFlags & (uint)Interop.Constants.VS_FF_Prerelease) != 0;
}
}
/// <summary>
/// Gets a value that specifies whether the file is a special build.
/// </summary>
public bool IsSpecialBuild
{
get
{
return (_fileFlags & (uint)Interop.Constants.VS_FF_SpecialBuild) != 0;
}
}
/// <summary>
/// Gets the default language string for the version info block.
/// </summary>
public string Language
{
get
{
return _language;
}
}
/// <summary>
/// Gets all copyright notices that apply to the specified file.
/// </summary>
public string LegalCopyright
{
get
{
return _legalCopyright;
}
}
/// <summary>
/// Gets the trademarks and registered trademarks that apply to the file.
/// </summary>
public string LegalTrademarks
{
get
{
return _legalTrademarks;
}
}
/// <summary>
/// Gets the name the file was created with.
/// </summary>
public string OriginalFilename
{
get
{
return _originalFilename;
}
}
/// <summary>
/// Gets information about a private version of the file.
/// </summary>
public string PrivateBuild
{
get
{
return _privateBuild;
}
}
/// <summary>
/// Gets the build number of the product this file is associated with.
/// </summary>
public int ProductBuildPart
{
get
{
return (int)_productBuild;
}
}
/// <summary>
/// Gets the major part of the version number for the product this file is associated with.
/// </summary>
public int ProductMajorPart
{
get
{
return (int)_productMajor;
}
}
/// <summary>
/// Gets the minor part of the version number for the product the file is associated with.
/// </summary>
public int ProductMinorPart
{
get
{
return (int)_productMinor;
}
}
/// <summary>
/// Gets the name of the product this file is distributed with.
/// </summary>
public string ProductName
{
get
{
return _productName;
}
}
/// <summary>
/// Gets the private part number of the product this file is associated with.
/// </summary>
public int ProductPrivatePart
{
get
{
return (int)_productPrivate;
}
}
/// <summary>
/// Gets the version of the product this file is distributed with.
/// </summary>
public string ProductVersion
{
get
{
return _productVersion;
}
}
/// <summary>
/// Gets the special build information for the file.
/// </summary>
public string SpecialBuild
{
get
{
return _specialBuild;
}
}
private static string ConvertTo8DigitHex(uint value)
{
string s = Convert.ToString(value, 16);
s = s.ToUpperInvariant();
if (s.Length == 8)
{
return s;
}
else
{
StringBuilder b = new StringBuilder(8);
for (int l = s.Length; l < 8; l++)
{
b.Append("0");
}
b.Append(s);
return b.ToString();
}
}
private static Interop.VS_FIXEDFILEINFO GetFixedFileInfo(IntPtr memPtr)
{
IntPtr memRef = IntPtr.Zero;
uint memLen;
if (Interop.mincore.VerQueryValue(memPtr, "\\", out memRef, out memLen))
{
Interop.VS_FIXEDFILEINFO fixedFileInfo =
(Interop.VS_FIXEDFILEINFO)Marshal.PtrToStructure<Interop.VS_FIXEDFILEINFO>(memRef);
return fixedFileInfo;
}
return new Interop.VS_FIXEDFILEINFO();
}
private static string GetFileVersionLanguage(IntPtr memPtr)
{
uint langid = GetVarEntry(memPtr) >> 16;
StringBuilder lang = new StringBuilder(256);
Interop.mincore.VerLanguageName(langid, lang, (uint)lang.Capacity);
return lang.ToString();
}
private static string GetFileVersionString(IntPtr memPtr, string name)
{
string data = "";
IntPtr memRef = IntPtr.Zero;
uint memLen;
if (Interop.mincore.VerQueryValue(memPtr, name, out memRef, out memLen))
{
if (memRef != IntPtr.Zero)
{
data = Marshal.PtrToStringUni(memRef);
}
}
return data;
}
private static uint GetVarEntry(IntPtr memPtr)
{
IntPtr memRef = IntPtr.Zero;
uint memLen;
if (Interop.mincore.VerQueryValue(memPtr, "\\VarFileInfo\\Translation", out memRef, out memLen))
{
return (uint)((Marshal.ReadInt16(memRef) << 16) + Marshal.ReadInt16((IntPtr)((long)memRef + 2)));
}
return 0x040904E4;
}
//
// This function tries to find version informaiton for a specific codepage.
// Returns true when version information is found.
//
private bool GetVersionInfoForCodePage(IntPtr memIntPtr, string codepage)
{
string template = "\\\\StringFileInfo\\\\{0}\\\\{1}";
_companyName = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "CompanyName"));
_fileDescription = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "FileDescription"));
_fileVersion = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "FileVersion"));
_internalName = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "InternalName"));
_legalCopyright = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "LegalCopyright"));
_originalFilename = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "OriginalFilename"));
_productName = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "ProductName"));
_productVersion = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "ProductVersion"));
_comments = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "Comments"));
_legalTrademarks = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "LegalTrademarks"));
_privateBuild = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "PrivateBuild"));
_specialBuild = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "SpecialBuild"));
_language = GetFileVersionLanguage(memIntPtr);
Interop.VS_FIXEDFILEINFO ffi = GetFixedFileInfo(memIntPtr);
_fileMajor = HIWORD(ffi.dwFileVersionMS);
_fileMinor = LOWORD(ffi.dwFileVersionMS);
_fileBuild = HIWORD(ffi.dwFileVersionLS);
_filePrivate = LOWORD(ffi.dwFileVersionLS);
_productMajor = HIWORD(ffi.dwProductVersionMS);
_productMinor = LOWORD(ffi.dwProductVersionMS);
_productBuild = HIWORD(ffi.dwProductVersionLS);
_productPrivate = LOWORD(ffi.dwProductVersionLS);
_fileFlags = ffi.dwFileFlags;
// fileVersion is chosen based on best guess. Other fields can be used if appropriate.
return (_fileVersion != string.Empty);
}
/// <summary>
/// Returns a System.Windows.Forms.FileVersionInfo representing the version information associated with the specified file.
/// </summary>
public unsafe static FileVersionInfo GetVersionInfo(string fileName)
{
// Check for the existence of the file. File.Exists returns false
// if Read permission is denied.
if (!File.Exists(fileName))
{
throw new FileNotFoundException(fileName);
}
uint handle; // This variable is not used, but we need an out variable.
uint infoSize = Interop.mincore.GetFileVersionInfoSizeEx(
(uint)Interop.Constants.FileVerGetLocalised, fileName, out handle);
FileVersionInfo versionInfo = new FileVersionInfo(fileName);
if (infoSize != 0)
{
byte[] mem = new byte[infoSize];
fixed (byte* memPtr = mem)
{
IntPtr memIntPtr = new IntPtr((void*)memPtr);
if (Interop.mincore.GetFileVersionInfoEx(
(uint)Interop.Constants.FileVerGetLocalised | (uint)Interop.Constants.FileVerGetNeutral,
fileName,
0U,
infoSize,
memIntPtr))
{
uint langid = GetVarEntry(memIntPtr);
if (!versionInfo.GetVersionInfoForCodePage(memIntPtr, ConvertTo8DigitHex(langid)))
{
// Some dlls might not contain correct codepage information. In this case we will fail during lookup.
// Explorer will take a few shots in dark by trying following ID:
//
// 040904B0 // US English + CP_UNICODE
// 040904E4 // US English + CP_USASCII
// 04090000 // US English + unknown codepage
// Explorer also randomly guess 041D04B0=Swedish+CP_UNICODE and 040704B0=German+CP_UNICODE) sometimes.
// We will try to simulate similiar behavior here.
uint[] ids = new uint[] { 0x040904B0, 0x040904E4, 0x04090000 };
foreach (uint id in ids)
{
if (id != langid)
{
if (versionInfo.GetVersionInfoForCodePage(memIntPtr, ConvertTo8DigitHex(id)))
{
break;
}
}
}
}
}
}
}
return versionInfo;
}
private static uint HIWORD(uint dword)
{
return (dword >> 16) & 0xffff;
}
private static uint LOWORD(uint dword)
{
return dword & 0xffff;
}
/// <summary>
/// Returns a partial list of properties in System.Windows.Forms.FileVersionInfo
/// and their values.
/// </summary>
public override string ToString()
{
StringBuilder sb = new StringBuilder(128);
String nl = "\r\n";
sb.Append("File: "); sb.Append(FileName); sb.Append(nl);
sb.Append("InternalName: "); sb.Append(InternalName); sb.Append(nl);
sb.Append("OriginalFilename: "); sb.Append(OriginalFilename); sb.Append(nl);
sb.Append("FileVersion: "); sb.Append(FileVersion); sb.Append(nl);
sb.Append("FileDescription: "); sb.Append(FileDescription); sb.Append(nl);
sb.Append("Product: "); sb.Append(ProductName); sb.Append(nl);
sb.Append("ProductVersion: "); sb.Append(ProductVersion); sb.Append(nl);
sb.Append("Debug: "); sb.Append(IsDebug.ToString()); sb.Append(nl);
sb.Append("Patched: "); sb.Append(IsPatched.ToString()); sb.Append(nl);
sb.Append("PreRelease: "); sb.Append(IsPreRelease.ToString()); sb.Append(nl);
sb.Append("PrivateBuild: "); sb.Append(IsPrivateBuild.ToString()); sb.Append(nl);
sb.Append("SpecialBuild: "); sb.Append(IsSpecialBuild.ToString()); sb.Append(nl);
sb.Append("Language: "); sb.Append(Language); sb.Append(nl);
return sb.ToString();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="System.Diagnostics.Debug" version="4.0.10-beta-22405" targetFramework="portable-net45+win" />
<package id="System.Diagnostics.Tools" version="4.0.0-beta-22405" targetFramework="portable-net45+win" />
<package id="System.Globalization" version="4.0.10-beta-22412" targetFramework="portable-net45+win" />
<package id="System.IO" version="4.0.10-beta-22405" targetFramework="portable-net45+win" />
<package id="System.IO.FileSystem" version="4.0.0-beta-22412" targetFramework="portable-net45+win" />
<package id="System.IO.FileSystem.Primitives" version="4.0.0-beta-22412" targetFramework="portable-net45+win" />
<package id="System.Reflection" version="4.0.10-beta-22405" targetFramework="portable-net45+win" />
<package id="System.Reflection.Primitives" version="4.0.0-beta-22412" targetFramework="portable-net45+win" />
<package id="System.Runtime" version="4.0.20-beta-22405" targetFramework="portable-net45+win" />
<package id="System.Runtime.Extensions" version="4.0.10-beta-22405" targetFramework="portable-net45+win" />
<package id="System.Runtime.Handles" version="4.0.0-beta-22412" targetFramework="portable-net45+win" />
<package id="System.Runtime.InteropServices" version="4.0.20-beta-22412" targetFramework="portable-net45+win" />
<package id="System.Text.Encoding" version="4.0.10-beta-22405" targetFramework="portable-net45+win" />
<package id="System.Threading.Tasks" version="4.0.10-beta-22405" targetFramework="portable-net45+win" />
</packages>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册