📄 storage.cpp
字号:
//****************************************************************************
//
// STORAGE.CPP - The CMDSPStorage class, which implements the IMDSPStorage,
// IMDSPObjectInfo, and IMDSPObject interfaces.
//
// Copyright (c) 2000 Cirrus Logic, Inc.
// Copyright (C) Microsoft Corporation, 1999 - 2001. All rights reserved.
//
//****************************************************************************
#include "stdafx.h"
//****************************************************************************
//
// The constructor for the CMDSPStorage class.
//
//****************************************************************************
CMDSPStorage::CMDSPStorage(void)
{
//
// Make sure that the name pointer is NULL.
//
m_pwcName = NULL;
}
//****************************************************************************
//
// The destructor for the CMDSPStorage class.
//
//****************************************************************************
CMDSPStorage::~CMDSPStorage(void)
{
//
// If this storage object is opened, then close it now.
//
if(m_bIsOpen)
{
Maverick_Close();
}
//
// If we allocated memory for the name, then free it now.
//
if(m_pwcName)
{
delete [] m_pwcName;
}
}
//****************************************************************************
//
// Initializes the information about this storage object.
//
//****************************************************************************
void
CMDSPStorage::SetStorageInfo(unsigned long ulDrive, WCHAR *pcName,
unsigned long bIsRoot, unsigned long ulSize,
unsigned long ulDate)
{
//
// Save the drive.
//
m_ulDrive = ulDrive;
//
// Allocate memory to hold the name.
//
m_pwcName = new WCHAR[wcslen(pcName) + 1];
if(!m_pwcName)
{
return;
}
//
// Copy the name.
//
wcscpy(m_pwcName, pcName);
//
// Save the root storage object indicator.
//
m_bIsRoot = bIsRoot;
//
// Save the size.
//
m_ulSize = ulSize;
//
// Save the date.
//
m_ulDate = ulDate;
//
// All storage objects are closed by default.
//
m_bIsOpen = FALSE;
}
//****************************************************************************
//
// The IMDSPStorage::CreateStorage method, which creates a new storage at the
// level of this storage object.
//
//****************************************************************************
STDMETHODIMP
CMDSPStorage::CreateStorage(DWORD dwAttributes, _WAVEFORMATEX *pFormat,
LPWSTR pwszName, IMDSPStorage **ppNewStorage)
{
CComObject<CMDSPStorage> *pObj;
HRESULT hr;
//
// If we do not have a secure channel server object, then return a failure.
//
if(!g_pAppSCServer)
{
return(S_FALSE);
}
//
// If we are not authenticated, then return a failure.
//
if(!(g_pAppSCServer->fIsAuthenticated()))
{
return(WMDM_E_NOTCERTIFIED);
}
//
// If we were passed a NULL pointer, then return a failure.
//
if(!pwszName || !ppNewStorage)
{
return(E_INVALIDARG);
}
//
// If this storage object has been deleted, then return a failure.
//
if(!m_pwcName[0])
{
return(WMDM_E_INTERFACEDEAD);
}
//
// We only support:
// 1) Inserting a new storage object into the root storage object, or
// 2) Inserting a new storage object before or after a non-root storage
// object,
// so if either of these two cases are not requested, then return a
// failure.
//
if((m_bIsRoot && (dwAttributes & (WMDM_STORAGECONTROL_INSERTBEFORE |
WMDM_STORAGECONTROL_INSERTAFTER))) ||
(!m_bIsRoot && (dwAttributes & WMDM_STORAGECONTROL_INSERTINTO)))
{
return(WMDM_E_NOTSUPPORTED);
}
//
// Create a new storage object.
//
hr = CComObject<CMDSPStorage>::CreateInstance(&pObj);
if(FAILED(hr))
{
return(hr);
}
//
// Get a pointer to the IMDSPStorage interface for the object.
//
hr = pObj->QueryInterface(IID_IMDSPStorage,
reinterpret_cast<void **>(ppNewStorage));
if(FAILED(hr))
{
delete pObj;
return(hr);
}
//
// Initialize the storage object.
//
pObj->SetStorageInfo(m_ulDrive, pwszName, FALSE, 0, 0);
//
// Success.
//
return(S_OK);
}
//****************************************************************************
//
// The IMDSPStorage::EnumStorage method, which returns an enumerator for the
// storage objects contained in this storage object.
//
//****************************************************************************
STDMETHODIMP
CMDSPStorage::EnumStorage(IMDSPEnumStorage **ppEnumStorage)
{
CComObject<CMDSPEnumStorage> *pEnumObj;
HRESULT hr;
//
// If we do not have a secure channel server object, then return a failure.
//
if(!g_pAppSCServer)
{
return(S_FALSE);
}
//
// If we are not authenticated, then return a failure.
//
if(!(g_pAppSCServer->fIsAuthenticated()))
{
return(WMDM_E_NOTCERTIFIED);
}
//
// If we were passed a NULL pointer, then return a failure.
//
if(!ppEnumStorage)
{
return(E_INVALIDARG);
}
//
// If this storage object is a file, then there are no storage objects to
// be enumerated.
//
if(!m_bIsRoot)
{
return(WMDM_E_NOTSUPPORTED);
}
//
// Create a new storage enumerator object.
//
hr = CComObject<CMDSPEnumStorage>::CreateInstance(&pEnumObj);
if(FAILED(hr))
{
return(hr);
}
//
// Get a pointer to the IMDSPEnumStorage interface for the object.
//
hr = pEnumObj->QueryInterface(IID_IMDSPEnumStorage,
reinterpret_cast<void **>(ppEnumStorage));
if(FAILED(hr))
{
delete pEnumObj;
return(hr);
}
//
// Specify the drive to be enumerated by the new object.
//
pEnumObj->SetDrive(m_ulDrive, FALSE);
//
// Success.
//
return(S_OK);
}
//****************************************************************************
//
// The IMDSPStorage::GetAttributes method, which returns the attributes of
// this storage object.
//
//****************************************************************************
STDMETHODIMP
CMDSPStorage::GetAttributes(DWORD *pdwAttributes, _WAVEFORMATEX *pFormat)
{
//
// If we do not have a secure channel server object, then return a failure.
//
if(!g_pAppSCServer)
{
return(S_FALSE);
}
//
// If we are not authenticated, then return a failure.
//
if(!(g_pAppSCServer->fIsAuthenticated()))
{
return(WMDM_E_NOTCERTIFIED);
}
//
// If we were passed a NULL pointer, then return a failure.
//
if(!pdwAttributes || !pFormat)
{
return(E_INVALIDARG);
}
//
// If this storage object has been deleted, then return a failure.
//
if(!m_pwcName[0])
{
return(WMDM_E_INTERFACEDEAD);
}
//
// See if we are a drive or a file.
//
if(m_bIsRoot)
{
//
// We are a drive, so return the base set of attributes.
//
*pdwAttributes = WMDM_STORAGE_ATTR_FILESYSTEM |
WMDM_FILE_ATTR_FOLDER | WMDM_FILE_ATTR_CANREAD;
//
// See if there are any files on this drive.
//
if(g_MaverickInfo.GetNumFiles(m_ulDrive) != 0)
{
//
// Indicate that there are files on this drive.
//
*pdwAttributes |= WMDM_STORAGE_ATTR_HAS_FILES;
}
}
else
{
//
// We are a file, so return the file attributes.
//
*pdwAttributes = WMDM_FILE_ATTR_FILE | WMDM_FILE_ATTR_CANREAD |
WMDM_FILE_ATTR_AUDIO;
}
//
// Success.
//
return(S_OK);
}
//****************************************************************************
//
// The IMDSPStorage::GetDate method, which returns the date on which this
// storage object was most recently modified.
//
//****************************************************************************
STDMETHODIMP
CMDSPStorage::GetDate(PWMDMDATETIME pDateTimeUTC)
{
unsigned char ucMonthLength[12] = { 31, 29, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31 };
TIME_ZONE_INFORMATION tzInfo;
unsigned long ulSeconds;
//
// If we do not have a secure channel server object, then return a failure.
//
if(!g_pAppSCServer)
{
return(S_FALSE);
}
//
// If we are not authenticated, then return a failure.
//
if(!(g_pAppSCServer->fIsAuthenticated()))
{
return(WMDM_E_NOTCERTIFIED);
}
//
// If we were passed a NULL pointer, then return a failure.
//
if(!pDateTimeUTC)
{
return(E_INVALIDARG);
}
//
// If this storage object has been deleted, then return a failure.
//
if(!m_pwcName[0])
{
return(WMDM_E_INTERFACEDEAD);
}
//
// Get the modification date/time of this storage object.
//
ulSeconds = m_ulDate;
//
// Get the current time zone information.
//
if(GetTimeZoneInformation(&tzInfo) != TIME_ZONE_ID_INVALID)
{
//
// Add the time zone bias to the modification date/time.
//
ulSeconds += tzInfo.Bias * 60;
}
//
// Extract the number of seconds from the time.
//
pDateTimeUTC->wSecond = (WORD)(ulSeconds % 60);
ulSeconds /= 60;
//
// Extract the number of minutes from the time.
//
pDateTimeUTC->wMinute = (WORD)(ulSeconds % 60);
ulSeconds /= 60;
//
// Extract the number of hours from the time.
//
pDateTimeUTC->wHour = (WORD)(ulSeconds % 24);
ulSeconds /= 24;
//
// We now have days, so add the number of days between January 1, 1900 and
// January 1, 1970.
//
ulSeconds += (70 * 365) + 18;
//
// Compute the number of years in terms of group of years from leap year to
// leap year.
//
pDateTimeUTC->wYear = (WORD)(4 * (ulSeconds / ((365 * 4) + 1)));
ulSeconds %= (365 * 4) + 1;
//
// If there are more than 365 days left in the current count of days, then
// subtract the days from the remaining non-leap years.
//
if(ulSeconds >= 366)
{
pDateTimeUTC->wYear += (WORD)((ulSeconds - 1) / 365);
ulSeconds = (ulSeconds - 1) % 365;
}
//
// The year is now the number of years since 1900, so add 1900 so it is the
// actual year.
//
pDateTimeUTC->wYear += 1900;
//
// If this is a non-leap year and the day is past February 28th, then
// increment the count of days by one (i.e. act as if each year is a leap
// year).
//
if(((pDateTimeUTC->wYear & 3) != 0) && (ulSeconds >= (31 + 28)))
{
ulSeconds++;
}
//
// Subtract days for each month till we find the current month.
//
pDateTimeUTC->wMonth = 0;
while(ulSeconds >= ucMonthLength[pDateTimeUTC->wMonth])
{
ulSeconds -= ucMonthLength[pDateTimeUTC->wMonth++];
}
//
// The month is actually 1 indexed, so add one now.
//
pDateTimeUTC->wMonth++;
//
// Save the computed day.
//
pDateTimeUTC->wDay = (WORD)(ulSeconds + 1);
//
// Success.
//
return(S_OK);
}
//****************************************************************************
//
// The IMDSPStorage::GetName method, which returns the name of this storage
// object.
//
//****************************************************************************
STDMETHODIMP
CMDSPStorage::GetName(LPWSTR pwszName, UINT nMaxChars)
{
//
// If we do not have a secure channel server object, then return a failure.
//
if(!g_pAppSCServer)
{
return(S_FALSE);
}
//
// If we are not authenticated, then return a failure.
//
if(!(g_pAppSCServer->fIsAuthenticated()))
{
return(WMDM_E_NOTCERTIFIED);
}
//
// If we were passed a NULL pointer, then return an error.
//
if(!pwszName)
{
return(E_INVALIDARG);
}
//
// If this storage object has been deleted, then return a failure.
//
if(!m_pwcName[0])
{
return(WMDM_E_INTERFACEDEAD);
}
//
// Make sure that the output buffer is large enough to hold the the name
// of this storage object.
//
if(wcslen(m_pwcName) >= nMaxChars)
{
return(WMDM_E_BUFFERTOOSMALL);
}
//
// Copy the name of this storage object into the output buffer.
//
wcscpy(pwszName, m_pwcName);
//
// Success.
//
return(S_OK);
}
//****************************************************************************
//
// The IMDSPStorage::GetRights method, which returns the rights information
// for this storage object.
//
//****************************************************************************
STDMETHODIMP
CMDSPStorage::GetRights(PWMDMRIGHTS *ppRights, UINT *pnRightsCount,
BYTE abMac[WMDM_MAC_LENGTH])
{
//
// If we do not have a secure channel server object, then return a failure.
//
if(!g_pAppSCServer)
{
return(S_FALSE);
}
//
// If we are not authenticated, then return a failure.
//
if(!(g_pAppSCServer->fIsAuthenticated()))
{
return(WMDM_E_NOTCERTIFIED);
}
//
// If this storage object has been deleted, then return a failure.
//
if(!m_pwcName[0])
{
return(WMDM_E_INTERFACEDEAD);
}
//
// We do not support rights management (at this time).
//
return(WMDM_E_NOTSUPPORTED);
}
//****************************************************************************
//
// The IMDSPStorage::GetSize method, which returns the size of this storage
// object.
//
//****************************************************************************
STDMETHODIMP
CMDSPStorage::GetSize(DWORD *pdwSizeLow, DWORD *pdwSizeHigh)
{
//
// If we do not have a secure channel server object, then return a failure.
//
if(!g_pAppSCServer)
{
return(S_FALSE);
}
//
// If we are not authenticated, then return a failure.
//
if(!(g_pAppSCServer->fIsAuthenticated()))
{
return(WMDM_E_NOTCERTIFIED);
}
//
// If we were passed a NULL pointer, then return a failure.
//
if(!pdwSizeLow)
{
return(E_INVALIDARG);
}
//
// If this storage object has been deleted, then return a failure.
//
if(!m_pwcName[0])
{
return(WMDM_E_INTERFACEDEAD);
}
//
// Return the size of this storage object.
//
*pdwSizeLow = m_ulSize;
if(pdwSizeHigh)
{
*pdwSizeHigh = 0;
}
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -