summaryrefslogtreecommitdiffstats
path: root/libraries/ganalytics
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-11-22 00:57:15 +0100
committerPetr Mrázek <peterix@gmail.com>2016-11-22 02:46:18 +0100
commit44805145dc385ba9ffe0d78f2e723cef42984537 (patch)
treeffbb3b8f08258e4627d008ae2b3e1c99860a81b6 /libraries/ganalytics
parent00c4aebeaafe08d6834c90b097c5018493ee62ec (diff)
downloadMultiMC-44805145dc385ba9ffe0d78f2e723cef42984537.tar
MultiMC-44805145dc385ba9ffe0d78f2e723cef42984537.tar.gz
MultiMC-44805145dc385ba9ffe0d78f2e723cef42984537.tar.lz
MultiMC-44805145dc385ba9ffe0d78f2e723cef42984537.tar.xz
MultiMC-44805145dc385ba9ffe0d78f2e723cef42984537.zip
NOISSUE add implementations of system query functions
* system memory size in bytes * system architecture is 64bit? * CPU architecture is 64bit?
Diffstat (limited to 'libraries/ganalytics')
-rw-r--r--libraries/ganalytics/src/sys.h6
-rw-r--r--libraries/ganalytics/src/sys_apple.cpp29
-rw-r--r--libraries/ganalytics/src/sys_unix.cpp36
-rw-r--r--libraries/ganalytics/src/sys_win32.cpp34
4 files changed, 105 insertions, 0 deletions
diff --git a/libraries/ganalytics/src/sys.h b/libraries/ganalytics/src/sys.h
index ef37cbde..40e4e513 100644
--- a/libraries/ganalytics/src/sys.h
+++ b/libraries/ganalytics/src/sys.h
@@ -8,4 +8,10 @@ namespace Sys
* @return os A QString with the name and version of the operating system.
*/
QString getSystemInfo();
+
+uint64_t getSystemRam();
+
+bool isSystem64bit();
+
+bool isCPU64bit();
}
diff --git a/libraries/ganalytics/src/sys_apple.cpp b/libraries/ganalytics/src/sys_apple.cpp
index c648970e..f221a527 100644
--- a/libraries/ganalytics/src/sys_apple.cpp
+++ b/libraries/ganalytics/src/sys_apple.cpp
@@ -1,5 +1,6 @@
#include "sys.h"
+// FIXME: replace with our version...
QString Sys::getSystemInfo()
{
QSysInfo::MacVersion version = QSysInfo::macVersion();
@@ -116,3 +117,31 @@ QString Sys::getSystemInfo()
}
return os;
}
+
+#include <sys/sysctl.h>
+
+uint64_t Sys::getSystemRam()
+{
+ uint64_t memsize;
+ size_t memsizesize = sizeof(memsize);
+ if(!sysctlbyname("hw.memsize", &memsize, &memsizesize, NULL, 0))
+ {
+ return memsize;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+bool Sys::isCPU64bit()
+{
+ // not even going to pretend I'm going to support anything else
+ return true;
+}
+
+bool Sys::isSystem64bit()
+{
+ // yep. maybe when we have 128bit CPUs on consumer devices.
+ return true;
+}
diff --git a/libraries/ganalytics/src/sys_unix.cpp b/libraries/ganalytics/src/sys_unix.cpp
index b4dd9b2b..9569fbb6 100644
--- a/libraries/ganalytics/src/sys_unix.cpp
+++ b/libraries/ganalytics/src/sys_unix.cpp
@@ -1,6 +1,7 @@
#include "sys.h"
#include <sys/utsname.h>
+#include <fstream>
QString Sys::getSystemInfo()
{
@@ -11,3 +12,38 @@ QString Sys::getSystemInfo()
return system + "; " + release;
}
+
+uint64_t Sys::getSystemRam()
+{
+ std::string token;
+ std::ifstream file("/proc/meminfo");
+ while(file >> token)
+ {
+ if(token == "MemTotal:")
+ {
+ uint64_t mem;
+ if(file >> mem)
+ {
+ return mem * 1024ull;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ // ignore rest of the line
+ file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
+ }
+ return 0; // nothing found
+}
+
+bool Sys::isCPU64bit()
+{
+ return isSystem64bit();
+}
+
+bool Sys::isSystem64bit()
+{
+ // kernel build arch on linux
+ return QSysInfo::currentCpuArchitecture() == "x86_64";
+}
diff --git a/libraries/ganalytics/src/sys_win32.cpp b/libraries/ganalytics/src/sys_win32.cpp
index 42c0f280..4c4e35a9 100644
--- a/libraries/ganalytics/src/sys_win32.cpp
+++ b/libraries/ganalytics/src/sys_win32.cpp
@@ -1,5 +1,6 @@
#include "sys.h"
+// FIXME: replace with our version...
QString Sys::getSystemInfo()
{
QSysInfo::WinVersion version = QSysInfo::windowsVersion();
@@ -48,3 +49,36 @@ QString Sys::getSystemInfo()
return os;
}
+#include <windows.h>
+
+uint64_t Sys::getSystemRam()
+{
+ MEMORYSTATUSEX status;
+ status.dwLength = sizeof(status);
+ GlobalMemoryStatusEx( &status );
+ // bytes
+ return (uint64_t)status.ullTotalPhys;
+}
+
+bool Sys::isSystem64bit()
+{
+#if defined(_WIN64)
+ return true; // 64-bit programs run only on Win64
+#elif defined(_WIN32)
+ // 32-bit programs run on both 32-bit and 64-bit Windows
+ // so must sniff
+ BOOL f64 = false;
+ return IsWow64Process(GetCurrentProcess(), &f64) && f64;
+#else
+ // it's some other kind of system...
+ return false;
+#endif
+}
+
+bool Sys::isCPU64bit()
+{
+ SYSTEM_INFO info;
+ GetNativeSystemInfo(&info);
+ auto arch = info.wProcessorArchitecture;
+ return arch == PROCESSOR_ARCHITECTURE_AMD64 || arch == PROCESSOR_ARCHITECTURE_IA64;
+}