📄 mavinfo.cpp
字号:
//****************************************************************************
//
// MAVINFO.CPP - The CMaverickInfo class.
//
// Copyright (c) 2000 Cirrus Logic, Inc.
//
//****************************************************************************
#include "stdafx.h"
//****************************************************************************
//
// TimeToSeconds converts the specified time as month, day, year, hour,
// minute, and second into the number of seconds since January 1, 1970.
//
//****************************************************************************
static unsigned long
TimeToSeconds(unsigned long ulYear, unsigned long ulMonth, unsigned long ulDay,
unsigned long ulHour, unsigned long ulMinute,
unsigned long ulSecond)
{
unsigned char ucMonthLength[12] = { 31, 29, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31 };
unsigned long ulRet, ulIdx;
//
// Compute the number of days that have past in this year.
//
ulRet = ulDay - 1;
ulIdx = ulMonth - 1;
while(ulIdx--)
{
ulRet += ucMonthLength[ulIdx];
}
//
// If this is a non-leap year and the day is past February 28th, then
// subtract the count of days by one (since we treat each year as if it
// were a leap year).
//
if(((ulYear & 3) != 0) && (ulRet >= (31 + 28)))
{
ulRet--;
}
//
// Add the days for the years that have past.
//
ulIdx = ulYear - 1970;
ulRet += (ulIdx * 365) + ((ulIdx + 1) / 4);
//
// Convert the days to hours and add the current hour.
//
ulRet = (ulRet * 24) + ulHour;
//
// Convert the hours to minutes and add the current minute.
//
ulRet = (ulRet * 60) + ulMinute;
//
// Convert the minutes to seconds and add the current second.
//
ulRet = (ulRet * 60) + ulSecond;
//
// Return the converted time.
//
return(ulRet);
}
//****************************************************************************
//
// Checks the clock on the player and updates it if it is "too far" out of
// sync with the host clock.
//
//****************************************************************************
static void
CheckTime(void)
{
SYSTEMTIME sLocalTime;
unsigned long ulLength, ulTime, ulPlayerTime;
//
// Get the current time from the player.
//
if(Maverick_GetDescriptor(USB_Vendor_Descriptor_CurrentTime, 0,
(char *)&ulPlayerTime, &ulLength) == 0)
{
//
// We could not get the current time from the player, so do nothing
// further.
//
return;
}
//
// Get the current host time.
//
GetLocalTime(&sLocalTime);
//
// Convert the current host time into seconds.
//
ulTime = TimeToSeconds(sLocalTime.wYear, sLocalTime.wMonth,
sLocalTime.wDay, sLocalTime.wHour,
sLocalTime.wMinute, sLocalTime.wSecond);
//
// See if the current player time is within 10 seconds on either side of
// the current host time.
//
if(((ulTime < ulPlayerTime) && ((ulPlayerTime - ulTime) > 10)) ||
((ulTime > ulPlayerTime) && ((ulTime - ulPlayerTime) > 10)))
{
//
// The current player time is more than 10 seconds different than the
// current host time, so change the player time to the current host
// time.
//
Maverick_SetDescriptor(USB_Vendor_Descriptor_CurrentTime, 0,
(char *)&ulTime, 4);
}
}
//****************************************************************************
//
// The constructor for the CMaverickInfo class.
//
//****************************************************************************
CMaverickInfo::CMaverickInfo(void)
{
//
// Initialize all the pointers to NULL, and the number of drives to zero.
//
m_pID = NULL;
m_pcManufacturerName = NULL;
m_ulNumDrives = 0;
m_ppcDriveNames = NULL;
m_pulNumFiles = NULL;
m_ppcFileNames = NULL;
m_ppulFileSizes = NULL;
m_ppulFileDates = NULL;
m_ppDevice = NULL;
m_ppStorageGlobals = NULL;
}
//****************************************************************************
//
// The destructor for the CMaverickInfo class.
//
//****************************************************************************
CMaverickInfo::~CMaverickInfo(void)
{
//
// Reset before we go away (which frees up any memory which has been
// allocated).
//
Reset();
}
//****************************************************************************
//
// Performs initialization of this object.
//
//****************************************************************************
void
CMaverickInfo::Initialize(void)
{
unsigned long ulDrive, ulLength;
//
// Obtain the critical section.
//
m_CriticalSection.Lock();
//
// Open the Maverick(tm) driver.
//
if(Maverick_OpenDevice() == 0)
{
//
// There is no device attached now, so set the number of drives to
// zero and return.
//
m_ulNumDrives = 0;
m_CriticalSection.Unlock();
return;
}
//
// Check and possibly update the time on the player.
//
CheckTime();
//
// Get the number of drives on the device.
//
m_ulNumDrives = Maverick_NumDrives();
//
// Allocate memory for the manufacturer name.
//
m_pcManufacturerName = new WCHAR[128];
if(!m_pcManufacturerName)
{
m_CriticalSection.Unlock();
return;
}
//
// Get the name of the device manufacturer.
//
if(Maverick_GetManufacturerName(m_pcManufacturerName, 256) == 0)
{
wcscpy(m_pcManufacturerName, L"Unknown");
}
//
// Get the version of the hardware.
//
ulLength = sizeof(unsigned long);
if(Maverick_GetDescriptor(USB_Vendor_Descriptor_FirmwareVersion, 0,
&m_ulVersion, &ulLength) == 0)
{
m_ulVersion = 0;
}
//
// Allocate memory for the serial number array.
//
m_pID = new WMDMID[m_ulNumDrives];
if(!m_pID)
{
m_CriticalSection.Unlock();
return;
}
//
// Allocate memory for the array of drive names.
//
m_ppcDriveNames = new WCHAR *[m_ulNumDrives];
if(!m_ppcDriveNames)
{
m_CriticalSection.Unlock();
return;
}
//
// Loop through the drives.
//
for(ulDrive = 0; ulDrive < m_ulNumDrives; ulDrive++)
{
//
// Allocate memory for the drive name.
//
m_ppcDriveNames[ulDrive] = new WCHAR[128];
//
// Get the name of this drive.
//
ulLength = 128;
if(Maverick_GetDescriptor(USB_Vendor_Descriptor_MediaName, ulDrive,
m_ppcDriveNames[ulDrive], &ulLength) == 0)
{
wcscpy(m_ppcDriveNames[ulDrive], L"Unknown");
}
//
// Get the media ID for this drive.
//
ulLength = WMDMID_LENGTH;
if(Maverick_GetDescriptor(USB_Vendor_Descriptor_MediaID, ulDrive,
m_pID[ulDrive].pID, &ulLength) != 0)
{
m_pID[ulDrive].cbSize = sizeof(WMDMID);
m_pID[ulDrive].SerialNumberLength = ulLength;
}
}
//
// Allocate memory for the number of files array.
//
m_pulNumFiles = new unsigned long[m_ulNumDrives];
if(!m_pulNumFiles)
{
m_CriticalSection.Unlock();
return;
}
//
// Allocate memory for the file names array.
//
m_ppcFileNames = new WCHAR *[m_ulNumDrives];
if(!m_ppcFileNames)
{
m_CriticalSection.Unlock();
return;
}
//
// Allocate memory for the file sizes array.
//
m_ppulFileSizes = new unsigned long *[m_ulNumDrives];
if(!m_ppulFileSizes)
{
m_CriticalSection.Unlock();
return;
}
//
// Allocate memory for the file modification date array.
//
m_ppulFileDates = new unsigned long *[m_ulNumDrives];
if(!m_ppulFileSizes)
{
m_CriticalSection.Unlock();
return;
}
//
// Allocate memory for the device object array.
//
m_ppDevice = new IMDSPDevice *[m_ulNumDrives];
if(!m_ppDevice)
{
m_CriticalSection.Unlock();
return;
}
//
// Allocate memory for the storage globals object array.
//
m_ppStorageGlobals = new IMDSPStorageGlobals *[m_ulNumDrives];
if(!m_ppStorageGlobals)
{
m_CriticalSection.Unlock();
return;
}
//
// Loop through the drives.
//
for(ulDrive = 0; ulDrive < m_ulNumDrives; ulDrive++)
{
//
// Initialize the information for this drive.
//
m_pulNumFiles[ulDrive] = 0;
m_ppcFileNames[ulDrive] = NULL;
m_ppulFileSizes[ulDrive] = NULL;
m_ppulFileDates[ulDrive] = NULL;
m_ppDevice[ulDrive] = NULL;
m_ppStorageGlobals[ulDrive] = NULL;
//
// Refresh this drive.
//
Refresh(ulDrive);
}
//
// Release the critical section.
//
m_CriticalSection.Unlock();
}
//****************************************************************************
//
// Frees the databases and resets this object.
//
//****************************************************************************
void
CMaverickInfo::Reset(void)
{
unsigned long ulDrive;
//
// Obtain the critical section.
//
m_CriticalSection.Lock();
//
// If there is a device manufacturer name string allocated, then delete it
// now.
//
if(m_pcManufacturerName)
{
delete [] m_pcManufacturerName;
m_pcManufacturerName = NULL;
}
//
// If there is a serial number array allocated, then delete it now.
//
if(m_pID)
{
delete [] m_pID;
m_pID = NULL;
}
//
// If there is a number of files array allocated, then delete it now.
//
if(m_pulNumFiles)
{
delete [] m_pulNumFiles;
m_pulNumFiles = NULL;
}
//
// Loop through all the drives.
//
for(ulDrive = 0; ulDrive < m_ulNumDrives; ulDrive++)
{
//
// If there is a drive name string allocated for this drive, then
// delete it now.
//
if(m_ppcDriveNames && m_ppcDriveNames[ulDrive])
{
delete [] m_ppcDriveNames[ulDrive];
}
//
// If there is a file name string allocated for this drive, then delete
// it now.
//
if(m_ppcFileNames && m_ppcFileNames[ulDrive])
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -