75 lines
3 KiB
C++
75 lines
3 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// File : gearnetwork.cpp - GEAR network detection
|
|
// Copyright (c) Ubisoft Entertainment. All rights reserved.
|
|
//
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "gearnetwork.h"
|
|
#include "gearhardware.h"
|
|
#include "systeminc.h"
|
|
|
|
#include <gear_detection/wmiinterface/wmiinterface.h>
|
|
|
|
namespace G4 {
|
|
|
|
namespace SystemDetection
|
|
{
|
|
GearNetwork::GearNetwork()
|
|
{
|
|
WMIInterface wmi;
|
|
|
|
available = false;
|
|
|
|
U32 index = 0;
|
|
GearDetectionString deviceID;
|
|
// http://msdn.microsoft.com/en-us/library/aa394216(VS.85).aspx
|
|
while (!available && wmi.Query("Win32_NetworkAdapter", index, "DeviceID", deviceID))
|
|
{
|
|
U32 adapterTypeId;
|
|
if (wmi.Query("Win32_NetworkAdapter", index, "AdapterTypeId", adapterTypeId))
|
|
{
|
|
U32 netConnectionStatus;
|
|
|
|
switch (adapterTypeId)
|
|
{
|
|
case 0: // Ethernet
|
|
case 9: // Wireless
|
|
if (wmi.Query("Win32_NetworkAdapter", index, "NetConnectionStatus", netConnectionStatus))
|
|
{
|
|
if (netConnectionStatus == 2)
|
|
{
|
|
// We found an adapter, Ethernet or wireless, that is connected
|
|
available = true;
|
|
|
|
// Let's look for that adapter bandwidth capability
|
|
OSVERSIONINFOEX info;
|
|
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
|
if (GetVersionEx((OSVERSIONINFO*) &info))
|
|
{
|
|
if(info.dwMajorVersion > 5)
|
|
{
|
|
GearDetectionString currentBandWidth;
|
|
if(wmi.Query("Win32_NetworkAdapter ", index, "Speed", currentBandWidth))
|
|
currentBandWidth.FromString(adapterBandwidth);
|
|
else
|
|
adapterBandwidth = 0;
|
|
}
|
|
else
|
|
{
|
|
if(!wmi.Query("Win32_PerfFormattedData_Tcpip_NetworkInterface", index, "CurrentBandwidth", (U32 &)adapterBandwidth))
|
|
adapterBandwidth = 0;
|
|
}
|
|
}
|
|
else
|
|
adapterBandwidth = 0;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
index++;
|
|
}
|
|
}
|
|
}
|
|
} // namespace G4()
|