JD2022-TU1/main/extern/gear4/gear_detection/detection/gearaudio.cpp

142 lines
5.7 KiB
C++

////////////////////////////////////////////////////////////////////////////////
//
// File : gearaudio.cpp - GEAR Sound detection
// Copyright (c) Ubisoft Entertainment. All rights reserved.
//
////////////////////////////////////////////////////////////////////////////////
#include "gearaudio.h"
#include "gearhardware.h"
#include "utils_private.h"
#include <gear_core/base/loghelper.h>
namespace G4 {
namespace SystemDetection
{
GearAudio::GearAudio()
{
FillInformation();
}
GearAudio::~GearAudio()
{
if(hardwareID)
G4_EAL_FREE(hardwareID);
if(deviceName)
G4_EAL_FREE(deviceName);
if(driverDate)
G4_EAL_FREE(driverDate);
if(driverVersion)
G4_EAL_FREE(driverVersion);
if(driverName)
G4_EAL_FREE(driverName);
}
void GearAudio::FillInformation()
{
available = false;
deviceName = 0;
hardwareID = 0;
manufacturerID = 0;
productID = 0;
driverName = 0;
driverVersion = 0;
driverDate = 0;
DetectionUtils utils;
// Get the root container
IDxDiagContainer* root = utils.InitDxDiag();
if (root)
{
// Get the direct sound
IDxDiagContainer* directSound = DetectionUtils::GetContainer("DxDiag_DirectSound", root);
if (directSound)
{
// Get the sound devices
IDxDiagContainer* soundDevices = DetectionUtils::GetContainer("DxDiag_SoundDevices", directSound);
if (soundDevices)
{
U32 index = 0;
char buffer[256];
buffer[0] = '\0';
// Enum all child container starting from 0 until it return NULL
IDxDiagContainer* childContainer = DetectionUtils::EnumContainer(soundDevices, index, buffer, sizeof(buffer));
// When no sound card, we have one empty container
while (childContainer)
{
// Look for Hardware ID
if((hardwareID = DetectionUtils::GetBSTRPropString(childContainer, "szHardwareID")) != 0)
{
available = true;
// Look for device description
if((deviceName = DetectionUtils::GetBSTRPropString(childContainer, "szDescription")) == 0)
{
G4_INTERNAL_LOG_ERROR(Audio, "Unable to get the \"szDescription\" property\n");
}
// Look for driver name
if((driverName = DetectionUtils::GetBSTRPropString(childContainer, "szDriverName")) == 0)
{
G4_INTERNAL_LOG_ERROR(Audio, "Unable to get the \"szDriverName\" property\n");
}
// Look for driver version
if((driverVersion = DetectionUtils::GetBSTRPropString(childContainer, "szDriverVersion")) == 0)
{
G4_INTERNAL_LOG_ERROR(Audio, "Unable to get the \"szDriverVersion\" property\n");
}
// Look for driver date
if((driverDate = DetectionUtils::GetBSTRPropString(childContainer, "szDriverDateEnglish")) == 0)
{
G4_INTERNAL_LOG_ERROR(Audio, "Unable to get the \"szDriverDateEnglish\" property\n");
}
// Look for device manufacturerID
if (DetectionUtils::GetBSTRProp(childContainer, "szManufacturerID", buffer, sizeof(buffer)) && Str::StringLength(buffer) > 0)
{
// Save device description to buffer
Str::FromString(buffer, manufacturerID);
}
else
G4_INTERNAL_LOG_ERROR(Audio, "Unable to get the \"szManufacturerID\" property\n");
// Look for device productID
if (DetectionUtils::GetBSTRProp(childContainer, "szProductID", buffer, sizeof(buffer)) && Str::StringLength(buffer) > 0)
{
// Save device description to buffer
Str::FromString(buffer, productID);
}
else
G4_INTERNAL_LOG_ERROR(Audio, "Unable to get the \"szProductID\" property\n");
}
childContainer->Release();
if (available)
break;
index++;
childContainer = DetectionUtils::EnumContainer(soundDevices, index, buffer, sizeof(buffer));
}
soundDevices->Release();
}
directSound->Release();
}
root->Release();
}
}
}
} // namespace G4()