Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142#include "SystemInfo.h"
#include "GPU.h"#include "Version.h"
#include <SDL3/SDL.h>
#include <cstdio>#include <fstream>
#if defined(_WIN32)#include <windows.h>#elif defined(__ANDROID__)#include <sys/system_properties.h>#elif defined(__linux__)#include <sys/utsname.h>#endif
// TODO: windows is unverified
void SystemInformation::appendLine(std::string& text, const char* key, const std::string& value) { if (value.empty()) { return; } text += std::string(key) + ": " + value + "\n";}
std::string SystemInformation::getOsVersion() {#if defined(_WIN32) // RtlGetVersion is used because GetVersionEx lies on unmanifested apps using RtlGetVersionFn = LONG (WINAPI*)(PRTL_OSVERSIONINFOW); HMODULE ntdll = GetModuleHandleW(L"ntdll.dll"); if (!ntdll) { return ""; } FARPROC proc = GetProcAddress(ntdll, "RtlGetVersion"); if (!proc) { return ""; } RTL_OSVERSIONINFOW info = {}; info.dwOSVersionInfoSize = sizeof(info); RtlGetVersionFn rtlGetVersion = reinterpret_cast<RtlGetVersionFn>(reinterpret_cast<void*>(proc)); if (rtlGetVersion(&info)) { return ""; } return std::to_string(info.dwMajorVersion) + "." + std::to_string(info.dwMinorVersion) + "." + std::to_string(info.dwBuildNumber);#elif defined(__ANDROID__) char release[PROP_VALUE_MAX] = {0}; int length = __system_property_get("ro.build.version.release", release); if (length <= 0) { return ""; } return std::string("Android ") + release;#elif defined(__linux__) utsname info = {}; if (uname(&info)) { return ""; } return std::string("Linux kernel ") + info.release;#else return "";#endif}
std::string SystemInformation::getProcessor() {#if defined(_WIN32) char name[256] = {0}; DWORD size = sizeof(name); LSTATUS status = RegGetValueA( HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", "ProcessorNameString", RRF_RT_REG_SZ, nullptr, name, &size ); if (status != ERROR_SUCCESS) { return ""; } return name;#elif defined(__linux__) std::ifstream file("/proc/cpuinfo"); std::string line; while (std::getline(file, line)) { std::string value = matchCpuLine(line); if (!value.empty()) { return value; } } return "";#else return "";#endif}
std::string SystemInformation::getMemory() { // SDL reports system RAM in MiB int mebibytes = SDL_GetSystemRAM(); if (mebibytes <= 0) { return ""; } char buffer[32] = {0}; std::snprintf(buffer, sizeof(buffer), "%.1f GiB", mebibytes / 1024.0); return buffer;}
std::string SystemInformation::matchCpuLine(const std::string& line) { size_t colon = line.find(':'); if (colon == std::string::npos) { return ""; } std::string key = line.substr(0, colon); bool matches = key.rfind("model name", 0) == 0 || key.rfind("Hardware", 0) == 0 || key.rfind("Processor", 0) == 0; if (!matches) { return ""; } size_t start = line.find_first_not_of(" \t", colon + 1); if (start == std::string::npos) { return ""; } return line.substr(start);}
void SystemInformation::Show() { std::string text = std::string(VERSION_STRING) + "\n"; appendLine(text, "Platform", SDL_GetPlatform()); appendLine(text, "Graphics", GPU::GetDetails()); appendLine(text, "OS Version", getOsVersion()); appendLine(text, "Processor", getProcessor()); appendLine(text, "Memory", getMemory()); SDL_ShowSimpleMessageBox( // migrate to panel modal eventually, sdl is blocking SDL_MESSAGEBOX_INFORMATION, "App & Device Information", text.c_str(), nullptr );}