SLProject  4.2.000
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 1261 of file Utils.cpp.

1262 {
1263 #if defined(_WIN32) //..................................................
1264 
1265  // Computer user name
1266  const char* envvar = std::getenv("USER");
1267  user = envvar ? string(envvar) : "USER?";
1268  if (user == "USER?")
1269  {
1270  const char* envvar = std::getenv("USERNAME");
1271  user = envvar ? string(envvar) : "USER?";
1272  }
1274 
1275  // Get architecture
1276  SYSTEM_INFO siSysInfo;
1277  GetSystemInfo(&siSysInfo);
1278  switch (siSysInfo.wProcessorArchitecture)
1279  {
1280  case PROCESSOR_ARCHITECTURE_AMD64: arch = "x64"; break;
1281  case PROCESSOR_ARCHITECTURE_ARM: arch = "ARM"; break;
1282  case 12: arch = "ARM64"; break; // PROCESSOR_ARCHITECTURE_ARM64
1283  case PROCESSOR_ARCHITECTURE_IA64: arch = "IA64"; break;
1284  case PROCESSOR_ARCHITECTURE_INTEL: arch = "x86"; break;
1285  default: arch = "???";
1286  }
1287 
1288  // Windows OS version
1289  OSVERSIONINFO osInfo;
1290  ZeroMemory(&osInfo, sizeof(OSVERSIONINFO));
1291  osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
1292  GetVersionEx(&osInfo);
1293  char osVersion[50];
1294  sprintf(osVersion, "%lu.%lu", osInfo.dwMajorVersion, osInfo.dwMinorVersion);
1295  osVer = string(osVersion);
1296 
1297  brand = "BRAND?";
1298  model = "MODEL?";
1299  os = "Windows";
1300 
1301 #elif defined(__APPLE__)
1302 # if defined(TARGET_OS_IOS) && (TARGET_OS_IOS == 1)
1303  // Model and architecture are retrieved before in iOS under Objective C
1304  brand = "Apple";
1305  os = "iOS";
1306  const char* envvar = std::getenv("USER");
1307  user = envvar ? string(envvar) : "USER?";
1308  if (user == "USER?")
1309  {
1310  const char* envvar = std::getenv("USERNAME");
1311  user = envvar ? string(envvar) : "USER?";
1312  }
1314 # else
1315  // Computer user name
1316  const char* envvar = std::getenv("USER");
1317  user = envvar ? string(envvar) : "USER?";
1318 
1319  if (user == "USER?")
1320  {
1321  const char* envvarUN = std::getenv("USERNAME");
1322  user = envvarUN ? string(envvarUN) : "USER?";
1323  }
1324 
1326  brand = "Apple";
1327  os = "MacOS";
1328 
1329  // Get MacOS version
1330  // SInt32 majorV, minorV, bugfixV;
1331  // Gestalt(gestaltSystemVersionMajor, &majorV);
1332  // Gestalt(gestaltSystemVersionMinor, &minorV);
1333  // Gestalt(gestaltSystemVersionBugFix, &bugfixV);
1334  // char osVer[50];
1335  // sprintf(osVer, "%d.%d.%d", majorV, minorV, bugfixV);
1336  // osVer = string(osVer);
1337 
1338  // Get model
1339  // size_t len = 0;
1340  // sysctlbyname("hw.model", nullptr, &len, nullptr, 0);
1341  // char model[255];
1342  // sysctlbyname("hw.model", model, &len, nullptr, 0);
1343  // model = model;
1344 # endif
1345 
1346 #elif defined(ANDROID) //................................................
1347 
1348  os = "Android";
1349 
1350  /*
1351  "ro.build.version.release" // * The user-visible version string. E.g., "1.0" or "3.4b5".
1352  "ro.build.version.incremental" // The internal value used by the underlying source control to represent this build.
1353  "ro.build.version.codename" // The current development codename, or the string "REL" if this is a release build.
1354  "ro.build.version.sdk" // The user-visible SDK version of the framework.
1355 
1356  "ro.product.model" // * The end-user-visible name for the end product..
1357  "ro.product.manufacturer" // The manufacturer of the product/hardware.
1358  "ro.product.board" // The name of the underlying board, like "goldfish".
1359  "ro.product.brand" // The brand (e.g., carrier) the software is customized for, if any.
1360  "ro.product.device" // The name of the industrial design.
1361  "ro.product.name" // The name of the overall product.
1362  "ro.hardware" // The name of the hardware (from the kernel command line or /proc).
1363  "ro.product.cpu.abi" // The name of the instruction set (CPU type + ABI convention) of native code.
1364  "ro.product.cpu.abi2" // The name of the second instruction set (CPU type + ABI convention) of native code.
1365 
1366  "ro.build.display.id" // * A build ID string meant for displaying to the user.
1367  "ro.build.host"
1368  "ro.build.user"
1369  "ro.build.id" // Either a changelist number, or a label like "M4-rc20".
1370  "ro.build.type" // The type of build, like "user" or "eng".
1371  "ro.build.tags" // Comma-separated tags describing the build, like "unsigned,debug".
1372  */
1373 
1374  int len;
1375 
1376  char hostC[PROP_VALUE_MAX];
1377  len = __system_property_get("ro.build.host", hostC);
1378  name = !string(hostC).empty() ? string(hostC) : "NAME?";
1379 
1380  char userC[PROP_VALUE_MAX];
1381  len = __system_property_get("ro.build.user", userC);
1382  user = !string(userC).empty() ? string(userC) : "USER?";
1383 
1384  char brandC[PROP_VALUE_MAX];
1385  len = __system_property_get("ro.product.brand", brandC);
1386  brand = string(brandC);
1387 
1388  char modelC[PROP_VALUE_MAX];
1389  len = __system_property_get("ro.product.model", modelC);
1390  model = string(modelC);
1391 
1392  char osVerC[PROP_VALUE_MAX];
1393  len = __system_property_get("ro.build.version.release", osVerC);
1394  osVer = string(osVerC);
1395 
1396  char archC[PROP_VALUE_MAX];
1397  len = __system_property_get("ro.product.cpu.abi", archC);
1398  arch = string(archC);
1399 
1400 #elif defined(linux) || defined(__linux) || defined(__linux__) //..................................................
1401 
1402  os = "Linux";
1403  user = "USER?";
1405  brand = "BRAND?";
1406  model = "MODEL?";
1407  osVer = "OSVER?";
1408  arch = "ARCH?";
1409 #endif
1410 
1411  // build a unique as possible ID string that can be used in a filename
1412  id = user + "-" + name + "-" + model;
1413  if (model.find("SM-") != string::npos)
1414  // Don't use computerName on Samsung phones. It's not constant!
1415  id = user + "-" + model;
1416  else
1417  id = user + "-" + name + "-" + model;
1419  std::replace(id.begin(), id.end(), '_', '-');
1420  return id;
1421 }
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: