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

140 lines
4.5 KiB
C++

////////////////////////////////////////////////////////////////////////////////
//
// File : geardisk.cpp - GEAR Disk detection
// Copyright (c) Ubisoft Entertainment. All rights reserved.
//
////////////////////////////////////////////////////////////////////////////////
#include "geardisk.h"
#include "gearhardware.h"
#include "utils_private.h"
namespace G4 {
namespace SystemDetection
{
GearLogicalDisks::GearLogicalDisks()
{
FillInformation();
}
void GearLogicalDisks::FillInformation()
{
DetectionUtils utils;
// Get the root container
IDxDiagContainer* root = utils.InitDxDiag();
if (root)
{
// Get the logical disks containers
IDxDiagContainer* logicalDisks = DetectionUtils::GetContainer("DxDiag_LogicalDisks", root);
if (logicalDisks)
{
U32 index = 0;
char buffer[256];
// Enum all child container starting from 0 until it return NULL
IDxDiagContainer* childContainer = DetectionUtils::EnumContainer(logicalDisks, index, buffer, sizeof(buffer));
while (childContainer)
{
// Init disk struct
GearDisk disk;
disk.freeSpace = 0;
disk.usedSpace = 0;
disk.totalSpace = 0;
disk.SetDriveLetter("unknown");
disk.SetDeviceId("unknown");
disk.SetFileSystem("unknown");
// Get all properties
if (DetectionUtils::GetBSTRProp(childContainer, "szDriveLetter", buffer, sizeof(buffer)) && Str::StringLength(buffer) > 0)
disk.SetDriveLetter(buffer);
if (DetectionUtils::GetBSTRProp(childContainer, "szPNPDeviceID", buffer, sizeof(buffer)) && Str::StringLength(buffer) > 0)
disk.SetDeviceId(buffer);
if (DetectionUtils::GetBSTRProp(childContainer, "szFileSystem", buffer, sizeof(buffer)) && Str::StringLength(buffer) > 0)
disk.SetFileSystem(buffer);
if (DetectionUtils::GetBSTRProp(childContainer, "szFreeSpace", buffer, sizeof(buffer)) && Str::StringLength(buffer) > 0)
Str::FromString(buffer, disk.freeSpace);
if (DetectionUtils::GetBSTRProp(childContainer, "szMaxSpace", buffer, sizeof(buffer)) && Str::StringLength(buffer) > 0)
Str::FromString(buffer, disk.totalSpace);
disk.usedSpace = disk.totalSpace - disk.freeSpace;
// Push disk struct in our vector
AddDisk(disk);
// Get the next container
childContainer->Release();
index++;
childContainer = DetectionUtils::EnumContainer(logicalDisks, index, buffer, sizeof(buffer));
}
logicalDisks->Release();
}
root->Release();
}
}
const GearDisk* GearLogicalDisks::GetDisk(unsigned long index) const
{
unsigned long vectorSize = (unsigned long)disks.size();
if (index < vectorSize)
{
return &disks[index];
}
else
{
return 0;
}
}
GearLogicalDisks::~GearLogicalDisks()
{
disks.clear();
}
void GearLogicalDisks::AddDisk(const GearDisk& disk)
{
disks.push_back(disk);
}
const char* GearDisk::GetDriveLetter() const
{
return m_driveLetter.CStr();
}
const char* GearDisk::GetDeviceId() const
{
return m_deviceId.CStr();
}
const char* GearDisk::GetFileSystem() const
{
return m_fileSystem.CStr();
}
void GearDisk::SetDriveLetter(const char* name)
{
m_driveLetter = name;
}
void GearDisk::SetDeviceId(const char* name)
{
m_deviceId = name;
}
void GearDisk::SetFileSystem(const char* name)
{
m_fileSystem = name;
}
}
} // namespace G4()