winegstreamer: Move the "flip" field to struct wg_parser_stream.
[wine/zf.git] / dlls / ntdll / version.c
blob740d8403f5ed4b200b004b16728c22593fc04343
1 /*
2 * Windows and DOS version functions
4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998 Patrik Stridvall
6 * Copyright 1998, 2003 Andreas Mohr
7 * Copyright 1997, 2003 Alexandre Julliard
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include <string.h>
25 #include <stdlib.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include "ntstatus.h"
29 #define WIN32_NO_STATUS
30 #include "windef.h"
31 #include "wine/debug.h"
32 #include "ntdll_misc.h"
33 #include "ddk/wdm.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(ver);
37 typedef enum
39 WIN20, /* Windows 2.0 */
40 WIN30, /* Windows 3.0 */
41 WIN31, /* Windows 3.1 */
42 WIN95, /* Windows 95 */
43 WIN98, /* Windows 98 */
44 WINME, /* Windows Me */
45 NT351, /* Windows NT 3.51 */
46 NT40, /* Windows NT 4.0 */
47 NT2K, /* Windows 2000 */
48 WINXP, /* Windows XP */
49 WINXP64, /* Windows XP 64-bit */
50 WIN2K3, /* Windows 2003 */
51 WINVISTA,/* Windows Vista */
52 WIN2K8, /* Windows 2008 */
53 WIN2K8R2,/* Windows 2008 R2 */
54 WIN7, /* Windows 7 */
55 WIN8, /* Windows 8 */
56 WIN81, /* Windows 8.1 */
57 WIN10, /* Windows 10 */
58 NB_WINDOWS_VERSIONS
59 } WINDOWS_VERSION;
61 /* FIXME: compare values below with original and fix.
62 * An *excellent* win9x version page (ALL versions !)
63 * can be found at www.mdgx.com/ver.htm */
64 static const RTL_OSVERSIONINFOEXW VersionData[NB_WINDOWS_VERSIONS] =
66 /* WIN20 FIXME: verify values */
68 sizeof(RTL_OSVERSIONINFOEXW), 2, 0, 0, VER_PLATFORM_WIN32s,
69 L"Win32s 1.3", 0, 0, 0, 0, 0
71 /* WIN30 FIXME: verify values */
73 sizeof(RTL_OSVERSIONINFOEXW), 3, 0, 0, VER_PLATFORM_WIN32s,
74 L"Win32s 1.3", 0, 0, 0, 0, 0
76 /* WIN31 */
78 sizeof(RTL_OSVERSIONINFOEXW), 3, 10, 0, VER_PLATFORM_WIN32s,
79 L"Win32s 1.3", 0, 0, 0, 0, 0
81 /* WIN95 */
83 /* Win95: 4, 0, 0x40003B6, ""
84 * Win95sp1: 4, 0, 0x40003B6, " A " (according to doc)
85 * Win95osr2: 4, 0, 0x4000457, " B " (according to doc)
86 * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
87 * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
88 * Win95a/b can be discerned via regkey SubVersionNumber
90 sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x40003B6, VER_PLATFORM_WIN32_WINDOWS,
91 L"", 0, 0, 0, 0, 0
93 /* WIN98 (second edition) */
95 /* Win98: 4, 10, 0x40A07CE, " " 4.10.1998
96 * Win98SE: 4, 10, 0x40A08AE, " A " 4.10.2222
98 sizeof(RTL_OSVERSIONINFOEXW), 4, 10, 0x40A08AE, VER_PLATFORM_WIN32_WINDOWS,
99 L" A ", 0, 0, 0, 0, 0
101 /* WINME */
103 sizeof(RTL_OSVERSIONINFOEXW), 4, 90, 0x45A0BB8, VER_PLATFORM_WIN32_WINDOWS,
104 L" ", 0, 0, 0, 0, 0
106 /* NT351 */
108 sizeof(RTL_OSVERSIONINFOEXW), 3, 51, 0x421, VER_PLATFORM_WIN32_NT,
109 L"Service Pack 5", 5, 0, 0, VER_NT_WORKSTATION, 0
111 /* NT40 */
113 sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x565, VER_PLATFORM_WIN32_NT,
114 L"Service Pack 6a", 6, 0, 0, VER_NT_WORKSTATION, 0
116 /* NT2K */
118 sizeof(RTL_OSVERSIONINFOEXW), 5, 0, 0x893, VER_PLATFORM_WIN32_NT,
119 L"Service Pack 4", 4, 0, 0, VER_NT_WORKSTATION,
120 30 /* FIXME: Great, a reserved field with a value! */
122 /* WINXP */
124 sizeof(RTL_OSVERSIONINFOEXW), 5, 1, 0xA28, VER_PLATFORM_WIN32_NT,
125 L"Service Pack 3", 3, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION,
126 30 /* FIXME: Great, a reserved field with a value! */
128 /* WINXP64 */
130 sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
131 L"Service Pack 2", 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
133 /* WIN2K3 */
135 sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
136 L"Service Pack 2", 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
138 /* WINVISTA */
140 sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1772, VER_PLATFORM_WIN32_NT,
141 L"Service Pack 2", 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
143 /* WIN2K8 */
145 sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1772, VER_PLATFORM_WIN32_NT,
146 L"Service Pack 2", 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
148 /* WIN7 */
150 sizeof(RTL_OSVERSIONINFOEXW), 6, 1, 0x1DB1, VER_PLATFORM_WIN32_NT,
151 L"Service Pack 1", 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
153 /* WIN2K8R2 */
155 sizeof(RTL_OSVERSIONINFOEXW), 6, 1, 0x1DB1, VER_PLATFORM_WIN32_NT,
156 L"Service Pack 1", 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
158 /* WIN8 */
160 sizeof(RTL_OSVERSIONINFOEXW), 6, 2, 0x23F0, VER_PLATFORM_WIN32_NT,
161 L"", 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
163 /* WIN81 */
165 sizeof(RTL_OSVERSIONINFOEXW), 6, 3, 0x2580, VER_PLATFORM_WIN32_NT,
166 L"", 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
168 /* WIN10 */
170 sizeof(RTL_OSVERSIONINFOEXW), 10, 0, 0x4563, VER_PLATFORM_WIN32_NT,
171 L"", 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
176 static const struct { WCHAR name[12]; WINDOWS_VERSION ver; } version_names[] =
178 { L"win20", WIN20 },
179 { L"win30", WIN30 },
180 { L"win31", WIN31 },
181 { L"win95", WIN95 },
182 { L"win98", WIN98 },
183 { L"winme", WINME },
184 { L"nt351", NT351 },
185 { L"nt40", NT40 },
186 { L"win2000", NT2K },
187 { L"win2k", NT2K },
188 { L"nt2k", NT2K },
189 { L"nt2000", NT2K },
190 { L"winxp", WINXP },
191 { L"winxp64", WINXP64 },
192 { L"win2003", WIN2K3 },
193 { L"win2k3", WIN2K3 },
194 { L"vista", WINVISTA },
195 { L"winvista", WINVISTA },
196 { L"win2008", WIN2K8 },
197 { L"win2k8", WIN2K8 },
198 { L"win2008r2", WIN2K8R2 },
199 { L"win2k8r2", WIN2K8R2 },
200 { L"win7", WIN7 },
201 { L"win8", WIN8 },
202 { L"win81", WIN81 },
203 { L"win10", WIN10 },
207 /* initialized to null so that we crash if we try to retrieve the version too early at startup */
208 static const RTL_OSVERSIONINFOEXW *current_version;
211 /**********************************************************************
212 * get_nt_registry_version
214 * Fetch the version information from the NT-style registry keys.
216 static BOOL get_nt_registry_version( RTL_OSVERSIONINFOEXW *version )
218 OBJECT_ATTRIBUTES attr;
219 UNICODE_STRING nameW, valueW;
220 HANDLE hkey, hkey2;
221 char tmp[64];
222 DWORD count;
223 BOOL ret = FALSE;
224 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
226 attr.Length = sizeof(attr);
227 attr.RootDirectory = 0;
228 attr.ObjectName = &nameW;
229 attr.Attributes = 0;
230 attr.SecurityDescriptor = NULL;
231 attr.SecurityQualityOfService = NULL;
232 RtlInitUnicodeString( &nameW, L"Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion" );
234 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
236 memset( version, 0, sizeof(*version) );
238 RtlInitUnicodeString( &valueW, L"CurrentVersion" );
239 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
241 WCHAR *p, *str = (WCHAR *)info->Data;
242 str[info->DataLength / sizeof(WCHAR)] = 0;
243 p = wcschr( str, '.' );
244 if (p)
246 *p++ = 0;
247 version->dwMinorVersion = wcstoul( p, NULL, 10 );
249 version->dwMajorVersion = wcstoul( str, NULL, 10 );
252 if (version->dwMajorVersion) /* we got the main version, now fetch the other fields */
254 ret = TRUE;
255 version->dwPlatformId = VER_PLATFORM_WIN32_NT;
257 /* get build number */
259 RtlInitUnicodeString( &valueW, L"CurrentBuildNumber" );
260 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
262 WCHAR *str = (WCHAR *)info->Data;
263 str[info->DataLength / sizeof(WCHAR)] = 0;
264 version->dwBuildNumber = wcstoul( str, NULL, 10 );
267 /* get version description */
269 RtlInitUnicodeString( &valueW, L"CSDVersion" );
270 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
272 DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
273 memcpy( version->szCSDVersion, info->Data, len );
274 version->szCSDVersion[len / sizeof(WCHAR)] = 0;
277 /* get service pack version */
279 RtlInitUnicodeString( &nameW, L"Machine\\System\\CurrentControlSet\\Control\\Windows" );
280 if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
282 RtlInitUnicodeString( &valueW, L"CSDVersion" );
283 if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
285 if (info->DataLength >= sizeof(DWORD))
287 DWORD dw = *(DWORD *)info->Data;
288 version->wServicePackMajor = LOWORD(dw) >> 8;
289 version->wServicePackMinor = LOWORD(dw) & 0xff;
292 NtClose( hkey2 );
295 /* get product type */
297 RtlInitUnicodeString( &nameW, L"Machine\\System\\CurrentControlSet\\Control\\ProductOptions" );
298 if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
300 RtlInitUnicodeString( &valueW, L"ProductType" );
301 if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
303 WCHAR *str = (WCHAR *)info->Data;
304 str[info->DataLength / sizeof(WCHAR)] = 0;
305 if (!wcsicmp( str, L"WinNT" )) version->wProductType = VER_NT_WORKSTATION;
306 else if (!wcsicmp( str, L"LanmanNT" )) version->wProductType = VER_NT_DOMAIN_CONTROLLER;
307 else if (!wcsicmp( str, L"ServerNT" )) version->wProductType = VER_NT_SERVER;
309 NtClose( hkey2 );
312 /* FIXME: get wSuiteMask */
315 NtClose( hkey );
316 return ret;
320 /**********************************************************************
321 * get_win9x_registry_version
323 * Fetch the version information from the Win9x-style registry keys.
325 static BOOL get_win9x_registry_version( RTL_OSVERSIONINFOEXW *version )
327 OBJECT_ATTRIBUTES attr;
328 UNICODE_STRING nameW, valueW;
329 HANDLE hkey;
330 char tmp[64];
331 DWORD count;
332 BOOL ret = FALSE;
333 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
335 attr.Length = sizeof(attr);
336 attr.RootDirectory = 0;
337 attr.ObjectName = &nameW;
338 attr.Attributes = 0;
339 attr.SecurityDescriptor = NULL;
340 attr.SecurityQualityOfService = NULL;
341 RtlInitUnicodeString( &nameW, L"Machine\\Software\\Microsoft\\Windows\\CurrentVersion" );
343 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
345 memset( version, 0, sizeof(*version) );
347 RtlInitUnicodeString( &valueW, L"VersionNumber" );
348 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
350 WCHAR *p, *str = (WCHAR *)info->Data;
351 str[info->DataLength / sizeof(WCHAR)] = 0;
352 p = wcschr( str, '.' );
353 if (p) *p++ = 0;
354 version->dwMajorVersion = wcstoul( str, NULL, 10 );
355 if (p)
357 str = p;
358 p = wcschr( str, '.' );
359 if (p)
361 *p++ = 0;
362 version->dwBuildNumber = wcstoul( p, NULL, 10 );
364 version->dwMinorVersion = wcstoul( str, NULL, 10 );
366 /* build number contains version too on Win9x */
367 version->dwBuildNumber |= MAKEWORD( version->dwMinorVersion, version->dwMajorVersion ) << 16;
370 if (version->dwMajorVersion) /* we got the main version, now fetch the other fields */
372 ret = TRUE;
373 version->dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;
375 RtlInitUnicodeString( &valueW, L"SubVersionNumber" );
376 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
378 DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
379 memcpy( version->szCSDVersion, info->Data, len );
380 version->szCSDVersion[len / sizeof(WCHAR)] = 0;
384 NtClose( hkey );
385 return ret;
389 /**********************************************************************
390 * parse_win_version
392 * Parse the contents of the Version key.
394 static BOOL parse_win_version( HANDLE hkey )
396 UNICODE_STRING valueW;
397 WCHAR *name, tmp[64];
398 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
399 DWORD i, count;
401 RtlInitUnicodeString( &valueW, L"Version" );
402 if (NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp) - sizeof(WCHAR), &count ))
403 return FALSE;
405 name = (WCHAR *)info->Data;
406 name[info->DataLength / sizeof(WCHAR)] = 0;
408 for (i = 0; i < ARRAY_SIZE(version_names); i++)
410 if (wcscmp( version_names[i].name, name )) continue;
411 current_version = &VersionData[version_names[i].ver];
412 TRACE( "got win version %s\n", debugstr_w(version_names[i].name) );
413 return TRUE;
416 ERR( "Invalid Windows version value %s specified in config file.\n", debugstr_w(name) );
417 return FALSE;
421 /**********************************************************************
422 * version_init
424 void version_init(void)
426 OBJECT_ATTRIBUTES attr;
427 UNICODE_STRING nameW;
428 HANDLE root, hkey, config_key;
429 BOOL got_win_ver = FALSE;
430 const WCHAR *p, *appname = NtCurrentTeb()->Peb->ProcessParameters->ImagePathName.Buffer;
431 WCHAR appversion[MAX_PATH+20];
433 current_version = &VersionData[WIN7];
435 RtlOpenCurrentUser( KEY_ALL_ACCESS, &root );
436 attr.Length = sizeof(attr);
437 attr.RootDirectory = root;
438 attr.ObjectName = &nameW;
439 attr.Attributes = 0;
440 attr.SecurityDescriptor = NULL;
441 attr.SecurityQualityOfService = NULL;
442 RtlInitUnicodeString( &nameW, L"Software\\Wine" );
444 /* @@ Wine registry key: HKCU\Software\Wine */
445 if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) config_key = 0;
446 NtClose( root );
447 if (!config_key) goto done;
449 /* open AppDefaults\\appname key */
451 if ((p = wcsrchr( appname, '/' ))) appname = p + 1;
452 if ((p = wcsrchr( appname, '\\' ))) appname = p + 1;
454 wcscpy( appversion, L"AppDefaults\\" );
455 wcscat( appversion, appname );
456 RtlInitUnicodeString( &nameW, appversion );
457 attr.RootDirectory = config_key;
459 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe */
460 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
462 TRACE( "getting version from %s\n", debugstr_w(appversion) );
463 got_win_ver = parse_win_version( hkey );
464 NtClose( hkey );
467 if (!got_win_ver)
469 TRACE( "getting default version\n" );
470 got_win_ver = parse_win_version( config_key );
472 NtClose( config_key );
474 done:
475 if (!got_win_ver)
477 static RTL_OSVERSIONINFOEXW registry_version;
479 TRACE( "getting registry version\n" );
480 if (get_nt_registry_version( &registry_version ) ||
481 get_win9x_registry_version( &registry_version ))
482 current_version = &registry_version;
486 NtCurrentTeb()->Peb->OSMajorVersion = current_version->dwMajorVersion;
487 NtCurrentTeb()->Peb->OSMinorVersion = current_version->dwMinorVersion;
488 NtCurrentTeb()->Peb->OSBuildNumber = current_version->dwBuildNumber;
489 NtCurrentTeb()->Peb->OSPlatformId = current_version->dwPlatformId;
491 TRACE( "got %d.%d platform %d build %x name %s service pack %d.%d product %d\n",
492 current_version->dwMajorVersion, current_version->dwMinorVersion,
493 current_version->dwPlatformId, current_version->dwBuildNumber,
494 debugstr_w(current_version->szCSDVersion),
495 current_version->wServicePackMajor, current_version->wServicePackMinor,
496 current_version->wProductType );
499 /***********************************************************************
500 * RtlGetProductInfo (NTDLL.@)
502 * Gives info about the current Windows product type, in a format compatible
503 * with the given Windows version
505 * Returns TRUE if the input is valid, FALSE otherwise
507 BOOLEAN WINAPI RtlGetProductInfo(DWORD dwOSMajorVersion, DWORD dwOSMinorVersion, DWORD dwSpMajorVersion,
508 DWORD dwSpMinorVersion, PDWORD pdwReturnedProductType)
510 TRACE("(%d, %d, %d, %d, %p)\n", dwOSMajorVersion, dwOSMinorVersion,
511 dwSpMajorVersion, dwSpMinorVersion, pdwReturnedProductType);
513 if (!pdwReturnedProductType)
514 return FALSE;
516 if (dwOSMajorVersion < 6)
518 *pdwReturnedProductType = PRODUCT_UNDEFINED;
519 return FALSE;
522 if (current_version->wProductType == VER_NT_WORKSTATION)
523 *pdwReturnedProductType = PRODUCT_ULTIMATE_N;
524 else
525 *pdwReturnedProductType = PRODUCT_STANDARD_SERVER;
527 return TRUE;
530 /***********************************************************************
531 * RtlGetVersion (NTDLL.@)
533 NTSTATUS WINAPI RtlGetVersion( RTL_OSVERSIONINFOEXW *info )
535 info->dwMajorVersion = current_version->dwMajorVersion;
536 info->dwMinorVersion = current_version->dwMinorVersion;
537 info->dwBuildNumber = current_version->dwBuildNumber;
538 info->dwPlatformId = current_version->dwPlatformId;
539 wcscpy( info->szCSDVersion, current_version->szCSDVersion );
540 if(info->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
542 info->wServicePackMajor = current_version->wServicePackMajor;
543 info->wServicePackMinor = current_version->wServicePackMinor;
544 info->wSuiteMask = current_version->wSuiteMask;
545 info->wProductType = current_version->wProductType;
547 return STATUS_SUCCESS;
551 /******************************************************************************
552 * RtlGetNtVersionNumbers (NTDLL.@)
554 * Get the version numbers of the run time library.
556 * PARAMS
557 * major [O] Destination for the Major version
558 * minor [O] Destination for the Minor version
559 * build [O] Destination for the Build version
561 * RETURNS
562 * Nothing.
564 * NOTES
565 * Introduced in Windows XP (NT5.1)
567 void WINAPI RtlGetNtVersionNumbers( LPDWORD major, LPDWORD minor, LPDWORD build )
569 if (major) *major = current_version->dwMajorVersion;
570 if (minor) *minor = current_version->dwMinorVersion;
571 /* FIXME: Does anybody know the real formula? */
572 if (build) *build = (0xF0000000 | current_version->dwBuildNumber);
576 /******************************************************************************
577 * RtlGetNtProductType (NTDLL.@)
579 BOOLEAN WINAPI RtlGetNtProductType( LPDWORD type )
581 if (type) *type = current_version->wProductType;
582 return TRUE;
585 static inline UCHAR version_update_condition(UCHAR *last_condition, UCHAR condition)
587 switch (*last_condition)
589 case 0:
590 *last_condition = condition;
591 break;
592 case VER_EQUAL:
593 if (condition >= VER_EQUAL && condition <= VER_LESS_EQUAL)
595 *last_condition = condition;
596 return condition;
598 break;
599 case VER_GREATER:
600 case VER_GREATER_EQUAL:
601 if (condition >= VER_EQUAL && condition <= VER_GREATER_EQUAL)
602 return condition;
603 break;
604 case VER_LESS:
605 case VER_LESS_EQUAL:
606 if (condition == VER_EQUAL || (condition >= VER_LESS && condition <= VER_LESS_EQUAL))
607 return condition;
608 break;
610 if (!condition) *last_condition |= 0x10;
611 return *last_condition & 0xf;
614 static inline NTSTATUS version_compare_values(ULONG left, ULONG right, UCHAR condition)
616 switch (condition) {
617 case VER_EQUAL:
618 if (left != right) return STATUS_REVISION_MISMATCH;
619 break;
620 case VER_GREATER:
621 if (left <= right) return STATUS_REVISION_MISMATCH;
622 break;
623 case VER_GREATER_EQUAL:
624 if (left < right) return STATUS_REVISION_MISMATCH;
625 break;
626 case VER_LESS:
627 if (left >= right) return STATUS_REVISION_MISMATCH;
628 break;
629 case VER_LESS_EQUAL:
630 if (left > right) return STATUS_REVISION_MISMATCH;
631 break;
632 default:
633 return STATUS_REVISION_MISMATCH;
635 return STATUS_SUCCESS;
638 /******************************************************************************
639 * RtlVerifyVersionInfo (NTDLL.@)
641 NTSTATUS WINAPI RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW *info,
642 DWORD dwTypeMask, DWORDLONG dwlConditionMask )
644 RTL_OSVERSIONINFOEXW ver;
645 NTSTATUS status;
647 TRACE("(%p,0x%x,0x%s)\n", info, dwTypeMask, wine_dbgstr_longlong(dwlConditionMask));
649 ver.dwOSVersionInfoSize = sizeof(ver);
650 if ((status = RtlGetVersion( &ver )) != STATUS_SUCCESS) return status;
652 if(!(dwTypeMask && dwlConditionMask)) return STATUS_INVALID_PARAMETER;
654 if(dwTypeMask & VER_PRODUCT_TYPE)
656 status = version_compare_values(ver.wProductType, info->wProductType, dwlConditionMask >> 7*3 & 0x07);
657 if (status != STATUS_SUCCESS)
658 return status;
660 if(dwTypeMask & VER_SUITENAME)
661 switch(dwlConditionMask >> 6*3 & 0x07)
663 case VER_AND:
664 if((info->wSuiteMask & ver.wSuiteMask) != info->wSuiteMask)
665 return STATUS_REVISION_MISMATCH;
666 break;
667 case VER_OR:
668 if(!(info->wSuiteMask & ver.wSuiteMask) && info->wSuiteMask)
669 return STATUS_REVISION_MISMATCH;
670 break;
671 default:
672 return STATUS_INVALID_PARAMETER;
674 if(dwTypeMask & VER_PLATFORMID)
676 status = version_compare_values(ver.dwPlatformId, info->dwPlatformId, dwlConditionMask >> 3*3 & 0x07);
677 if (status != STATUS_SUCCESS)
678 return status;
680 if(dwTypeMask & VER_BUILDNUMBER)
682 status = version_compare_values(ver.dwBuildNumber, info->dwBuildNumber, dwlConditionMask >> 2*3 & 0x07);
683 if (status != STATUS_SUCCESS)
684 return status;
687 if(dwTypeMask & (VER_MAJORVERSION|VER_MINORVERSION|VER_SERVICEPACKMAJOR|VER_SERVICEPACKMINOR))
689 unsigned char condition, last_condition = 0;
690 BOOLEAN do_next_check = TRUE;
692 if(dwTypeMask & VER_MAJORVERSION)
694 condition = version_update_condition(&last_condition, dwlConditionMask >> 1*3 & 0x07);
695 status = version_compare_values(ver.dwMajorVersion, info->dwMajorVersion, condition);
696 do_next_check = (ver.dwMajorVersion == info->dwMajorVersion) &&
697 ((condition >= VER_EQUAL) && (condition <= VER_LESS_EQUAL));
699 if((dwTypeMask & VER_MINORVERSION) && do_next_check)
701 condition = version_update_condition(&last_condition, dwlConditionMask >> 0*3 & 0x07);
702 status = version_compare_values(ver.dwMinorVersion, info->dwMinorVersion, condition);
703 do_next_check = (ver.dwMinorVersion == info->dwMinorVersion) &&
704 ((condition >= VER_EQUAL) && (condition <= VER_LESS_EQUAL));
706 if((dwTypeMask & VER_SERVICEPACKMAJOR) && do_next_check)
708 condition = version_update_condition(&last_condition, dwlConditionMask >> 5*3 & 0x07);
709 status = version_compare_values(ver.wServicePackMajor, info->wServicePackMajor, condition);
710 do_next_check = (ver.wServicePackMajor == info->wServicePackMajor) &&
711 ((condition >= VER_EQUAL) && (condition <= VER_LESS_EQUAL));
713 if((dwTypeMask & VER_SERVICEPACKMINOR) && do_next_check)
715 condition = version_update_condition(&last_condition, dwlConditionMask >> 4*3 & 0x07);
716 status = version_compare_values(ver.wServicePackMinor, info->wServicePackMinor, condition);
719 if (status != STATUS_SUCCESS)
720 return status;
723 return STATUS_SUCCESS;