/
DiscFormatData.cpp
198 lines (165 loc) · 4.35 KB
/
DiscFormatData.cpp
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
///////////////////////////////////////////////////////////////////////
// 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_hResult(0)
, m_hNotificationWnd(NULL)
, m_closeMedia(true)
{
}
CDiscFormatData::~CDiscFormatData(void)
{
if (m_discFormatData != NULL)
{
m_discFormatData->Release();
}
}
///////////////////////////////////////////////////////////////////////
//
// CDiskFormat::getInformation about total space and free space
//
//
//
long CDiscFormatData::getTotalSpaceOfMedia()
{
if(m_discFormatData != NULL)
{
//MessageBox(NULL,L"asd asd",NULL,0);
long allSpace;
m_discFormatData->get_TotalSectorsOnMedia(&allSpace);
return allSpace;
}
else
return 0;
}
long CDiscFormatData::getFreeSpaceOfMedia()
{
if(m_discFormatData != NULL)
{
//MessageBox(NULL,L"asd asd",NULL,0);
long freeSpace;
m_discFormatData->get_FreeSectorsOnMedia(&freeSpace);
return freeSpace;
}
else
return 0;
}
///////////////////////////////////////////////////////////////////////
//
// 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;
}
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;
}
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_discFormatData->SetWriteSpeed(1,true);
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;
}