📄 mavinfo.cpp
字号:
CMaverickInfo::GetDriveName(unsigned long ulDrive, WCHAR *pcName,
unsigned long ulLength)
{
//
// Obtain the critical section.
//
m_CriticalSection.Lock();
//
// Make sure that:
// 1) the specified drive is valid, and
// 2) we have a string of drive names.
//
if((ulDrive >= m_ulNumDrives) || !m_ppcDriveNames)
{
m_CriticalSection.Unlock();
pcName[0] = L'\0';
return;
}
//
// Return the name of this drive.
//
wcsncpy(pcName, m_ppcDriveNames[ulDrive], ulLength);
//
// Release the critical section.
//
m_CriticalSection.Unlock();
}
//****************************************************************************
//
// Returns the number of files on the given drive.
//
//****************************************************************************
unsigned long
CMaverickInfo::GetNumFiles(unsigned long ulDrive)
{
unsigned long ulNumFiles;
//
// Obtain the critical section.
//
m_CriticalSection.Lock();
//
// Make sure that:
// 1) the specified drive is valid, and
// 2) we have an array of the number of files per drive.
//
if((ulDrive >= m_ulNumDrives) || !m_pulNumFiles)
{
m_CriticalSection.Unlock();
return(0);
}
//
// Get the number of files on this drive.
//
ulNumFiles = m_pulNumFiles[ulDrive];
//
// Release the critical section.
//
m_CriticalSection.Unlock();
//
// Return the number of files on this drive.
//
return(ulNumFiles);
}
//****************************************************************************
//
// Returns the name of the given file on the given drive.
//
//****************************************************************************
void
CMaverickInfo::GetFileName(unsigned long ulDrive, unsigned long ulFile,
WCHAR *pcName, unsigned long ulLength)
{
WCHAR *pcFileName;
//
// Obtain the critical section.
//
m_CriticalSection.Lock();
//
// Make sure that:
// 1) the specified drive is valid,
// 2) we have an array of the number of files per drive,
// 3) the specified file is valid,
// 4) we have an array of the names of the files on each drive, and
// 5) we have a string of the file names on this drive.
//
if((ulDrive >= m_ulNumDrives) || !m_pulNumFiles ||
(ulFile >= m_pulNumFiles[ulDrive]) || !m_ppcFileNames ||
!m_ppcFileNames[ulDrive])
{
m_CriticalSection.Unlock();
pcName[0] = L'\0';
return;
}
//
// Get a local copy of the file name string.
//
pcFileName = m_ppcFileNames[ulDrive];
//
// Find the specified file.
//
while(ulFile--)
{
//
// Skip to the next file name.
//
pcFileName += wcslen(pcFileName) + 1;
}
//
// Return the name of this file.
//
wcsncpy(pcName, pcFileName, ulLength);
//
// Release the critical section.
//
m_CriticalSection.Unlock();
}
//****************************************************************************
//
// Returns the length of the given file on the given drive.
//
//****************************************************************************
unsigned long
CMaverickInfo::GetFileLength(unsigned long ulDrive, unsigned long ulFile)
{
unsigned long ulFileSize;
//
// Obtain the critical section.
//
m_CriticalSection.Lock();
//
// Make sure that:
// 1) the specified drive is valid,
// 2) we have an array of the number of files per drive,
// 3) the specified file is valid,
// 4) we have an array of file sizes per drive, and
// 5) we have an array of file sizes for this drive.
//
if((ulDrive >= m_ulNumDrives) || !m_pulNumFiles ||
(ulFile >= m_pulNumFiles[ulDrive]) || !m_ppulFileSizes ||
!m_ppulFileSizes[ulDrive])
{
ulFileSize = 0;
}
else
{
//
// Get the length of this file.
//
ulFileSize = m_ppulFileSizes[ulDrive][ulFile];
}
//
// Release the critical section.
//
m_CriticalSection.Unlock();
//
// Return the length of this file.
//
return(ulFileSize);
}
//****************************************************************************
//
// Returns the modification date/time of the given file on the given drive.
//
//****************************************************************************
unsigned long
CMaverickInfo::GetFileDate(unsigned long ulDrive, unsigned long ulFile)
{
unsigned long ulFileSize;
//
// Obtain the critical section.
//
m_CriticalSection.Lock();
//
// Make sure that:
// 1) the specified drive is valid,
// 2) we have an array of the number of files per drive,
// 3) the specified file is valid,
// 4) we have an array of file sizes per drive, and
// 5) we have an array of file sizes for this drive.
//
if((ulDrive >= m_ulNumDrives) || !m_pulNumFiles ||
(ulFile >= m_pulNumFiles[ulDrive]) || !m_ppulFileDates ||
!m_ppulFileDates[ulDrive])
{
ulFileSize = 0;
}
else
{
//
// Get the modification date/time of this file.
//
ulFileSize = m_ppulFileDates[ulDrive][ulFile];
}
//
// Release the critical section.
//
m_CriticalSection.Unlock();
//
// Return the length of this file.
//
return(ulFileSize);
}
//****************************************************************************
//
// Returns the storage globals object for the given drive.
//
//****************************************************************************
IMDSPStorageGlobals *
CMaverickInfo::GetStorageGlobals(unsigned long ulDrive)
{
CComObject<CMDSPStorageGlobals> *pObj;
IMDSPStorageGlobals *pGlobals;
HRESULT hr;
//
// Obtain the critical section.
//
m_CriticalSection.Lock();
//
// Make sure that:
// 1) the specified drive is valid, and
// 2) we have an array of storage globals objects.
//
if((ulDrive >= m_ulNumDrives) || !m_ppStorageGlobals)
{
m_CriticalSection.Unlock();
return(NULL);
}
//
// See if there is already a storage globals object for this drive.
//
if(m_ppStorageGlobals[ulDrive])
{
//
// There is already a storage globals object for this drive, so add a
// reference to that object.
//
m_ppStorageGlobals[ulDrive]->AddRef();
//
// Release the critical section.
//
m_CriticalSection.Unlock();
//
// Return the storage globals object for this drive.
//
return(m_ppStorageGlobals[ulDrive]);
}
//
// Create a new storage globals object.
//
hr = CComObject<CMDSPStorageGlobals>::CreateInstance(&pObj);
if(FAILED(hr))
{
m_CriticalSection.Unlock();
return(NULL);
}
//
// Get a pointer to the IMDSPStorageGlobals interface of the object.
//
hr = pObj->QueryInterface(IID_IMDSPStorageGlobals,
reinterpret_cast<void **>(&pGlobals));
if(FAILED(hr))
{
delete pObj;
m_CriticalSection.Unlock();
return(NULL);
}
//
// Since we'll be saving a pointer to this object and use it for subsequent
// calls, add a reference so it doesn't get deleted when the caller
// releases the object.
//
pGlobals->AddRef();
//
// Initialize the storage globals object.
//
pObj->SetDrive(ulDrive);
//
// Save this object in our array.
//
m_ppStorageGlobals[ulDrive] = pGlobals;
//
// Release the critical section.
//
m_CriticalSection.Unlock();
//
// Return the storage globals object.
//
return(pGlobals);
}
//****************************************************************************
//
// Returns the device object for the device.
//
//****************************************************************************
IMDSPDevice *
CMaverickInfo::GetDevice(unsigned long ulDrive)
{
CComObject<CMDSPDevice> *pObj;
IMDSPDevice *pDevice;
HRESULT hr;
//
// Obtain the critical section.
//
m_CriticalSection.Lock();
//
// Make sure that:
// 1) the specified drive is valid, and
// 2) we have an array of device objects.
//
if((ulDrive >= m_ulNumDrives) || !m_ppDevice)
{
m_CriticalSection.Unlock();
return(NULL);
}
//
// See if there is already a device object for this drive.
//
if(m_ppDevice[ulDrive])
{
//
// There is already a device object for this drive, so add a reference
// to that object.
//
m_ppDevice[ulDrive]->AddRef();
//
// Release the critical section.
//
m_CriticalSection.Unlock();
//
// Return the device object for this drive.
//
return(m_ppDevice[ulDrive]);
}
//
// Create a new device object.
//
hr = CComObject<CMDSPDevice>::CreateInstance(&pObj);
if(FAILED(hr))
{
m_CriticalSection.Unlock();
return(NULL);
}
//
// Get a pointer to the IMDSPDevice interface of the object.
//
hr = pObj->QueryInterface(IID_IMDSPDevice,
reinterpret_cast<void **>(&pDevice));
if(FAILED(hr))
{
delete pObj;
m_CriticalSection.Unlock();
return(NULL);
}
//
// Since we'll be saving a pointer to this object and use it for subsequent
// calls, add a reference so it doesn't get deleted when the caller
// releases the object.
//
pDevice->AddRef();
//
// Initialize the device object.
//
pObj->SetDrive(ulDrive);
//
// Save this object.
//
m_ppDevice[ulDrive] = pDevice;
//
// Release the critical section.
//
m_CriticalSection.Unlock();
//
// Return the device object.
//
return(pDevice);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -