SLProject  4.3.020
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
Utils::ComputerInfos Class Reference

Class for holding computer information. More...

#include <Utils.h>

Static Public Member Functions

static std::string get ()
 

Static Public Attributes

static std::string user = "USER?"
 
static std::string name = "NAME?"
 
static std::string brand = "BRAND?"
 
static std::string model = "MODEL?"
 
static std::string os = "OS?"
 
static std::string osVer = "OSVER?"
 
static std::string arch = "ARCH?"
 
static std::string id = "ID?"
 

Detailed Description

Class for holding computer information.

Definition at line 287 of file Utils.h.

Member Function Documentation

◆ get()

std::string Utils::ComputerInfos::get ( )
static

Definition at line 1258 of file Utils.cpp.

1259 {
1260 #if defined(_WIN32) //..................................................
1261 
1262  // Computer user name
1263  const char* envvar = std::getenv("USER");
1264  user = envvar ? string(envvar) : "USER?";
1265  if (user == "USER?")
1266  {
1267  const char* envvar = std::getenv("USERNAME");
1268  user = envvar ? string(envvar) : "USER?";
1269  }
1271 
1272  // Get architecture
1273  SYSTEM_INFO siSysInfo;
1274  GetSystemInfo(&siSysInfo);
1275  switch (siSysInfo.wProcessorArchitecture)
1276  {
1277  case PROCESSOR_ARCHITECTURE_AMD64: arch = "x64"; break;
1278  case PROCESSOR_ARCHITECTURE_ARM: arch = "ARM"; break;
1279  case 12: arch = "ARM64"; break; // PROCESSOR_ARCHITECTURE_ARM64
1280  case PROCESSOR_ARCHITECTURE_IA64: arch = "IA64"; break;
1281  case PROCESSOR_ARCHITECTURE_INTEL: arch = "x86"; break;
1282  default: arch = "???";
1283  }
1284 
1285  // Windows OS version. GetVersionEx is deprecated since Windows 8.1 and
1286  // reports 6.2 for anything newer unless the app ships a compatibility
1287  // manifest, which none of our apps do. RtlGetVersion is not subject to
1288  // that shimming. It is resolved dynamically to avoid a DDK dependency.
1289  RTL_OSVERSIONINFOW osInfo;
1290  ZeroMemory(&osInfo, sizeof(osInfo));
1291  osInfo.dwOSVersionInfoSize = sizeof(osInfo);
1292 
1293  typedef LONG(WINAPI * RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
1294  if (HMODULE ntdll = GetModuleHandleW(L"ntdll.dll"))
1295  {
1296  auto rtlGetVersion = reinterpret_cast<RtlGetVersionPtr>(
1297  GetProcAddress(ntdll, "RtlGetVersion"));
1298  if (rtlGetVersion)
1299  rtlGetVersion(&osInfo);
1300  }
1301 
1302  // The build number is included because Windows 10 and 11 both report 10.0
1303  // and only the build (>= 22000 is Windows 11) tells them apart.
1304  char osVersion[50];
1305  snprintf(osVersion,
1306  sizeof(osVersion),
1307  "%lu.%lu.%lu",
1308  osInfo.dwMajorVersion,
1309  osInfo.dwMinorVersion,
1310  osInfo.dwBuildNumber);
1311  osVer = string(osVersion);
1312 
1313  brand = "BRAND?";
1314  model = "MODEL?";
1315  os = "Windows";
1316 
1317 #elif defined(__APPLE__)
1318 # if defined(TARGET_OS_IOS) && (TARGET_OS_IOS == 1)
1319  // Model and architecture are retrieved before in iOS under Objective C
1320  brand = "Apple";
1321  os = "iOS";
1322  const char* envvar = std::getenv("USER");
1323  user = envvar ? string(envvar) : "USER?";
1324  if (user == "USER?")
1325  {
1326  const char* envvar = std::getenv("USERNAME");
1327  user = envvar ? string(envvar) : "USER?";
1328  }
1330 # else
1331  // Computer user name
1332  const char* envvar = std::getenv("USER");
1333  user = envvar ? string(envvar) : "USER?";
1334 
1335  if (user == "USER?")
1336  {
1337  const char* envvarUN = std::getenv("USERNAME");
1338  user = envvarUN ? string(envvarUN) : "USER?";
1339  }
1340 
1342  brand = "Apple";
1343  os = "MacOS";
1344 
1345  // Get MacOS version
1346  // SInt32 majorV, minorV, bugfixV;
1347  // Gestalt(gestaltSystemVersionMajor, &majorV);
1348  // Gestalt(gestaltSystemVersionMinor, &minorV);
1349  // Gestalt(gestaltSystemVersionBugFix, &bugfixV);
1350  // char osVer[50];
1351  // sprintf(osVer, "%d.%d.%d", majorV, minorV, bugfixV);
1352  // osVer = string(osVer);
1353 
1354  // Get model
1355  // size_t len = 0;
1356  // sysctlbyname("hw.model", nullptr, &len, nullptr, 0);
1357  // char model[255];
1358  // sysctlbyname("hw.model", model, &len, nullptr, 0);
1359  // model = model;
1360 # endif
1361 
1362 #elif defined(ANDROID) //................................................
1363 
1364  os = "Android";
1365 
1366  /*
1367  "ro.build.version.release" // * The user-visible version string. E.g., "1.0" or "3.4b5".
1368  "ro.build.version.incremental" // The internal value used by the underlying source control to represent this build.
1369  "ro.build.version.codename" // The current development codename, or the string "REL" if this is a release build.
1370  "ro.build.version.sdk" // The user-visible SDK version of the framework.
1371 
1372  "ro.product.model" // * The end-user-visible name for the end product..
1373  "ro.product.manufacturer" // The manufacturer of the product/hardware.
1374  "ro.product.board" // The name of the underlying board, like "goldfish".
1375  "ro.product.brand" // The brand (e.g., carrier) the software is customized for, if any.
1376  "ro.product.device" // The name of the industrial design.
1377  "ro.product.name" // The name of the overall product.
1378  "ro.hardware" // The name of the hardware (from the kernel command line or /proc).
1379  "ro.product.cpu.abi" // The name of the instruction set (CPU type + ABI convention) of native code.
1380  "ro.product.cpu.abi2" // The name of the second instruction set (CPU type + ABI convention) of native code.
1381 
1382  "ro.build.display.id" // * A build ID string meant for displaying to the user.
1383  "ro.build.host"
1384  "ro.build.user"
1385  "ro.build.id" // Either a changelist number, or a label like "M4-rc20".
1386  "ro.build.type" // The type of build, like "user" or "eng".
1387  "ro.build.tags" // Comma-separated tags describing the build, like "unsigned,debug".
1388  */
1389 
1390  int len;
1391 
1392  char hostC[PROP_VALUE_MAX];
1393  len = __system_property_get("ro.build.host", hostC);
1394  name = !string(hostC).empty() ? string(hostC) : "NAME?";
1395 
1396  char userC[PROP_VALUE_MAX];
1397  len = __system_property_get("ro.build.user", userC);
1398  user = !string(userC).empty() ? string(userC) : "USER?";
1399 
1400  char brandC[PROP_VALUE_MAX];
1401  len = __system_property_get("ro.product.brand", brandC);
1402  brand = string(brandC);
1403 
1404  char modelC[PROP_VALUE_MAX];
1405  len = __system_property_get("ro.product.model", modelC);
1406  model = string(modelC);
1407 
1408  char osVerC[PROP_VALUE_MAX];
1409  len = __system_property_get("ro.build.version.release", osVerC);
1410  osVer = string(osVerC);
1411 
1412  char archC[PROP_VALUE_MAX];
1413  len = __system_property_get("ro.product.cpu.abi", archC);
1414  arch = string(archC);
1415 
1416 #elif defined(linux) || defined(__linux) || defined(__linux__) //..................................................
1417 
1418  os = "Linux";
1419  user = "USER?";
1421  brand = "BRAND?";
1422  model = "MODEL?";
1423  osVer = "OSVER?";
1424  arch = "ARCH?";
1425 #endif
1426 
1427  // build a unique as possible ID string that can be used in a filename
1428  id = user + "-" + name + "-" + model;
1429  if (model.find("SM-") != string::npos)
1430  // Don't use computerName on Samsung phones. It's not constant!
1431  id = user + "-" + model;
1432  else
1433  id = user + "-" + name + "-" + model;
1435  std::replace(id.begin(), id.end(), '_', '-');
1436  return id;
1437 }
static std::string model
Definition: Utils.h:293
static std::string brand
Definition: Utils.h:292
static std::string user
Definition: Utils.h:290
static std::string os
Definition: Utils.h:294
static std::string id
Definition: Utils.h:297
static std::string osVer
Definition: Utils.h:295
static std::string arch
Definition: Utils.h:296
static std::string name
Definition: Utils.h:291
string getHostName()
Returns the computer name.
Definition: Utils.cpp:310
string replaceNonFilenameChars(string src, const char replaceChar)
replaces non-filename characters: /|?%*:"<>'
Definition: Utils.cpp:244

Member Data Documentation

◆ arch

std::string Utils::ComputerInfos::arch = "ARCH?"
static

Definition at line 296 of file Utils.h.

◆ brand

std::string Utils::ComputerInfos::brand = "BRAND?"
static

Definition at line 292 of file Utils.h.

◆ id

std::string Utils::ComputerInfos::id = "ID?"
static

Definition at line 297 of file Utils.h.

◆ model

std::string Utils::ComputerInfos::model = "MODEL?"
static

Definition at line 293 of file Utils.h.

◆ name

std::string Utils::ComputerInfos::name = "NAME?"
static

Definition at line 291 of file Utils.h.

◆ os

std::string Utils::ComputerInfos::os = "OS?"
static

Definition at line 294 of file Utils.h.

◆ osVer

std::string Utils::ComputerInfos::osVer = "OSVER?"
static

Definition at line 295 of file Utils.h.

◆ user

std::string Utils::ComputerInfos::user = "USER?"
static

Definition at line 290 of file Utils.h.


The documentation for this class was generated from the following files: