bool Platform::is32BitOs() { bool result = false; #if defined _WIN64 result = false; #elif defined _WIN32 // 32-bit programs run on both 32-bit and 64-bit Windows so must check result = !isWow64(); #endif return result; }
SYSTEM_INFO w32_getSystemInfo( bool * success ) { typedef LPSYSTEM_INFO (WINAPI * LPFN_GETNATIVESYSTEMINFO) (LPSYSTEM_INFO); if( success ) *success = false; SYSTEM_INFO sysInfo; if( isWow64() ) { static LPFN_GETNATIVESYSTEMINFO fnGetNativeSystemInfo = 0; if( !fnGetNativeSystemInfo ) fnGetNativeSystemInfo = (LPFN_GETNATIVESYSTEMINFO)QLibrary::resolve( "kernel32", "GetNativeSystemInfo" ); if( fnGetNativeSystemInfo ) fnGetNativeSystemInfo( &sysInfo ); } else GetSystemInfo( &sysInfo ); if( success ) *success = true; return sysInfo; }
void Host::updateHardwareInfo() { SystemMemInfo mi = systemMemoryInfo(); if( mi.caps & SystemMemInfo::TotalMemory ) setMemory( mi.totalMemory / 1024 ); #ifdef Q_OS_LINUX QString cpu = backtick("cat /proc/cpuinfo"); QRegExp cpuRx("physical id\\s+: (\\d+)"); QRegExp bogoRx("bogomips\\s+: (\\d+)"); QRegExp cpuCoresRx("cpu cores\\s+: (\\d+)"); LOG_3( "trying to get CPU info\n"+cpu ); if( bogoRx.indexIn(cpu) != -1 ) setMhz( bogoRx.cap(1).toInt() ); int cores = 1; if( cpuCoresRx.indexIn(cpu) != -1 ) cores = cpuCoresRx.cap(1).toInt(); int cpuId = 0; int pos = 0; while ((pos = cpuRx.indexIn(cpu, pos)) != -1) { int foundCpuId = cpuRx.cap(1).toInt(); LOG_3("found cpu with physical id: " + QString::number(foundCpuId)); if( foundCpuId > cpuId ) cpuId = foundCpuId; pos += cpuRx.matchedLength(); setCpus( (cpuId+1)*cores ); } setCpuName(backtick("uname -p").replace("\n","")); setOs(backtick("uname").replace("\n","")); setOsVersion(backtick("uname -r").replace("\n","")); setArchitecture(backtick("uname -m").replace("\n","")); commit(); #endif #ifdef Q_OS_MAC QString sys_profile = backtick("system_profiler -detailLevel -2"); QRegExp mhzRx("(CPU|Processor) Speed: ([\\d.]+) GHz"); if( mhzRx.indexIn(sys_profile) != -1 ) setMhz( (mhzRx.cap(2).toFloat() * 1000) ); QRegExp cpuNameRx("(CPU|Processor) Name: (.*)\n"); if( cpuNameRx.indexIn(sys_profile) != -1 ) setCpuName( cpuNameRx.cap(2).replace("\n","") ); QRegExp memRx("Memory: (\\d+) GB"); if( memRx.indexIn(sys_profile) != -1 ) setMemory( (memRx.cap(1).toInt() * 1024) ); QRegExp cpuRx("Number Of (CPUs|Cores): (\\d+)"); if( cpuRx.indexIn(sys_profile) != -1 ) setCpus( cpuRx.cap(2).toInt() ); QRegExp osRx("System Version: (Mac OS X) ([\\d.]+)"); if( osRx.indexIn(sys_profile) != -1 ) { setOs( osRx.cap(1) ); setOsVersion( osRx.cap(2) ); } setArchitecture(backtick("uname -m").replace("\n","")); #endif #ifdef Q_OS_WIN bool sysInfoSuccess; SYSTEM_INFO sysInfo = w32_getSystemInfo( &sysInfoSuccess ); if( sysInfoSuccess ) { QString arch; switch( sysInfo.wProcessorArchitecture ) { case PROCESSOR_ARCHITECTURE_AMD64: arch = "x86_64"; break; case PROCESSOR_ARCHITECTURE_IA64: arch = "Itanium"; break; case PROCESSOR_ARCHITECTURE_INTEL: arch = "x86"; break; } #ifndef _WIN64 if( !isWow64() ) setOs( "win32" ); else #endif setOs( "win64" ); setArchitecture( arch ); QString servicePackVersion; int buildNumber; setOsVersion( w32_getOsVersion(&servicePackVersion,&buildNumber) ); setServicePackVersion(servicePackVersion); setBuildNumber(buildNumber); setCpus( sysInfo.dwNumberOfProcessors ); QSettings mhzReg( "HKEY_LOCAL_MACHINE\\Hardware\\Description\\System\\CentralProcessor\\0", QSettings::NativeFormat ); setMhz( mhzReg.value( "~MHz" ).toInt() ); setWindowsDomain( localDomain() ); } #endif commit(); /* * Anything that will change every time this function is run should probably be in HostStatus, not in Host. * All the above will be recalculated but rarely ever change and cause an actual update. */ HostStatus hs = hostStatus(); Interval uptime = systemUpTime(); hs.setSystemStartupTimestamp( uptime == Interval() ? QDateTime() : (uptime * -1.0).adjust(QDateTime::currentDateTime()) ); hs.commit(); }