#include "SystemInfo.h" #include "GPU.h" #include "Version.h" #include #include #include #if defined(_WIN32) #include #elif defined(__ANDROID__) #include #elif defined(__linux__) #include #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(reinterpret_cast(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 ); }