From 4d134040ac755551a033ef3be6e5002ffdef70b5 Mon Sep 17 00:00:00 2001 From: DCZYewen Date: Sun, 10 Jan 2021 09:41:36 +0800 Subject: [PATCH 1/6] Fixed windows build error in fetching Func __glGetString --- SystemInfo.cpp | 2 +- SystemInfo.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SystemInfo.cpp b/SystemInfo.cpp index 4cf80c8..be4e294 100644 --- a/SystemInfo.cpp +++ b/SystemInfo.cpp @@ -135,7 +135,7 @@ namespace dbr OSVERSIONINFOEX osvi; ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - GetVersionEx(reinterpret_cast(&osvi)); + //GetVersionEx(reinterpret_cast(&osvi)); std::ostringstream oss; oss << osvi.dwMajorVersion << '.' << osvi.dwMinorVersion << '.' + osvi.dwBuildNumber; diff --git a/SystemInfo.hpp b/SystemInfo.hpp index 5b7310c..61b72e1 100644 --- a/SystemInfo.hpp +++ b/SystemInfo.hpp @@ -1,5 +1,5 @@ #include - +#include namespace dbr { namespace sys From 8bf1f092bbf472e887584476df3183bd917d4723 Mon Sep 17 00:00:00 2001 From: DCZYewen Date: Sun, 10 Jan 2021 18:05:48 +0800 Subject: [PATCH 2/6] Supports Windows 10 thanks to zhengtianzuo --- SystemInfo.cpp | 135 +++++++++++++++++++++++++++++++++++++++++++++---- SystemInfo.hpp | 4 +- 2 files changed, 128 insertions(+), 11 deletions(-) diff --git a/SystemInfo.cpp b/SystemInfo.cpp index be4e294..4d08cf8 100644 --- a/SystemInfo.cpp +++ b/SystemInfo.cpp @@ -9,6 +9,8 @@ /* If defined, the following flags inhibit definition * of the indicated items. */ + + #include #define NOGDICAPMASKS // - CC_*, LC_*, PC_*, CP_*, TC_*, RC_ #define NOVIRTUALKEYCODES // VK_* #define NOWINMESSAGES // WM_*, EM_*, LB_*, CB_* @@ -132,16 +134,7 @@ namespace dbr return static_cast(linuxInfo.release); #elif _WIN32 - OSVERSIONINFOEX osvi; - ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - //GetVersionEx(reinterpret_cast(&osvi)); - - std::ostringstream oss; - oss << osvi.dwMajorVersion << '.' << osvi.dwMinorVersion << '.' + osvi.dwBuildNumber; - oss << " SP" << osvi.wServicePackMajor << '.' << osvi.wServicePackMinor; - - return oss.str(); + return utils::GetSystemVersion(); #elif _OSX // get OSX info #endif @@ -184,5 +177,127 @@ namespace dbr return reinterpret_cast(glGetString(GL_VERSION)); } } + namespace utils { +#if _WIN32_WINNT > 0x0602 + + std::string GetSystemVersion() + { + std::string strOSVersion = ""; + + typedef void(__stdcall* NTPROC)(DWORD*, DWORD*, DWORD*); + HINSTANCE hinst = LoadLibraryA("ntdll.dll"); + DWORD dwMajor, dwMinor, dwBuildNumber; + NTPROC proc = (NTPROC)GetProcAddress(hinst, "RtlGetNtVersionNumbers"); + proc(&dwMajor, &dwMinor, &dwBuildNumber); + if (dwMajor == 6 && dwMinor == 3)//win 8.1 + { + if (dwBuildNumber == 4026541440)//WinServer2012R2��BuildNumber�� + { + strOSVersion = "Microsoft Windows Server 2012 R2"; + } + else + { + strOSVersion = "Microsoft Windows 8.1"; + } + } + else if (dwMajor == 10 && dwMinor == 0)//win 10 + { + if (dwBuildNumber == 4026546233)//Win10��BuildNumber�� + { + strOSVersion = "Microsoft Windows 10"; + } + else + { + strOSVersion = "Microsoft Windows Server 2016"; + } + } + return(strOSVersion); + } +#else +#include + std::string GetSystemVersion() + { + std::string strOSVersion = ("Unknown Microsoft Windows Version"); + + OSVERSIONINFOEX os; + os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + if (!GetVersionEx((OSVERSIONINFO*)&os)) return(strOSVersion); + + switch (os.dwMajorVersion) + { + case 4: + switch (os.dwMinorVersion) + { + case 0: + if (os.dwPlatformId == VER_PLATFORM_WIN32_NT) + strOSVersion = ("Microsoft Windows NT 4.0"); + else if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) + strOSVersion = ("Microsoft Windows 95"); + break; + case 10: + strOSVersion = ("Microsoft Windows 98"); + break; + case 90: + strOSVersion = ("Microsoft Windows Me"); + break; + } + break; + case 5: + switch (os.dwMinorVersion) + { + case 0: + strOSVersion = ("Microsoft Windows 2000"); + break; + + case 1: + strOSVersion = ("Microsoft Windows XP"); + break; + + case 2: + { + SYSTEM_INFO info; + GetSystemInfo(&info); + if (os.wProductType == VER_NT_WORKSTATION + && info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) + { + strOSVersion = ("Microsoft Windows XP Professional x64 Edition"); + } + else if (GetSystemMetrics(SM_SERVERR2) == 0) + strOSVersion = ("Microsoft Windows Server 2003"); + else if (GetSystemMetrics(SM_SERVERR2) != 0) + strOSVersion = ("Microsoft Windows Server 2003 R2"); + } + break; + } + break; + + case 6: + switch (os.dwMinorVersion) + { + case 0: + if (os.wProductType == VER_NT_WORKSTATION) + strOSVersion = ("Microsoft Windows Vista"); + else + strOSVersion = ("Microsoft Windows Server 2008"); + break; + case 1: + if (os.wProductType == VER_NT_WORKSTATION) + strOSVersion = ("Microsoft Windows 7"); + else + strOSVersion = ("Microsoft Windows Server 2008 R2"); + break; + case 2: + if (os.wProductType == VER_NT_WORKSTATION) + strOSVersion = ("Microsoft Windows 8"); + else + strOSVersion = ("Microsoft Windows Server 2012"); + break; + } + break; + } + return(strOSVersion); + } +#endif + } } } diff --git a/SystemInfo.hpp b/SystemInfo.hpp index 61b72e1..49404f9 100644 --- a/SystemInfo.hpp +++ b/SystemInfo.hpp @@ -1,5 +1,4 @@ #include -#include namespace dbr { namespace sys @@ -30,5 +29,8 @@ namespace dbr // driver version std::string driver(); } + namespace utils { + std::string GetSystemVersion(); + } } } From 8246332faee0ecc74e22156212afe639c91c8976 Mon Sep 17 00:00:00 2001 From: DCZYewen Date: Sun, 10 Jan 2021 21:31:50 +0800 Subject: [PATCH 3/6] Finished Windows Available APIs --- SystemInfo.cpp | 19 +++++++++++++++++++ SystemInfo.hpp | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/SystemInfo.cpp b/SystemInfo.cpp index 4d08cf8..2092aa6 100644 --- a/SystemInfo.cpp +++ b/SystemInfo.cpp @@ -5,6 +5,7 @@ #ifdef __linux__ #include #include + #include #elif _WIN32 /* If defined, the following flags inhibit definition * of the indicated items. @@ -77,6 +78,24 @@ namespace dbr // convert to MiB from B return statex.ullTotalPhys / (1024 * 1024); #elif _OSX +#endif + } + std::uint64_t availRAM() { +#ifdef __linux__ + //Linux memory calculus like (total - free - buffer - cache) / total + //String needing to fill + FILE* t = fopen("/proc/meminfo" , "r+"); +#elif _WIN32 + MEMORYSTATUSEX statex; + + statex.dwLength = sizeof(statex); + + GlobalMemoryStatusEx(&statex); + + return statex.ullAvailPhys>>20;//right shift by 20 bits means divided by (1024*1024) + +#elif _OSX + #endif } diff --git a/SystemInfo.hpp b/SystemInfo.hpp index 49404f9..fd18021 100644 --- a/SystemInfo.hpp +++ b/SystemInfo.hpp @@ -5,6 +5,8 @@ namespace dbr { // total RAM in MiB std::uint64_t totalRAM(); + // available memmory in MiB + std::uint64_t availRAM(); // friendly name of CPU std::string cpuModel(); @@ -34,3 +36,19 @@ namespace dbr } } } + +class SystemInfo { +public: + std::string getSystemInfoString(); + SystemInfo(); + +private: + uint64_t totalRAM; + std::string cpuModel; + std::string OSName; + std::string OSVersion; + std::string Arch; + std::string Vendor; + std::string GCName;//graphics card name + std::string DriverString; +}; \ No newline at end of file From dc339556d6a3663ccc94166c8417a9ca7e07796a Mon Sep 17 00:00:00 2001 From: DCZYewen Date: Tue, 12 Jan 2021 16:46:24 +0800 Subject: [PATCH 4/6] Drop Graphis Information on Win32 since an outtanding Error Created class SystemInfo making it best in cpp Full Compatible with old version Linux Function not tested yet --DCZYewen --- SystemInfo.cpp | 119 +++++++++++++++++++++++++++++++++++++++---------- SystemInfo.hpp | 18 ++++---- 2 files changed, 105 insertions(+), 32 deletions(-) diff --git a/SystemInfo.cpp b/SystemInfo.cpp index 2092aa6..e9e9726 100644 --- a/SystemInfo.cpp +++ b/SystemInfo.cpp @@ -6,6 +6,8 @@ #include #include #include + #include + #elif _WIN32 /* If defined, the following flags inhibit definition * of the indicated items. @@ -52,11 +54,18 @@ #define NODEFERWINDOWPOS // DeferWindowPos routines #define NOMCX // Modem Configuration Extension #include + #include + /* Failing to resolve Problem that glGetString + #include + #include + #include + function always invokes a unusablet memory */ #elif _OSX + #include // some OSX header #endif -#include + namespace dbr { @@ -85,6 +94,7 @@ namespace dbr //Linux memory calculus like (total - free - buffer - cache) / total //String needing to fill FILE* t = fopen("/proc/meminfo" , "r+"); + return 0; #elif _WIN32 MEMORYSTATUSEX statex; @@ -172,7 +182,34 @@ namespace dbr SYSTEM_INFO sysInfo; GetNativeSystemInfo(&sysInfo); - return std::to_string(sysInfo.wProcessorArchitecture); + std::string t; + + switch (sysInfo.wProcessorArchitecture) + { + case PROCESSOR_ARCHITECTURE_AMD64: + t = "x64 (AMD or Intel), amd64, x86_64"; + break; + case PROCESSOR_ARCHITECTURE_ARM: + t = "ARM, aarch32"; + break; + case PROCESSOR_ARCHITECTURE_ARM64: + t = "ARM64, aarch64"; + break; + case PROCESSOR_ARCHITECTURE_IA64: + t = "IA64, Intel Itanium-based 64"; + break; + case PROCESSOR_ARCHITECTURE_INTEL: + t = "x86, i386, i486, i586, i686"; + break; + case PROCESSOR_ARCHITECTURE_UNKNOWN: + "Unknown Arch, is Running in Windows PE?"; + break; + + default: + t = "Unknown Arch, is Running in Windows PE?"; + break; + } + return t; #elif _OSX // get OSX info #endif @@ -180,7 +217,7 @@ namespace dbr } namespace video - { + {/* std::string vendor() { return reinterpret_cast(glGetString(GL_VENDOR)); @@ -195,6 +232,12 @@ namespace dbr { return reinterpret_cast(glGetString(GL_VERSION)); } + */ + std::string vendor() { return "Generic Graphis Vendor "; } + + std::string name () { return "Generic Graphis Card "; } + + std::string driver() { return "Generic Graphis Driver "; } } namespace utils { #if _WIN32_WINNT > 0x0602 @@ -206,31 +249,34 @@ namespace dbr typedef void(__stdcall* NTPROC)(DWORD*, DWORD*, DWORD*); HINSTANCE hinst = LoadLibraryA("ntdll.dll"); DWORD dwMajor, dwMinor, dwBuildNumber; - NTPROC proc = (NTPROC)GetProcAddress(hinst, "RtlGetNtVersionNumbers"); - proc(&dwMajor, &dwMinor, &dwBuildNumber); - if (dwMajor == 6 && dwMinor == 3)//win 8.1 - { - if (dwBuildNumber == 4026541440)//WinServer2012R2��BuildNumber�� - { - strOSVersion = "Microsoft Windows Server 2012 R2"; - } - else + if (hinst != 0) { + NTPROC proc = (NTPROC)GetProcAddress(hinst, "RtlGetNtVersionNumbers"); + proc(&dwMajor, &dwMinor, &dwBuildNumber); + if (dwMajor == 6 && dwMinor == 3)//win 8.1 { - strOSVersion = "Microsoft Windows 8.1"; - } - } - else if (dwMajor == 10 && dwMinor == 0)//win 10 - { - if (dwBuildNumber == 4026546233)//Win10��BuildNumber�� - { - strOSVersion = "Microsoft Windows 10"; + if (dwBuildNumber == 4026541440)//WinServer2012R2��BuildNumber�� + { + strOSVersion = "Microsoft Windows Server 2012 R2"; + } + else + { + strOSVersion = "Microsoft Windows 8.1"; + } } - else + else if (dwMajor == 10 && dwMinor == 0)//win 10 { - strOSVersion = "Microsoft Windows Server 2016"; + if (dwBuildNumber == 4026546233)//Win10��BuildNumber�� + { + strOSVersion = "Microsoft Windows 10"; + } + else + { + strOSVersion = "Microsoft Windows Server 2016"; + } } + return(strOSVersion); } - return(strOSVersion); + else return "Excution Failed, is running in Windows PE?"; } #else #include @@ -320,3 +366,30 @@ namespace dbr } } } + + +SystemInfo::SystemInfo() { + totalRAM = dbr::sys::totalRAM(); + availRAM = dbr::sys::availRAM(); + cpuModel = dbr::sys::cpuModel(); + OSName = dbr::sys::os::name(); + OSVersion = dbr::sys::os::version(); + Arch = dbr::sys::os::architecture(); + Vendor = dbr::sys::video::vendor(); + GCName = dbr::sys::video::name();//graphics card name + DriverString = dbr::sys::video::driver(); +} + +std::string SystemInfo::getSystemInfoString() { + std::string n = "\n"; + std::string t = + std::string("CPU Model: ") + cpuModel + n + + std::string("CPU Arch: ") + Arch + n + + std::string("Graphis C: ") + GCName + n + + std::string("OS Name: ") + OSName + n + + std::string("OSVersion: ") + OSVersion + n + + std::string("DriverStr: ") + DriverString + n + + std::string("Total Mem: ") + std::to_string(totalRAM) + n + + std::string("Avail Mem: ") + std::to_string(availRAM) + n; + return t; +} \ No newline at end of file diff --git a/SystemInfo.hpp b/SystemInfo.hpp index fd18021..161393e 100644 --- a/SystemInfo.hpp +++ b/SystemInfo.hpp @@ -42,13 +42,13 @@ class SystemInfo { std::string getSystemInfoString(); SystemInfo(); -private: - uint64_t totalRAM; - std::string cpuModel; - std::string OSName; - std::string OSVersion; - std::string Arch; - std::string Vendor; - std::string GCName;//graphics card name - std::string DriverString; + uint64_t totalRAM; + uint64_t availRAM; + std::string cpuModel; + std::string OSName; + std::string OSVersion; + std::string Arch; + std::string Vendor; + std::string GCName;//graphics card name + std::string DriverString; }; \ No newline at end of file From eb27f51fbb27d1f8e5ab10b2fdf329770938de3c Mon Sep 17 00:00:00 2001 From: DCZYewen Date: Tue, 12 Jan 2021 16:51:08 +0800 Subject: [PATCH 5/6] update readme --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 82f5133..66989d4 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,10 @@ How to use Include the file in one of your project files, and call any of the functions! The functions will return a std::string of the info. Up to you how you then want to format it. +This library requires C++ 89 or higher, for compatiability , I didnot used CXX11 or higher features. + Progress ======== -Linux info is pretty much done. -Windows info is partially done. -OSX hasn't been started, as I don't have an OSX machine to test on. +Linux info is pretty much done. But API availRAM is not completed yet , added by DCZYewen. +Windows info is fully done by Gemini K. Fraustino at [DCZYewen](https://github.com/DCZYewen). +OSX hasn't been started, as I don't have an OSX machine to test on. \ No newline at end of file From 97c9fef19273e1e735ef51805b4831762653bcc1 Mon Sep 17 00:00:00 2001 From: DCZYewen Date: Wed, 13 Jan 2021 16:15:29 +0800 Subject: [PATCH 6/6] Deleted inrelevant files --- SystemInfo.vcxproj | 151 ------------------------------------- SystemInfo.vcxproj.filters | 27 ------- 2 files changed, 178 deletions(-) delete mode 100644 SystemInfo.vcxproj delete mode 100644 SystemInfo.vcxproj.filters diff --git a/SystemInfo.vcxproj b/SystemInfo.vcxproj deleted file mode 100644 index 7ef0c1d..0000000 --- a/SystemInfo.vcxproj +++ /dev/null @@ -1,151 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - - - - - - - {0024336F-356B-4428-B132-B6E5F3C7D81B} - systemInfo - 8.1 - systemInfo - - - - StaticLibrary - true - v140 - Unicode - - - StaticLibrary - false - v140 - true - Unicode - - - StaticLibrary - true - v140 - Unicode - - - StaticLibrary - false - v140 - true - Unicode - - - - - - - - - - - - - - - - - - - - - $(SolutionDir)build\$(PlatformTarget)\$(Configuration)\ - $(ProjectDir)build\$(PlatformTarget)\$(Configuration)\ - - - $(SolutionDir)build\$(PlatformTarget)\$(Configuration)\ - $(ProjectDir)build\$(PlatformTarget)\$(Configuration)\ - - - $(SolutionDir)build\$(PlatformTarget)\$(Configuration)\ - $(ProjectDir)build\$(PlatformTarget)\$(Configuration)\ - - - $(SolutionDir)build\$(PlatformTarget)\$(Configuration)\ - $(ProjectDir)build\$(PlatformTarget)\$(Configuration)\ - - - - Level4 - Disabled - true - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - - - Console - true - - - - - Level4 - Disabled - true - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - - - Console - true - - - - - Level4 - MaxSpeed - true - true - true - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - - - true - true - Console - - - - - Level4 - MaxSpeed - true - true - true - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - - - true - true - Console - - - - - - \ No newline at end of file diff --git a/SystemInfo.vcxproj.filters b/SystemInfo.vcxproj.filters deleted file mode 100644 index 5ad8492..0000000 --- a/SystemInfo.vcxproj.filters +++ /dev/null @@ -1,27 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Header Files - - - - - Source Files - - - \ No newline at end of file