| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- ///////////////////////////////////////////////////////////////////////
- // DiscFormatData.cpp
- //
- // Wrapper for IDiscFormat2Data Interface
- //
- // Written by Eric Haddan
- //
- #include "StdAfx.h"
- #include "DiscFormatData.h"
- #include "DiscRecorder.h"
- #include "DiscFormatDataEvent.h"
- CDiscFormatData::CDiscFormatData(void)
- : m_discFormatData(NULL)
- , m_mediaTypesArray(NULL)
- , m_supportedSpeeds(NULL)
- , m_hResult(0)
- , m_hNotificationWnd(NULL)
- , m_closeMedia(true)
- {
- }
- CDiscFormatData::~CDiscFormatData(void)
- {
- if (m_discFormatData != NULL)
- {
- m_discFormatData->Release();
- }
- }
- ///////////////////////////////////////////////////////////////////////
- //
- // CDiscFormatData::Initialize()
- //
- // Description:
- // Creates and initializes the IDiscFormat2Data interface
- //
- bool CDiscFormatData::Initialize(CDiscRecorder* pDiscRecorder, const CString& clientName)
- {
- ASSERT(m_discFormatData == NULL);
- ASSERT(pDiscRecorder != NULL);
- if (pDiscRecorder == NULL)
- {
- m_errorMessage = _T("Error - CDiscFormatData::Initialize - pDiscRecorder is NULL");
- return false;
- }
- //
- // Initialize the IDiscFormat2Data Interface
- //
- m_hResult = CoCreateInstance(__uuidof(MsftDiscFormat2Data), NULL, CLSCTX_INPROC_SERVER,
- __uuidof(IDiscFormat2Data), (void**)&m_discFormatData);
- if (!SUCCEEDED(m_hResult))
- {
- m_errorMessage.Format(_T("Unable to Initialize IDiscFormat2Data - Error:0x%08x"), m_hResult);
- return false;
- }
- //
- // Setup the Disc Format Information
- //
- VARIANT_BOOL isSupported = VARIANT_FALSE;
- m_hResult = m_discFormatData->IsRecorderSupported(pDiscRecorder->GetInterface(), &isSupported);
- if (isSupported == VARIANT_FALSE)
- {
- m_errorMessage = _T("Recorder not supported");
- return false;
- }
- m_hResult = m_discFormatData->put_Recorder(pDiscRecorder->GetInterface());
- if (!SUCCEEDED(m_hResult))
- {
- m_errorMessage.Format(_T("IDiscFormat2Data->put_Recorder Failed - Error:0x%08x"), m_hResult);
- return false;
- }
- m_hResult = m_discFormatData->put_ClientName(clientName.AllocSysString());
- if (!SUCCEEDED(m_hResult))
- {
- m_errorMessage.Format(_T("IDiscFormat2Data->put_ClientName Failed - Error:0x%08x"), m_hResult);
- return false;
- }
- // 检索刻录机支持的媒体类型;
- m_hResult = m_discFormatData->get_SupportedMediaTypes(&m_mediaTypesArray);
- if (!SUCCEEDED(m_hResult))
- {
- m_errorMessage.Format(_T("IDiscFormat2Data->get_SupportedMediaTypes Failed - Error:0x%08x"), m_hResult);
- return false;
- }
- // 检索当前刻录机或当前媒体支持的写入速度列表;
- m_hResult = m_discFormatData->get_SupportedWriteSpeeds(&m_supportedSpeeds);
- if (!SUCCEEDED(m_hResult))
- {
- m_errorMessage.Format(_T("IDiscFormat2Data->get_SupportedWriteSpeeds Failed - Error:0x%08x"), m_hResult);
- return false;
- }
- return true;
- }
- ULONG CDiscFormatData::GetTotalSupportedMediaTypes()
- {
- if (m_mediaTypesArray == NULL)
- return 0;
- return m_mediaTypesArray->rgsabound[0].cElements;
- }
- int CDiscFormatData::GetSupportedMediaType(ULONG index)
- {
- ASSERT(index < GetTotalSupportedMediaTypes());
- if (index < GetTotalSupportedMediaTypes())
- {
- if (m_mediaTypesArray)
- {
- return ((VARIANT*)(m_mediaTypesArray->pvData))[index].intVal;
- }
- }
- return 0;
- }
- ULONG CDiscFormatData::GetTotalSupportedWriteSpeeds()
- {
- if (m_supportedSpeeds == NULL)
- return 0;
- return m_supportedSpeeds->rgsabound[0].cElements;
- }
- int CDiscFormatData::GetSupportedWriteSpeed(ULONG index)
- {
- ASSERT(index < GetTotalSupportedWriteSpeeds());
- if ( index < GetTotalSupportedWriteSpeeds())
- {
- if (m_supportedSpeeds)
- return ((VARIANT*)(m_supportedSpeeds->pvData))[index].ulVal; // 每秒写入的扇区数;
- }
- return 0;
- }
- bool CDiscFormatData::SetWriteSpeed(ULONG index)
- {
- ASSERT(index < GetTotalSupportedWriteSpeeds());
- if ( index < GetTotalSupportedWriteSpeeds())
- {
- if (m_supportedSpeeds)
- m_discFormatData->SetWriteSpeed(((VARIANT*)(m_supportedSpeeds->pvData))[index].ulVal, VARIANT_FALSE);
- }
- return false;
- }
- /*
- bool CDiscFormatData::SetBurnVerification(IMAPI_BURN_VERIFICATION_LEVEL VerificationLevel)
- {
- HRESULT hr = S_OK;
- IBurnVerification *burnVerifier = NULL;
- hr = m_discFormatData->QueryInterface(IID_PPV_ARGS(&burnVerifier));
- if (SUCCEEDED(hr))
- {
- hr = burnVerifier->put_BurnVerificationLevel(VerificationLevel);
- }
- if (burnVerifier != NULL)
- {
- burnVerifier->Release();
- burnVerifier = NULL;
- }
- return hr;
- }*/
- bool CDiscFormatData::Burn(HWND hNotificationWnd, IStream* streamData)
- {
- if (m_discFormatData == NULL)
- return false;
- if (hNotificationWnd == NULL)
- return false;
- if (streamData == NULL)
- return false;
- m_streamData = streamData;
- m_hNotificationWnd = hNotificationWnd;
- // Create the event sink
- CDiscFormatDataEvent* eventSink = CDiscFormatDataEvent::CreateEventSink();
- if (eventSink == NULL)
- {
- m_errorMessage = _T("Unable to create event sink");
- return false;
- }
- if (!eventSink->ConnectDiscFormatData(this))
- {
- m_errorMessage = _T("Unable to connect event sink with interface");
- return false;
- }
- eventSink->SetHwnd(m_hNotificationWnd);
- m_discFormatData->put_ForceMediaToBeClosed(m_closeMedia ? VARIANT_TRUE : VARIANT_FALSE);
- m_hResult = m_discFormatData->Write(m_streamData);
- delete eventSink;
- if (SUCCEEDED(m_hResult))
- {
- return true;
- }
- m_errorMessage.Format(_T("IDiscFormat2Data->Write Failed! Error:0x%08x"),
- m_hResult);
- return true;
- }
- /************************************************************************/
- /* 函数:获取媒体总扇区大小(不是空闲扇区大小)[3/20/2018 Jeff];
- /* 描述:;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- bool CDiscFormatData::GetFreeSectorsOnMedia(LONG& lFreeSectorOnMedia)
- {
- if (m_discFormatData == NULL)
- return false;
- HRESULT hr = m_discFormatData->get_FreeSectorsOnMedia(&lFreeSectorOnMedia);
- if (SUCCEEDED(hr))
- {
- lFreeSectorOnMedia *= 2;
- lFreeSectorOnMedia /= 1024;
- //lFreeSectorOnMedia /= 1024;
- return true;
- }
- return false;
- }
|