2013-03-12 15:48:47 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2013 Birunthan Mohanathas
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2014-01-05 11:21:00 +00:00
|
|
|
#include "StdAfx.h"
|
2013-03-12 15:48:47 +00:00
|
|
|
#include "Platform.h"
|
|
|
|
|
|
|
|
namespace Platform {
|
|
|
|
|
2014-02-13 16:19:54 +00:00
|
|
|
LPCWSTR GetPlatformName()
|
2014-02-11 19:17:05 +00:00
|
|
|
{
|
2014-02-13 17:21:38 +00:00
|
|
|
const bool isServer = IsWindowsServer();
|
2014-02-13 08:16:42 +00:00
|
|
|
|
2014-02-13 16:19:54 +00:00
|
|
|
// Note: Place newer versions at the top.
|
2014-02-13 08:16:42 +00:00
|
|
|
|
2014-02-13 17:21:38 +00:00
|
|
|
if (IsWindows8Point1OrGreater()) return isServer ? L"Windows Server 2012 R2" : L"Windows 8.1";
|
|
|
|
if (IsWindows8OrGreater()) return isServer ? L"Windows Server 2012" : L"Windows 8";
|
|
|
|
if (IsWindows7OrGreater()) return isServer ? L"Windows Server 2008 R2" : L"Windows 7";
|
|
|
|
if (IsWindowsVistaOrGreater()) return isServer ? L"Windows Server 2008" : L"Windows Vista";
|
|
|
|
if (IsWindowsXPOrGreater()) return isServer ? L"Windows Server 2003" : L"Windows XP";
|
2014-02-13 08:16:42 +00:00
|
|
|
|
2014-02-13 16:19:54 +00:00
|
|
|
return L"Unknown";
|
|
|
|
}
|
2014-02-13 08:16:42 +00:00
|
|
|
|
2014-02-13 16:57:08 +00:00
|
|
|
std::wstring GetPlatformFriendlyName()
|
2014-02-13 16:19:54 +00:00
|
|
|
{
|
2014-02-13 16:57:08 +00:00
|
|
|
std::wstring name;
|
2014-02-13 17:21:38 +00:00
|
|
|
|
|
|
|
WCHAR buffer[256];
|
|
|
|
DWORD size = _countof(buffer);
|
2014-02-13 08:16:42 +00:00
|
|
|
|
2014-02-13 16:19:54 +00:00
|
|
|
HKEY hKey;
|
|
|
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
if (RegQueryValueEx(hKey, L"ProductName", nullptr, nullptr, (LPBYTE)buffer, (LPDWORD)&size) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
name += buffer;
|
|
|
|
name += L' ';
|
2014-02-13 17:21:38 +00:00
|
|
|
name += Is64BitWindows() ? L"64" : L"32";
|
2014-02-13 16:19:54 +00:00
|
|
|
name += L"-bit";
|
2014-02-13 08:16:42 +00:00
|
|
|
|
2014-02-13 17:21:38 +00:00
|
|
|
size = _countof(buffer);
|
|
|
|
if (RegQueryValueEx(hKey, L"CurrentBuildNumber", nullptr, nullptr, (LPBYTE)buffer, (LPDWORD)&size) == ERROR_SUCCESS ||
|
|
|
|
RegQueryValueEx(hKey, L"CurrentBuild", nullptr, nullptr, (LPBYTE)buffer, (LPDWORD)&size) == ERROR_SUCCESS)
|
2014-02-11 19:17:05 +00:00
|
|
|
{
|
2014-02-13 16:19:54 +00:00
|
|
|
name += L" (build ";
|
|
|
|
name += buffer;
|
|
|
|
name += L')';
|
2014-02-11 19:17:05 +00:00
|
|
|
}
|
2014-02-13 08:16:42 +00:00
|
|
|
|
2014-02-13 17:21:38 +00:00
|
|
|
size = _countof(buffer);
|
2014-02-13 16:19:54 +00:00
|
|
|
if (RegQueryValueEx(hKey, L"CSDVersion", nullptr, nullptr, (LPBYTE)buffer, (LPDWORD)&size) == ERROR_SUCCESS)
|
2014-02-11 19:17:05 +00:00
|
|
|
{
|
2014-02-13 16:19:54 +00:00
|
|
|
name += L' ';
|
|
|
|
name += buffer;
|
2014-02-11 19:17:05 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-13 16:19:54 +00:00
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
2014-02-11 19:17:05 +00:00
|
|
|
}
|
2014-02-13 16:19:54 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
name = L"Windows version unknown";
|
|
|
|
}
|
|
|
|
|
2014-02-13 16:57:08 +00:00
|
|
|
return name;
|
2014-02-11 19:17:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-02-13 17:21:38 +00:00
|
|
|
** Returns |true| if running on 64-bit Windows.
|
2014-02-11 19:17:05 +00:00
|
|
|
*/
|
2014-02-13 17:21:38 +00:00
|
|
|
bool Is64BitWindows()
|
2014-02-11 19:17:05 +00:00
|
|
|
{
|
|
|
|
#if _WIN64
|
|
|
|
return true;
|
2014-02-13 17:21:38 +00:00
|
|
|
#endif
|
2014-02-11 19:17:05 +00:00
|
|
|
|
2014-02-28 16:35:09 +00:00
|
|
|
auto isWow64Process = (decltype(IsWow64Process)*)GetProcAddress(GetModuleHandle(L"kernel32"), "IsWow64Process");
|
2014-02-13 17:21:38 +00:00
|
|
|
if (isWow64Process)
|
2014-02-11 19:17:05 +00:00
|
|
|
{
|
2014-02-13 17:21:38 +00:00
|
|
|
BOOL isWow64 = FALSE;
|
|
|
|
return isWow64Process(GetCurrentProcess(), &isWow64) && isWow64;
|
2014-02-11 19:17:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-12 15:48:47 +00:00
|
|
|
} // namespace Platform
|