From ef9dc92d4d4872b06a1c35959c6e82b6b4a91231 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 4 Feb 2018 10:58:52 +0300 Subject: [PATCH] Windows --- ColumbusInfo.hpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/ColumbusInfo.hpp b/ColumbusInfo.hpp index ebdbaa2..3e3cc3e 100644 --- a/ColumbusInfo.hpp +++ b/ColumbusInfo.hpp @@ -1,9 +1,16 @@ +#ifdef _WIN32 + #define COLUMBUS_PLATFORM_WINDOWS + #include +#endif + #ifdef __linux #define COLUMBUS_PLATFORM_LINUX #include #include #endif +#include + namespace Columbus { @@ -11,6 +18,7 @@ namespace Columbus { public: static unsigned int getCPUCount(); + static unsigned int getCPUSpeed(); static unsigned long getRAMSize(); static unsigned long getRAMFree(); @@ -22,6 +30,35 @@ namespace Columbus #ifdef COLUMBUS_PLATFORM_LINUX return sysconf(_SC_NPROCESSORS_ONLN); #endif + + #ifdef COLUMBUS_PLATFORM_WINDOWS + SYSTEM_INFO sysinfo; + GetSystemInfo(&sysinfo); + return sysinfo.dwNumberOfProcessors; + #endif + } + + unsigned int Info::getCPUSpeed() + { + #ifdef COLUMBUS_PLATFORM_WINDOWS + wchar_t Buffer[_MAX_PATH]; + DWORD BufSize = _MAX_PATH; + DWORD dwMHz = _MAX_PATH; + HKEY hKey; + + long lError = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &hKey); + + if (lError != ERROR_SUCCESS) + { + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, lError, 0, Buffer, _MAX_PATH, 0); + wprintf(Buffer); + return 0; + } + + RegQueryValueEx(hKey, L"~MHz", NULL, NULL, (LPBYTE)&dwMHz, &BufSize); + return dwMHz; + #endif } unsigned long Info::getRAMSize() @@ -31,6 +68,13 @@ namespace Columbus if (sysinfo(&info) == -1) return 0; return info.totalram / (1024 * 1024); #endif + + #ifdef COLUMBUS_PLATFORM_WINDOWS + MEMORYSTATUSEX memInfo; + memInfo.dwLength = sizeof(memInfo); + GlobalMemoryStatusEx(&memInfo); + return memInfo.ullTotalPhys / (1024 * 1024); + #endif } unsigned long Info::getRAMFree() @@ -40,6 +84,13 @@ namespace Columbus if (sysinfo(&info) == -1) return 0; return info.freeram / (1024 * 1024); #endif + + #ifdef COLUMBUS_PLATFORM_WINDOWS + MEMORYSTATUSEX memInfo; + memInfo.dwLength = sizeof(memInfo); + GlobalMemoryStatusEx(&memInfo); + return memInfo.ullAvailPhys / (1024 * 1024); + #endif } int Info::getRAMUsage() @@ -50,11 +101,21 @@ namespace Columbus float usage = static_cast(getRAMFree()) / static_cast(getRAMSize()); return static_cast(100 - usage * 100); #endif + + #ifdef COLUMBUS_PLATFORM_WINDOWS + MEMORYSTATUSEX memInfo; + memInfo.dwLength = sizeof(memInfo); + GlobalMemoryStatusEx(&memInfo); + return memInfo.dwMemoryLoad; + #endif + + return 0; } } +#undef COLUMBUS_PLATFORM_WINDOWS #undef COLUMBUS_PLATFORM_LINUX