The OpenD Programming Language

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