Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promoted the library #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
233 changes: 220 additions & 13 deletions SystemInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
#ifdef __linux__
#include <sys/utsname.h>
#include <unistd.h>
#include <stdio.h>
#include <GL/gl.h>

#elif _WIN32
/* If defined, the following flags inhibit definition
* of the indicated items.
*/

#include <GLFW/glfw3.h>
#define NOGDICAPMASKS // - CC_*, LC_*, PC_*, CP_*, TC_*, RC_
#define NOVIRTUALKEYCODES // VK_*
#define NOWINMESSAGES // WM_*, EM_*, LB_*, CB_*
Expand Down Expand Up @@ -49,11 +54,18 @@
#define NODEFERWINDOWPOS // DeferWindowPos routines
#define NOMCX // Modem Configuration Extension
#include <windows.h>
#include <GL/gl.h>
/* Failing to resolve Problem that glGetString
#include <GL/glut.h>
#include <stdlib.h>
#include <string.h>
function always invokes a unusablet memory */
#elif _OSX
#include <GL/gl.h>
// some OSX header
#endif

#include <GL/gl.h>


namespace dbr
{
Expand All @@ -75,6 +87,25 @@ 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+");
return 0;
#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
}

Expand Down Expand Up @@ -132,16 +163,7 @@ namespace dbr

return static_cast<std::string>(linuxInfo.release);
#elif _WIN32
OSVERSIONINFOEX osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&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
Expand All @@ -160,15 +182,42 @@ 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
}
}

namespace video
{
{/*
std::string vendor()
{
return reinterpret_cast<const char*>(glGetString(GL_VENDOR));
Expand All @@ -183,6 +232,164 @@ namespace dbr
{
return reinterpret_cast<const char*>(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

std::string GetSystemVersion()
{
std::string strOSVersion = "";

typedef void(__stdcall* NTPROC)(DWORD*, DWORD*, DWORD*);
HINSTANCE hinst = LoadLibraryA("ntdll.dll");
DWORD dwMajor, dwMinor, dwBuildNumber;
if (hinst != 0) {
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 return "Excution Failed, is running in Windows PE?";
}
#else
#include <WinUser.h>
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
}
}
}


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;
}
22 changes: 21 additions & 1 deletion SystemInfo.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <string>

namespace dbr
{
namespace sys
{
// total RAM in MiB
std::uint64_t totalRAM();
// available memmory in MiB
std::uint64_t availRAM();

// friendly name of CPU
std::string cpuModel();
Expand All @@ -30,5 +31,24 @@ namespace dbr
// driver version
std::string driver();
}
namespace utils {
std::string GetSystemVersion();
}
}
}

class SystemInfo {
public:
std::string getSystemInfoString();
SystemInfo();

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;
};
Loading