-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiscFormat2Data.cpp
More file actions
109 lines (93 loc) · 2.93 KB
/
DiscFormat2Data.cpp
File metadata and controls
109 lines (93 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// DiscFormat2Data.cpp : implementation file
//
#include "pch.h"
#include "CdBurnApp.h"
#include "DiscFormat2Data.h"
DiscFormat2Data::DiscFormat2Data() {
}
DiscFormat2Data::~DiscFormat2Data()
{
if (m_discFormatData != NULL)
{
m_discFormatData->Release();
}
}
int DiscFormat2Data::GetSupportedMediaType(ULONG index) {
if (m_discFormatData != NULL)
{
VARIANT varItem;
VariantInit(&varItem);
if (index < GetTotalNumberSupportedMediaTypes())
{
m_result = SafeArrayGetElement(m_supportedMediaTypes, (LONG*)&index, &varItem);
if (FAILED(m_result))
{
m_errorMessage.Format(_T("SafeArrayGetElement Error DiscFormat2 - Error:0x%08x"), m_result); return -1;
}
return varItem.intVal;
}
}
return -1;
}
bool DiscFormat2Data::initialize(DiscRecorder* pDiscRecorder, const CString& clientName) {
if (pDiscRecorder == NULL)
{
m_errorMessage.Format(_T("Error - CDiscFormatData::Initialize - pDiscRecorder is NULL"));
return false;
}
if (m_discFormatData == NULL)
{
m_result = CoCreateInstance(__uuidof(MsftDiscFormat2Data), NULL, CLSCTX_INPROC_SERVER,
__uuidof(IDiscFormat2Data), (void**)&m_discFormatData);
if (FAILED(m_result))
{
m_errorMessage.Format(_T("Failed to create instance of IDiscFormat2Data: %08X"), m_result);
return false;
}
VARIANT_BOOL isSupported = VARIANT_FALSE;
m_result = m_discFormatData->IsRecorderSupported(pDiscRecorder->GetRecorder(), &isSupported);
if (isSupported == VARIANT_FALSE)
{
m_errorMessage.Format(_T("Recorder not supported")); return false;
}
m_result = m_discFormatData->put_Recorder(pDiscRecorder->GetRecorder());
if (FAILED(m_result))
{
m_errorMessage.Format(_T("put_Recorder Error DiscFormat2 - Error:0x%08x"), m_result); return false;
}
m_result = m_discFormatData->put_ClientName(clientName.AllocSysString());
if (FAILED(m_result))
{
m_errorMessage.Format(_T("put_ClientName Error DiscFormat2 - Error:0x%08x"), m_result); return false;
}
m_result = m_discFormatData->get_SupportedMediaTypes(&m_supportedMediaTypes);
if (FAILED(m_result))
{
m_errorMessage.Format(_T("get_SupportedMediaTypes Error DiscFormat2 - Error:0x%08x"), m_result); return false;
}
return true;
}
return false;
}
ULONG DiscFormat2Data::GetTotalNumberSupportedMediaTypes() {
if (m_discFormatData != NULL)
{
return m_supportedMediaTypes->rgsabound[0].cElements;
}
return 0;
}
bool DiscFormat2Data::Burn(IStream* data) {//add encryption and notifcation part to track the progress
if (m_discFormatData == NULL || data == nullptr)
{
return false;
}
//Is VARIANT_TRUE if the next write session ends by marking the disc as closed to subsequent write sessions.
m_discFormatData->put_ForceMediaToBeClosed(m_closeMedia ? VARIANT_TRUE : VARIANT_FALSE);//Our case it should be true
m_result = m_discFormatData->Write(data);
if (FAILED(m_result))
{
m_errorMessage.Format(_T("IDiscFormat2Data->Write Failed! Error:0x%08x"), m_result);
return false;
}
return true;
}