1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
//------------------------------------------------------------------------------
// <copyright file="versioninfo.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* Support for getting file versions
*
* Copyright (c) 1999 Microsoft Corporation
*/
namespace System.Web.Util {
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Text;
using System.Runtime.Serialization.Formatters;
using System.Configuration.Assemblies;
using System.Security.Permissions;
//
// Support for getting file version of relevant files
//
internal class VersionInfo {
static private string _engineVersion;
static private string _mscoreeVersion;
static private string _exeName;
static private object _lock = new object();
private VersionInfo() {
}
[FileIOPermission(SecurityAction.Assert, Unrestricted = true)]
internal static string GetFileVersion(String filename) {
#if !FEATURE_PAL // FEATURE_PAL does not fully support FileVersionInfo
try {
FileVersionInfo ver = FileVersionInfo.GetVersionInfo(filename);
return string.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}.{3}",
ver.FileMajorPart, ver.FileMinorPart, ver.FileBuildPart, ver.FilePrivatePart);
}
catch {
return String.Empty;
}
#else // !FEATURE_PAL
// ROTORTODO
return String.Empty;
#endif // !FEATURE_PAL
}
internal static string GetLoadedModuleFileName(string module) {
#if !FEATURE_PAL // FEATURE_PAL does not fully support FileVersionInfo
IntPtr h = UnsafeNativeMethods.GetModuleHandle(module);
if (h == IntPtr.Zero)
return null;
StringBuilder buf = new StringBuilder(256);
if (UnsafeNativeMethods.GetModuleFileName(h, buf, 256) == 0)
return null;
String fileName = buf.ToString();
if (StringUtil.StringStartsWith(fileName, "\\\\?\\")) // on Whistler GetModuleFileName migth return this
fileName = fileName.Substring(4);
return fileName;
#else // !FEATURE_PAL
// ROTORTODO
return String.Empty;
#endif // !FEATURE_PAL
}
internal static string GetLoadedModuleVersion(string module) {
String filename = GetLoadedModuleFileName(module);
if (filename == null)
return null;
return GetFileVersion(filename);
}
internal static string SystemWebVersion {
get {
// Previously this represented the File version of mscorlib.dll. Many other libraries in the framework and outside took dependencies on the first three parts of this version
// remaining constant throughout 4.x. From 4.0 to 4.5.2 this was fine since the file version only incremented the last part. Starting with 4.6 we switched to a file versioning
// scheme that matched the product version. In order to preserve compatibility with existing libraries, this needs to be hard-coded.
return "4.0.30319.42000";
}
}
internal static string EngineVersion {
#if !FEATURE_PAL // FEATURE_PAL does not enable IIS-based hosting features
get {
if (_engineVersion == null) {
lock(_lock) {
if (_engineVersion == null)
_engineVersion = GetLoadedModuleVersion(ModName.ENGINE_FULL_NAME);
}
}
return _engineVersion;
#else // !FEATURE_PAL
// ROTORTODO
return "1.2.0.0";
#endif // !FEATURE_PAL
}
}
internal static string ClrVersion {
get {
if (_mscoreeVersion == null) {
lock(_lock) {
if (_mscoreeVersion == null) {
//@
// Substring(1) removes the 'v' character.
_mscoreeVersion =
System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion().Substring(1);
}
}
}
return _mscoreeVersion;
}
}
internal static string ExeName {
get {
if (_exeName == null) {
lock(_lock) {
if (_exeName == null) {
String s = GetLoadedModuleFileName(null);
if (s == null)
s = String.Empty;
// strip path
int i = s.LastIndexOf('\\');
if (i >= 0)
s = s.Substring(i+1);
// strip extension
i = s.LastIndexOf('.');
if (i >= 0)
s = s.Substring(0, i);
_exeName = s.ToLower(CultureInfo.InvariantCulture);
}
}
}
return _exeName;
}
}
}
//
// Support for getting OS Flavor
//
internal enum OsFlavor {
Undetermined,
Other,
WebBlade,
StdServer,
AdvServer,
DataCenter,
}
}
|