📄 mavinfo.cpp
字号:
{
delete [] m_ppcFileNames[ulDrive];
}
//
// If there is a file size array allocated for this drive, then delete
// it now.
//
if(m_ppulFileSizes && m_ppulFileSizes[ulDrive])
{
delete [] m_ppulFileSizes[ulDrive];
}
//
// If there is a file date array allocated for this drive, then delete
// it now.
//
if(m_ppulFileDates && m_ppulFileDates[ulDrive])
{
delete [] m_ppulFileDates[ulDrive];
}
//
// If there is a device object for this drive, then release it now.
//
if(m_ppDevice && m_ppDevice[ulDrive])
{
m_ppDevice[ulDrive]->Release();
}
//
// If there is a storage globals object for this drive, then release it
// now.
//
if(m_ppStorageGlobals && m_ppStorageGlobals[ulDrive])
{
m_ppStorageGlobals[ulDrive]->Release();
}
}
//
// If there is a drive names array allocated, then delete it now.
//
if(m_ppcDriveNames)
{
delete [] m_ppcDriveNames;
m_ppcDriveNames = NULL;
}
//
// If there is a file name array allocated, then delete it now.
//
if(m_ppcFileNames)
{
delete [] m_ppcFileNames;
m_ppcFileNames = NULL;
}
//
// If there is a file size array allocated, then delete it now.
//
if(m_ppulFileSizes)
{
delete [] m_ppulFileSizes;
m_ppulFileSizes = NULL;
}
//
// If there is a file date array allocated, then delete it now.
//
if(m_ppulFileDates)
{
delete [] m_ppulFileDates;
m_ppulFileDates = NULL;
}
//
// If there is a device array allocated, then delete it now.
//
if(m_ppDevice)
{
delete [] m_ppDevice;
m_ppDevice = NULL;
}
//
// If there is a storage globals array allocated, then delete it now.
//
if(m_ppStorageGlobals)
{
delete [] m_ppStorageGlobals;
m_ppStorageGlobals = NULL;
}
//
// Reset the number of drives to zero.
//
m_ulNumDrives = 0;
//
// Release the critical section.
//
m_CriticalSection.Unlock();
//
// Close the Maverick(tm) driver.
//
Maverick_CloseDevice();
}
//****************************************************************************
//
// Refreshes the local copy of the list of files on the device.
//
//****************************************************************************
void
CMaverickInfo::Refresh(unsigned long ulDrive)
{
WCHAR *pwcString = NULL, *pwcTemp, pwcName[256];
unsigned long *pulLength = NULL, *pulDate = NULL, *pulTemp;
unsigned long ulNumFiles = 0, ulFiles = 0, ulStrLen = 0;
//
// Open the root directory on this drive.
//
if(Maverick_OpenDir(ulDrive, L"\\") == 1)
{
//
// Loop through all the files on this drive.
//
while(Maverick_ReadDir(pwcName, 1) == 1)
{
//
// Attempt to open this file.
//
if(Maverick_Open(ulDrive, pwcName, 1) == 0)
{
//
// We could not open this file, so we'll leave the database as
// is for now.
//
return;
}
//
// See if the current file name string length is zero.
//
if(ulStrLen == 0)
{
//
// Allocate memory to hold the name of this file.
//
pwcString = new WCHAR[wcslen(pwcName) + 1];
}
else
{
//
// Allocate memory to hold the names of all the previous files,
// along with the name of this file.
//
pwcTemp = new WCHAR[ulStrLen + wcslen(pwcName) + 1];
//
// Copy the names of all the previous files to the newly
// allocated string.
//
memcpy(pwcTemp, pwcString, ulStrLen * sizeof(WCHAR));
//
// Delete the previous string.
//
delete [] pwcString;
//
// Use the newly allocated string.
//
pwcString = pwcTemp;
}
//
// Copy the name of this file to the end of the string of file
// names.
//
wcscpy(pwcString + ulStrLen, pwcName);
//
// Increment the length of the file names string by the length of
// the name of this file.
//
ulStrLen += wcslen(pwcName) + 1;
//
// See if there is any more space in the length and date arrays.
//
if(ulNumFiles == ulFiles)
{
//
// See if we have allocated the length and date arrays.
//
if(!ulFiles)
{
//
// Set the initial size of the length and date arrays at
// 16.
//
ulFiles = 16;
//
// Allocate the array to hold the file lengths.
//
pulLength = new unsigned long[ulFiles];
//
// Allocate the array to hold the file dates.
//
pulDate = new unsigned long[ulFiles];
}
else
{
//
// Double the size of the length and date arrays.
//
ulFiles *= 2;
//
// Allocate a new array to hold the file lengths.
//
pulTemp = new unsigned long[ulFiles];
//
// Copy the existing file lengths to the new array.
//
memcpy(pulTemp, pulLength,
ulNumFiles * sizeof(unsigned long));
//
// Delete the existing array for the file lengths.
//
delete [] pulLength;
//
// Use the newly allocated array for the file lengths.
//
pulLength = pulTemp;
//
// Allocate a new array to hold the file dates.
//
pulTemp = new unsigned long[ulFiles];
//
// Copy the existing file dates to the new array.
//
memcpy(pulTemp, pulDate,
ulNumFiles * sizeof(unsigned long));
//
// Delete the existing array for the file dates.
//
delete [] pulDate;
//
// Use the newly allocated array for the file dates.
//
pulDate = pulTemp;
}
}
//
// Get the length of this file.
//
pulLength[ulNumFiles] = Maverick_Length();
//
// Get the modification date/time of this file.
//
pulDate[ulNumFiles] = Maverick_GetDate();
//
// Close this file.
//
Maverick_Close();
//
// Increment the number of files on this drive.
//
ulNumFiles++;
}
//
// Close the root directory.
//
Maverick_CloseDir();
}
//
// Save the number of files on this drive.
//
m_pulNumFiles[ulDrive] = ulNumFiles;
//
// Save the string of names of the files on this drive.
//
if(m_ppcFileNames[ulDrive])
{
delete [] m_ppcFileNames[ulDrive];
}
m_ppcFileNames[ulDrive] = pwcString;
//
// Save the array of file lengths.
//
if(m_ppulFileSizes[ulDrive])
{
delete [] m_ppulFileSizes[ulDrive];
}
m_ppulFileSizes[ulDrive] = pulLength;
//
// Save the array of file dates.
//
if(m_ppulFileDates[ulDrive])
{
delete [] m_ppulFileDates[ulDrive];
}
m_ppulFileDates[ulDrive] = pulDate;
}
//****************************************************************************
//
// Returns the serial number of the device.
//
//****************************************************************************
void
CMaverickInfo::GetSerialNumber(unsigned long ulDrive, WMDMID *pID)
{
//
// Obtain the critical section.
//
m_CriticalSection.Lock();
//
// Make sure that:
// 1) the specified drive is valid, and
// 2) we have an array of serial numbers.
//
if((ulDrive >= m_ulNumDrives) || !m_pID)
{
m_CriticalSection.Unlock();
pID->cbSize = 0;
return;
}
//
// Return our serial number in the WMDMID structure.
//
*pID = m_pID[ulDrive];
//
// Release the critical section.
//
m_CriticalSection.Unlock();
}
//****************************************************************************
//
// Returns the name of the device manufacturer.
//
//****************************************************************************
void
CMaverickInfo::GetManufacturerName(WCHAR *pcName, unsigned long ulLength)
{
//
// Obtain the critical section.
//
m_CriticalSection.Lock();
//
// Return the device manufacturer name.
//
if(!m_pcManufacturerName)
{
pcName[0] = L'\0';
}
else
{
wcsncpy(pcName, m_pcManufacturerName, ulLength);
}
//
// Release the critical section.
//
m_CriticalSection.Unlock();
}
//****************************************************************************
//
// Returns the version number of the device.
//
//****************************************************************************
unsigned long
CMaverickInfo::GetVersion(void)
{
//
// Return the version number.
//
return(m_ulVersion);
}
//****************************************************************************
//
// Returns the number of drives on the device.
//
//****************************************************************************
unsigned long
CMaverickInfo::GetNumDrives(void)
{
//
// Return the number of drives.
//
return(m_ulNumDrives);
}
//****************************************************************************
//
// Returns the name of the given drive.
//
//****************************************************************************
void
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -