diff options
Diffstat (limited to 'src/VBox/Runtime/r3/win/RTSystemQueryOSInfo-win.cpp')
-rw-r--r-- | src/VBox/Runtime/r3/win/RTSystemQueryOSInfo-win.cpp | 228 |
1 files changed, 35 insertions, 193 deletions
diff --git a/src/VBox/Runtime/r3/win/RTSystemQueryOSInfo-win.cpp b/src/VBox/Runtime/r3/win/RTSystemQueryOSInfo-win.cpp index 50dee1aa..28c34625 100644 --- a/src/VBox/Runtime/r3/win/RTSystemQueryOSInfo-win.cpp +++ b/src/VBox/Runtime/r3/win/RTSystemQueryOSInfo-win.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -27,9 +27,11 @@ /******************************************************************************* * Header Files * *******************************************************************************/ +#include "internal/iprt.h" #include <Windows.h> #include <WinUser.h> +#include "internal-r3-win.h" #include <iprt/system.h> #include <iprt/assert.h> #include <iprt/string.h> @@ -39,35 +41,6 @@ /******************************************************************************* * Structures and Typedefs * *******************************************************************************/ -/** - * Windows OS type as determined by rtSystemWinOSType(). - */ -typedef enum RTWINOSTYPE -{ - kRTWinOSType_UNKNOWN = 0, - kRTWinOSType_9XFIRST = 1, - kRTWinOSType_95 = kRTWinOSType_9XFIRST, - kRTWinOSType_95SP1, - kRTWinOSType_95OSR2, - kRTWinOSType_98, - kRTWinOSType_98SP1, - kRTWinOSType_98SE, - kRTWinOSType_ME, - kRTWinOSType_9XLAST = 99, - kRTWinOSType_NTFIRST = 100, - kRTWinOSType_NT31 = kRTWinOSType_NTFIRST, - kRTWinOSType_NT351, - kRTWinOSType_NT4, - kRTWinOSType_2K, - kRTWinOSType_XP, - kRTWinOSType_2003, - kRTWinOSType_VISTA, - kRTWinOSType_2008, - kRTWinOSType_7, - kRTWinOSType_8, - kRTWinOSType_NT_UNKNOWN = 199, - kRTWinOSType_NT_LAST = kRTWinOSType_UNKNOWN -} RTWINOSTYPE; /** * These are the PRODUCT_* defines found in the Vista Platform SDK and returned @@ -111,112 +84,6 @@ typedef enum RTWINPRODTYPE /** - * Translates OSVERSIONINOFEX into a Windows OS type. - * - * @returns The Windows OS type. - * @param pOSInfoEx The OS info returned by Windows. - * - * @remarks This table has been assembled from Usenet postings, personal - * observations, and reading other people's code. Please feel - * free to add to it or correct it. - * <pre> - dwPlatFormID dwMajorVersion dwMinorVersion dwBuildNumber -95 1 4 0 950 -95 SP1 1 4 0 >950 && <=1080 -95 OSR2 1 4 <10 >1080 -98 1 4 10 1998 -98 SP1 1 4 10 >1998 && <2183 -98 SE 1 4 10 >=2183 -ME 1 4 90 3000 - -NT 3.51 2 3 51 1057 -NT 4 2 4 0 1381 -2000 2 5 0 2195 -XP 2 5 1 2600 -2003 2 5 2 3790 -Vista 2 6 0 - -CE 1.0 3 1 0 -CE 2.0 3 2 0 -CE 2.1 3 2 1 -CE 3.0 3 3 0 -</pre> - */ -static RTWINOSTYPE rtSystemWinOSType(OSVERSIONINFOEX const *pOSInfoEx) -{ - RTWINOSTYPE enmVer = kRTWinOSType_UNKNOWN; - BYTE const bProductType = pOSInfoEx->wProductType; - DWORD const dwPlatformId = pOSInfoEx->dwPlatformId; - DWORD const dwMinorVersion = pOSInfoEx->dwMinorVersion; - DWORD const dwMajorVersion = pOSInfoEx->dwMajorVersion; - DWORD const dwBuildNumber = pOSInfoEx->dwBuildNumber & 0xFFFF; /* Win 9x needs this. */ - - if ( dwPlatformId == VER_PLATFORM_WIN32_WINDOWS - && dwMajorVersion == 4) - { - if ( dwMinorVersion < 10 - && dwBuildNumber == 950) - enmVer = kRTWinOSType_95; - else if ( dwMinorVersion < 10 - && dwBuildNumber > 950 - && dwBuildNumber <= 1080) - enmVer = kRTWinOSType_95SP1; - else if ( dwMinorVersion < 10 - && dwBuildNumber > 1080) - enmVer = kRTWinOSType_95OSR2; - else if ( dwMinorVersion == 10 - && dwBuildNumber == 1998) - enmVer = kRTWinOSType_98; - else if ( dwMinorVersion == 10 - && dwBuildNumber > 1998 - && dwBuildNumber < 2183) - enmVer = kRTWinOSType_98SP1; - else if ( dwMinorVersion == 10 - && dwBuildNumber >= 2183) - enmVer = kRTWinOSType_98SE; - else if (dwMinorVersion == 90) - enmVer = kRTWinOSType_ME; - } - else if (dwPlatformId == VER_PLATFORM_WIN32_NT) - { - if ( dwMajorVersion == 3 - && dwMinorVersion == 51) - enmVer = kRTWinOSType_NT351; - else if ( dwMajorVersion == 4 - && dwMinorVersion == 0) - enmVer = kRTWinOSType_NT4; - else if ( dwMajorVersion == 5 - && dwMinorVersion == 0) - enmVer = kRTWinOSType_2K; - else if ( dwMajorVersion == 5 - && dwMinorVersion == 1) - enmVer = kRTWinOSType_XP; - else if ( dwMajorVersion == 5 - && dwMinorVersion == 2) - enmVer = kRTWinOSType_2003; - else if ( dwMajorVersion == 6 - && dwMinorVersion == 0) - { - if (bProductType != VER_NT_WORKSTATION) - enmVer = kRTWinOSType_2008; - else - enmVer = kRTWinOSType_VISTA; - } - else if ( dwMajorVersion == 6 - && dwMinorVersion == 1) - enmVer = kRTWinOSType_7; - else if ( dwMajorVersion == 6 - && dwMinorVersion == 2) - enmVer = kRTWinOSType_8; - else - enmVer = kRTWinOSType_NT_UNKNOWN; - } - - return enmVer; -} - - -/** * Wrapper around the GetProductInfo API. * * @returns The vista type. @@ -224,7 +91,7 @@ static RTWINOSTYPE rtSystemWinOSType(OSVERSIONINFOEX const *pOSInfoEx) static RTWINPRODTYPE rtSystemWinGetProductInfo(DWORD dwOSMajorVersion, DWORD dwOSMinorVersion, DWORD dwSpMajorVersion, DWORD dwSpMinorVersion) { BOOL (WINAPI *pfnGetProductInfo)(DWORD, DWORD, DWORD, DWORD, PDWORD); - pfnGetProductInfo = (BOOL (WINAPI *)(DWORD, DWORD, DWORD, DWORD, PDWORD))GetProcAddress(GetModuleHandle("KERNEL32.DLL"), "GetProductInfo"); + pfnGetProductInfo = (BOOL (WINAPI *)(DWORD, DWORD, DWORD, DWORD, PDWORD))GetProcAddress(GetModuleHandle("kernel32.dll"), "GetProductInfo"); if (pfnGetProductInfo) { DWORD dwProductType = kRTWinProdType_UNDEFINED; @@ -291,48 +158,21 @@ static void rtSystemWinAppendProductType(char *pszTmp) */ static int rtSystemWinQueryOSVersion(RTSYSOSINFO enmInfo, char *pszInfo, size_t cchInfo) { - int rc; - /* * Make sure it's terminated correctly in case of error. */ *pszInfo = '\0'; /* - * Query the Windows version. - * - * ASSUMES OSVERSIONINFOEX starts with the exact same layout as OSVERSIONINFO (safe). + * Check that we got the windows version at init time. */ - OSVERSIONINFOEX OSInfoEx; - memset(&OSInfoEx, '\0', sizeof(OSInfoEx)); - OSInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - if (!GetVersionEx((LPOSVERSIONINFO) &OSInfoEx)) - { - DWORD err = GetLastError(); - rc = RTErrConvertFromWin32(err); - AssertMsgFailedReturn(("err=%d\n", err), rc == VERR_BUFFER_OVERFLOW ? VERR_INTERNAL_ERROR : rc); - } - - /* Get extended version info for 2000 and later. */ - if ( OSInfoEx.dwPlatformId == VER_PLATFORM_WIN32_NT - && OSInfoEx.dwMajorVersion >= 5) - { - ZeroMemory(&OSInfoEx, sizeof(OSInfoEx)); - OSInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - if (!GetVersionEx((LPOSVERSIONINFO) &OSInfoEx)) - { - DWORD err = GetLastError(); - rc = RTErrConvertFromWin32(err); - AssertMsgFailedReturn(("err=%d\n", err), rc == VERR_BUFFER_OVERFLOW ? VERR_INTERNAL_ERROR : rc); - } - } + AssertReturn(g_WinOsInfoEx.dwOSVersionInfoSize, VERR_WRONG_ORDER); /* * Service the request. */ char szTmp[512]; szTmp[0] = '\0'; - rc = VINF_SUCCESS; switch (enmInfo) { /* @@ -340,8 +180,7 @@ static int rtSystemWinQueryOSVersion(RTSYSOSINFO enmInfo, char *pszInfo, size_t */ case RTSYSOSINFO_PRODUCT: { - RTWINOSTYPE enmVer = rtSystemWinOSType(&OSInfoEx); - switch (enmVer) + switch (g_enmWinVer) { case kRTWinOSType_95: strcpy(szTmp, "Windows 95"); break; case kRTWinOSType_95SP1: strcpy(szTmp, "Windows 95 (Service Pack 1)"); break; @@ -355,10 +194,10 @@ static int rtSystemWinQueryOSVersion(RTSYSOSINFO enmInfo, char *pszInfo, size_t case kRTWinOSType_2K: strcpy(szTmp, "Windows 2000"); break; case kRTWinOSType_XP: strcpy(szTmp, "Windows XP"); - if (OSInfoEx.wSuiteMask & VER_SUITE_PERSONAL) + if (g_WinOsInfoEx.wSuiteMask & VER_SUITE_PERSONAL) strcat(szTmp, " Home"); - if ( OSInfoEx.wProductType == VER_NT_WORKSTATION - && !(OSInfoEx.wSuiteMask & VER_SUITE_PERSONAL)) + if ( g_WinOsInfoEx.wProductType == VER_NT_WORKSTATION + && !(g_WinOsInfoEx.wSuiteMask & VER_SUITE_PERSONAL)) strcat(szTmp, " Professional"); #if 0 /** @todo fixme */ if (GetSystemMetrics(SM_MEDIACENTER)) @@ -376,15 +215,18 @@ static int rtSystemWinQueryOSVersion(RTSYSOSINFO enmInfo, char *pszInfo, size_t case kRTWinOSType_2008: strcpy(szTmp, "Windows 2008"); break; case kRTWinOSType_7: strcpy(szTmp, "Windows 7"); break; case kRTWinOSType_8: strcpy(szTmp, "Windows 8"); break; + case kRTWinOSType_81: strcpy(szTmp, "Windows 8.1"); break; case kRTWinOSType_NT_UNKNOWN: - RTStrPrintf(szTmp, sizeof(szTmp), "Unknown NT v%u.%u", OSInfoEx.dwMajorVersion, OSInfoEx.dwMinorVersion); + RTStrPrintf(szTmp, sizeof(szTmp), "Unknown NT v%u.%u", + g_WinOsInfoEx.dwMajorVersion, g_WinOsInfoEx.dwMinorVersion); break; default: AssertFailed(); case kRTWinOSType_UNKNOWN: - RTStrPrintf(szTmp, sizeof(szTmp), "Unknown %d v%u.%u", OSInfoEx.dwPlatformId, OSInfoEx.dwMajorVersion, OSInfoEx.dwMinorVersion); + RTStrPrintf(szTmp, sizeof(szTmp), "Unknown %d v%u.%u", + g_WinOsInfoEx.dwPlatformId, g_WinOsInfoEx.dwMajorVersion, g_WinOsInfoEx.dwMinorVersion); break; } break; @@ -395,8 +237,8 @@ static int rtSystemWinQueryOSVersion(RTSYSOSINFO enmInfo, char *pszInfo, size_t */ case RTSYSOSINFO_RELEASE: { - RTWINOSTYPE enmVer = rtSystemWinOSType(&OSInfoEx); - RTStrPrintf(szTmp, sizeof(szTmp), "%u.%u.%u", OSInfoEx.dwMajorVersion, OSInfoEx.dwMinorVersion, OSInfoEx.dwBuildNumber); + RTStrPrintf(szTmp, sizeof(szTmp), "%u.%u.%u", + g_WinOsInfoEx.dwMajorVersion, g_WinOsInfoEx.dwMinorVersion, g_WinOsInfoEx.dwBuildNumber); break; } @@ -406,24 +248,25 @@ static int rtSystemWinQueryOSVersion(RTSYSOSINFO enmInfo, char *pszInfo, size_t */ case RTSYSOSINFO_SERVICE_PACK: { - if (OSInfoEx.wServicePackMajor) + if (g_WinOsInfoEx.wServicePackMajor) { - if (OSInfoEx.wServicePackMinor) - RTStrPrintf(szTmp, sizeof(szTmp), "%u.%u", (unsigned)OSInfoEx.wServicePackMajor, (unsigned)OSInfoEx.wServicePackMinor); + if (g_WinOsInfoEx.wServicePackMinor) + RTStrPrintf(szTmp, sizeof(szTmp), "%u.%u", + (unsigned)g_WinOsInfoEx.wServicePackMajor, (unsigned)g_WinOsInfoEx.wServicePackMinor); else - RTStrPrintf(szTmp, sizeof(szTmp), "%u", (unsigned)OSInfoEx.wServicePackMajor); + RTStrPrintf(szTmp, sizeof(szTmp), "%u", + (unsigned)g_WinOsInfoEx.wServicePackMajor); } - else if (OSInfoEx.szCSDVersion[0]) + else if (g_WinOsInfoEx.szCSDVersion[0]) { /* just copy the entire string. */ - memcpy(szTmp, OSInfoEx.szCSDVersion, sizeof(OSInfoEx.szCSDVersion)); - szTmp[sizeof(OSInfoEx.szCSDVersion)] = '\0'; - AssertCompile(sizeof(szTmp) > sizeof(OSInfoEx.szCSDVersion)); + memcpy(szTmp, g_WinOsInfoEx.szCSDVersion, sizeof(g_WinOsInfoEx.szCSDVersion)); + szTmp[sizeof(g_WinOsInfoEx.szCSDVersion)] = '\0'; + AssertCompile(sizeof(szTmp) > sizeof(g_WinOsInfoEx.szCSDVersion)); } else { - RTWINOSTYPE enmVer = rtSystemWinOSType(&OSInfoEx); - switch (enmVer) + switch (g_enmWinVer) { case kRTWinOSType_95SP1: strcpy(szTmp, "1"); break; case kRTWinOSType_98SP1: strcpy(szTmp, "1"); break; @@ -444,15 +287,13 @@ static int rtSystemWinQueryOSVersion(RTSYSOSINFO enmInfo, char *pszInfo, size_t size_t cchTmp = strlen(szTmp); Assert(cchTmp < sizeof(szTmp)); if (cchTmp < cchInfo) - memcpy(pszInfo, szTmp, cchTmp + 1); - else { - memcpy(pszInfo, szTmp, cchInfo - 1); - pszInfo[cchInfo - 1] = '\0'; - if (RT_SUCCESS(rc)) - rc = VERR_BUFFER_OVERFLOW; + memcpy(pszInfo, szTmp, cchTmp + 1); + return VINF_SUCCESS; } - return VINF_SUCCESS; + memcpy(pszInfo, szTmp, cchInfo - 1); + pszInfo[cchInfo - 1] = '\0'; + return VERR_BUFFER_OVERFLOW; } @@ -481,7 +322,8 @@ RTDECL(int) RTSystemQueryOSInfo(RTSYSOSINFO enmInfo, char *pszInfo, size_t cchIn case RTSYSOSINFO_VERSION: default: *pszInfo = '\0'; - return VERR_NOT_SUPPORTED; } + + return VERR_NOT_SUPPORTED; } |