14 #error TnbImageMastering.h is necessary fot OLE Object.
30 template<
typename T>
void** IID_PPV_ARGS_Helper(T** pp)
32 static_cast<IUnknown*
>(*pp);
33 return reinterpret_cast<void**
>(pp);
35 #define IID_PPV_ARGS(ppType) __uuidof(**(ppType)), IID_PPV_ARGS_Helper(ppType)
41 #define __RPC__in_ecount_full(X)
43 #define __RPC__out_ecount_full(X)
44 #define __RPC__out_ecount_part(X, Y)
45 #define __RPC__deref_out_opt
46 #define __RPC__deref_out_ecount_full_opt(X)
49#include "sdk/imapi2.h"
50#include "sdk/imapi2error.h"
51#include "sdk/imapi2fs.h"
52#include "sdk/imapi2fserror.h"
135#define EXTERN_IMAPI2_GUID(itf,id) EXTERN_GUID(itf, id, 0x7F64, 0x5B0F, 0x8F, 0x00, 0x5D, 0x77, 0xAF, 0xBE, 0x26, 0x1E)
136#define EXTERN_IMAPI2FS_GUID(itf,id) EXTERN_GUID(itf, id, 0x975B, 0x59BE, 0xA9, 0x60, 0x9A, 0x2A, 0x26, 0x28, 0x53, 0xA5)
138EXTERN_IMAPI2_GUID(CLSID_MsftDiscMaster2 , 0x2735412E);
139EXTERN_IMAPI2_GUID(CLSID_MsftDiscRecorder2 , 0x2735412D);
140EXTERN_IMAPI2_GUID(CLSID_MsftDiscFormat2Erase , 0x2735412B);
141EXTERN_IMAPI2_GUID(CLSID_MsftDiscFormat2Data , 0x2735412A);
142EXTERN_IMAPI2FS_GUID(CLSID_MsftFileSystemImage , 0x2C941FC5);
144EXTERN_IMAPI2_GUID(LIBID_IMAPILib2 , 0x2735412F);
145EXTERN_IMAPI2_GUID(IID_IDiscMaster2 , 0x2735412E);
146EXTERN_IMAPI2_GUID(IID_IDiscRecorder2 , 0x2735412D);
147EXTERN_IMAPI2_GUID(IID_IWriteEngine2 , 0x2735412C);
148EXTERN_IMAPI2_GUID(IID_IDiscFormat2Erase , 0x2735412B);
149EXTERN_IMAPI2_GUID(IID_IDiscFormat2Data , 0x2735412A);
150EXTERN_IMAPI2_GUID(IID_IDiscFormat2TrackAtOnce , 0x27354129);
151EXTERN_IMAPI2_GUID(IID_IDiscFormat2RawCD , 0x27354128);
152EXTERN_IMAPI2_GUID(IID_IWriteSpeedDescriptor , 0x27354123);
153EXTERN_IMAPI2_GUID(IID_IMultisessionSequential , 0x27354122);
154EXTERN_IMAPI2_GUID(IID_DDiscFormat2EraseEvents , 0x2735413A);
155EXTERN_IMAPI2_GUID(IID_DDiscFormat2DataEvents , 0x2735413C);
156EXTERN_IMAPI2_GUID(IID_DDiscMaster2Events , 0x27354131);
158EXTERN_IMAPI2FS_GUID(LIBID_IMAPI2FS , 0x2C941FD0);
159EXTERN_IMAPI2FS_GUID(IID_IBootOptions , 0x2C941FCE);
160EXTERN_IMAPI2FS_GUID(IID_IFsiStream , 0x2C941FCD);
161EXTERN_IMAPI2FS_GUID(IID_IFileSystemImageResult , 0x2C941FCC);
162EXTERN_IMAPI2FS_GUID(IID_IProgressItem , 0x2C941FCB);
163EXTERN_IMAPI2FS_GUID(IID_IEnumProgressItems , 0x2C941FCA);
164EXTERN_IMAPI2FS_GUID(IID_IProgressItems , 0x2C941FC9);
165EXTERN_IMAPI2FS_GUID(IID_IFsiDirectoryItem , 0x2C941FC8);
166EXTERN_IMAPI2FS_GUID(IID_IFsiFileItem , 0x2C941FC7);
167EXTERN_IMAPI2FS_GUID(IID_IEnumFsiItems , 0x2C941FC6);
168EXTERN_IMAPI2FS_GUID(IID_IFileSystemImage , 0x2C941FC5);
169EXTERN_IMAPI2FS_GUID(IID_DFileSystemImageEvents , 0x2C941FDF);
172#define _TnbImageMasterEventSuper(CLS, SID, LIB) \
173 public ::ATL::CComObjectRootEx<::ATL::CComSingleThreadModel>, \
174 public ::ATL::CComCoClass<CLS>, \
175 public ::ATL::IDispatchImpl< IDispatch, &SID, &LIBID_IMAPI##LIB, IMAPI##LIB##_MajorVersion, IMAPI##LIB##_MinorVersion>, \
176 public ::ATL::IDispEventImpl<1, CLS, &SID, &LIBID_IMAPI##LIB, IMAPI##LIB##_MajorVersion, IMAPI##LIB##_MinorVersion>
178#define _TnbImageMasterEventMember(CLS) \
179 DECLARE_NOT_AGGREGATABLE(CLS) \
181 COM_INTERFACE_ENTRY(IDispatch) \
185struct IImageMasteringWriterListener
187 virtual void OnWriterEvent(IDispatch* pObject, IDispatch* pProgressDisp) = 0;
191class CImageMasteringWriterEvent : _TnbImageMasterEventSuper(CImageMasteringWriterEvent, IID_DDiscFormat2DataEvents, Lib2)
193 _TnbImageMasterEventMember(CImageMasteringWriterEvent)
194 BEGIN_SINK_MAP(CImageMasteringWriterEvent)
195 SINK_ENTRY_EX(1, IID_DDiscFormat2DataEvents, DISPID_DDISCFORMAT2DATAEVENTS_UPDATE, &Update)
198 STDMETHOD_(VOID, Update)(IDispatch* pObject, IDispatch* pProgressDisp)
200 m_pListener->OnWriterEvent(pObject, pProgressDisp);
202 IImageMasteringWriterListener* m_pListener;
206struct IImageMasteringEraseListener
208 virtual void OnEraseEvent(IDispatch* pObject, LONG elapsedSeconds, LONG expectedSeconds) = 0;
212class CImageMasteringEraseEvent : _TnbImageMasterEventSuper(CImageMasteringEraseEvent, IID_DDiscFormat2EraseEvents, Lib2)
214 _TnbImageMasterEventMember(CImageMasteringEraseEvent)
215 BEGIN_SINK_MAP(CImageMasteringEraseEvent)
216 SINK_ENTRY_EX(1, IID_DDiscFormat2EraseEvents, DISPID_IDISCFORMAT2ERASEEVENTS_UPDATE, &Update)
219 STDMETHOD_(VOID, Update)(IDispatch* pObject, LONG elapsedSeconds, LONG expectedSeconds)
221 m_pListener->OnEraseEvent(pObject, elapsedSeconds, expectedSeconds);
223 IImageMasteringEraseListener* m_pListener;
227struct IImageMasteringFileListener
229 virtual void OnFileEvent(IDispatch* pObject, BSTR currentFile, LONG copiedSectors, LONG totalSectors) = 0;
233class CImageMasteringFileEvent : _TnbImageMasterEventSuper(CImageMasteringFileEvent, IID_DFileSystemImageEvents, 2FS)
235 _TnbImageMasterEventMember(CImageMasteringFileEvent)
236 BEGIN_SINK_MAP(CImageMasteringFileEvent)
237 SINK_ENTRY_EX(1, IID_DFileSystemImageEvents, DISPID_DFILESYSTEMIMAGEEVENTS_UPDATE, &Update)
240 STDMETHOD_(VOID, Update)(IDispatch* pObject, BSTR currentFile, LONG copiedSectors, LONG totalSectors)
242 m_pListener->OnFileEvent(pObject, currentFile, copiedSectors, totalSectors);
244 IImageMasteringFileListener* m_pListener;
248struct IImageMasteringListener
250 virtual void OnAddedDevice(IDispatch* pObject, BSTR value);
251 virtual void OnRemovedDevice(IDispatch* pObject, BSTR value);
255class CImageMasteringEvent : _TnbImageMasterEventSuper(CImageMasteringEvent, IID_DDiscMaster2Events, Lib2)
258 _TnbImageMasterEventMember(CImageMasteringEvent)
259 BEGIN_SINK_MAP(CImageMasteringEvent)
260 SINK_ENTRY_EX(1, IID_DDiscMaster2Events, DISPID_DDISCMASTER2EVENTS_DEVICEADDED, &NotifyDeviceAdded )
261 SINK_ENTRY_EX(1, IID_DDiscMaster2Events, DISPID_DDISCMASTER2EVENTS_DEVICEREMOVED, &NotifyDeviceRemoved)
264 STDMETHOD_(VOID, NotifyDeviceAdded)(IDispatch* pObject, BSTR value)
266 m_pListener->OnAddedDevice(pObject, value);
268 STDMETHOD_(VOID, NotifyDeviceRemoved)(IDispatch* pObject, BSTR value)
270 m_pListener->OnRemovedDevice(pObject, value);
272 IImageMasteringListener* m_pListener;
276template<
typename T>
struct TImReleasePointerT
279 void operator()(T P) { P->Release(); }
312 ASSERT( _pModule != NULL );
314 if ( _pAtlModule == NULL )
316 static CAtlMfcModule a;
317 VERIFY( ::OleInitialize(NULL) == S_OK );
348 CStr s = _T(
"Unknown");
349 DWORD flag = FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER;
351 LPWSTR lpBuff =
reinterpret_cast<LPWSTR
>(&lpMsgBuf);
352 DWORD ret = ::FormatMessageW(flag | FORMAT_MESSAGE_FROM_HMODULE
353 , ::GetModuleHandle(_T(
"imapi2.dll"))
354 , hr, LANG_USER_DEFAULT, lpBuff, 0, NULL);
357 _GetLastError(
"FormatMessage");
358 ret = ::FormatMessageW(flag | FORMAT_MESSAGE_FROM_HMODULE
359 , ::GetModuleHandle(_T(
"imapi2fs.dll"))
360 , hr, LANG_USER_DEFAULT, lpBuff, 0, NULL);
364 _GetLastError(
"FormatMessage");
365 ret = ::FormatMessageW(flag | FORMAT_MESSAGE_FROM_SYSTEM
367 , hr, LANG_USER_DEFAULT, lpBuff, 0, NULL);
371 _GetLastError(
"FormatMessage");
375 s =
static_cast<LPCWSTR
>(lpMsgBuf);
378 ::LocalFree(lpMsgBuf);
396 typedef HRESULT (WINAPI* P_CSOFW)(LPCWSTR, DWORD, IStream**);
399 typedef HRESULT (WINAPI* P_CSOFA)(LPCSTR, DWORD, IStream**);
402 return func()(lpszFile, grfMode, ppstm);
427 TRACE2(
" Result =(0x%08X,[%s]\n", hr,
ToString(hr));
432 mutable HRESULT m_lastResult;
523 CDiscImage(
void) : m_useJoliet(true), m_pListener(NULL), m_pEventSink(NULL), m_pRoot(NULL)
532 if ( m_pRoot != NULL )
548 return m_pRoot != NULL;
570 if ( m_pRoot != NULL )
575 IFileSystemImage* P = NULL;
576 if (
CheckRes(::CoCreateInstance(CLSID_MsftFileSystemImage, NULL, CLSCTX_ALL, IID_PPV_ARGS(&P))) )
579 if (
CheckRes(m_hpImage->put_FreeMediaBlocks(0)) )
581 CheckRes(m_hpImage->get_Root(&m_pRoot));
584 return m_pRoot != NULL;
596 m_useJoliet = isEnable;
610 if (
CheckRes(CComObject<CImageMasteringFileEvent>::CreateInstance(&m_pEventSink)) )
612 m_pEventSink->AddRef();
613 m_pEventSink->m_pListener =
this;
614 CheckRes(m_pEventSink->DispEventAdvise(m_hpImage));
627 return isXA ? 2336 : 2048;
639 return CheckRes(m_hpImage->get_UsedBlocks(&r)) ? r : 0;
650 return CheckRes(m_hpImage->get_FileCount(&r)) ? r : 0;
661 return CheckRes(m_hpImage->get_DirectoryCount(&r)) ? r : 0;
672 if (
CheckRes(m_hpImage->get_VolumeName(&s)) )
687 CComBSTR s = lpszVolume;
688 return CheckRes(m_hpImage->put_VolumeName(s));
710 IFsiDirectoryItem* pDir = NULL;
711 CComBSTR name = lpszPath;
712 if ( lpszImagePath == NULL )
714 return CheckRes(m_pRoot->AddTree(name,
false));
716 HRESULT hr = m_AddDirectory(m_pRoot, lpszImagePath);
719 CComBSTR path = lpszImagePath;
720 hr = m_pRoot->get_Item(path,
reinterpret_cast<IFsiItem**
>(&pDir));
721 if ( SUCCEEDED(hr) && lpszPath != NULL )
723 hr = pDir->AddTree(name,
false);
741 IFsiDirectoryItem* pDir = NULL;
742 if ( lpszImagePath == NULL )
744 return CheckRes(m_AddFile(m_pRoot, lpszName));
746 HRESULT hr = m_AddDirectory(m_pRoot, lpszImagePath);
749 CComBSTR path = lpszImagePath;
750 hr = m_pRoot->get_Item(path,
reinterpret_cast<IFsiItem**
>(&pDir));
751 if ( SUCCEEDED(hr) && lpszName != NULL )
753 hr = m_AddFile(pDir, lpszName);
772 CComBSTR s = lpszImagePath;
773 return CheckRes(m_pRoot->RemoveTree(s));
787 CComBSTR s = lpszImageName;
788 return CheckRes(m_pRoot->Remove(s));
800 IBootOptions* pBootOptions = NULL;
801 if ( !
CheckRes(::CoCreateInstance(CLSID_BootOptions, NULL, CLSCTX_ALL, IID_PPV_ARGS(&pBootOptions))) )
805 IStream* pBootStream = NULL;
807 , STGM_READ | STGM_SHARE_DENY_WRITE, &pBootStream);
810 hr = pBootOptions->AssignBootImage(pBootStream);
814 hr = m_hpImage->put_BootImageOptions(pBootOptions);
816 if ( pBootStream != NULL )
818 pBootStream->Release();
821 pBootOptions->Release();
836 CComBSTR s = lpszPath;
837 return CheckRes(m_hpImage->put_WorkingDirectory(s));
861 return m_EnumFiles(_items, m_pRoot);
876 if ( pSrcStream != NULL )
878 IStream* pDstStream = NULL;
880 , STGM_WRITE | STGM_CREATE, &pDstStream);
883 STATSTG stat = { 0 };
884 hr = pSrcStream->Stat(&stat, STATFLAG_NONAME);
887 ULARGE_INTEGER cbRead = {0};
888 ULARGE_INTEGER cbWritten = {0};
889 hr = pSrcStream->CopyTo(pDstStream, stat.cbSize, &cbRead, &cbWritten);
891 pDstStream->Release();
894 pSrcStream->Release();
910 HRESULT hr = m_hpImage->put_FileSystemsToCreate(m_ToFileSystem(type));
913 IFileSystemImageResult* pResultStream = NULL;
914 hr = m_hpImage->CreateResultImage(&pResultStream);
917 IStream* pStream = NULL;
918 hr = pResultStream->get_ImageStream(&pStream);
919 pResultStream->Release();
920 pResultStream = NULL;
935 FsiFileSystems f = FsiFileSystemUDF;
943 f =
static_cast<FsiFileSystems
>(FsiFileSystemJoliet | FsiFileSystemISO9660);
947 f = FsiFileSystemISO9660;
956 HRESULT m_AddDirectory(IFsiDirectoryItem* _pDir, LPCTSTR lpszPath)
958 CStr path = lpszPath;
960 path.
Trim(_T(
"\\/"));
973 HRESULT hr = m_AddDirectory(_pDir, path.
Left(f));
974 if ( ! SUCCEEDED(hr) )
980 return _pDir->AddDirectory(p);
983 HRESULT m_AddFile(IFsiDirectoryItem* _pDir, LPCTSTR lpszFileName)
985 IStream* pStream = NULL;
987 , STGM_READ | STGM_SHARE_DENY_WRITE, &pStream);
990 CStr s = lpszFileName;
1003 STATSTG stat = { 0 };
1004 hr = pStream->Stat(&stat, STATFLAG_NONAME);
1005 if ( SUCCEEDED(hr) )
1007 IFsiFileItem* I = NULL;
1008 hr = m_hpImage->CreateFileItem(name, &I);
1009 if ( SUCCEEDED(hr) )
1011 I->put_Data(pStream);
1012 I->put_CreationTime(COleDateTime(stat.ctime));
1013 I->put_LastAccessedTime(COleDateTime(stat.atime));
1014 I->put_LastModifiedTime(COleDateTime(stat.mtime));
1028 IEnumFsiItems* pItems = NULL;
1029 HRESULT hr = pDirs->get_EnumFsiItems(&pItems);
1033 IFsiItem* pFI = NULL;
1034 hr = pItems->Next(1, &pFI, &celt);
1042 IFsiDirectoryItem* P = NULL;
1043 fi.isDirectory = SUCCEEDED(pFI->QueryInterface(&P));
1045 pFI->get_FullPath(&s);
1048 if ( P != NULL && ! m_EnumFiles(_items, P) )
1061 void m_ReleaseSink(
void)
1063 if ( m_pEventSink != NULL )
1065 m_pEventSink->DispEventUnadvise(m_pRoot);
1066 m_pEventSink->Release();
1067 m_pEventSink = NULL;
1071 virtual void OnFileEvent(IDispatch*
object, BSTR currentFile, LONG copiedSectors, LONG totalSectors)
1073 if ( m_pListener != NULL )
1079 IFsiDirectoryItem* m_pRoot;
1081 IListener* m_pListener;
1082 CComObject<CImageMasteringFileEvent>* m_pEventSink;
1208 if ( ! m_Recorder().IsNull() )
1211 if ( !
CheckRes(m_Recorder()->InitializeDiscRecorder(s)) )
1213 m_Recorder().
Null();
1215 m_Writer() = m_CreateDiscFormatData();
1216 if ( m_Writer().IsNull() )
1218 m_Recorder().Null();
1232 return ! m_Recorder().IsNull();
1241 return m_Recorder();
1250 m_member.pListener = pListener;
1268 hr = hpEraser->put_FullErase(VARIANT_TRUE);
1272 CComObject<CImageMasteringEraseEvent>* pEventSink = NULL;
1273 if (
CheckRes(CComObject<CImageMasteringEraseEvent>::CreateInstance(&pEventSink)) )
1275 pEventSink->AddRef();
1276 pEventSink->m_pListener = &m_member;
1277 pEventSink->DispEventAdvise(hpEraser);
1278 hr = hpEraser->EraseMedia();
1280 pEventSink->DispEventUnadvise(hpEraser);
1281 pEventSink->Release();
1303 IFileSystemImage* pImage = discImage.operator->();
1304 if ( pImage == NULL )
1308 LONG changePoint = -1;
1309 bool r =
CheckRes(pImage->get_ChangePoint(&changePoint));
1310 IStream* pSrcStream = NULL;
1314 if ( pSrcStream == NULL )
1320 r = m_SetCloseDiscMode(isClose);
1323 r = m_CheckDvdplusrdl();
1327 r = m_MultiDisp(pImage);
1331 r = m_Burn(pSrcStream);
1333 if ( pSrcStream != NULL )
1335 pSrcStream->Release();
1338 if ( changePoint >= 0 )
1340 pImage->RollbackToChangePoint(changePoint);
1356 bool Burn(LPCTSTR lpszFileName,
bool isClose =
true)
1358 if ( m_Writer().IsNull() )
1362 if ( ! m_SetCloseDiscMode(isClose) )
1366 IStream* pStream = NULL;
1368 , STGM_READ | STGM_SHARE_DENY_WRITE, &pStream);
1372 r = m_Burn(pStream);
1374 if ( pStream != NULL )
1389 return m_Tray(
true);
1400 return m_Tray(
false);
1421 if ( ! m_Recorder().IsNull() )
1423 info.
vendorId = m_GetBstrKindString(BstrKind_VendorId);
1424 info.
productId = m_GetBstrKindString(BstrKind_ProductId);
1441 SAFEARRAY* pSA = NULL;
1442 if ( ! m_Recorder().IsNull() &&
CheckRes(m_Recorder()->get_VolumePathNames(&pSA)) )
1444 VARIANT* P =
static_cast<VARIANT*
>(pSA->pvData);
1445 loop ( i, pSA->rgsabound[0].cElements )
1447 ASSERT( P[i].vt == VT_BSTR );
1448 _mountPaths.
Add(
CStr(P[i].bstrVal));
1450 ::SafeArrayDestroyData(pSA);
1477 SAFEARRAY* pSA = NULL;
1478 if ( ! m_Writer().IsNull() &&
CheckRes(m_Writer()->get_SupportedWriteSpeeds(&pSA)) )
1480 VARIANT* P =
static_cast<VARIANT*
>(pSA->pvData);
1481 loop ( i, pSA->rgsabound[0].cElements )
1483 _speeds.
Add(
static_cast<WORD
>(P[i].ulVal));
1485 ::SafeArrayDestroyData(pSA);
1505 if ( ! m_Writer().IsNull() )
1507 VARIANT_BOOL r = isPureCAV ? VARIANT_TRUE : VARIANT_FALSE;
1521 if ( ! m_Writer().IsNull() )
1524 if (
CheckRes(m_Writer()->get_TotalSectorsOnMedia(&l)) )
1539 if ( ! m_Writer().IsNull() )
1542 if (
CheckRes(m_Writer()->get_FreeSectorsOnMedia(&l)) )
1560 if ( ! m_Writer().IsNull() )
1562 VARIANT_BOOL isBlank = FALSE;
1566 HRESULT hr = m_Writer()->get_MediaHeuristicallyBlank(&isBlank);
1567 if ( hr == E_IMAPI_RECORDER_MEDIA_NO_MEDIA || hr == E_IMAPI_RECORDER_MEDIA_BECOMING_READY )
1599 if ( ! m_Writer().IsNull() )
1601 CheckRes(m_Writer()->get_CurrentMediaStatus(&s));
1620 DWORD fileSystemFlags;
1621 bool r = !!::GetVolumeInformation(mountPaths[i], path.
GetBuffer(1000), 1000
1622 , &serialNumber, &maxLen, &fileSystemFlags, NULL, 0);
1640 if ( ! m_Writer().IsNull() )
1642 VARIANT_BOOL isBlank = FALSE;
1643 HRESULT hr = m_Writer()->get_MediaHeuristicallyBlank(&isBlank);
1674 SAFEARRAY* pSA = NULL;
1675 if ( ! m_Writer().IsNull() &&
CheckRes(m_Writer()->get_SupportedMediaTypes(&pSA)) )
1677 VARIANT* P =
static_cast<VARIANT*
>(pSA->pvData);
1678 loop ( i, pSA->rgsabound[0].cElements )
1680 ASSERT( P[i].vt == VT_I4 );
1684 ::SafeArrayDestroyData(pSA);
1700 if ( ! m_Writer().IsNull() )
1702 CheckRes(m_Writer()->get_CurrentPhysicalMediaType(&type));
1728 IFileSystemImage* pImage = _diskImage.operator ->();
1729 bool r = m_MultiDisp(pImage);
1740 bool m_Burn(IStream* pStream)
1742 ASSERT( pStream != NULL );
1743 CComObject<CImageMasteringWriterEvent>* pEventSink = NULL;
1744 HRESULT hr = CComObject<CImageMasteringWriterEvent>::CreateInstance(&pEventSink);
1745 if ( SUCCEEDED(hr) )
1747 ASSERT( pEventSink != NULL );
1748 pEventSink->AddRef();
1749 pEventSink->m_pListener = &m_member;
1750 pEventSink->DispEventAdvise(m_Writer());
1751 hr = m_Writer()->Write(pStream);
1752 pEventSink->DispEventUnadvise(m_Writer());
1753 pEventSink->Release();
1759 bool m_SetCloseDiscMode(
bool isClose =
true)
1761 HRESULT hr = m_Writer()->put_ForceMediaToBeClosed(isClose ? VARIANT_TRUE : VARIANT_FALSE);
1766 bool m_CheckDvdplusrdl(
void)
1771 HRESULT hr = m_Writer()->get_StartAddressOfPreviousSession(&value);
1772 if ( SUCCEEDED(hr) && value == -1 )
1774 hr = m_Writer()->put_ForceMediaToBeClosed(VARIANT_TRUE);
1780 bool m_MultiDisp(IFileSystemImage* pImage)
const
1782 SAFEARRAY* pSA = NULL;
1783 if ( SUCCEEDED(pImage->get_MultisessionInterfaces(&pSA)) )
1785 ULONG l = pSA->rgsabound[0].cElements;
1786 ::SafeArrayDestroyData(pSA);
1793 SAFEARRAY* pMultiSession = NULL;
1795 HRESULT hr = m_Writer()->get_MultisessionInterfaces(&pMultiSession);
1797 if ( SUCCEEDED(hr) )
1799 hr = pImage->put_MultisessionInterfaces(pMultiSession);
1801 if ( SUCCEEDED(hr) )
1803 FsiFileSystems fileSystems;
1804 hr = pImage->ImportFileSystem(&fileSystems);
1805 if ( hr == IMAPI_E_EMPTY_DISC )
1811 if ( pMultiSession != NULL )
1813 ::SafeArrayDestroy(pMultiSession);
1814 pMultiSession = NULL;
1819 bool m_Tray(
bool isOpen)
1821 if ( ! m_Recorder().IsNull() )
1823 if (
CheckRes(m_Recorder()->DisableMcn()) )
1825 bool r =
CheckRes(isOpen ? m_Recorder()->EjectMedia() : m_Recorder()->
CloseTray());
1826 m_Recorder()->EnableMcn();
1837 BstrKind_ProductRevision,
1838 BstrKind_ExclusiveAccessOwner,
1841 CStr m_GetBstrKindString(EBstrKind k)
const
1844 if ( ! m_Recorder().IsNull() )
1847 HRESULT hr = E_FAIL;
1850 case BstrKind_VendorId:
1851 hr = m_Recorder()->get_VendorId(&str);
1853 case BstrKind_ProductId:
1854 hr = m_Recorder()->get_ProductId(&str);
1856 case BstrKind_ProductRevision:
1857 hr = m_Recorder()->get_ProductRevision(&str);
1859 case BstrKind_ExclusiveAccessOwner:
1860 hr = m_Recorder()->get_ExclusiveAccessOwner(&str);
1873 template<
typename TYP>
1874 void m_AdjustHandle(TYP& hp)
const
1876 if ( !
CheckRes(hp->put_Recorder(m_Recorder())) )
1882 CComBSTR s = _T(
"TnbImageMastering");
1883 if ( !
CheckRes(hp->put_ClientName(s)) )
1893 if ( ! m_Recorder().IsNull() )
1895 IDiscFormat2Data* P = NULL;
1896 if (
CheckRes(::CoCreateInstance(CLSID_MsftDiscFormat2Data, NULL, CLSCTX_ALL, IID_PPV_ARGS(&P))) )
1908 if ( ! m_Recorder().IsNull() )
1910 IDiscFormat2Erase* P = NULL;
1911 if (
CheckRes(::CoCreateInstance(CLSID_MsftDiscFormat2Erase, NULL, CLSCTX_ALL, IID_PPV_ARGS(&P))) )
1927 return m_member.hpRecorder;
1932 return m_member.hpWriter;
1935 class CMyProgressData :
public IListener::CProgressData
1939 CMyProgressData(
void) : m_elapsedTime(0), m_expectedTime(0)
1940 , m_startLba(0), m_sectorCount(0), m_lastWrittenLba(0)
1942 LONG GetRemainingTime(
void)
const {
return m_expectedTime - m_elapsedTime; }
1943 LONG GetElapsedTime(
void)
const {
return m_elapsedTime; }
1944 LONG GetExpectedTime(
void)
const {
return m_expectedTime; }
1945 LONG GetStartLba(
void)
const {
return m_startLba; }
1946 LONG GetTotalSectorCount(
void)
const {
return m_sectorCount; }
1947 LONG GetWrittenLba(
void)
const {
return m_lastWrittenLba; }
1948 LONG GetWrittenSector(
void)
const {
return m_lastWrittenLba - m_startLba; }
1951 LONG m_expectedTime;
1954 LONG m_lastWrittenLba;
1957 struct TMember : IImageMasteringWriterListener, IImageMasteringEraseListener
1960 TMember(
void) : pListener(NULL)
1963 virtual void OnWriterEvent(IDispatch* pObjectDisp, IDispatch* pProgressDisp)
1965 if ( pListener == NULL ) {
return; }
1966 IDiscFormat2DataEventArgs* pProgress = NULL;
1967 HRESULT hr = pProgressDisp->QueryInterface(IID_PPV_ARGS(&pProgress));
1970 pListener->OnDriveErrorResult(hr);
1974 hr = pProgress->get_CurrentAction(¤tAction);
1977 pListener->OnDriveErrorResult(hr);
1981 pProgress->get_ElapsedTime(&pd.m_elapsedTime);
1982 pProgress->get_TotalTime(&pd.m_expectedTime);
1983 pProgress->get_StartLba(&pd.m_startLba);
1984 pProgress->get_SectorCount(&pd.m_sectorCount);
1985 pProgress->get_LastWrittenLba(&pd.m_lastWrittenLba);
1986 switch ( currentAction )
1990 pd.m_elapsedTime = pd.m_expectedTime;
1991 pd.m_lastWrittenLba = pd.m_startLba + pd.m_sectorCount;
1996 if ( ! pListener->OnDriveWriteEvent(pd, currentAction) )
1998 hpWriter->CancelWrite();
2002 virtual void OnEraseEvent(IDispatch*
object, LONG elapsedSeconds, LONG expectedSeconds)
2004 if ( pListener != NULL )
2007 pd.m_elapsedTime = elapsedSeconds;
2008 pd.m_expectedTime = expectedSeconds;
2009 pListener->OnDriveEraseEvent(pd);
2012 IListener* pListener;
2016 mutable TMember m_member;
2039 if ( ! m_hpDiscMaster.
IsNull() )
2042 HRESULT hr = m_hpDiscMaster->get_IsSupportedEnvironment(&b);
2043 if ( SUCCEEDED(hr) )
2059 if ( ! m_hpDiscMaster.
IsNull() )
2062 HRESULT hr = m_hpDiscMaster->get_Count(&cnt);
2063 if ( SUCCEEDED(hr) )
2083 HRESULT hr = m_hpDiscMaster->get_Item(index, &str);
2084 if ( SUCCEEDED(hr) )
2101 IDiscRecorder2* P = NULL;
2102 CheckRes(::CoCreateInstance(CLSID_MsftDiscRecorder2, NULL, CLSCTX_ALL, IID_PPV_ARGS(&P)));
2141 bool m_CheckInst(
void)
const
2143 if ( m_hpDiscMaster.
IsNull() )
2145 IDiscMaster2* P = NULL;
2146 CheckRes(::CoCreateInstance(CLSID_MsftDiscMaster2, NULL, CLSCTX_ALL, IID_PPV_ARGS(&P)));
2149 return ! m_hpDiscMaster.
IsNull();
2230 When unlocking a recorder, the lock count must reach zero to free
2231 the device
for other clients. Calling the IDiscRecorder2::ReleaseExclusiveAccess
2232 method decrements the lock count by one.
2234 An equal number of calls to the AcquireExclusiveAccess and
2235 ReleaseExclusiveAccess methods are needed to free a device.
2236 Should the application exit unexpectedly or crash
while holding
2237 the exclusive access, the CDROM.SYS driver will automatically
2238 release these exclusive locks.
2240 If the device is already locked, you can call IDiscRecorder2::get_ExclusiveAccessOwner
2241 to retrieve the name of the client application that currently has exclusive access.
2245 VC++6 、MFC で作成したダイアログ上で、書き込みしている時、
2246 フォーカス移動で、なぞの アクセスバイオレーション発生!
#define loop(VAR, CNT)
loop構文.
static HRESULT CreateStreamOnFile(LPCTSTR lpszFile, DWORD grfMode, IStream **ppstm)
[作成] ファイルストリーム作成.
CStr GetLastResultString(void) const
[取得] リザルト文字列取得.
bool CheckRes(HRESULT hr) const
[設定] リザルトチェック.
HRESULT GetLastResult(void) const
[取得] リザルトコード取得.
static CStr ToString(HRESULT hr)
[変換] リザルト文字列変換.
CImageMasteringResult(void)
コンストラクタ
size_t GetFileCount(void) const
[取得] 登録済みファイル数取得.
void SetJolietSystem(bool isEnable)
[設定] Jolietモード設定.
void SetListener(IListener *P)
[設定]リスナー登録.
bool AddSourceFile(LPCTSTR lpszName, LPCTSTR lpszImagePath=NULL)
[追加] ファイル追加.
size_t GetSectorSize(bool isXA=false) const
[取得] セクタサイズ取得.
bool SetVolumeName(LPCTSTR lpszVolume)
[設定] ボリューム名設定.
bool SetWorkingDirestory(LPCTSTR lpszPath)
[設定] ワークディレクトリ設定.
bool SetBootImage(LPCTSTR lpszBootFileName)
[設定] Bootイメージ設定.
bool RemoveFile(LPCTSTR lpszImageName)
[削除] ファイル削除.
bool AddSourceDirectory(LPCTSTR lpszPath, LPCTSTR lpszImagePath=NULL)
[追加] ディレクトリ追加.
bool IsValid(void) const
[確認] 有効確認.
size_t GetSectorsCount(void) const
[取得] 登録済みセクタ数取得.
IFileSystemImage * operator->(void) const
[取得] FileSystemImageインターフェース取得.
bool EnumerationFiles(CVectorT< TFileItem > &_items) const
[取得] ファイル一覧.
size_t GetDirectoryCount(void) const
[取得] 登録済みディレクトリ数取得
bool CreateImageFile(LPCTSTR lpszFileName, IMAPI_MEDIA_PHYSICAL_TYPE type=IMAPI_MEDIA_TYPE_CDR)
[作成] イメージファイル作成.
IStream * CreateImageSteam(IMAPI_MEDIA_PHYSICAL_TYPE type=IMAPI_MEDIA_TYPE_CDR) const
[作成] イメージストリーム作成.
CStr GetVolumeName(void) const
[取得] ボリューム名取得.
bool RemoveDirectory(LPCTSTR lpszImagePath)
[削除] ディレクトリ削除.
bool Reset(void)
[設定] 初期化.
virtual LONG GetTotalSectorCount(void) const =0
[取得] 全セクタ数.
virtual LONG GetElapsedTime(void) const =0
[取得] 経過時間.
virtual LONG GetWrittenLba(void) const =0
[取得] 書込み LBA 数.
virtual LONG GetStartLba(void) const =0
[取得] 開始 LBA.
virtual LONG GetWrittenSector(void) const =0
[取得] 書込みセクタ数.
virtual LONG GetRemainingTime(void) const =0
[取得] 残り時間.
virtual LONG GetExpectedTime(void) const =0
[取得] 予想全時間.
bool EnumerationMountPath(CStrVector &_mountPaths) const
[取得] マウントパス取得.
IMAPI_MEDIA_PHYSICAL_TYPE GetTypeOnDisc(void) const
[取得] ディスク種類取得.
bool EnumerationSupportWriteSpeeds(CWordVector &_speeds) const
[取得] サポート書き込み速度一覧.
bool ReadMultiSession(CDiscImage &_diskImage) const
[取得] セッション情報取得.
bool OpenTray(void)
[処理] トレイオープン.
IDiscRecorder2 * operator->(void)
[取得] IDiscRecorder2インターフェース取得.
bool CloseTray(void)
[処理] トレイクローズ.
size_t GetSectorSize(void) const
[取得] セクタサイズ取得.
bool Burn(const CDiscImage &discImage, bool isClose=true)
[書込] 書き込み.
bool IsBlankDisc(void) const
[確認] ブランクディスク確認.
CVectorT< IMAPI_MEDIA_PHYSICAL_TYPE > CTypeVector
ディスクタイプ配列型
bool IsValid(void) const
[確認] 有効確認.
bool Burn(LPCTSTR lpszFileName, bool isClose=true)
[書込] イメージファイル書き込み.
size_t GetTotalSectorsOnDisc(void) const
[取得] ディスク全セクタ数取得.
bool ExistDisc(DWORD time=0) const
[確認] ディスク確認.
size_t GetFreeSectorsOnDisc(void) const
[取得] ディスク空きセクタ数取得.
TInformation GetInformation(void) const
[取得] ドライブ情報情報.
void SetListener(IListener *pListener)
[設定] リスナー設定.
bool IsAppendableDisc(void) const
[確認] 追記可能ディスク確認.
CStr GetTypeStringOnDisc(void) const
[取得] ディスク種類名取得.
bool Erase(bool isFull=false)
[消去] 消去.
bool SetWriteSpeed(int speed=-1, bool isPureCAV=false)
[設定] 速度設定.
CDrive(CDiscRecorderHandle dr, LPCTSTR name)
コンストラクタ.
int GetStatusOnDisc(void) const
[取得] ディスク状態取得.
bool EnumerationSupportedDiscTypes(CTypeVector &_types) const
[取得] 対応ディスクタイプ一覧取得.
CStr GetVolumeOnDisc(void) const
[取得] ディスクボリューム名取得.
CDrive CreateDrive(INDEX index) const
[取得] ドライブ管理クラス取得.
CImageMastering(void)
コンストラクタ
size_t GetDriveCount(void) const
[取得] ドライブ数取得.
CStr GetDriveName(INDEX index) const
[取得] ドライブ名取得.
CPointerHandleBaseT< IDiscFormat2Data *, TImReleasePointerT< IDiscFormat2Data * > > CDiscFormatDataHandle
DiscFormatData ハンドル
static CStr ToString(IMAPI_MEDIA_PHYSICAL_TYPE type)
[取得] ディスク種類文字取得.
CPointerHandleBaseT< IDiscRecorder2 *, TImReleasePointerT< IDiscRecorder2 * > > CDiscRecorderHandle
DiscRecorder ハンドル
CPointerHandleBaseT< IFileSystemImage *, TImReleasePointerT< IFileSystemImage * > > CFileSystemImageHandle
FileSystemImage ハンドル
CPointerHandleBaseT< IDiscMaster2 *, TImReleasePointerT< IDiscMaster2 * > > CDiscMasterHandle
DiscMaster ハンドル
bool IsSupported(void) const
[確認] サポート確認.
CPointerHandleBaseT< IDiscFormat2Erase *, TImReleasePointerT< IDiscFormat2Erase * > > CDiscFormatEraseHandle
DiscFormatErase ハンドル
bool IsNull(void) const
[確認] NULLチェック
static VAL Find(const TYP &key, const TYPS &ts, const VAL &def=VAL())
[検索] 値検索
INT_PTR ReverseFindOneOf(const TYP *lpsz) const
[確認] 検索(後ろから)
bool IsEmpty(void) const
[確認] 空チェック
CStrT Left(size_t iSize) const
[作成] 範囲取得.
void ReleaseBuffer(void)
[操作] 割り当てたバッファを開放.
CStrT & TrimRight(TYP t=' ')
[処理] 末尾から文字をトリム.
CStrT & Trim(TYP t=' ')
[処理] 両端から文字をトリム.
CStrT Mid(INDEX iOffset, size_t iSize=INVALID_SIZE) const
[作成] 範囲取得.
TYP * GetBuffer(size_t iLength=0)
[操作] 書き込みバッファ要求.
bool IsPassed(DWORD dwTime) const
[確認] 経過確認.
void OnCatch(void) const
[表示] 内容表示
virtual size_t GetSize(void) const
[取得] サイズ取得
virtual bool RemoveAll(void)
[削除] 空化
virtual INDEX Add(const TYP &t)
[追加] 要素一つ追加.
IMAPI_MEDIA_PHYSICAL_TYPE
ディスクタイプ.
IMAPI_FORMAT2_DATA_WRITE_ACTION
書き込みアクション.
IMAPI_FORMAT2_DATA_MEDIA_STATE
ディスク状態.
@ IMAPI_MEDIA_TYPE_BDRE
BD-RE
@ IMAPI_MEDIA_TYPE_DVDPLUSR
DVD+R
@ IMAPI_MEDIA_TYPE_DVDPLUSR_DUALLAYER
DVD+R DL
@ IMAPI_MEDIA_TYPE_DVDDASHRW
DVD-RW
@ IMAPI_MEDIA_TYPE_HDDVDRAM
HD DVD-RAM
@ IMAPI_MEDIA_TYPE_BDROM
BD-ROM
@ IMAPI_MEDIA_TYPE_DISK
DISK
@ IMAPI_MEDIA_TYPE_CDRW
CD-RW
@ IMAPI_MEDIA_TYPE_CDROM
CD-ROM
@ IMAPI_MEDIA_TYPE_UNKNOWN
不明,
@ IMAPI_MEDIA_TYPE_DVDRAM
DVD-RAM
@ IMAPI_MEDIA_TYPE_HDDVDR
HD DVD-R
@ IMAPI_MEDIA_TYPE_HDDVDROM
HD DVD-ROM
@ IMAPI_MEDIA_TYPE_DVDROM
DVD-ROM
@ IMAPI_MEDIA_TYPE_CDR
CD-R
@ IMAPI_MEDIA_TYPE_DVDPLUSRW
DVD+RW
@ IMAPI_MEDIA_TYPE_DVDDASHR
DVD-R
@ IMAPI_MEDIA_TYPE_DVDPLUSRW_DUALLAYER
DVD+RW DL
@ IMAPI_MEDIA_TYPE_DVDDASHR_DUALLAYER
DVD-R DL
@ IMAPI_MEDIA_TYPE_BDR
BD-R
@ IMAPI_FORMAT2_DATA_WRITE_ACTION_VALIDATING_MEDIA
ディスク確認中
@ IMAPI_FORMAT2_DATA_WRITE_ACTION_FORMATTING_MEDIA
ディスクフォーマット中
@ IMAPI_FORMAT2_DATA_WRITE_ACTION_FINALIZATION
ファイナライズ中
@ IMAPI_FORMAT2_DATA_WRITE_ACTION_INITIALIZING_HARDWARE
初期化中
@ IMAPI_FORMAT2_DATA_WRITE_ACTION_WRITING_DATA
データ書き込み中
@ IMAPI_FORMAT2_DATA_WRITE_ACTION_CALIBRATING_POWER
パワー調整中
@ IMAPI_FORMAT2_DATA_WRITE_ACTION_COMPLETED
完了
@ IMAPI_FORMAT2_DATA_MEDIA_STATE_FINALIZED
ファイナライズ済み
@ IMAPI_FORMAT2_DATA_MEDIA_STATE_APPENDABLE
追記可能
@ IMAPI_FORMAT2_DATA_MEDIA_STATE_WRITE_PROTECTED
書き込み禁止
@ IMAPI_FORMAT2_DATA_MEDIA_STATE_FINAL_SESSION
最後のセクション
@ IMAPI_FORMAT2_DATA_MEDIA_STATE_NON_EMPTY_SESSION
セクション有り
@ IMAPI_FORMAT2_DATA_MEDIA_STATE_UNSUPPORTED_MEDIA
未サポートディスク
@ IMAPI_FORMAT2_DATA_MEDIA_STATE_DAMAGED
ダメージ
@ IMAPI_FORMAT2_DATA_MEDIA_STATE_BLANK
ブランク
@ IMAPI_FORMAT2_DATA_MEDIA_STATE_OVERWRITE_ONLY
上書きのみ
@ IMAPI_FORMAT2_DATA_MEDIA_STATE_ERASE_REQUIRED
消去必要あり
TNB::CStrT< TCHAR > CStr
文字列クラス
virtual void OnDiscImageAdded(LPCTSTR file, LONG copiedSectors, LONG totalSectors)=0
[通知] 進捗通知.
virtual ~IListener(void)
デストラクタ
bool isDirectory
ディレクトリフラグ. true ならディレクトリ、 false ならファイル
virtual ~IListener(void)
デストラクタ
virtual void OnDriveErrorResult(HRESULT hr)=0
[通知] エラー発生通知.
virtual void OnDriveEraseEvent(const CProgressData &pd)=0
[通知] 消去進捗通知.
virtual bool OnDriveWriteEvent(const CProgressData &pd, IMAPI_FORMAT2_DATA_WRITE_ACTION action)=0
[通知] 書き込み進捗通知.