mirror of https://github.com/BOINC/boinc.git
227 lines
6.5 KiB
C++
Executable File
227 lines
6.5 KiB
C++
Executable File
// The contents of this file are subject to the Mozilla Public License
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
// http://www.mozilla.org/MPL/
|
|
//
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
// License for the specific language governing rights and limitations
|
|
// under the License.
|
|
//
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
//
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
//
|
|
// Contributor(s):
|
|
//
|
|
|
|
#include <afxwin.h>
|
|
#include "client_types.h"
|
|
#include "hostinfo.h"
|
|
|
|
double GetDiskFree();
|
|
double GetDiskSize();
|
|
|
|
// Returns the number of seconds difference from UTC
|
|
//
|
|
int get_timezone(void) {
|
|
TIME_ZONE_INFORMATION tzi;
|
|
ZeroMemory(&tzi, sizeof(TIME_ZONE_INFORMATION));
|
|
GetTimeZoneInformation(&tzi);
|
|
return (tzi.Bias * 60);
|
|
}
|
|
|
|
// Gets windows specific host information (not complete)
|
|
//
|
|
int get_host_info(HOST_INFO& host) {
|
|
OSVERSIONINFO OSVersionInfo;
|
|
memset( &OSVersionInfo, NULL, sizeof( OSVersionInfo ) );
|
|
OSVersionInfo.dwOSVersionInfoSize = sizeof( OSVersionInfo );
|
|
::GetVersionEx( &OSVersionInfo );
|
|
switch ( OSVersionInfo.dwPlatformId ) {
|
|
case VER_PLATFORM_WIN32s:
|
|
strcpy( host.os_name, "Windows 3.1/Win32s" ); // does ANYBODY use this anymore?
|
|
break;
|
|
case VER_PLATFORM_WIN32_WINDOWS:
|
|
if ( OSVersionInfo.dwMajorVersion > 4
|
|
|| ( OSVersionInfo.dwMajorVersion == 4
|
|
&& OSVersionInfo.dwMinorVersion >= 90 ) )
|
|
{
|
|
strcpy( host.os_name, "Windows Me" );
|
|
}
|
|
else if ( OSVersionInfo.dwMajorVersion == 4
|
|
&& OSVersionInfo.dwMinorVersion >= 10 )
|
|
{
|
|
strcpy( host.os_name, "Windows 98" );
|
|
}
|
|
else
|
|
{
|
|
strcpy( host.os_name, "Windows 95" );
|
|
}
|
|
break;
|
|
|
|
case VER_PLATFORM_WIN32_NT:
|
|
if ( OSVersionInfo.dwMajorVersion > 5
|
|
|| (OSVersionInfo.dwMajorVersion == 5
|
|
&& OSVersionInfo.dwMinorVersion >= 2) )
|
|
{
|
|
strcpy( host.os_name, "Windows .NET Server" );
|
|
}
|
|
else if (OSVersionInfo.dwMajorVersion == 5
|
|
&& OSVersionInfo.dwMinorVersion == 1)
|
|
{
|
|
strcpy( host.os_name, "Windows XP" );
|
|
}
|
|
else if (OSVersionInfo.dwMajorVersion == 5
|
|
&& OSVersionInfo.dwMinorVersion == 0)
|
|
{
|
|
strcpy( host.os_name, "Windows 2000" );
|
|
}
|
|
else if (OSVersionInfo.dwMajorVersion == 4
|
|
&& OSVersionInfo.dwMinorVersion == 0)
|
|
{
|
|
strcpy( host.os_name, "Windows NT 4.0" );
|
|
}
|
|
else if (OSVersionInfo.dwMajorVersion == 3
|
|
&& OSVersionInfo.dwMinorVersion == 51)
|
|
{
|
|
strcpy( host.os_name, "Windows NT 3.51" );
|
|
}
|
|
else
|
|
{
|
|
strcpy( host.os_name, "Windows NT" );
|
|
}
|
|
break;
|
|
|
|
default:
|
|
sprintf( host.os_name, "Unknown Win32 (%ld)", OSVersionInfo.dwPlatformId );
|
|
break;
|
|
}
|
|
|
|
char Version[ 25 ];
|
|
Version[ 0 ] = NULL;
|
|
sprintf(
|
|
Version, "%lu.%lu", OSVersionInfo.dwMajorVersion,
|
|
OSVersionInfo.dwMinorVersion
|
|
);
|
|
strcpy( host.os_version, Version );
|
|
|
|
SYSTEM_INFO SystemInfo;
|
|
memset( &SystemInfo, NULL, sizeof( SystemInfo ) );
|
|
::GetSystemInfo( &SystemInfo );
|
|
|
|
host.p_ncpus = SystemInfo.dwNumberOfProcessors;
|
|
|
|
switch ( SystemInfo.wProcessorArchitecture ) {
|
|
case PROCESSOR_ARCHITECTURE_INTEL:
|
|
switch ( SystemInfo.dwProcessorType ) {
|
|
case PROCESSOR_INTEL_386:
|
|
strcpy( host.p_model, "Intel 80386" );
|
|
break;
|
|
case PROCESSOR_INTEL_486:
|
|
strcpy( host.p_model, "Intel 80486" );
|
|
break;
|
|
case PROCESSOR_INTEL_PENTIUM:
|
|
strcpy( host.p_model, "Intel Pentium" );
|
|
break;
|
|
default:
|
|
strcpy( host.p_model, "Intel x86" );
|
|
break;
|
|
}
|
|
break;
|
|
|
|
case PROCESSOR_ARCHITECTURE_MIPS:
|
|
strcpy( host.p_model, "MIPS" );
|
|
break;
|
|
|
|
case PROCESSOR_ARCHITECTURE_ALPHA:
|
|
strcpy( host.p_model, "Alpha" );
|
|
break;
|
|
|
|
case PROCESSOR_ARCHITECTURE_PPC:
|
|
strcpy( host.p_model, "Power PC" );
|
|
break;
|
|
|
|
case PROCESSOR_ARCHITECTURE_UNKNOWN:
|
|
default:
|
|
strcpy( host.p_model, "Unknown" );
|
|
break;
|
|
}
|
|
|
|
host.d_total = GetDiskSize();
|
|
host.d_free = GetDiskFree();
|
|
|
|
get_local_domain_name(host.domain_name);
|
|
get_local_ip_addr_str(host.ip_addr);
|
|
|
|
host.timezone = get_timezone();
|
|
|
|
MEMORYSTATUS mStatus;
|
|
ZeroMemory(&mStatus, sizeof(MEMORYSTATUS));
|
|
mStatus.dwLength = sizeof(MEMORYSTATUS);
|
|
GlobalMemoryStatus(&mStatus);
|
|
host.m_nbytes = (double)mStatus.dwTotalPhys;
|
|
host.m_swap = (double)mStatus.dwTotalPageFile;
|
|
|
|
// gets processor vendor name from registry, works for intel
|
|
char vendorName[256];
|
|
HKEY hKey;
|
|
LONG retval;
|
|
DWORD nameSize;
|
|
retval = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Hardware\\Description\\System\\CentralProcessor\\0", 0, KEY_QUERY_VALUE, &hKey);
|
|
if(retval == ERROR_SUCCESS) {
|
|
nameSize = sizeof(vendorName);
|
|
retval = RegQueryValueEx(hKey, "VendorIdentifier", NULL, NULL, (LPBYTE)vendorName, &nameSize);
|
|
if(retval == ERROR_SUCCESS) {
|
|
strcpy(host.p_vendor, vendorName);
|
|
}
|
|
}
|
|
RegCloseKey(hKey);
|
|
return 0;
|
|
}
|
|
|
|
bool host_is_running_on_batteries() {
|
|
SYSTEM_POWER_STATUS pStatus;
|
|
ZeroMemory(&pStatus, sizeof(SYSTEM_POWER_STATUS));
|
|
GetSystemPowerStatus(&pStatus);
|
|
return (pStatus.ACLineStatus != 1);
|
|
}
|
|
|
|
//////////
|
|
// GetDiskFree
|
|
// arguments: void
|
|
// returns: amount of free disk space in MB
|
|
// function: calculates free disk space on current drive
|
|
double GetDiskFree()
|
|
{
|
|
ULARGE_INTEGER TotalNumberOfFreeBytes;
|
|
char path[256];
|
|
char drive[256];
|
|
GetCurrentDirectory(256, path);
|
|
memcpy(drive, path, 3);
|
|
drive[3] = 0;
|
|
GetDiskFreeSpaceEx(drive, NULL, NULL, &TotalNumberOfFreeBytes);
|
|
unsigned int MB = TotalNumberOfFreeBytes.QuadPart / (1024 * 1024);
|
|
return (double)MB * 1024.0 * 1024.0;
|
|
}
|
|
|
|
//////////
|
|
// GetDiskSize
|
|
// arguments: void
|
|
// returns: total disk space in bytes
|
|
// function: calculates total disk space on current drive
|
|
double GetDiskSize()
|
|
{
|
|
ULARGE_INTEGER TotalNumberOfBytes;
|
|
char path[256];
|
|
char drive[256];
|
|
GetCurrentDirectory(256, path);
|
|
memcpy(drive, path, 3);
|
|
drive[3] = 0;
|
|
GetDiskFreeSpaceEx(drive, NULL, &TotalNumberOfBytes, NULL);
|
|
unsigned int MB = TotalNumberOfBytes.QuadPart / (1024 * 1024);
|
|
return (double)MB * 1024.0 * 1024.0;
|
|
}
|