1 /***********************************************************************\ 2 * winver.d * 3 * * 4 * Windows API header module * 5 * * 6 * Translated from MinGW Windows headers * 7 * by Stewart Gordon * 8 * * 9 * Placed into public domain * 10 \***********************************************************************/ 11 module windows.winver; 12 import windows.winbase; 13 import windows.sdkddkver; 14 pragma(lib, "version"); 15 nothrow: 16 private import windows.windef; 17 18 // FIXME: type weirdness 19 enum { 20 VS_FILE_INFO = 16, 21 VS_VERSION_INFO = 1, 22 VS_USER_DEFINED = 100 23 } 24 25 enum { 26 VS_FFI_SIGNATURE = 0xFEEF04BD, 27 VS_FFI_STRUCVERSION = 0x10000, 28 VS_FFI_FILEFLAGSMASK = 0x3F 29 } 30 31 enum { 32 VS_FF_DEBUG = 1, 33 VS_FF_PRERELEASE = 2, 34 VS_FF_PATCHED = 4, 35 VS_FF_PRIVATEBUILD = 8, 36 VS_FF_INFOINFERRED = 16, 37 VS_FF_SPECIALBUILD = 32 38 } 39 40 enum { 41 VOS_UNKNOWN = 0, 42 VOS_DOS = 0x10000, 43 VOS_OS216 = 0x20000, 44 VOS_OS232 = 0x30000, 45 VOS_NT = 0x40000, 46 VOS__BASE = 0, 47 VOS__WINDOWS16 = 1, 48 VOS__PM16 = 2, 49 VOS__PM32 = 3, 50 VOS__WINDOWS32 = 4, 51 VOS_DOS_WINDOWS16 = 0x10001, 52 VOS_DOS_WINDOWS32 = 0x10004, 53 VOS_OS216_PM16 = 0x20002, 54 VOS_OS232_PM32 = 0x30003, 55 VOS_NT_WINDOWS32 = 0x40004 56 } 57 58 enum { 59 VFT_UNKNOWN = 0, 60 VFT_APP = 1, 61 VFT_DLL = 2, 62 VFT_DRV = 3, 63 VFT_FONT = 4, 64 VFT_VXD = 5, 65 VFT_STATIC_LIB = 7 66 } 67 68 enum { 69 VFT2_UNKNOWN = 0, 70 VFT2_DRV_PRINTER = 1, 71 VFT2_DRV_KEYBOARD = 2, 72 VFT2_DRV_LANGUAGE = 3, 73 VFT2_DRV_DISPLAY = 4, 74 VFT2_DRV_MOUSE = 5, 75 VFT2_DRV_NETWORK = 6, 76 VFT2_DRV_SYSTEM = 7, 77 VFT2_DRV_INSTALLABLE = 8, 78 VFT2_DRV_SOUND = 9, 79 VFT2_DRV_COMM = 10, 80 VFT2_DRV_INPUTMETHOD = 11, 81 VFT2_FONT_RASTER = 1, 82 VFT2_FONT_VECTOR = 2, 83 VFT2_FONT_TRUETYPE = 3 84 } 85 86 enum : DWORD { 87 VFFF_ISSHAREDFILE = 1 88 } 89 90 enum : DWORD { 91 VFF_CURNEDEST = 1, 92 VFF_FILEINUSE = 2, 93 VFF_BUFFTOOSMALL = 4 94 } 95 96 enum : DWORD { 97 VIFF_FORCEINSTALL = 1, 98 VIFF_DONTDELETEOLD 99 } 100 101 enum { 102 VIF_TEMPFILE = 0x00001, 103 VIF_MISMATCH = 0x00002, 104 VIF_SRCOLD = 0x00004, 105 VIF_DIFFLANG = 0x00008, 106 VIF_DIFFCODEPG = 0x00010, 107 VIF_DIFFTYPE = 0x00020, 108 VIF_WRITEPROT = 0x00040, 109 VIF_FILEINUSE = 0x00080, 110 VIF_OUTOFSPACE = 0x00100, 111 VIF_ACCESSVIOLATION = 0x00200, 112 VIF_SHARINGVIOLATION = 0x00400, 113 VIF_CANNOTCREATE = 0x00800, 114 VIF_CANNOTDELETE = 0x01000, 115 VIF_CANNOTRENAME = 0x02000, 116 VIF_CANNOTDELETECUR = 0x04000, 117 VIF_OUTOFMEMORY = 0x08000, 118 VIF_CANNOTREADSRC = 0x10000, 119 VIF_CANNOTREADDST = 0x20000, 120 VIF_BUFFTOOSMALL = 0x40000 121 } 122 123 struct VS_FIXEDFILEINFO { 124 DWORD dwSignature; 125 DWORD dwStrucVersion; 126 DWORD dwFileVersionMS; 127 DWORD dwFileVersionLS; 128 DWORD dwProductVersionMS; 129 DWORD dwProductVersionLS; 130 DWORD dwFileFlagsMask; 131 DWORD dwFileFlags; 132 DWORD dwFileOS; 133 DWORD dwFileType; 134 DWORD dwFileSubtype; 135 DWORD dwFileDateMS; 136 DWORD dwFileDateLS; 137 } 138 139 extern (Windows) { 140 DWORD VerFindFileA(DWORD, LPCSTR, LPCSTR, LPCSTR, LPSTR, PUINT, LPSTR, 141 PUINT); 142 DWORD VerFindFileW(DWORD, LPCWSTR, LPCWSTR, LPCWSTR, LPWSTR, PUINT, LPWSTR, 143 PUINT); 144 DWORD VerInstallFileA(DWORD, LPCSTR, LPCSTR, LPCSTR, LPCSTR, LPCSTR, LPSTR, 145 PUINT); 146 DWORD VerInstallFileW(DWORD, LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, 147 LPWSTR, PUINT); 148 DWORD GetFileVersionInfoSizeA(LPCSTR, PDWORD); 149 DWORD GetFileVersionInfoSizeW(LPCWSTR, PDWORD); 150 BOOL GetFileVersionInfoA(LPCSTR, DWORD, DWORD, PVOID); 151 BOOL GetFileVersionInfoW(LPCWSTR, DWORD, DWORD, PVOID); 152 DWORD VerLanguageNameA(DWORD, LPSTR, DWORD); 153 DWORD VerLanguageNameW(DWORD, LPWSTR, DWORD); 154 BOOL VerQueryValueA(LPCVOID, LPCSTR, LPVOID*, PUINT); 155 BOOL VerQueryValueW(LPCVOID, LPCWSTR, LPVOID*, PUINT); 156 } 157 158 version (Unicode) { 159 alias VerFindFileW VerFindFile; 160 alias VerQueryValueW VerQueryValue; 161 alias VerInstallFileW VerInstallFile; 162 alias GetFileVersionInfoSizeW GetFileVersionInfoSize; 163 alias GetFileVersionInfoW GetFileVersionInfo; 164 alias VerLanguageNameW VerLanguageName; 165 alias VerQueryValueW VerQueryValue; 166 } else { 167 alias VerQueryValueA VerQueryValue; 168 alias VerFindFileA VerFindFile; 169 alias VerInstallFileA VerInstallFile; 170 alias GetFileVersionInfoSizeA GetFileVersionInfoSize; 171 alias GetFileVersionInfoA GetFileVersionInfo; 172 alias VerLanguageNameA VerLanguageName; 173 alias VerQueryValueA VerQueryValue; 174 } 175 176 177 alias VERSIONHELPERAPI = BOOL; 178 VERSIONHELPERAPI IsWindowsVersionOrGreater(WORD wMajorVersion, WORD wMinorVersion, WORD wServicePackMajor) 179 { 180 OSVERSIONINFOEXW osvi; 181 const DWORDLONG dwlConditionMask = VerSetConditionMask( 182 VerSetConditionMask( 183 VerSetConditionMask( 184 0, VER_MAJORVERSION, VER_GREATER_EQUAL), 185 VER_MINORVERSION, VER_GREATER_EQUAL), 186 VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); 187 osvi.dwMajorVersion = wMajorVersion; 188 osvi.dwMinorVersion = wMinorVersion; 189 osvi.wServicePackMajor = wServicePackMajor; 190 191 return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != FALSE; 192 } 193 194 VERSIONHELPERAPI 195 IsWindowsXPOrGreater() 196 { 197 return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINXP), LOBYTE(_WIN32_WINNT_WINXP), 0); 198 } 199 200 VERSIONHELPERAPI 201 IsWindowsXPSP1OrGreater() 202 { 203 return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINXP), LOBYTE(_WIN32_WINNT_WINXP), 1); 204 } 205 206 VERSIONHELPERAPI 207 IsWindowsXPSP2OrGreater() 208 { 209 return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINXP), LOBYTE(_WIN32_WINNT_WINXP), 2); 210 } 211 212 VERSIONHELPERAPI 213 IsWindowsXPSP3OrGreater() 214 { 215 return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINXP), LOBYTE(_WIN32_WINNT_WINXP), 3); 216 } 217 218 VERSIONHELPERAPI 219 IsWindowsVistaOrGreater() 220 { 221 return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_VISTA), LOBYTE(_WIN32_WINNT_VISTA), 0); 222 } 223 224 VERSIONHELPERAPI 225 IsWindowsVistaSP1OrGreater() 226 { 227 return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_VISTA), LOBYTE(_WIN32_WINNT_VISTA), 1); 228 } 229 230 VERSIONHELPERAPI 231 IsWindowsVistaSP2OrGreater() 232 { 233 return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_VISTA), LOBYTE(_WIN32_WINNT_VISTA), 2); 234 } 235 236 VERSIONHELPERAPI 237 IsWindows7OrGreater() 238 { 239 return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN7), LOBYTE(_WIN32_WINNT_WIN7), 0); 240 } 241 242 VERSIONHELPERAPI 243 IsWindows7SP1OrGreater() 244 { 245 return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN7), LOBYTE(_WIN32_WINNT_WIN7), 1); 246 } 247 248 VERSIONHELPERAPI 249 IsWindows8OrGreater() 250 { 251 return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN8), LOBYTE(_WIN32_WINNT_WIN8), 0); 252 } 253 254 VERSIONHELPERAPI 255 IsWindows8Point1OrGreater() 256 { 257 return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINBLUE), LOBYTE(_WIN32_WINNT_WINBLUE), 0); 258 } 259 260 VERSIONHELPERAPI 261 IsWindows10OrGreater() 262 { 263 return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN10), LOBYTE(_WIN32_WINNT_WIN10), 0); 264 } 265 266 267 VERSIONHELPERAPI 268 IsWindowsServer() 269 { 270 OSVERSIONINFOEXW osvi = { OSVERSIONINFOEXW.sizeof, 0, 0, 0, 0, [0], 0, 0, 0, VER_NT_WORKSTATION }; 271 const DWORDLONG dwlConditionMask = VerSetConditionMask( 0, VER_PRODUCT_TYPE, VER_EQUAL ); 272 273 return !VerifyVersionInfoW(&osvi, VER_PRODUCT_TYPE, dwlConditionMask); 274 }