Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6123 lines
210 KiB

  1. #include "shellprv.h"
  2. #include "ids.h"
  3. #include "views.h"
  4. #include "stgutil.h"
  5. #include "imapi.h"
  6. #include "propsht.h"
  7. #include "mtpt.h"
  8. #include "shcombox.h"
  9. #include "datautil.h"
  10. #include "fstreex.h"
  11. #include <imapierror.h>
  12. #include <imapi/imapiregistry.h>
  13. #include "cowsite.h"
  14. #include <cfgmgr32.h>
  15. #include "cdmedia.h"
  16. #include <lmcons.h>
  17. #include "prop.h"
  18. #include "clsobj.h"
  19. #include "filetbl.h"
  20. #include "cdburn.h"
  21. #include "setupapi.h"
  22. #include "isproc.h"
  23. #include "ole2dup.h"
  24. #include "copy.h"
  25. #pragma hdrstop
  26. #define REGSTR_PATH_CDBURNING REGSTR_PATH_EXPLORER TEXT("\\CD Burning")
  27. #define REGSTR_PATH_DRIVES REGSTR_PATH_CDBURNING TEXT("\\Drives")
  28. #define REGSTR_PATH_HANDLERS REGSTR_PATH_CDBURNING TEXT("\\Extensions")
  29. #define REGSTR_PATH_PERMEDIA REGSTR_PATH_CDBURNING TEXT("\\Current Media")
  30. #define REGSTR_PATH_EXCLUDE REGSTR_PATH_CDBURNING TEXT("\\ExcludedFS")
  31. #define REGSTR_PATH_AUDIOEXTS REGSTR_PATH_CDBURNING TEXT("\\AudioBurnHandlers")
  32. #define REGVALUE_FILEEXTS TEXT("SupportedFileTypes")
  33. #define REGVALUE_CURRENTDRIVE TEXT("CD Recorder Drive")
  34. #define REGVALUE_AUTOEJECT TEXT("Auto Eject")
  35. #define REGVALUE_AUTOCLOSE TEXT("Auto Close")
  36. #define REGVALUE_FIRSTHANDLER TEXT("FirstHandler")
  37. #define REGVALUE_CLSID TEXT("CLSID")
  38. #define REGVALUE_VERB TEXT("verb")
  39. #define REGVALUE_CACHEDINDEX TEXT("DriveIndex")
  40. #define REGVALUE_DRIVETYPE TEXT("Drive Type")
  41. #define REGVALUE_CURRENTSPEED TEXT("CurrentCDWriteSpeed")
  42. #define REGVALUE_MAXSPEED TEXT("MaxCDWriteSpeed")
  43. #define REGVALUE_TOTALBYTES TEXT("TotalBytes")
  44. #define REGVALUE_FREEBYTES TEXT("FreeBytes")
  45. #define REGVALUE_MEDIATYPE TEXT("Media Type")
  46. #define REGVALUE_UDF TEXT("UDF")
  47. #define REGVALUE_DISCLABEL TEXT("Disc Label")
  48. #define REGVALUE_SET TEXT("Set")
  49. #define REGVALUE_ERASETIME TEXT("Erase Time")
  50. #define REGVALUE_STAGERATE TEXT("Stage Rate")
  51. #define REGVALUE_BURNRATE TEXT("Burn Rate")
  52. #define REGVALUE_CLOSEFACTOR TEXT("Close Factor")
  53. #define WRITESPEED_FASTEST 0xFFFFFFFF
  54. #define JOLIET_MAX_LABEL 16
  55. #define PROPSTR_EJECT TEXT("Eject")
  56. #define PROPSTR_ERASE TEXT("Erase")
  57. #define PROPSTR_HR TEXT("HR")
  58. #define PROPSTR_DISCLABEL REGVALUE_DISCLABEL
  59. #define PROPSTR_AUTOCLOSE REGVALUE_AUTOCLOSE
  60. #define PROPSTR_DISCFULLTEXT TEXT("DiscFullText")
  61. #define PROPSTR_CURRENTEXT TEXT("CurrentExt")
  62. #define PROPSTR_FAILSILENTLY TEXT("FailSilently")
  63. #define PROPSTR_STATUSTEXT TEXT("StatusText")
  64. #define INDEX_DLG_BURNWIZ_MAX 30
  65. #define PROGRESS_INCREMENTS 1000
  66. enum {
  67. DRIVE_USEEXISTING = 0,
  68. DRIVE_CDR = RECORDER_CDR,
  69. DRIVE_CDRW = RECORDER_CDRW,
  70. DRIVE_NOTSUPPORTED
  71. };
  72. #define SUPPORTED(x) ((x) && !((x) == DRIVE_NOTSUPPORTED))
  73. typedef struct
  74. {
  75. INT idPage;
  76. INT idHeading;
  77. INT idSubHeading;
  78. DWORD dwFlags;
  79. DLGPROC dlgproc;
  80. } WIZPAGE;
  81. typedef struct
  82. {
  83. DWORD dwSecStaging, dwTickStagingStart, dwTickStagingEnd;
  84. DWORD dwSecBurn, dwTickBurnStart, dwTickBurnEnd;
  85. DWORD dwSecClose, dwTickCloseStart, dwTickCloseEnd;
  86. DWORD dwSecErase, dwTickEraseStart, dwTickEraseEnd;
  87. DWORD dwSecRemaining, dwSecTotal;
  88. } TIMESTATS;
  89. class CCDBurn;
  90. typedef struct
  91. {
  92. CCDBurn *pcdb;
  93. IStream *pstmDataObj;
  94. BOOL fMove;
  95. } CDDROPPARAMS;
  96. // CLSIDs used for merged namespace for CD mastering
  97. /* 00da2f99-f2a6-40c2-b770-a920f8e44abc */
  98. const CLSID CLSID_StagingFolder = {0x00da2f99, 0xf2a6, 0x40c2, {0xb7, 0x70, 0xa9, 0x20, 0xf8, 0xe4, 0x4a, 0xbc}};
  99. // CDBurn - object which performs the CDBurning and displaying the progress etc.
  100. class CCDBurn : public CObjectWithSite,
  101. public IShellExtInit,
  102. public IContextMenu,
  103. public IShellPropSheetExt,
  104. public IDiscMasterProgressEvents,
  105. public IDropTarget,
  106. public IPersistFile,
  107. public IOleCommandTarget,
  108. public ICDBurn,
  109. public ICDBurnPriv,
  110. public IPersistPropertyBag,
  111. public IDriveFolderExt,
  112. public INamespaceWalkCB,
  113. public IWizardSite,
  114. public IServiceProvider,
  115. public ITransferAdviseSink,
  116. public IQueryCancelAutoPlay
  117. {
  118. public:
  119. // IUnknown methods
  120. STDMETHOD(QueryInterface)(REFIID riid, void **ppvObj);
  121. STDMETHOD_(ULONG, AddRef)();
  122. STDMETHOD_(ULONG, Release)();
  123. // IPersist methods
  124. STDMETHOD(GetClassID)(CLSID *pClassID)
  125. { *pClassID = CLSID_CDBurn; return S_OK; };
  126. // IPersistFile methods
  127. STDMETHOD(IsDirty)(void)
  128. { return S_FALSE; };
  129. STDMETHOD(Load)(LPCOLESTR pszFileName, DWORD dwMode)
  130. { return S_OK; };
  131. STDMETHOD(Save)(LPCOLESTR pszFileName, BOOL fRemember)
  132. { return S_OK; };
  133. STDMETHOD(SaveCompleted)(LPCOLESTR pszFileName)
  134. { return S_OK; };
  135. STDMETHOD(GetCurFile)(LPOLESTR *ppszFileName)
  136. { *ppszFileName = NULL; return S_OK; };
  137. // IDropTarget methods
  138. STDMETHOD(DragEnter)(IDataObject *pdtobj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
  139. STDMETHOD(DragOver)(DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
  140. STDMETHOD(DragLeave)(void);
  141. STDMETHOD(Drop)(IDataObject *pdtobj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
  142. // IShellExtInit methods
  143. STDMETHOD(Initialize)(LPCITEMIDLIST pidlFolder, LPDATAOBJECT lpdobj, HKEY hkeyProgID);
  144. // IContextMenu methods
  145. STDMETHOD(QueryContextMenu)(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags);
  146. STDMETHOD(GetCommandString)(UINT_PTR idCommand, UINT uFlags, LPUINT lpReserved, LPSTR pszName, UINT uMaxNameLen);
  147. STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO lpcmi);
  148. // IShellPropSheetExt methods
  149. STDMETHOD(AddPages)(LPFNADDPROPSHEETPAGE pAddPageProc, LPARAM lParam);
  150. STDMETHOD(ReplacePage)(UINT uPageID, LPFNADDPROPSHEETPAGE pReplacePageFunc, LPARAM lParam)
  151. { return S_OK; };
  152. // IDiscMasterProgressEvents methods
  153. STDMETHOD(QueryCancel)(boolean *pbCancel);
  154. STDMETHOD(NotifyPnPActivity)();
  155. STDMETHOD(NotifyAddProgress)(long nCompletedSteps, long nTotalSteps);
  156. STDMETHOD(NotifyBlockProgress)(long nCompleted, long nTotal);
  157. STDMETHOD(NotifyTrackProgress)(long nCurrentTrack, long nTotalTracks);
  158. STDMETHOD(NotifyPreparingBurn)(long nEstimatedSeconds);
  159. STDMETHOD(NotifyClosingDisc)(long nEstimatedSeconds);
  160. STDMETHOD(NotifyBurnComplete)(HRESULT status);
  161. STDMETHOD(NotifyEraseComplete)(HRESULT status);
  162. // IOleCommandTarget methods
  163. STDMETHOD(QueryStatus)(const GUID* pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT* pCmdText);
  164. STDMETHOD(Exec)(const GUID* pguidCmdGroup, DWORD nCmdID, DWORD nCmdExecOpt, VARIANTARG* pvaIn, VARIANTARG* pvaOut);
  165. // ICDBurn methods
  166. STDMETHOD(GetRecorderDriveLetter)(LPWSTR pszDrive, UINT cch);
  167. STDMETHOD(Burn)(HWND hwnd);
  168. STDMETHOD(HasRecordableDrive)(BOOL *pfHasRecorder);
  169. // ICDBurnPriv methods
  170. STDMETHOD(GetMediaCapabilities)(DWORD *pdwCaps, BOOL *pfUDF);
  171. STDMETHOD(GetContentState)(BOOL *pfStagingHasFiles, BOOL *pfDiscHasFiles);
  172. STDMETHOD(IsWizardUp)();
  173. // IPersistPropertyBag methods
  174. STDMETHOD(InitNew)();
  175. STDMETHOD(Load)(IPropertyBag *ppb, IErrorLog *pErr);
  176. STDMETHOD(Save)(IPropertyBag *ppb, BOOL fClearDirty, BOOL fSaveAll)
  177. { return E_NOTIMPL; }
  178. // IDriveFolderExt methods
  179. STDMETHOD(DriveMatches)(int iDrive);
  180. STDMETHOD(Bind)(LPCITEMIDLIST pidl, IBindCtx *pbc, REFIID riid, void **ppv);
  181. STDMETHOD(GetSpace)(ULONGLONG *pcbTotal, ULONGLONG *pcbFree);
  182. // INamespaceWalkCB methods
  183. STDMETHOD(FoundItem)(IShellFolder *psf, LPCITEMIDLIST pidl);
  184. STDMETHOD(EnterFolder)(IShellFolder *psf, LPCITEMIDLIST pidl)
  185. { return S_OK; }
  186. STDMETHOD(LeaveFolder)(IShellFolder *psf, LPCITEMIDLIST pidl)
  187. { return S_OK; }
  188. STDMETHOD(InitializeProgressDialog)(LPWSTR *ppszTitle, LPWSTR *ppszCancel)
  189. { *ppszTitle = NULL; *ppszCancel = NULL; return E_NOTIMPL; }
  190. // IWizardSite methods
  191. STDMETHOD(GetNextPage)(HPROPSHEETPAGE *phPage);
  192. STDMETHOD(GetPreviousPage)(HPROPSHEETPAGE *phPage);
  193. STDMETHOD(GetCancelledPage)(HPROPSHEETPAGE *phPage)
  194. { return E_NOTIMPL; }
  195. // IServiceProvider methods
  196. STDMETHOD(QueryService)(REFGUID guidService, REFIID riid, void **ppv);
  197. // IQueryCancelAutoPlay methods
  198. STDMETHOD(AllowAutoPlay)(LPCWSTR pszPath, DWORD dwContentType, LPCWSTR pszLabel, DWORD dwSerialNumber);
  199. // ITransferAdviseSink methods
  200. STDMETHOD(PreOperation)(const STGOP op, IShellItem *psiItem, IShellItem *psiDest)
  201. { return S_OK; }
  202. STDMETHOD(ConfirmOperation)(IShellItem *psiSource, IShellItem *psiDest, STGTRANSCONFIRMATION stc, LPCUSTOMCONFIRMATION pcc);
  203. STDMETHOD(OperationProgress)(const STGOP op, IShellItem *psiItem, IShellItem *psiDest, ULONGLONG ullTotal, ULONGLONG ullComplete)
  204. { return S_OK; }
  205. STDMETHOD(PostOperation)(const STGOP op, IShellItem *psiItem, IShellItem *psiDest, HRESULT hrResult)
  206. { return S_OK; }
  207. STDMETHOD(QueryContinue)()
  208. { return S_OK; }
  209. // exposed for the static tables
  210. static INT_PTR s_WelcomeDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  211. { CCDBurn *pcdb = s_GetCDBurn(hwnd, uMsg, lParam); return pcdb->_WelcomeDlgProc(hwnd, uMsg, wParam, lParam); }
  212. static INT_PTR s_EjectDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  213. { CCDBurn *pcdb = s_GetCDBurn(hwnd, uMsg, lParam); return pcdb->_EjectDlgProc(hwnd, uMsg, wParam, lParam); }
  214. static INT_PTR s_ProgressDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  215. { CCDBurn *pcdb = s_GetCDBurn(hwnd, uMsg, lParam); return pcdb->_ProgressDlgProc(hwnd, uMsg, wParam, lParam); }
  216. static INT_PTR s_DoneDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  217. { CCDBurn *pcdb = s_GetCDBurn(hwnd, uMsg, lParam); return pcdb->_DoneDlgProc(hwnd, uMsg, wParam, lParam); }
  218. static INT_PTR s_WaitForMediaDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  219. { CCDBurn *pcdb = s_GetCDBurn(hwnd, uMsg, lParam); return pcdb->_WaitForMediaDlgProc(hwnd, uMsg, wParam, lParam); }
  220. static INT_PTR s_StartEraseDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  221. { CCDBurn *pcdb = s_GetCDBurn(hwnd, uMsg, lParam); return pcdb->_StartEraseDlgProc(hwnd, uMsg, wParam, lParam); }
  222. static INT_PTR s_DiskFullDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  223. { CCDBurn *pcdb = s_GetCDBurn(hwnd, uMsg, lParam); return pcdb->_DiskFullDlgProc(hwnd, uMsg, wParam, lParam); }
  224. static INT_PTR s_EarlyExitDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  225. { CCDBurn *pcdb = s_GetCDBurn(hwnd, uMsg, lParam); return pcdb->_EarlyExitDlgProc(hwnd, uMsg, wParam, lParam); }
  226. static INT_PTR s_HDFullDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  227. { CCDBurn *pcdb = s_GetCDBurn(hwnd, uMsg, lParam); return pcdb->_HDFullDlgProc(hwnd, uMsg, wParam, lParam); }
  228. static INT_PTR s_NoFilesDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  229. { CCDBurn *pcdb = s_GetCDBurn(hwnd, uMsg, lParam); return pcdb->_NoFilesDlgProc(hwnd, uMsg, wParam, lParam); }
  230. private:
  231. CCDBurn();
  232. ~CCDBurn();
  233. LONG _cRef;
  234. TCHAR _szVolumeName[MAX_PATH]; // device path of the drive that we were invoked on
  235. IDataObject *_pdo; // IDataObject (from IShellExtInit::Initialize)
  236. LPITEMIDLIST _pidl; // pidl we're sited on (only for droptarget, through IShellExtInit::Initialize)
  237. BOOL _fCancelled;
  238. BOOL _fRecording;
  239. BOOL _fIsRecordingDrive; // if this is the current recording drive (on init)
  240. BOOL _fPropSheetDirty;
  241. IDropTarget *_pdt; // IDropTarget object that we wrap
  242. DWORD _dwDropEffect; // drop effect chosen in dragenter
  243. IPropertyBag *_ppb; // propertybag to track state in wizard
  244. HWND _hwndWizardPage; // hwnd of the wizard page (used in progress)
  245. HWND _hwndBrowser; // browser hwnd, used to parent error dialogs
  246. ULONGLONG _cbStagedSize; // total size of staged files
  247. DWORD _dwCurSpeed; // current burning speed
  248. DWORD _dwTimeSet, _dwLastTime; // state variables for showing estimated time remaining
  249. TIMESTATS _ts;
  250. HDPA _hdpaExts; // pointers to the extensibility objects
  251. HPROPSHEETPAGE _rgWizPages[INDEX_DLG_BURNWIZ_MAX];
  252. HANDLE _hMutexBurning; // this tells us if we're burning or not.
  253. static HWND s_hwndWiz; // we can call SetForegroundWindow on this to bring up the wizard if its already up
  254. static BOOL s_fDriveInUse;
  255. DWORD _dwROTRegister; // DWORD to track our moniker stuff for autoplay cancellation
  256. // namespace
  257. static HRESULT _GetPidlForDriveIndex(int iDrive, LPITEMIDLIST *ppidl);
  258. static HRESULT _GetPidlForVolumeName(LPCTSTR pszVolume, LPITEMIDLIST *ppidl);
  259. static HRESULT _GetFolderPidl(LPITEMIDLIST *ppidl);
  260. static HRESULT _GetBurnStagingPath(LPTSTR pszPath, UINT cchBuf);
  261. static HRESULT _GetPlainCDPidl(LPITEMIDLIST *ppidl);
  262. static BOOL _HasFiles(LPCITEMIDLIST pidl);
  263. static BOOL _StagingAreaHasFiles();
  264. static BOOL _DiscHasFiles();
  265. static HRESULT _GetStagingFolder(LPCITEMIDLIST pidlDrive, REFIID riid, void **ppv);
  266. // drop / transfer engine
  267. HRESULT _EnsureDropTarget();
  268. static void _FreeDropParams(CDDROPPARAMS *pcddp);
  269. static DWORD WINAPI _DropThread(void *pv);
  270. HRESULT _GetDropPidl(LPITEMIDLIST *ppidl);
  271. HRESULT _StorageDrop(IDataObject *pdtobj, BOOL fMove);
  272. BOOL _IsStagingAreaSource(IDataObject *pdtobj, LPCITEMIDLIST pidlDrop);
  273. HRESULT _StagingPidlFromMerged(LPCITEMIDLIST pidlDrop, LPITEMIDLIST *ppidlDest);
  274. static HRESULT _LockCurrentDrive(BOOL fLock, BOOL fForce = FALSE);
  275. // initialization helpers
  276. static DWORD WINAPI _ExecThread(void *pv);
  277. // registry and cached info management
  278. static HRESULT _GetCurrentBurnVolumeName(LPTSTR pszVolumeName, UINT cchBuf);
  279. static HRESULT _SetCurrentBurnVolumeName(LPCTSTR pszVolumeName, BOOL fDelete);
  280. static BOOL _BurningIsEnabled();
  281. static HRESULT _GetStashFile(LPTSTR pszFile, UINT cchBuf);
  282. static HRESULT _GetCurrentStashDrive(LPTSTR pszDrive, UINT cchBuf);
  283. static HRESULT _SetCurrentStashDrive(LPCTSTR pszDrive);
  284. static HRESULT _DumpDiscInfo();
  285. static HRESULT _GetDiscInfoUsingIMAPI(IJolietDiscMaster *pjdm, IDiscRecorder *pdr, ULONGLONG *pcbFree);
  286. static HRESULT _GetDiscInfoUsingFilesystem(ULONGLONG *pcbTotal, ULONGLONG *pcbFree, BOOL *pfUDF);
  287. static HRESULT _StoreDiscInfo();
  288. static HRESULT _GetDiscRecorderInfo(IDiscRecorder *pdr, DWORD *pdwCurrentWriteSpeed, DWORD *pdwMaxWriteSpeed, DWORD *pdwDriveType);
  289. HRESULT _SetRecorderProps(IDiscRecorder *pdr, DWORD dwWriteSpeed);
  290. HRESULT _SetJolietProps(IJolietDiscMaster *pjdm);
  291. static HRESULT _GetCachedDriveInfo(LPCTSTR pszVolumeName, DWORD *pdwDriveType, DWORD *pdwCurWrite, DWORD *pdwMaxWrite);
  292. static HRESULT _SetCachedDriveInfo(LPCTSTR pszVolumeName, DWORD dwDriveType, DWORD dwCurWrite, DWORD dwMaxWrite);
  293. HRESULT _GetEjectSetting(BOOL *pfEject);
  294. HRESULT _SetEjectSetting(BOOL fEject);
  295. static HRESULT _GetRecorderPath(IDiscRecorder *pdr, LPTSTR pszPath, UINT cchBuf);
  296. static void _PruneRemovedDevices();
  297. // drive helpers
  298. static HRESULT _GetMediaCapabilities(DWORD *pdwCaps, BOOL *pfUDF);
  299. static HRESULT _GetVolumeNameForDriveIndex(int iDrive, LPTSTR pszVolumeName, UINT cchBuf);
  300. static HRESULT _GetDriveIndexForVolumeName(LPCTSTR pszVolumeName, int *piDrive);
  301. static HRESULT _GetCurrentDriveIndex(int *piDrive);
  302. static HRESULT _GetVolumeNameForDevicePath(LPCTSTR pszDevice, LPTSTR pszVolumeName, UINT cchBuf);
  303. static BOOL _DevicePathMatchesVolumeName(LPCTSTR pszDevice, LPCTSTR pszVolumeName);
  304. static DWORD _ExecSyncIoctl(HANDLE hDriver, DWORD dwIoctl, void *pbuf, DWORD cbBuf);
  305. static BOOL _CouldPossiblySupport(LPCWSTR pszVolume);
  306. HRESULT _GetVolumeNameFromDataObject(BOOL fCheckIsConfiguredDrive, LPTSTR pszVolumeName, UINT cchBuf);
  307. HRESULT _CheckTotal();
  308. HRESULT _Validate();
  309. static BOOL _HasMedia();
  310. // main IMAPI helpers
  311. HRESULT _GetDriveInfo(LPCTSTR pszVolumeName, DWORD *pdwDriveType, DWORD *pdwCurWrite, DWORD *pdwMaxWrite);
  312. HRESULT _GetDiscMasters(IDiscMaster **ppdm, IJolietDiscMaster **ppjdm);
  313. HRESULT _GetDiscRecorderForDrive(IDiscMaster *pdm, LPCTSTR pszVolumeName, IDiscRecorder **ppdr);
  314. HRESULT _FindAndSetRecorder(LPCTSTR pszVolumeName, IDiscMaster *pdm, BOOL fSetActive, IDiscRecorder **ppdr);
  315. HRESULT _FindAndSetDefaultRecorder(IDiscMaster *pdm, BOOL fSetActive, IDiscRecorder **ppdr);
  316. HRESULT _AddData(IJolietDiscMaster *pjdm);
  317. static BOOL _IsBurningNow();
  318. BOOL _EnterExclusiveBurning();
  319. void _LeaveExclusiveBurning();
  320. static void _HandleBookkeeping();
  321. // property sheet stuff
  322. void _MarkDirty(HWND hDlg);
  323. static BOOL_PTR CALLBACK s_DlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam);
  324. void _EnableRecordingDlgArea(HWND hwnd, BOOL fEnable);
  325. void _RecordingPrshtInit(HWND hDlg);
  326. BOOL _HandleApply(HWND hDlg);
  327. // UI
  328. HRESULT _Balloon();
  329. static BOOL CALLBACK _EnumProc(HWND hwnd, LPCITEMIDLIST pidl, LPARAM lParam);
  330. static BOOL _BurningFolderOpen();
  331. static DWORD CALLBACK _NotifyThreadProc(void *pv);
  332. void _CheckStagingArea();
  333. // wizard
  334. void _SetStatus(UINT uID);
  335. HRESULT _CreateDefaultPropBag(REFIID riid, void **ppv);
  336. static CCDBurn* s_GetCDBurn(HWND hwnd, UINT uMsg, LPARAM lParam);
  337. void _SetupFirstPage(HWND hwnd, BOOL fSubclass);
  338. static LRESULT CALLBACK _WizSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRefData);
  339. HRESULT _GetBurnHR();
  340. void _ShowRoxio();
  341. INT_PTR _WelcomeDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  342. INT_PTR _EjectDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  343. INT_PTR _ProgressDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  344. INT_PTR _DoneDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  345. INT_PTR _WaitForMediaDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  346. INT_PTR _StartEraseDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  347. INT_PTR _DiskFullDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  348. INT_PTR _EarlyExitDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  349. INT_PTR _HDFullDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  350. INT_PTR _NoFilesDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  351. void _HDFullSetText(HWND hwnd);
  352. void _InitProgressPage(HWND hwnd);
  353. void _SetEstimatedTime(DWORD dwSeconds);
  354. void _ConstructTimeString(DWORD dwEstTime, LPTSTR psz, UINT cch);
  355. void _DisplayEstimatedTime(HWND hwnd);
  356. void _InitTimeStats(BOOL fErase);
  357. void _SaveTimeStats(BOOL fErase);
  358. void _SetUpStartPage(HWND hwnd);
  359. void _LeaveStartPage(HWND hwnd);
  360. void _DisplayMediaErrorOnNext(HWND hwnd, UINT idMsg, UINT idMsgInsert);
  361. void _SetNextPage(HWND hwnd, int iIndex);
  362. HRESULT _PostOperation();
  363. HRESULT _ShowWizard();
  364. HRESULT _ShowWizardOnSeparateThread();
  365. static DWORD WINAPI _WizardThreadWrapper(void *pv);
  366. HRESULT _WizardThreadProc();
  367. void _RegisterAutoplayCanceller();
  368. void _UnregisterAutoplayCanceller();
  369. // verbs
  370. HRESULT _GetVerb(UINT_PTR idCmd, LPSTR pszName, UINT cchMax, BOOL bUnicode);
  371. static INT_PTR CALLBACK _ConfirmDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  372. HRESULT _CleanUp(LPCMINVOKECOMMANDINFO lpcmi, BOOL fRecycle);
  373. HRESULT _PrepWiz(LPCMINVOKECOMMANDINFO lpcmi, BOOL fErase, BOOL fFailSilently);
  374. static DWORD WINAPI _BurnThread(void *pv);
  375. static DWORD WINAPI _EraseThread(void *pv);
  376. // extensibility
  377. void _PruneExts();
  378. static HRESULT _TryCLSID(REFCLSID clsid, DWORD dwExtType, REFIID riid, void **ppv);
  379. static HRESULT _TryKey(LPTSTR pszKey, DWORD dwExtType, REFIID riid, void **ppv);
  380. static HRESULT _TestDropEffect(IDropTarget *pdt, IDataObject *pdo, REFIID riid, void **ppv);
  381. static HRESULT _TryCLSIDWithDropEffect(REFCLSID clsid, DWORD dwExtType, IDataObject *pdo, REFIID riid, void **ppv);
  382. static HRESULT _TryKeyWithDropEffect(LPTSTR pszKey, DWORD dwExtType, IDataObject *pdo, REFIID riid, void **ppv);
  383. void _AddExtensionToDPA(IWizardExtension *pwe, HPROPSHEETPAGE *rgPages, UINT cNumPages, UINT *pcPagesAdded);
  384. HRESULT _FillExtensionDPA(HPROPSHEETPAGE *rgPages, UINT cNumPages, UINT *pcPagesAdded);
  385. HRESULT _GetExtPage(int nExt, BOOL fNext, HPROPSHEETPAGE *phpage);
  386. HRESULT _GetExtPageFromPropBag(BOOL fNext, HPROPSHEETPAGE *phpage);
  387. void _SetExtPageFromPropBag(HWND hwnd, BOOL fNext);
  388. // "exports"
  389. friend HRESULT CCDBurn_CreateInstance(IUnknown* punkOuter, REFIID riid, void **ppv);
  390. friend HRESULT CDBurn_OnEject(HWND hwnd, INT iDrive);
  391. friend HRESULT CDBurn_OnDeviceAdded(DWORD dwDriveMask, BOOL fFullRefresh, BOOL fPickNewDrive);
  392. friend HRESULT CDBurn_OnDeviceRemoved(DWORD dwDriveMask);
  393. friend HRESULT CDBurn_GetCDInfo(LPCTSTR pszVolume, DWORD *pdwDriveCapabilities, DWORD *pdwMediaCapabilities);
  394. friend HRESULT CDBurn_OnMediaChange(BOOL fInsert, LPCWSTR pszDrive);
  395. friend HRESULT CDBurn_GetExtensionObject(DWORD dwExtType, IDataObject *pdo, REFIID riid, void **ppv);
  396. friend HRESULT CheckStagingArea();
  397. };
  398. HWND CCDBurn::s_hwndWiz = NULL;
  399. BOOL CCDBurn::s_fDriveInUse = FALSE;
  400. const static DWORD aPrshtHelpIDs[] =
  401. {
  402. IDC_RECORD_ENABLE, IDH_CDMEDIA_ENABLERECORDING,
  403. IDC_RECORD_TEXTIMAGE, IDH_CDMEDIA_STOREDISCIMAGE,
  404. IDC_RECORD_IMAGELOC, IDH_CDMEDIA_STOREDISCIMAGE,
  405. IDC_RECORD_TEXTWRITE, IDH_CDMEDIA_WRITESPEED,
  406. IDC_RECORD_WRITESPEED, IDH_CDMEDIA_WRITESPEED,
  407. IDC_RECORD_EJECT, IDH_CDMEDIA_EJECT,
  408. 0, 0
  409. };
  410. CCDBurn::CCDBurn() :
  411. _cRef(1)
  412. {
  413. DllAddRef();
  414. }
  415. CCDBurn::~CCDBurn()
  416. {
  417. if (_pdo)
  418. {
  419. _pdo->Release();
  420. }
  421. if (_pdt)
  422. {
  423. _pdt->Release();
  424. }
  425. ILFree(_pidl);
  426. if (_hMutexBurning)
  427. {
  428. CloseHandle(_hMutexBurning);
  429. }
  430. DllRelease();
  431. }
  432. // IUnknown
  433. STDMETHODIMP_(ULONG) CCDBurn::AddRef()
  434. {
  435. return InterlockedIncrement(&_cRef);
  436. }
  437. STDMETHODIMP_(ULONG) CCDBurn::Release()
  438. {
  439. ASSERT(0 != _cRef);
  440. ULONG cRef = InterlockedDecrement(&_cRef);
  441. if (0 == cRef)
  442. {
  443. delete this;
  444. }
  445. return cRef;
  446. }
  447. HRESULT CCDBurn::QueryInterface(REFIID riid, void **ppv)
  448. {
  449. static const QITAB qit[] =
  450. {
  451. QITABENT(CCDBurn, IObjectWithSite),
  452. QITABENT(CCDBurn, IContextMenu),
  453. QITABENT(CCDBurn, IShellExtInit),
  454. QITABENT(CCDBurn, IShellPropSheetExt),
  455. QITABENT(CCDBurn, IDiscMasterProgressEvents),
  456. QITABENT(CCDBurn, IDropTarget),
  457. QITABENT(CCDBurn, IPersistFile),
  458. QITABENT(CCDBurn, IOleCommandTarget),
  459. QITABENT(CCDBurn, ICDBurn),
  460. QITABENT(CCDBurn, ICDBurnPriv),
  461. QITABENT(CCDBurn, IPersistPropertyBag),
  462. QITABENT(CCDBurn, IDriveFolderExt),
  463. QITABENT(CCDBurn, INamespaceWalkCB),
  464. QITABENT(CCDBurn, IWizardSite),
  465. QITABENT(CCDBurn, IServiceProvider),
  466. QITABENT(CCDBurn, IQueryCancelAutoPlay),
  467. QITABENT(CCDBurn, ITransferAdviseSink),
  468. { 0 },
  469. };
  470. return QISearch(this, qit, riid, ppv);
  471. }
  472. STDAPI CCDBurn_CreateInstance(IUnknown* punkOuter, REFIID riid, void **ppv)
  473. {
  474. if (punkOuter)
  475. return CLASS_E_NOAGGREGATION;
  476. if (SHRestricted(REST_NOCDBURNING))
  477. return E_FAIL;
  478. CCDBurn *pcdb = new CCDBurn();
  479. if (!pcdb)
  480. return E_OUTOFMEMORY;
  481. HRESULT hr = pcdb->QueryInterface(riid, ppv);
  482. pcdb->Release();
  483. return hr;
  484. }
  485. // IShellExtInit
  486. STDMETHODIMP CCDBurn::Initialize(LPCITEMIDLIST pidlFolder, IDataObject* pdo, HKEY hkeyProgID)
  487. {
  488. if (!pdo && !pidlFolder)
  489. return E_INVALIDARG;
  490. IUnknown_Set((IUnknown **)&_pdo, (IUnknown *)pdo);
  491. Pidl_Set(&_pidl, pidlFolder);
  492. return (_pidl || _pdo) ? S_OK : E_FAIL;
  493. }
  494. HRESULT CCDBurn::_GetVolumeNameFromDataObject(BOOL fCheckIsConfiguredDrive, LPTSTR pszVolumeName, UINT cchBuf)
  495. {
  496. HRESULT hr = E_FAIL;
  497. if (!SHRestricted(REST_NOCDBURNING) && _pdo)
  498. {
  499. STGMEDIUM medium;
  500. LPIDA pida = DataObj_GetHIDA(_pdo, &medium);
  501. if (pida)
  502. {
  503. // we only display the page if there is a single item selected
  504. if (pida->cidl == 1)
  505. {
  506. // get the IDLIST an try to determine the drive we are showing this for
  507. LPITEMIDLIST pidl = IDA_ILClone(pida, 0);
  508. if (pidl)
  509. {
  510. TCHAR szPath[MAX_PATH];
  511. SHGetPathFromIDList(pidl, szPath);
  512. // only go farther if the drive is a CD ROM
  513. if ((GetDriveType(szPath) == DRIVE_CDROM) &&
  514. (GetVolumeNameForVolumeMountPoint(szPath, pszVolumeName, cchBuf)))
  515. {
  516. hr = S_OK;
  517. if (fCheckIsConfiguredDrive)
  518. {
  519. TCHAR szCurrent[MAX_PATH];
  520. hr = _GetCurrentBurnVolumeName(szCurrent, ARRAYSIZE(szCurrent));
  521. if (SUCCEEDED(hr))
  522. {
  523. hr = (lstrcmpi(szCurrent, pszVolumeName) == 0) ? S_OK : E_FAIL;
  524. }
  525. }
  526. }
  527. ILFree(pidl);
  528. }
  529. }
  530. HIDA_ReleaseStgMedium(pida, &medium);
  531. }
  532. }
  533. return hr;
  534. }
  535. // Property sheet code (for configuring the burnable drive)
  536. HRESULT CCDBurn::_GetCurrentBurnVolumeName(LPTSTR pszVolumeName, UINT cchBuf)
  537. {
  538. HRESULT hr = E_FAIL; // failed == no drive.
  539. if (!SHRestricted(REST_NOCDBURNING))
  540. {
  541. ULONG cb = cchBuf * sizeof(*pszVolumeName);
  542. if (ERROR_SUCCESS == SHGetValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_CURRENTDRIVE, NULL, pszVolumeName, &cb))
  543. {
  544. // we encode an empty string as a special failure case as well.
  545. hr = (lstrlen(pszVolumeName) > 0) ? S_OK : E_UNEXPECTED;
  546. }
  547. }
  548. return hr;
  549. }
  550. BOOL CCDBurn::_BurningIsEnabled()
  551. {
  552. TCHAR szDummy[MAX_PATH];
  553. return SUCCEEDED(_GetCurrentBurnVolumeName(szDummy, ARRAYSIZE(szDummy)));
  554. }
  555. HRESULT CCDBurn::_SetCurrentBurnVolumeName(LPCTSTR pszVolumeName, BOOL fDelete)
  556. {
  557. // setcurrentburnvolumename is called when the burning drive is getting switched,
  558. // whether because were turning off burning or moving it to a different drive.
  559. // whenever this changes, that means drivefolder's Parse() and Enum() will start returning
  560. // different stuff for the affected drive letters.
  561. // so we issue SHCNE_DRIVEADD and SHCNE_DRIVEREMOVED for the changes.
  562. LPITEMIDLIST pidlBeforeOld = NULL, pidlBeforeNew = NULL, pidlAfterOld = NULL, pidlAfterNew = NULL;
  563. DWORD dwDriveOld = 0, cb = sizeof(dwDriveOld);
  564. if (ERROR_SUCCESS == SHGetValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_CACHEDINDEX, NULL, &dwDriveOld, &cb))
  565. {
  566. _GetPidlForDriveIndex(dwDriveOld, &pidlBeforeOld);
  567. }
  568. _GetPidlForVolumeName(pszVolumeName, &pidlAfterOld);
  569. SHDeleteValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_CACHEDINDEX);
  570. DWORD dwRet;
  571. if (!fDelete)
  572. {
  573. cb = (lstrlen(pszVolumeName) + 1) * sizeof(TCHAR);
  574. dwRet = SHSetValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_CURRENTDRIVE, REG_SZ, pszVolumeName, cb);
  575. int iDrive;
  576. if ((ERROR_SUCCESS == dwRet) && SUCCEEDED(_GetDriveIndexForVolumeName(pszVolumeName, &iDrive)))
  577. {
  578. dwRet = SHSetValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_CACHEDINDEX, REG_DWORD, &iDrive, sizeof(iDrive));
  579. }
  580. }
  581. else
  582. {
  583. dwRet = SHDeleteValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_CURRENTDRIVE);
  584. }
  585. HRESULT hr = (ERROR_SUCCESS == dwRet) ? S_OK : E_FAIL;
  586. if (SUCCEEDED(hr))
  587. {
  588. if (dwDriveOld)
  589. {
  590. _GetPidlForDriveIndex(dwDriveOld, &pidlBeforeNew);
  591. }
  592. _GetPidlForVolumeName(pszVolumeName, &pidlAfterNew);
  593. if (pidlBeforeOld && pidlBeforeNew && !ILIsEqual(pidlBeforeOld, pidlBeforeNew))
  594. {
  595. SHChangeNotify(SHCNE_DRIVEREMOVED, SHCNF_IDLIST, pidlBeforeOld, NULL);
  596. SHChangeNotify(SHCNE_DRIVEADD, SHCNF_IDLIST, pidlBeforeNew, NULL);
  597. }
  598. if (pidlAfterOld && pidlAfterNew && !ILIsEqual(pidlAfterOld, pidlAfterNew))
  599. {
  600. SHChangeNotify(SHCNE_DRIVEREMOVED, SHCNF_IDLIST, pidlAfterOld, NULL);
  601. SHChangeNotify(SHCNE_DRIVEADD, SHCNF_IDLIST, pidlAfterNew, NULL);
  602. }
  603. }
  604. ILFree(pidlBeforeOld);
  605. ILFree(pidlBeforeNew);
  606. ILFree(pidlAfterOld);
  607. ILFree(pidlAfterNew);
  608. return hr;
  609. }
  610. HRESULT CCDBurn::_GetBurnStagingPath(LPTSTR pszPath, UINT cchBuf)
  611. {
  612. ASSERTMSG(cchBuf >= MAX_PATH, "caller needs to pass bigger buffer");
  613. return (cchBuf < MAX_PATH) ? E_FAIL : SHGetFolderPath(NULL, CSIDL_CDBURN_AREA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, pszPath);
  614. }
  615. HRESULT CCDBurn::_GetStashFile(LPTSTR pszFile, UINT cchBuf)
  616. {
  617. TCHAR szPath[MAX_PATH];
  618. ULONG cb = sizeof(szPath);
  619. DWORD dwRet = SHGetValue(HKEY_LOCAL_MACHINE, TEXT(IMAPI_REGKEY_STASHFILE2), TEXT(IMAPI_REGVAL_PATH), NULL, szPath, &cb);
  620. HRESULT hr = E_FAIL;
  621. if (dwRet == ERROR_SUCCESS)
  622. {
  623. lstrcpyn(pszFile, szPath, cchBuf);
  624. hr = S_OK;
  625. }
  626. return hr;
  627. }
  628. HRESULT CCDBurn::_GetCurrentStashDrive(LPTSTR pszDrive, UINT cchBuf)
  629. {
  630. TCHAR szPath[MAX_PATH];
  631. HRESULT hr = _GetStashFile(szPath, ARRAYSIZE(szPath));
  632. if (SUCCEEDED(hr) && PathStripToRoot(szPath))
  633. {
  634. lstrcpyn(pszDrive, szPath, cchBuf);
  635. hr = S_OK;
  636. }
  637. return hr;
  638. }
  639. HRESULT CCDBurn::_SetCurrentStashDrive(LPCTSTR pszDrive)
  640. {
  641. // we're using the root of the hard drive.
  642. UINT cbStashFile = (lstrlen(pszDrive) + 1) * sizeof(TCHAR);
  643. DWORD dwRet = SHSetValue(HKEY_LOCAL_MACHINE, TEXT(IMAPI_REGKEY_STASHFILE2), TEXT(IMAPI_REGVAL_PATH), REG_SZ, pszDrive, cbStashFile);
  644. return (dwRet == ERROR_SUCCESS) ? S_OK : E_FAIL;
  645. }
  646. HRESULT CCDBurn::_GetEjectSetting(BOOL *pfEject)
  647. {
  648. DWORD dwEject, cb = sizeof(dwEject);
  649. DWORD dwRet = SHGetValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_AUTOEJECT, NULL, &dwEject, &cb);
  650. HRESULT hr = E_FAIL;
  651. if (dwRet == ERROR_SUCCESS)
  652. {
  653. *pfEject = dwEject;
  654. hr = S_OK;
  655. }
  656. return hr;
  657. }
  658. HRESULT CCDBurn::_SetEjectSetting(BOOL fEject)
  659. {
  660. DWORD dwEject = fEject;
  661. DWORD dwRet = SHSetValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_AUTOEJECT, REG_DWORD, &dwEject, sizeof(dwEject));
  662. return (dwRet == ERROR_SUCCESS) ? S_OK : E_FAIL;
  663. }
  664. HRESULT CCDBurn::_GetCachedDriveInfo(LPCTSTR pszVolumeName, DWORD *pdwDriveType, DWORD *pdwCurrentWriteSpeed, DWORD *pdwMaxWriteSpeed)
  665. {
  666. HRESULT hr = S_OK;
  667. TCHAR szRegPath[MAX_PATH];
  668. lstrcpyn(szRegPath, REGSTR_PATH_DRIVES, ARRAYSIZE(szRegPath));
  669. StrCatBuff(szRegPath, TEXT("\\"), ARRAYSIZE(szRegPath));
  670. StrCatBuff(szRegPath, PathFindFileName(pszVolumeName), ARRAYSIZE(szRegPath));
  671. if (pdwDriveType)
  672. {
  673. DWORD dwTemp;
  674. ULONG cb = sizeof(dwTemp);
  675. DWORD dwRet = SHGetValue(HKEY_CURRENT_USER, szRegPath, REGVALUE_DRIVETYPE, NULL, &dwTemp, &cb);
  676. if (dwRet == ERROR_SUCCESS)
  677. {
  678. *pdwDriveType = dwTemp;
  679. }
  680. else
  681. {
  682. // this is the one value that should always be present if the key is there,
  683. // so fail if it's not there yet.
  684. hr = E_FAIL;
  685. }
  686. }
  687. if (pdwCurrentWriteSpeed)
  688. {
  689. DWORD dwTemp;
  690. ULONG cb = sizeof(dwTemp);
  691. DWORD dwRet = SHGetValue(HKEY_CURRENT_USER, szRegPath, REGVALUE_CURRENTSPEED, NULL, &dwTemp, &cb);
  692. if (dwRet == ERROR_SUCCESS)
  693. {
  694. *pdwCurrentWriteSpeed = dwTemp;
  695. }
  696. }
  697. if (pdwMaxWriteSpeed)
  698. {
  699. DWORD dwTemp;
  700. ULONG cb = sizeof(dwTemp);
  701. DWORD dwRet = SHGetValue(HKEY_CURRENT_USER, szRegPath, REGVALUE_MAXSPEED, NULL, &dwTemp, &cb);
  702. if (dwRet == ERROR_SUCCESS)
  703. {
  704. *pdwMaxWriteSpeed = dwTemp;
  705. }
  706. }
  707. return hr;
  708. }
  709. HRESULT CCDBurn::_SetCachedDriveInfo(LPCTSTR pszVolumeName, DWORD dwDriveType, DWORD dwWriteSpeed, DWORD dwMaxWriteSpeed)
  710. {
  711. TCHAR szRegPath[MAX_PATH];
  712. lstrcpyn(szRegPath, REGSTR_PATH_DRIVES, ARRAYSIZE(szRegPath));
  713. StrCatBuff(szRegPath, TEXT("\\"), ARRAYSIZE(szRegPath));
  714. StrCatBuff(szRegPath, PathFindFileName(pszVolumeName), ARRAYSIZE(szRegPath));
  715. if (dwDriveType > 0)
  716. {
  717. SHSetValue(HKEY_CURRENT_USER, szRegPath, REGVALUE_DRIVETYPE, REG_DWORD, &dwDriveType, sizeof(dwDriveType));
  718. }
  719. if (dwWriteSpeed > 0)
  720. {
  721. SHSetValue(HKEY_CURRENT_USER, szRegPath, REGVALUE_CURRENTSPEED, REG_DWORD, &dwWriteSpeed, sizeof(dwWriteSpeed));
  722. }
  723. if (dwMaxWriteSpeed > 0)
  724. {
  725. SHSetValue(HKEY_CURRENT_USER, szRegPath, REGVALUE_MAXSPEED, REG_DWORD, &dwMaxWriteSpeed, sizeof(dwMaxWriteSpeed));
  726. }
  727. return S_OK;
  728. }
  729. HRESULT CCDBurn::_GetDiscRecorderInfo(IDiscRecorder *pdr, DWORD *pdwCurrentWriteSpeed, DWORD *pdwMaxWriteSpeed, DWORD *pdwDriveType)
  730. {
  731. IPropertyStorage *pps;
  732. HRESULT hr = pdr->GetRecorderProperties(&pps);
  733. if (SUCCEEDED(hr))
  734. {
  735. PROPSPEC rgpspec[2];
  736. rgpspec[0].ulKind = PRSPEC_LPWSTR;
  737. rgpspec[0].lpwstr = L"WriteSpeed";
  738. rgpspec[1].ulKind = PRSPEC_LPWSTR;
  739. rgpspec[1].lpwstr = L"MaxWriteSpeed";
  740. PROPVARIANT rgvar[2];
  741. hr = pps->ReadMultiple(2, rgpspec, rgvar);
  742. if (SUCCEEDED(hr))
  743. {
  744. if ((V_VT(&rgvar[0]) == VT_I4) &&
  745. (V_VT(&rgvar[1]) == VT_I4))
  746. {
  747. if (pdwCurrentWriteSpeed)
  748. *pdwCurrentWriteSpeed = rgvar[0].lVal;
  749. if (pdwMaxWriteSpeed)
  750. *pdwMaxWriteSpeed = rgvar[1].lVal;
  751. }
  752. else
  753. {
  754. hr = E_FAIL;
  755. }
  756. }
  757. pps->Release();
  758. }
  759. if (SUCCEEDED(hr) && pdwDriveType)
  760. {
  761. long lType;
  762. hr = pdr->GetRecorderType(&lType);
  763. if (SUCCEEDED(hr))
  764. {
  765. *pdwDriveType = lType;
  766. }
  767. }
  768. return hr;
  769. }
  770. HRESULT CCDBurn::_SetRecorderProps(IDiscRecorder *pdr, DWORD dwWriteSpeed)
  771. {
  772. IPropertyStorage *pps;
  773. HRESULT hr = pdr->GetRecorderProperties(&pps);
  774. if (SUCCEEDED(hr))
  775. {
  776. PROPSPEC rgpspec[1];
  777. PROPVARIANT rgvar[1];
  778. rgpspec[0].ulKind = PRSPEC_LPWSTR;
  779. rgpspec[0].lpwstr = L"WriteSpeed";
  780. rgvar[0].vt = VT_I4;
  781. rgvar[0].lVal = dwWriteSpeed;
  782. hr = pps->WriteMultiple(1, rgpspec, rgvar, PID_FIRST_USABLE);
  783. if (SUCCEEDED(hr))
  784. {
  785. // commit propertystorage to the discrecorder
  786. hr = pdr->SetRecorderProperties(pps);
  787. }
  788. pps->Release();
  789. }
  790. return hr;
  791. }
  792. HRESULT CCDBurn::_SetJolietProps(IJolietDiscMaster *pjdm)
  793. {
  794. IPropertyStorage *pps;
  795. HRESULT hr = pjdm->GetJolietProperties(&pps);
  796. if (SUCCEEDED(hr))
  797. {
  798. WCHAR szLabel[JOLIET_MAX_LABEL + 1];
  799. szLabel[0] = 0;
  800. SHPropertyBag_ReadStr(_ppb, PROPSTR_DISCLABEL, szLabel, ARRAYSIZE(szLabel));
  801. PROPSPEC rgpspec[1];
  802. PROPVARIANT rgvar[1];
  803. rgpspec[0].ulKind = PRSPEC_LPWSTR;
  804. rgpspec[0].lpwstr = L"VolumeName";
  805. rgvar[0].vt = VT_BSTR;
  806. rgvar[0].bstrVal = SysAllocString(szLabel);
  807. hr = pps->WriteMultiple(1, rgpspec, rgvar, PID_FIRST_USABLE);
  808. if (SUCCEEDED(hr))
  809. {
  810. // commit propertystorage to the joliet disc master
  811. hr = pjdm->SetJolietProperties(pps);
  812. }
  813. PropVariantClear(&rgvar[0]);
  814. pps->Release();
  815. }
  816. return hr;
  817. }
  818. HRESULT CCDBurn::_GetDriveInfo(LPCTSTR pszVolumeName, DWORD *pdwDriveType, DWORD *pdwCurWrite, DWORD *pdwMaxWrite)
  819. {
  820. HRESULT hr = _GetCachedDriveInfo(pszVolumeName, pdwDriveType, pdwCurWrite, pdwMaxWrite);
  821. if (FAILED(hr))
  822. {
  823. IDiscMaster *pdm;
  824. IJolietDiscMaster *pjdm;
  825. hr = _GetDiscMasters(&pdm, &pjdm);
  826. if (SUCCEEDED(hr))
  827. {
  828. IDiscRecorder *pdr;
  829. hr = _GetDiscRecorderForDrive(pdm, pszVolumeName, &pdr);
  830. if (SUCCEEDED(hr))
  831. {
  832. if (S_OK == hr)
  833. {
  834. DWORD dwMaxWrite, dwDriveType;
  835. hr = _GetDiscRecorderInfo(pdr, NULL, &dwMaxWrite, &dwDriveType);
  836. if (SUCCEEDED(hr))
  837. {
  838. // default to fastest speed
  839. _SetCachedDriveInfo(pszVolumeName, dwDriveType, WRITESPEED_FASTEST, dwMaxWrite);
  840. if (pdwMaxWrite)
  841. {
  842. *pdwMaxWrite = dwMaxWrite;
  843. }
  844. if (pdwCurWrite)
  845. {
  846. *pdwCurWrite = dwMaxWrite;
  847. }
  848. if (pdwDriveType)
  849. {
  850. *pdwDriveType = dwDriveType;
  851. }
  852. }
  853. pdr->Release();
  854. }
  855. else
  856. {
  857. if (pdwDriveType)
  858. {
  859. *pdwDriveType = DRIVE_NOTSUPPORTED;
  860. }
  861. _SetCachedDriveInfo(pszVolumeName, DRIVE_NOTSUPPORTED, 0, 0);
  862. }
  863. }
  864. pdm->Release();
  865. pjdm->Release();
  866. }
  867. }
  868. return hr;
  869. }
  870. STDMETHODIMP CCDBurn::AddPages(LPFNADDPROPSHEETPAGE pAddPageProc, LPARAM lParam)
  871. {
  872. // get the destination burn drive from the IDataObject we recieved during initialization
  873. HRESULT hr = _GetVolumeNameFromDataObject(FALSE, _szVolumeName, ARRAYSIZE(_szVolumeName));
  874. if (SUCCEEDED(hr))
  875. {
  876. DWORD dwDriveType;
  877. // only add page if we're supported by IMAPI.
  878. if (SUCCEEDED(_GetDriveInfo(_szVolumeName, &dwDriveType, NULL, NULL)) && SUPPORTED(dwDriveType))
  879. {
  880. // is this drive configured to be the recording drive?
  881. _fIsRecordingDrive = FALSE;
  882. TCHAR szCurrent[MAX_PATH];
  883. if (SUCCEEDED(_GetCurrentBurnVolumeName(szCurrent, ARRAYSIZE(szCurrent))))
  884. {
  885. _fIsRecordingDrive = (lstrcmpi(szCurrent, _szVolumeName) == 0);
  886. }
  887. PROPSHEETPAGE psp = { 0 };
  888. psp.dwSize = sizeof(psp); // extra data
  889. psp.dwFlags = PSP_DEFAULT;
  890. psp.hInstance = HINST_THISDLL;
  891. psp.pszTemplate = MAKEINTRESOURCE(DLG_DRV_RECORDINGTAB);
  892. psp.pfnDlgProc = s_DlgProc;
  893. psp.lParam = (LPARAM)this; // pass out a reference to our object
  894. AddRef();
  895. // create the page, and add it using the cb function they gave us
  896. hr = E_OUTOFMEMORY;
  897. HPROPSHEETPAGE hPage = CreatePropertySheetPage(&psp);
  898. if (hPage)
  899. {
  900. if (!pAddPageProc(hPage, lParam))
  901. {
  902. DestroyPropertySheetPage(hPage);
  903. }
  904. else
  905. {
  906. hr = S_OK; // success
  907. }
  908. }
  909. if (FAILED(hr))
  910. {
  911. Release();
  912. }
  913. }
  914. }
  915. return hr;
  916. }
  917. void CCDBurn::_EnableRecordingDlgArea(HWND hwnd, BOOL fEnable)
  918. {
  919. EnableWindow(GetDlgItem(hwnd, IDC_RECORD_IMAGELOC), IsUserAnAdmin() ? fEnable : FALSE);
  920. EnableWindow(GetDlgItem(hwnd, IDC_RECORD_WRITESPEED), fEnable);
  921. EnableWindow(GetDlgItem(hwnd, IDC_RECORD_TEXTIMAGE), fEnable);
  922. EnableWindow(GetDlgItem(hwnd, IDC_RECORD_TEXTWRITE), fEnable);
  923. EnableWindow(GetDlgItem(hwnd, IDC_RECORD_EJECT), fEnable);
  924. }
  925. void CCDBurn::_RecordingPrshtInit(HWND hDlg)
  926. {
  927. DECLAREWAITCURSOR;
  928. SetWaitCursor();
  929. HWND hwndWriteSpeed = GetDlgItem(hDlg, IDC_RECORD_WRITESPEED);
  930. HWND hwndImageLoc = GetDlgItem(hDlg, IDC_RECORD_IMAGELOC);
  931. // get the icon for the drive
  932. HICON hIcon = LoadIcon(HINST_THISDLL, MAKEINTRESOURCE(IDI_DRIVECD));
  933. ReplaceDlgIcon(hDlg, IDC_RECORD_ICON, hIcon);
  934. // set the "we are the recording drive" flag
  935. CheckDlgButton(hDlg, IDC_RECORD_ENABLE, _fIsRecordingDrive);
  936. _EnableRecordingDlgArea(hDlg, _fIsRecordingDrive);
  937. BOOL fAutoEject = TRUE;
  938. _GetEjectSetting(&fAutoEject);
  939. CheckDlgButton(hDlg, IDC_RECORD_EJECT, fAutoEject);
  940. // populate the controls for the write speed
  941. TCHAR szTemp[MAX_PATH];
  942. LoadString(HINST_THISDLL, IDS_BURN_WRITESPEED_NX, szTemp, ARRAYSIZE(szTemp));
  943. // if the registry info is missing
  944. // then default to 1x.
  945. DWORD dwMaxSpeed = 1;
  946. DWORD dwCurSpeed = 1;
  947. _GetDriveInfo(_szVolumeName, NULL, &dwCurSpeed, &dwMaxSpeed);
  948. int iCurSel = 0, iSelIndex = 0;
  949. TCHAR szSpeed[20];
  950. LoadString(HINST_THISDLL, IDS_BURN_WRITESPEED_FASTEST, szSpeed, ARRAYSIZE(szSpeed));
  951. ComboBox_AddString(hwndWriteSpeed, szSpeed);
  952. ComboBox_SetItemData(hwndWriteSpeed, iSelIndex, WRITESPEED_FASTEST);
  953. iSelIndex++;
  954. // we want the following:
  955. // 8x drive: 8, 4, 2, 1
  956. // 10x drive: 10, 8, 4, 2, 1
  957. for (DWORD dwSpeed = dwMaxSpeed; dwSpeed >= 1; iSelIndex++)
  958. {
  959. if (dwSpeed == dwCurSpeed)
  960. {
  961. iCurSel = iSelIndex;
  962. }
  963. _sntprintf(szSpeed, ARRAYSIZE(szSpeed), szTemp, dwSpeed);
  964. ComboBox_AddString(hwndWriteSpeed, szSpeed);
  965. ComboBox_SetItemData(hwndWriteSpeed, iSelIndex, dwSpeed);
  966. // so if we just added the max speed, set dwSpeed to the lowest
  967. // power of two greater than the max speed.
  968. // then divide by two.
  969. // thus 10->8, 8->4, etc.
  970. if (dwSpeed == dwMaxSpeed)
  971. {
  972. for (dwSpeed = 1; dwSpeed < dwMaxSpeed; dwSpeed *= 2);
  973. }
  974. dwSpeed /= 2;
  975. }
  976. ComboBox_SetCurSel(hwndWriteSpeed, iCurSel);
  977. // populate the staging drive information, and try and set the drive
  978. SendMessage(hwndImageLoc, CBEM_SETIMAGELIST, 0, (LPARAM)GetSystemImageListSmallIcons());
  979. PopulateLocalDrivesCombo(hwndImageLoc, NULL, (LPARAM)hwndImageLoc);
  980. BOOL fSetAlready = FALSE;
  981. if (SUCCEEDED(_GetCurrentStashDrive(szTemp, ARRAYSIZE(szTemp))))
  982. {
  983. for (int i = 0; (i < ComboBox_GetCount(hwndImageLoc)) && !fSetAlready; i++)
  984. {
  985. LPTSTR pszData = (LPTSTR)ComboBox_GetItemData(hwndImageLoc, i);
  986. if (lstrcmpi(szTemp, pszData) == 0)
  987. {
  988. ComboBox_SetCurSel(hwndImageLoc, i);
  989. fSetAlready = TRUE;
  990. }
  991. }
  992. }
  993. if (!fSetAlready)
  994. ComboBox_SetCurSel(hwndImageLoc, 0);
  995. // if we're not an admin, the user wont be able to change the stash location due to kernel security
  996. // issues. thus disable that part.
  997. if (!IsUserAnAdmin())
  998. {
  999. EnableWindow(hwndImageLoc, FALSE);
  1000. WCHAR szText[200];
  1001. LoadString(HINST_THISDLL, IDS_BURN_USERBLOCK, szText, ARRAYSIZE(szText));
  1002. SetWindowText(GetDlgItem(hDlg, IDC_RECORD_TEXTIMAGE), szText);
  1003. }
  1004. _fPropSheetDirty = FALSE;
  1005. ResetWaitCursor();
  1006. }
  1007. BOOL CCDBurn::_HandleApply(HWND hDlg)
  1008. {
  1009. BOOL fGoAhead = TRUE;
  1010. if (_fPropSheetDirty)
  1011. {
  1012. if (IsDlgButtonChecked(hDlg, IDC_RECORD_ENABLE) == BST_CHECKED)
  1013. {
  1014. _fIsRecordingDrive = TRUE;
  1015. // get the stash drive setup
  1016. HWND hwndStash = GetDlgItem(hDlg, IDC_RECORD_IMAGELOC);
  1017. int iItem = ComboBox_GetCurSel(hwndStash);
  1018. if (iItem != (int)CB_ERR)
  1019. {
  1020. LPTSTR pszStashDrive = (LPTSTR)ComboBox_GetItemData(hwndStash, iItem);
  1021. // set the stash drive
  1022. _SetCurrentStashDrive(pszStashDrive);
  1023. // mark the drive we are going to burn to
  1024. _SetCurrentBurnVolumeName(_szVolumeName, FALSE);
  1025. // set speed
  1026. HWND hwndSpeed = GetDlgItem(hDlg, IDC_RECORD_WRITESPEED);
  1027. iItem = ComboBox_GetCurSel(hwndSpeed);
  1028. if (iItem != (int)CB_ERR)
  1029. {
  1030. DWORD dwSpeed = (DWORD)ComboBox_GetItemData(hwndSpeed, iItem);
  1031. _SetCachedDriveInfo(_szVolumeName, DRIVE_USEEXISTING, dwSpeed, 0);
  1032. }
  1033. // set autoeject
  1034. BOOL fAutoEject = (IsDlgButtonChecked(hDlg, IDC_RECORD_EJECT) == BST_CHECKED);
  1035. _SetEjectSetting(fAutoEject);
  1036. // redo free space
  1037. _HandleBookkeeping();
  1038. }
  1039. _fPropSheetDirty = FALSE;
  1040. }
  1041. else if (_fIsRecordingDrive)
  1042. {
  1043. if (!_StagingAreaHasFiles() ||
  1044. (IDYES == ShellMessageBox(HINST_THISDLL, hDlg, MAKEINTRESOURCE(IDS_BURN_CONFIRM_DISABLE), MAKEINTRESOURCE(IDS_BURN),
  1045. MB_YESNO | MB_ICONQUESTION)))
  1046. {
  1047. // clear out any trash, we're disabling the cd burning now.
  1048. _SetCurrentBurnVolumeName(TEXT(""), FALSE); // there is no recording drive now
  1049. _fPropSheetDirty = FALSE;
  1050. }
  1051. else
  1052. {
  1053. fGoAhead = FALSE;
  1054. }
  1055. }
  1056. }
  1057. return fGoAhead;
  1058. }
  1059. void CCDBurn::_MarkDirty(HWND hDlg)
  1060. {
  1061. PropSheet_Changed(GetParent(hDlg), hDlg);
  1062. _fPropSheetDirty = TRUE;
  1063. }
  1064. BOOL_PTR CCDBurn::s_DlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
  1065. {
  1066. if (uMessage == WM_INITDIALOG)
  1067. {
  1068. PROPSHEETPAGE *psp = (PROPSHEETPAGE*)lParam;
  1069. CCDBurn *pcdb = (CCDBurn*)psp->lParam;
  1070. SetWindowLongPtr(hDlg, GWLP_USERDATA, psp->lParam);
  1071. pcdb->_RecordingPrshtInit(hDlg);
  1072. }
  1073. else
  1074. {
  1075. CCDBurn *pcdb = (CCDBurn*)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  1076. switch (uMessage)
  1077. {
  1078. case WM_DESTROY:
  1079. ReplaceDlgIcon(hDlg, IDC_RECORD_ICON, NULL);
  1080. SetWindowLongPtr(hDlg, GWLP_USERDATA, 0x0);
  1081. pcdb->Release();
  1082. break;
  1083. case WM_HELP:
  1084. WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle, CDBURN_HELPFILE, HELP_WM_HELP, (ULONG_PTR)(LPTSTR) aPrshtHelpIDs);
  1085. break;
  1086. case WM_CONTEXTMENU:
  1087. WinHelp((HWND)wParam, CDBURN_HELPFILE, HELP_CONTEXTMENU, (ULONG_PTR)(void *)aPrshtHelpIDs);
  1088. break;
  1089. case WM_COMMAND:
  1090. switch (GET_WM_COMMAND_ID(wParam, lParam))
  1091. {
  1092. case IDC_RECORD_ENABLE:
  1093. {
  1094. BOOL fRecordingEnabled = (IsDlgButtonChecked(hDlg, IDC_RECORD_ENABLE) == BST_CHECKED);
  1095. pcdb->_EnableRecordingDlgArea(hDlg, fRecordingEnabled);
  1096. pcdb->_MarkDirty(hDlg);
  1097. }
  1098. break;
  1099. case IDC_RECORD_IMAGELOC:
  1100. case IDC_RECORD_WRITESPEED:
  1101. if (GET_WM_COMMAND_CMD(wParam, lParam) == LBN_SELCHANGE)
  1102. {
  1103. pcdb->_MarkDirty(hDlg);
  1104. }
  1105. break;
  1106. case IDC_RECORD_EJECT:
  1107. pcdb->_MarkDirty(hDlg);
  1108. break;
  1109. default:
  1110. return TRUE;
  1111. }
  1112. break;
  1113. case WM_NOTIFY:
  1114. switch (((NMHDR *)lParam)->code)
  1115. {
  1116. case PSN_SETACTIVE:
  1117. break;
  1118. case PSN_APPLY:
  1119. if (!pcdb->_HandleApply(hDlg))
  1120. {
  1121. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  1122. }
  1123. else
  1124. {
  1125. PropSheet_UnChanged(GetParent(hDlg), hDlg);
  1126. }
  1127. return TRUE;
  1128. default:
  1129. return FALSE;
  1130. }
  1131. break;
  1132. default:
  1133. return FALSE;
  1134. }
  1135. }
  1136. return TRUE;
  1137. }
  1138. // IContextMenu
  1139. STDMETHODIMP CCDBurn::QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
  1140. {
  1141. INT idMax = idCmdFirst;
  1142. // only display this if we are invoked on the currently configured burn drive
  1143. TCHAR szDummy[MAX_PATH];
  1144. if (SUCCEEDED(_GetVolumeNameFromDataObject(TRUE, szDummy, ARRAYSIZE(szDummy))))
  1145. {
  1146. // load and merge the context menu with the current menu
  1147. HMENU hmMerge = SHLoadPopupMenu(HINST_THISDLL, POPUP_BURN_POPUPMERGE);
  1148. if (hmMerge)
  1149. {
  1150. idMax = Shell_MergeMenus(hmenu, hmMerge, indexMenu, idCmdFirst, idCmdLast, 0);
  1151. BOOL fInStaging, fOnMedia;
  1152. if (SUCCEEDED(GetContentState(&fInStaging, &fOnMedia)))
  1153. {
  1154. DWORD dwCaps = 0;
  1155. BOOL fUDF = FALSE;
  1156. _GetMediaCapabilities(&dwCaps, &fUDF); // this will fail if there is no media in the drive.
  1157. // delete write to cd if it's UDF
  1158. if (fUDF)
  1159. DeleteMenu(hmenu, idCmdFirst + FSIDM_BURN, MF_BYCOMMAND);
  1160. // delete clear staging area if no files to burn or it's UDF
  1161. if (!fInStaging || fUDF)
  1162. DeleteMenu(hmenu, idCmdFirst + FSIDM_CLEANUP, MF_BYCOMMAND);
  1163. // delete erase if it's not UDF and no cd-rw or no files on disc
  1164. if (!(dwCaps & HWDMC_CDREWRITABLE) || (!fOnMedia && !fUDF))
  1165. DeleteMenu(hmenu, idCmdFirst + FSIDM_ERASE, MF_BYCOMMAND);
  1166. }
  1167. DestroyMenu(hmMerge);
  1168. }
  1169. }
  1170. return ResultFromShort(idMax - idCmdFirst);
  1171. }
  1172. const ICIVERBTOIDMAP c_CDBurnMap[] =
  1173. {
  1174. { L"burn", "burn", FSIDM_BURN, FSIDM_BURN, },
  1175. { L"cleanup", "cleanup", FSIDM_CLEANUP, FSIDM_CLEANUP, },
  1176. { L"erase", "erase", FSIDM_ERASE, FSIDM_ERASE, },
  1177. };
  1178. STDMETHODIMP CCDBurn::GetCommandString(UINT_PTR idCmd, UINT uFlags, LPUINT lpReserved, LPSTR pszName, UINT cchMax)
  1179. {
  1180. HRESULT hr;
  1181. switch(uFlags)
  1182. {
  1183. case GCS_VERBA:
  1184. case GCS_VERBW:
  1185. hr = SHMapCmdIDToVerb(idCmd, c_CDBurnMap, ARRAYSIZE(c_CDBurnMap), pszName, cchMax, uFlags == GCS_VERBW);
  1186. break;
  1187. default:
  1188. hr = E_NOTIMPL;
  1189. break;
  1190. }
  1191. return hr;
  1192. }
  1193. STDMETHODIMP CCDBurn::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
  1194. {
  1195. UINT uID;
  1196. HRESULT hr = SHMapICIVerbToCmdID(lpcmi, c_CDBurnMap, ARRAYSIZE(c_CDBurnMap), &uID);
  1197. if (SUCCEEDED(hr))
  1198. {
  1199. switch (uID)
  1200. {
  1201. case FSIDM_BURN:
  1202. case FSIDM_ERASE:
  1203. hr = InitNew();
  1204. if (SUCCEEDED(hr))
  1205. {
  1206. hr = _PrepWiz(lpcmi, (uID == FSIDM_ERASE), FALSE);
  1207. }
  1208. break;
  1209. case FSIDM_CLEANUP:
  1210. hr = _CleanUp(lpcmi, TRUE);
  1211. break;
  1212. default:
  1213. hr = E_FAIL;
  1214. break;
  1215. }
  1216. }
  1217. return hr;
  1218. }
  1219. // IMAPI Advise Sink
  1220. STDMETHODIMP CCDBurn::QueryCancel(boolean *pbCancel)
  1221. {
  1222. *pbCancel = (boolean)_fCancelled;
  1223. return S_OK;
  1224. }
  1225. STDMETHODIMP CCDBurn::NotifyPnPActivity()
  1226. {
  1227. return E_NOTIMPL;
  1228. }
  1229. STDMETHODIMP CCDBurn::NotifyAddProgress(long nCompletedSteps, long nTotalSteps)
  1230. {
  1231. if (nTotalSteps != 0)
  1232. {
  1233. _SetEstimatedTime((DWORD)((float) _ts.dwSecStaging * (nTotalSteps - nCompletedSteps) / nTotalSteps + _ts.dwSecBurn + _ts.dwSecClose));
  1234. }
  1235. return S_OK;
  1236. }
  1237. STDMETHODIMP CCDBurn::NotifyBlockProgress(long nCompleted, long nTotal)
  1238. {
  1239. // Unfortunately we need to set the "burning" text here,
  1240. // because we get this notification immediately after the NotifyPreparingBurn.
  1241. if (!_fRecording)
  1242. {
  1243. _SetStatus(IDS_BURN_RECORDING);
  1244. _ts.dwTickBurnStart = GetTickCount();
  1245. _fRecording = TRUE;
  1246. }
  1247. if (nTotal != 0)
  1248. {
  1249. _SetEstimatedTime((DWORD)((float) _ts.dwSecBurn * (nTotal - nCompleted) / nTotal + _ts.dwSecClose));
  1250. }
  1251. return S_OK;
  1252. }
  1253. STDMETHODIMP CCDBurn::NotifyTrackProgress(long nCurrentTrack, long nTotalTracks)
  1254. {
  1255. // audio cd only
  1256. return E_NOTIMPL;
  1257. }
  1258. STDMETHODIMP CCDBurn::NotifyPreparingBurn(long nEstimatedSeconds)
  1259. {
  1260. _SetStatus(IDS_BURN_PREPARINGBURN);
  1261. return S_OK;
  1262. }
  1263. STDMETHODIMP CCDBurn::NotifyClosingDisc(long nEstimatedSeconds)
  1264. {
  1265. _ts.dwTickBurnEnd = _ts.dwTickCloseStart = GetTickCount();
  1266. _SetEstimatedTime(_ts.dwSecClose);
  1267. _SetStatus(IDS_BURN_CLOSINGDISC);
  1268. return S_OK;
  1269. }
  1270. STDMETHODIMP CCDBurn::NotifyBurnComplete(HRESULT status)
  1271. {
  1272. _ts.dwTickCloseEnd = GetTickCount();
  1273. _SetEstimatedTime(0);
  1274. _SetStatus(IDS_BURN_COMPLETE);
  1275. return S_OK;
  1276. }
  1277. STDMETHODIMP CCDBurn::NotifyEraseComplete(HRESULT status)
  1278. {
  1279. _ts.dwTickEraseEnd = GetTickCount();
  1280. _SetEstimatedTime(0);
  1281. _SetStatus(IDS_BURN_COMPLETE);
  1282. return S_OK;
  1283. }
  1284. HRESULT CCDBurn::_LockCurrentDrive(BOOL fLock, BOOL fForce)
  1285. {
  1286. HRESULT hr = S_OK;
  1287. // fForce defaults to FALSE
  1288. if (fForce || (fLock != s_fDriveInUse))
  1289. {
  1290. TCHAR szVolume[MAX_PATH];
  1291. hr = _GetCurrentBurnVolumeName(szVolume, ARRAYSIZE(szVolume));
  1292. if (SUCCEEDED(hr))
  1293. {
  1294. // strip trailing backslash (always there)
  1295. ASSERT(szVolume[lstrlen(szVolume) - 1] == TEXT('\\'));
  1296. szVolume[lstrlen(szVolume) - 1] = 0;
  1297. hr = E_FAIL;
  1298. HANDLE hDevice = CreateFile(szVolume, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL);
  1299. if (hDevice != INVALID_HANDLE_VALUE)
  1300. {
  1301. PREVENT_MEDIA_REMOVAL pmr = {0};
  1302. pmr.PreventMediaRemoval = BOOLIFY(fLock);
  1303. DWORD dwDummy;
  1304. if (DeviceIoControl(hDevice, IOCTL_STORAGE_MEDIA_REMOVAL, &pmr, sizeof(pmr), NULL, 0, &dwDummy, NULL))
  1305. {
  1306. // we're sealed up tight now, set the state var.
  1307. s_fDriveInUse = fLock;
  1308. hr = S_OK;
  1309. }
  1310. CloseHandle(hDevice);
  1311. }
  1312. }
  1313. }
  1314. return hr;
  1315. }
  1316. BOOL CCDBurn::_HasFiles(LPCITEMIDLIST pidl)
  1317. {
  1318. BOOL fHasFiles = FALSE;
  1319. IBindCtx *pbc;
  1320. HRESULT hr = SHCreateSkipBindCtx(NULL, &pbc);
  1321. if (SUCCEEDED(hr))
  1322. {
  1323. IStorage *pstg;
  1324. hr = SHBindToObjectEx(NULL, pidl, pbc, IID_PPV_ARG(IStorage, &pstg));
  1325. if (SUCCEEDED(hr))
  1326. {
  1327. IEnumSTATSTG *penum;
  1328. hr = pstg->EnumElements(0, NULL, 0, &penum);
  1329. if (SUCCEEDED(hr))
  1330. {
  1331. STATSTG stat;
  1332. hr = penum->Next(1, &stat, NULL);
  1333. if (hr == S_OK)
  1334. {
  1335. fHasFiles = TRUE;
  1336. CoTaskMemFree(stat.pwcsName);
  1337. }
  1338. penum->Release();
  1339. }
  1340. pstg->Release();
  1341. }
  1342. pbc->Release();
  1343. }
  1344. return fHasFiles;
  1345. }
  1346. BOOL CCDBurn::_StagingAreaHasFiles()
  1347. {
  1348. BOOL fHasFiles = FALSE;
  1349. LPITEMIDLIST pidl;
  1350. if (SUCCEEDED(SHGetFolderLocation(NULL, CSIDL_CDBURN_AREA, NULL, 0, &pidl)))
  1351. {
  1352. fHasFiles = _HasFiles(pidl);
  1353. ILFree(pidl);
  1354. }
  1355. return fHasFiles;
  1356. }
  1357. BOOL CCDBurn::_DiscHasFiles()
  1358. {
  1359. BOOL fHasFiles = FALSE;
  1360. LPITEMIDLIST pidl;
  1361. if (SUCCEEDED(_GetPlainCDPidl(&pidl)))
  1362. {
  1363. fHasFiles = _HasFiles(pidl);
  1364. ILFree(pidl);
  1365. }
  1366. return fHasFiles;
  1367. }
  1368. HRESULT CCDBurn::GetContentState(BOOL *pfStagingHasFiles, BOOL *pfDiscHasFiles)
  1369. {
  1370. if (pfStagingHasFiles)
  1371. *pfStagingHasFiles = _StagingAreaHasFiles();
  1372. if (pfDiscHasFiles)
  1373. *pfDiscHasFiles = _DiscHasFiles();
  1374. return S_OK;
  1375. }
  1376. HRESULT CCDBurn::IsWizardUp()
  1377. {
  1378. HRESULT hr;
  1379. CCDBurn *pcdb = new CCDBurn();
  1380. if (pcdb)
  1381. {
  1382. // check if the wizard is currently running.
  1383. // the reason why we have to do both the s_hwndWiz and the exclusive mutex check is that
  1384. // there could be other explorer.exe's that are running. the s_hwndWiz is a shortcut for
  1385. // the typical case where we're the only one.
  1386. if (!pcdb->s_hwndWiz && pcdb->_EnterExclusiveBurning())
  1387. {
  1388. // if we could get the exclusive mutex, we werent up yet, so release it.
  1389. pcdb->_LeaveExclusiveBurning();
  1390. hr = S_FALSE;
  1391. }
  1392. else
  1393. {
  1394. // the window is up or we couldn't get the mutex so we're definitely burning now.
  1395. hr = S_OK;
  1396. }
  1397. pcdb->Release();
  1398. }
  1399. else
  1400. {
  1401. hr = E_OUTOFMEMORY;
  1402. }
  1403. return hr;
  1404. }
  1405. HRESULT CCDBurn::_GetRecorderPath(IDiscRecorder *pdr, LPTSTR pszPath, UINT cchBuf)
  1406. {
  1407. BSTR bstr;
  1408. HRESULT hr = pdr->GetPath(&bstr);
  1409. if (SUCCEEDED(hr))
  1410. {
  1411. lstrcpyn(pszPath, bstr, cchBuf);
  1412. SysFreeString(bstr);
  1413. }
  1414. return hr;
  1415. }
  1416. HRESULT CCDBurn::_GetVolumeNameForDriveIndex(int iDrive, LPTSTR pszVolumeName, UINT cchBuf)
  1417. {
  1418. HRESULT hr = E_FAIL;
  1419. TCHAR szDriveLetter[4];
  1420. if (PathBuildRoot(szDriveLetter, iDrive) &&
  1421. GetVolumeNameForVolumeMountPoint(szDriveLetter, pszVolumeName, cchBuf))
  1422. {
  1423. hr = S_OK;
  1424. }
  1425. return hr;
  1426. }
  1427. HRESULT CCDBurn::_GetDriveIndexForVolumeName(LPCTSTR pszVolumeName, int *piDrive)
  1428. {
  1429. HRESULT hr = E_FAIL;
  1430. DWORD cchLen;
  1431. BOOL fRet = GetVolumePathNamesForVolumeName(pszVolumeName, NULL, 0, &cchLen);
  1432. if (fRet || (GetLastError() == ERROR_MORE_DATA))
  1433. {
  1434. LPWSTR pszBuf = new WCHAR[cchLen];
  1435. if (pszBuf)
  1436. {
  1437. hr = E_FAIL;
  1438. if (GetVolumePathNamesForVolumeName(pszVolumeName, pszBuf, cchLen, NULL))
  1439. {
  1440. for (PWSTR pszPath = pszBuf; *pszPath; pszPath += lstrlenW(pszPath) + 1)
  1441. {
  1442. // if it's mounted at more than one root, take the first one.
  1443. if (PathIsRoot(pszPath))
  1444. {
  1445. *piDrive = PathGetDriveNumber(pszBuf);
  1446. hr = S_OK;
  1447. break;
  1448. }
  1449. }
  1450. }
  1451. delete [] pszBuf;
  1452. }
  1453. else
  1454. {
  1455. hr = E_OUTOFMEMORY;
  1456. }
  1457. }
  1458. return hr;
  1459. }
  1460. HRESULT CCDBurn::_GetCurrentDriveIndex(int *piDrive)
  1461. {
  1462. TCHAR szCurrent[MAX_PATH];
  1463. HRESULT hr = _GetCurrentBurnVolumeName(szCurrent, ARRAYSIZE(szCurrent));
  1464. if (SUCCEEDED(hr))
  1465. {
  1466. hr = _GetDriveIndexForVolumeName(szCurrent, piDrive);
  1467. }
  1468. return hr;
  1469. }
  1470. HRESULT CCDBurn::_GetVolumeNameForDevicePath(LPCTSTR pszDevice, LPTSTR pszVolumeName, UINT cchBuf)
  1471. {
  1472. TCHAR szMountPoint[MAX_PATH];
  1473. lstrcpyn(szMountPoint, TEXT("\\\\?\\GLOBALROOT"), ARRAYSIZE(szMountPoint));
  1474. StrCatBuff(szMountPoint, pszDevice, ARRAYSIZE(szMountPoint));
  1475. StrCatBuff(szMountPoint, TEXT("\\"), ARRAYSIZE(szMountPoint));
  1476. return GetVolumeNameForVolumeMountPoint(szMountPoint, pszVolumeName, cchBuf) ? S_OK : E_FAIL;
  1477. }
  1478. BOOL CCDBurn::_DevicePathMatchesVolumeName(LPCTSTR pszDevice, LPCTSTR pszVolumeName)
  1479. {
  1480. BOOL fRet = FALSE;
  1481. TCHAR szVolumeNameTest[MAX_PATH];
  1482. if (SUCCEEDED(_GetVolumeNameForDevicePath(pszDevice, szVolumeNameTest, ARRAYSIZE(szVolumeNameTest))))
  1483. {
  1484. fRet = (lstrcmpi(pszVolumeName, szVolumeNameTest) == 0);
  1485. }
  1486. return fRet;
  1487. }
  1488. // can return S_FALSE and not fill up ppdr
  1489. HRESULT CCDBurn::_GetDiscRecorderForDrive(IDiscMaster *pdm, LPCTSTR pszVolumeName, IDiscRecorder **ppdr)
  1490. {
  1491. IEnumDiscRecorders *penumdr;
  1492. HRESULT hr = pdm->EnumDiscRecorders(&penumdr);
  1493. if (SUCCEEDED(hr))
  1494. {
  1495. BOOL fDone = FALSE;
  1496. do
  1497. {
  1498. ULONG celt;
  1499. IDiscRecorder *pdr;
  1500. hr = penumdr->Next(1, &pdr, &celt);
  1501. if (hr == S_OK)
  1502. {
  1503. TCHAR szPath[MAX_PATH];
  1504. hr = _GetRecorderPath(pdr, szPath, ARRAYSIZE(szPath));
  1505. if (SUCCEEDED(hr))
  1506. {
  1507. if (_DevicePathMatchesVolumeName(szPath, pszVolumeName))
  1508. {
  1509. if (ppdr)
  1510. {
  1511. pdr->AddRef();
  1512. *ppdr = pdr;
  1513. }
  1514. fDone = TRUE;
  1515. }
  1516. }
  1517. pdr->Release();
  1518. }
  1519. else
  1520. {
  1521. fDone = TRUE;
  1522. }
  1523. } while (!fDone);
  1524. penumdr->Release();
  1525. }
  1526. return hr;
  1527. }
  1528. HRESULT CCDBurn::_FindAndSetRecorder(LPCTSTR pszVolumeName, IDiscMaster *pdm, BOOL fSetActive, IDiscRecorder **ppdr)
  1529. {
  1530. IDiscRecorder *pdr;
  1531. HRESULT hr = _GetDiscRecorderForDrive(pdm, pszVolumeName, &pdr);
  1532. if (S_OK == hr)
  1533. {
  1534. DWORD dwCurSpeed = 1, dwMaxSpeed = 1;
  1535. _GetCachedDriveInfo(pszVolumeName, NULL, &dwCurSpeed, &dwMaxSpeed);
  1536. if (fSetActive)
  1537. {
  1538. hr = pdm->SetActiveDiscRecorder(pdr);
  1539. if (SUCCEEDED(hr))
  1540. {
  1541. hr = _SetRecorderProps(pdr, dwCurSpeed);
  1542. }
  1543. }
  1544. // _dwCurSpeed is used only for timing, so if it's 0xFFFFFFFF we need to scale
  1545. // it back down to what we think is the max speed.
  1546. // this may be incorrect for certain drives that have an actual speed different
  1547. // from what they report but it's the best we can do (and it'll be compensated for
  1548. // in the next burn).
  1549. _dwCurSpeed = (WRITESPEED_FASTEST == dwCurSpeed) ? dwMaxSpeed : dwCurSpeed;
  1550. if (SUCCEEDED(hr))
  1551. {
  1552. *ppdr = pdr;
  1553. pdr->AddRef();
  1554. }
  1555. pdr->Release();
  1556. }
  1557. else
  1558. {
  1559. // munge S_FALSE into E_FAIL (i.e. we got through the whole enumerator without
  1560. // finding a match, so that's bad)
  1561. if (hr == S_FALSE)
  1562. {
  1563. hr = E_FAIL;
  1564. }
  1565. }
  1566. return hr;
  1567. }
  1568. HRESULT CCDBurn::_FindAndSetDefaultRecorder(IDiscMaster *pdm, BOOL fSetActive, IDiscRecorder **ppdr)
  1569. {
  1570. TCHAR szCurrent[MAX_PATH];
  1571. HRESULT hr = _GetCurrentBurnVolumeName(szCurrent, ARRAYSIZE(szCurrent));
  1572. if (SUCCEEDED(hr))
  1573. {
  1574. hr = _FindAndSetRecorder(szCurrent, pdm, fSetActive, ppdr);
  1575. }
  1576. return hr;
  1577. }
  1578. INT_PTR CALLBACK CCDBurn::_ConfirmDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1579. {
  1580. switch (uMsg)
  1581. {
  1582. case WM_INITDIALOG:
  1583. {
  1584. LPITEMIDLIST pidl;
  1585. if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_BITBUCKET, &pidl)))
  1586. {
  1587. SHFILEINFO fi;
  1588. if (SHGetFileInfo((LPCTSTR)pidl, 0, &fi, sizeof(fi), SHGFI_PIDL | SHGFI_ICON | SHGFI_LARGEICON))
  1589. {
  1590. ReplaceDlgIcon(hwndDlg, IDD_ICON, fi.hIcon);
  1591. }
  1592. ILFree(pidl);
  1593. }
  1594. }
  1595. break;
  1596. case WM_DESTROY:
  1597. ReplaceDlgIcon(hwndDlg, IDD_ICON, NULL);
  1598. break;
  1599. case WM_COMMAND:
  1600. switch (GET_WM_COMMAND_ID(wParam, lParam))
  1601. {
  1602. case IDNO:
  1603. EndDialog(hwndDlg, IDNO);
  1604. break;
  1605. case IDYES:
  1606. EndDialog(hwndDlg, IDYES);
  1607. break;
  1608. }
  1609. break;
  1610. default:
  1611. return FALSE;
  1612. }
  1613. return TRUE;
  1614. }
  1615. HRESULT CCDBurn::_CleanUp(LPCMINVOKECOMMANDINFO lpcmi, BOOL fRecycle)
  1616. {
  1617. // delete the files in the staging area, by deleting the entire staging area
  1618. TCHAR szStaging[MAX_PATH + 1]; // a little room for double-null
  1619. HRESULT hr = _GetBurnStagingPath(szStaging, MAX_PATH);
  1620. if (SUCCEEDED(hr) && PathFileExists(szStaging))
  1621. {
  1622. // cant use shfileop confirmation because its too hacky.
  1623. if ((lpcmi->fMask & CMIC_MASK_FLAG_NO_UI) ||
  1624. (IDYES == DialogBoxParam(HINST_THISDLL, MAKEINTRESOURCE(DLG_DELETE_STAGING), lpcmi->hwnd, _ConfirmDialogProc, NULL)))
  1625. {
  1626. PathAppend(szStaging, c_szStarDotStar);
  1627. // double-null
  1628. szStaging[lstrlen(szStaging) + 1] = 0;
  1629. SHFILEOPSTRUCT fo = {0};
  1630. fo.wFunc = FO_DELETE;
  1631. fo.pFrom = szStaging;
  1632. fo.fFlags = FOF_NOCONFIRMATION;
  1633. if (fRecycle)
  1634. {
  1635. fo.fFlags |= FOF_ALLOWUNDO;
  1636. }
  1637. fo.hwnd = lpcmi->hwnd;
  1638. hr = (SHFileOperation(&fo) == ERROR_SUCCESS) ? S_OK : E_FAIL;
  1639. }
  1640. }
  1641. return hr;
  1642. }
  1643. HRESULT CCDBurn::_CreateDefaultPropBag(REFIID riid, void **ppv)
  1644. {
  1645. IPropertyBag *ppb;
  1646. HRESULT hr = SHCreatePropertyBagOnMemory(STGM_READWRITE, IID_PPV_ARG(IPropertyBag, &ppb));
  1647. if (SUCCEEDED(hr))
  1648. {
  1649. // default to think we didn't hit eject
  1650. SHPropertyBag_WriteBOOL(ppb, PROPSTR_EJECT, FALSE);
  1651. // do volume name
  1652. TCHAR szDiscLabel[JOLIET_MAX_LABEL + 1];
  1653. ULONG cb = sizeof(szDiscLabel);
  1654. if (ERROR_SUCCESS != SHGetValue(HKEY_CURRENT_USER, REGSTR_PATH_PERMEDIA, REGVALUE_DISCLABEL, NULL, szDiscLabel, &cb))
  1655. {
  1656. // make a default string like "Feb 02 2001"
  1657. TCHAR szFormat[JOLIET_MAX_LABEL + 1];
  1658. LoadString(HINST_THISDLL, IDS_BURN_FORMAT_DISCLABEL, szFormat, ARRAYSIZE(szFormat));
  1659. if (!GetDateFormat(LOCALE_USER_DEFAULT, 0, NULL, szFormat, szDiscLabel, ARRAYSIZE(szDiscLabel)))
  1660. {
  1661. szDiscLabel[0] = 0;
  1662. }
  1663. }
  1664. SHPropertyBag_WriteStr(ppb, PROPSTR_DISCLABEL, szDiscLabel);
  1665. // do autoclose
  1666. DWORD dwClose;
  1667. cb = sizeof(dwClose);
  1668. if (ERROR_SUCCESS == SHGetValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_AUTOCLOSE, NULL, &dwClose, &cb) && dwClose)
  1669. {
  1670. SHPropertyBag_WriteBOOL(ppb, PROPSTR_AUTOCLOSE, TRUE);
  1671. }
  1672. hr = ppb->QueryInterface(riid, ppv);
  1673. ppb->Release();
  1674. }
  1675. return hr;
  1676. }
  1677. HRESULT CCDBurn::_PrepWiz(LPCMINVOKECOMMANDINFO lpcmi, BOOL fErase, BOOL fFailSilently)
  1678. {
  1679. HRESULT hr = E_FAIL;
  1680. if (s_hwndWiz)
  1681. {
  1682. // if we know the shell is burning and we have an hwnd to the wizard, pop it up.
  1683. SetForegroundWindow(s_hwndWiz);
  1684. hr = S_OK;
  1685. }
  1686. else
  1687. {
  1688. SHPropertyBag_WriteBOOL(_ppb, PROPSTR_ERASE, fErase);
  1689. SHPropertyBag_WriteBOOL(_ppb, PROPSTR_FAILSILENTLY, fFailSilently);
  1690. hr = _ShowWizardOnSeparateThread();
  1691. }
  1692. return hr;
  1693. }
  1694. void CCDBurn::_SetStatus(UINT uID)
  1695. {
  1696. TCHAR szBuf[MAX_PATH];
  1697. LoadString(HINST_THISDLL, uID, szBuf, ARRAYSIZE(szBuf));
  1698. SetDlgItemText(_hwndWizardPage, IDC_BURNWIZ_STATUSTEXT, szBuf);
  1699. }
  1700. HRESULT CCDBurn::_GetDiscMasters(IDiscMaster **ppdm, IJolietDiscMaster **ppjdm)
  1701. {
  1702. *ppdm = NULL;
  1703. *ppjdm = NULL;
  1704. HRESULT hr = CoCreateInstance(CLSID_MSDiscMasterObj, NULL, CLSCTX_LOCAL_SERVER | CLSCTX_NO_FAILURE_LOG, IID_PPV_ARG(IDiscMaster, ppdm));
  1705. if (SUCCEEDED(hr))
  1706. {
  1707. // open() takes some time, so set up the progress dialog
  1708. _SetStatus(IDS_BURN_INITIALIZESTASH);
  1709. hr = (*ppdm)->Open();
  1710. if (SUCCEEDED(hr))
  1711. {
  1712. hr = (*ppdm)->SetActiveDiscMasterFormat(IID_PPV_ARG(IJolietDiscMaster, ppjdm));
  1713. }
  1714. // clean up if we couldn't get the joliet disc master.
  1715. if (FAILED(hr))
  1716. {
  1717. ATOMICRELEASE(*ppdm);
  1718. }
  1719. }
  1720. ASSERT(SUCCEEDED(hr) ? ((*ppdm != NULL) && (*ppjdm != NULL)) : ((*ppdm == NULL) && (*ppjdm == NULL)));
  1721. return hr;
  1722. }
  1723. HRESULT CCDBurn::_AddData(IJolietDiscMaster *pjdm)
  1724. {
  1725. _SetStatus(IDS_BURN_ADDDATA);
  1726. LPITEMIDLIST pidl;
  1727. HRESULT hr = SHGetFolderLocation(NULL, CSIDL_CDBURN_AREA, NULL, 0, &pidl);
  1728. if (SUCCEEDED(hr))
  1729. {
  1730. IStorage *pstg;
  1731. hr = SHBindToObjectEx(NULL, pidl, NULL, IID_PPV_ARG(IStorage, &pstg));
  1732. if (SUCCEEDED(hr))
  1733. {
  1734. _ts.dwTickStagingStart = GetTickCount();
  1735. hr = pjdm->AddData(pstg, 1);
  1736. _ts.dwTickStagingEnd = GetTickCount();
  1737. pstg->Release();
  1738. }
  1739. ILFree(pidl);
  1740. }
  1741. return hr;
  1742. }
  1743. BOOL CCDBurn::_IsBurningNow()
  1744. {
  1745. BOOL fBurning = TRUE;
  1746. CCDBurn *pcdb = new CCDBurn();
  1747. if (pcdb)
  1748. {
  1749. // if the shell is burning, we know it for sure. otherwise we have to check imapi to see if any other
  1750. // process is using imapi to burn.
  1751. if (!pcdb->s_hwndWiz && pcdb->_EnterExclusiveBurning())
  1752. {
  1753. pcdb->_LeaveExclusiveBurning();
  1754. // if we can get the mutex, we're not burning.
  1755. fBurning = FALSE;
  1756. IDiscMaster *pdm;
  1757. IJolietDiscMaster *pjdm;
  1758. if (SUCCEEDED(pcdb->_GetDiscMasters(&pdm, &pjdm)))
  1759. {
  1760. IDiscRecorder *pdr;
  1761. if (SUCCEEDED(pcdb->_FindAndSetDefaultRecorder(pdm, FALSE, &pdr)))
  1762. {
  1763. ULONG ulState;
  1764. if (SUCCEEDED(pdr->GetRecorderState(&ulState)))
  1765. {
  1766. fBurning = (ulState & (RECORDER_BURNING | RECORDER_OPENED));
  1767. }
  1768. pdr->Release();
  1769. }
  1770. pdm->Release();
  1771. pjdm->Release();
  1772. }
  1773. }
  1774. pcdb->Release();
  1775. }
  1776. return fBurning;
  1777. }
  1778. // handy stuff from lowdisk
  1779. BOOL CCDBurn::_EnterExclusiveBurning()
  1780. {
  1781. if (NULL == _hMutexBurning)
  1782. {
  1783. SECURITY_ATTRIBUTES* psa = SHGetAllAccessSA();
  1784. if (psa)
  1785. {
  1786. // since imapi runs in the system context and only one client can use it at a time,
  1787. // make the mutex in the global namespace.
  1788. _hMutexBurning = CreateMutex(psa, FALSE, L"Global\\CDBurnExclusive");
  1789. if (!_hMutexBurning)
  1790. {
  1791. // we'll get here if we're running as a limited user.
  1792. // we don't have access to the global namespace so create it in the current session.
  1793. // this will look normal within the session but across users it'll be more bogus since we'll let the
  1794. // user start the burn from the wizard but we'll fail later. that's good enough.
  1795. _hMutexBurning = CreateMutex(psa, FALSE, L"CDBurnExclusive");
  1796. }
  1797. }
  1798. }
  1799. return _hMutexBurning && (WAIT_OBJECT_0 == WaitForSingleObject(_hMutexBurning, 0)); // zero timeout
  1800. }
  1801. void CCDBurn::_LeaveExclusiveBurning()
  1802. {
  1803. ASSERT(_hMutexBurning);
  1804. ReleaseMutex(_hMutexBurning);
  1805. }
  1806. HRESULT CCDBurn::_Balloon()
  1807. {
  1808. WCHAR szTitle[50];
  1809. LoadString(HINST_THISDLL, IDS_BURN_NOTIFY_TITLE, szTitle, ARRAYSIZE(szTitle));
  1810. WCHAR szMsg[100];
  1811. LoadString(HINST_THISDLL, IDS_BURN_NOTIFY, szMsg, ARRAYSIZE(szMsg));
  1812. HICON hIcon = LoadIcon(g_hinst, MAKEINTRESOURCE(IDI_DRIVECD));
  1813. IUserNotification *pun;
  1814. // usernotification has to go over to the main explorer.exe and we might not be it...?
  1815. HRESULT hr = CoCreateInstance(CLSID_UserNotification, NULL, CLSCTX_ALL, IID_PPV_ARG(IUserNotification, &pun));
  1816. if (SUCCEEDED(hr))
  1817. {
  1818. pun->SetBalloonRetry(30 * 1000, -1, 0);
  1819. pun->SetIconInfo(hIcon, szTitle);
  1820. pun->SetBalloonInfo(szTitle, szMsg, NIIF_INFO);
  1821. hr = pun->Show(NULL, 0);
  1822. pun->Release();
  1823. }
  1824. if (hIcon)
  1825. {
  1826. DestroyIcon(hIcon);
  1827. }
  1828. return hr;
  1829. }
  1830. typedef struct
  1831. {
  1832. LPCITEMIDLIST pidlFolder;
  1833. BOOL fRet;
  1834. } CDBURNENUMSTRUCT;
  1835. BOOL CALLBACK CCDBurn::_EnumProc(HWND hwnd, LPCITEMIDLIST pidl, LPARAM lParam)
  1836. {
  1837. CDBURNENUMSTRUCT *pes = (CDBURNENUMSTRUCT*)lParam;
  1838. if (ILIsParent(pes->pidlFolder, pidl, FALSE))
  1839. {
  1840. pes->fRet = TRUE;
  1841. return FALSE; // stop enumerating, we know we got it.
  1842. }
  1843. return TRUE;
  1844. }
  1845. BOOL CCDBurn::_BurningFolderOpen()
  1846. {
  1847. BOOL fRet = FALSE;
  1848. LPITEMIDLIST pidlFolder;
  1849. if (SUCCEEDED(_GetFolderPidl(&pidlFolder)))
  1850. {
  1851. CDBURNENUMSTRUCT es = { 0 };
  1852. es.pidlFolder = pidlFolder;
  1853. EnumShellWindows(_EnumProc, (LPARAM)&es);
  1854. fRet = es.fRet;
  1855. ILFree(pidlFolder);
  1856. }
  1857. return fRet;
  1858. }
  1859. DWORD CALLBACK CCDBurn::_NotifyThreadProc(void *pv)
  1860. {
  1861. CCDBurn *pcdb = (CCDBurn *)pv;
  1862. SECURITY_ATTRIBUTES* psa = SHGetAllAccessSA();
  1863. if (psa)
  1864. {
  1865. HANDLE hMutexNotify = CreateMutex(psa, FALSE, L"CDBurnNotify");
  1866. if (hMutexNotify)
  1867. {
  1868. if (WAIT_OBJECT_0 == WaitForSingleObject(hMutexNotify, 0))
  1869. {
  1870. if (!_BurningFolderOpen() && !_IsBurningNow())
  1871. {
  1872. if (S_OK == pcdb->_Balloon())
  1873. {
  1874. LPITEMIDLIST pidl;
  1875. if (SUCCEEDED(_GetFolderPidl(&pidl)))
  1876. {
  1877. // Use shellexecuteex to open a view folder
  1878. SHELLEXECUTEINFO sei = { 0 };
  1879. sei.cbSize = sizeof(sei);
  1880. sei.lpIDList = pidl;
  1881. sei.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_IDLIST;
  1882. sei.nShow = SW_SHOWNORMAL;
  1883. sei.lpVerb = c_szOpen;
  1884. ShellExecuteEx(&sei); // hardcoded to "open" on a pidl.
  1885. ILFree(pidl);
  1886. }
  1887. }
  1888. }
  1889. ReleaseMutex(hMutexNotify);
  1890. }
  1891. CloseHandle(hMutexNotify);
  1892. }
  1893. }
  1894. pcdb->Release();
  1895. return 0;
  1896. }
  1897. void CCDBurn::_CheckStagingArea()
  1898. {
  1899. // only do stuff if we're enabled.
  1900. int iCurrent;
  1901. if (SUCCEEDED(_GetCurrentDriveIndex(&iCurrent)) && _StagingAreaHasFiles())
  1902. {
  1903. AddRef();
  1904. if (!SHCreateThread(_NotifyThreadProc, this, CTF_COINIT, NULL))
  1905. {
  1906. Release();
  1907. }
  1908. }
  1909. }
  1910. STDAPI CheckStagingArea()
  1911. {
  1912. CCDBurn *pcdb = new CCDBurn();
  1913. if (pcdb)
  1914. {
  1915. pcdb->_CheckStagingArea();
  1916. pcdb->Release();
  1917. }
  1918. return S_OK;
  1919. }
  1920. HRESULT _CreateDataObject(IDataObject **ppdo)
  1921. {
  1922. LPITEMIDLIST pidl;
  1923. HRESULT hr = SHGetFolderLocation(NULL, CSIDL_CDBURN_AREA, NULL, 0, &pidl);
  1924. if (SUCCEEDED(hr))
  1925. {
  1926. hr = SHGetUIObjectOf(pidl, NULL, IID_PPV_ARG(IDataObject, ppdo));
  1927. ILFree(pidl);
  1928. }
  1929. return hr;
  1930. }
  1931. // this will eventually put up confirmation UI. for now just tally size.
  1932. HRESULT CCDBurn::FoundItem(IShellFolder *psf, LPCITEMIDLIST pidl)
  1933. {
  1934. IShellFolder2 *psf2;
  1935. if (SUCCEEDED(psf->QueryInterface(IID_PPV_ARG(IShellFolder2, &psf2))))
  1936. {
  1937. ULONGLONG cbItemSize;
  1938. if (SUCCEEDED(GetLongProperty(psf2, pidl, &SCID_SIZE, &cbItemSize)))
  1939. {
  1940. _cbStagedSize += cbItemSize;
  1941. }
  1942. psf2->Release();
  1943. }
  1944. return S_OK;
  1945. }
  1946. HRESULT CCDBurn::_CheckTotal()
  1947. {
  1948. ULONGLONG cbTotal, cbFree;
  1949. HRESULT hr = GetSpace(&cbTotal, &cbFree);
  1950. if (SUCCEEDED(hr))
  1951. {
  1952. if (_cbStagedSize > cbFree)
  1953. {
  1954. hr = HRESULT_FROM_WIN32(ERROR_DISK_FULL);
  1955. TCHAR szStaged[40], szFree[40], szOver[40];
  1956. StrFormatByteSize64(_cbStagedSize, szStaged, ARRAYSIZE(szStaged));
  1957. StrFormatByteSize64(cbFree, szFree, ARRAYSIZE(szFree));
  1958. StrFormatByteSize64(_cbStagedSize - cbFree, szOver, ARRAYSIZE(szOver));
  1959. LPTSTR pszMessage = ShellConstructMessageString(HINST_THISDLL, MAKEINTRESOURCE(IDS_BURN_DISCFULLTEXT), szFree, szStaged, szOver);
  1960. if (pszMessage)
  1961. {
  1962. SHPropertyBag_WriteStr(_ppb, PROPSTR_DISCFULLTEXT, pszMessage);
  1963. LocalFree(pszMessage);
  1964. }
  1965. }
  1966. }
  1967. return hr;
  1968. }
  1969. HRESULT CCDBurn::_Validate()
  1970. {
  1971. INamespaceWalk *pnsw;
  1972. HRESULT hr = CoCreateInstance(CLSID_NamespaceWalker, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(INamespaceWalk, &pnsw));
  1973. if (SUCCEEDED(hr))
  1974. {
  1975. LPITEMIDLIST pidlStaging;
  1976. hr = SHGetFolderLocation(NULL, CSIDL_CDBURN_AREA, NULL, 0, &pidlStaging);
  1977. if (SUCCEEDED(hr))
  1978. {
  1979. IShellFolder *psf;
  1980. hr = SHBindToObjectEx(NULL, pidlStaging, NULL, IID_PPV_ARG(IShellFolder, &psf));
  1981. if (SUCCEEDED(hr))
  1982. {
  1983. _cbStagedSize = 0;
  1984. // walk 15 levels deep, TODO figure out what Joliet's limitations are.
  1985. hr = pnsw->Walk(psf, NSWF_DONT_TRAVERSE_LINKS, 15, this);
  1986. if (SUCCEEDED(hr))
  1987. {
  1988. hr = _CheckTotal();
  1989. }
  1990. psf->Release();
  1991. }
  1992. ILFree(pidlStaging);
  1993. }
  1994. pnsw->Release();
  1995. }
  1996. return hr;
  1997. }
  1998. DWORD WINAPI CCDBurn::_BurnThread(void *pv)
  1999. {
  2000. CCDBurn *pcdb = (CCDBurn *) pv;
  2001. HRESULT hr = pcdb->_Validate();
  2002. if (SUCCEEDED(hr))
  2003. {
  2004. IDiscMaster *pdm;
  2005. IJolietDiscMaster *pjdm;
  2006. hr = pcdb->_GetDiscMasters(&pdm, &pjdm);
  2007. if (SUCCEEDED(hr))
  2008. {
  2009. hr = pcdb->_SetJolietProps(pjdm);
  2010. if (SUCCEEDED(hr))
  2011. {
  2012. UINT_PTR lCookie;
  2013. hr = pdm->ProgressAdvise(pcdb, &lCookie);
  2014. if (SUCCEEDED(hr))
  2015. {
  2016. IDiscRecorder *pdr;
  2017. hr = pcdb->_FindAndSetDefaultRecorder(pdm, TRUE, &pdr);
  2018. if (SUCCEEDED(hr))
  2019. {
  2020. pcdb->_InitTimeStats(FALSE);
  2021. hr = pcdb->_AddData(pjdm);
  2022. boolean bCancelled;
  2023. pcdb->QueryCancel(&bCancelled);
  2024. if (SUCCEEDED(hr) && !bCancelled)
  2025. {
  2026. BOOL fAutoEject = TRUE;
  2027. pcdb->_GetEjectSetting(&fAutoEject);
  2028. // false is to make a real recording instead of a simulated one
  2029. hr = pdm->RecordDisc(FALSE, (boolean)fAutoEject);
  2030. if (SUCCEEDED(hr))
  2031. {
  2032. // bug: recorddisc doesnt call back into NotifyBurnComplete so this has to be done here
  2033. pcdb->_ts.dwTickCloseEnd = GetTickCount();
  2034. pcdb->_SaveTimeStats(FALSE);
  2035. }
  2036. }
  2037. pdr->Release();
  2038. }
  2039. pdm->ProgressUnadvise(lCookie);
  2040. }
  2041. }
  2042. pdm->Release();
  2043. pjdm->Release();
  2044. }
  2045. }
  2046. _LockCurrentDrive(FALSE);
  2047. if (!pcdb->_fCancelled)
  2048. {
  2049. SHPropertyBag_WriteDWORD(pcdb->_ppb, PROPSTR_HR, hr);
  2050. PropSheet_SetWizButtons(GetParent(pcdb->_hwndWizardPage), PSWIZB_NEXT);
  2051. PropSheet_PressButton(GetParent(pcdb->_hwndWizardPage), PSBTN_NEXT);
  2052. }
  2053. pcdb->Release();
  2054. return 0;
  2055. }
  2056. DWORD WINAPI CCDBurn::_EraseThread(void *pv)
  2057. {
  2058. CCDBurn *pcdb = (CCDBurn *) pv;
  2059. IDiscMaster *pdm;
  2060. IJolietDiscMaster *pjdm;
  2061. HRESULT hr = pcdb->_GetDiscMasters(&pdm, &pjdm);
  2062. if (SUCCEEDED(hr))
  2063. {
  2064. IDiscRecorder *pdr;
  2065. hr = pcdb->_FindAndSetDefaultRecorder(pdm, FALSE, &pdr);
  2066. if (SUCCEEDED(hr))
  2067. {
  2068. pcdb->_SetStatus(IDS_BURN_ERASEDISC);
  2069. hr = pdr->OpenExclusive();
  2070. if (SUCCEEDED(hr))
  2071. {
  2072. pcdb->_InitTimeStats(TRUE);
  2073. pcdb->_ts.dwTickEraseStart = GetTickCount();
  2074. hr = pdr->Erase(FALSE); // do quick erase
  2075. if (SUCCEEDED(hr))
  2076. {
  2077. hr = pdr->Close();
  2078. // bug: this is here only because Erase doesn't call NotifyEraseComplete
  2079. pcdb->_ts.dwTickEraseEnd = GetTickCount();
  2080. pcdb->_SaveTimeStats(TRUE);
  2081. }
  2082. }
  2083. pdr->Release();
  2084. }
  2085. pdm->Release();
  2086. pjdm->Release();
  2087. }
  2088. _LockCurrentDrive(FALSE);
  2089. if (!pcdb->_fCancelled)
  2090. {
  2091. SHPropertyBag_WriteDWORD(pcdb->_ppb, PROPSTR_HR, hr);
  2092. PropSheet_SetWizButtons(GetParent(pcdb->_hwndWizardPage), PSWIZB_NEXT);
  2093. PropSheet_PressButton(GetParent(pcdb->_hwndWizardPage), PSBTN_NEXT);
  2094. }
  2095. pcdb->Release();
  2096. return 0;
  2097. }
  2098. HRESULT CCDBurn::_GetPidlForDriveIndex(int iDrive, LPITEMIDLIST *ppidl)
  2099. {
  2100. HRESULT hr = E_FAIL;
  2101. TCHAR szPath[4];
  2102. if (PathBuildRoot(szPath, iDrive))
  2103. {
  2104. hr = SHILCreateFromPath(szPath, ppidl, NULL);
  2105. }
  2106. return hr;
  2107. }
  2108. HRESULT CCDBurn::_GetPidlForVolumeName(LPCTSTR pszVolume, LPITEMIDLIST *ppidl)
  2109. {
  2110. int iDrive;
  2111. HRESULT hr = _GetDriveIndexForVolumeName(pszVolume, &iDrive);
  2112. if (SUCCEEDED(hr))
  2113. {
  2114. WCHAR szRoot[4];
  2115. hr = PathBuildRoot(szRoot, iDrive) ? S_OK : E_FAIL;
  2116. if (SUCCEEDED(hr))
  2117. {
  2118. hr = SHILCreateFromPath(szRoot, ppidl, NULL);
  2119. }
  2120. }
  2121. return hr;
  2122. }
  2123. HRESULT CCDBurn::_GetFolderPidl(LPITEMIDLIST *ppidl)
  2124. {
  2125. TCHAR szCurrent[MAX_PATH];
  2126. HRESULT hr = _GetCurrentBurnVolumeName(szCurrent, ARRAYSIZE(szCurrent));
  2127. if (SUCCEEDED(hr))
  2128. {
  2129. hr = _GetPidlForVolumeName(szCurrent, ppidl);
  2130. }
  2131. return hr;
  2132. }
  2133. void CCDBurn::_HandleBookkeeping()
  2134. {
  2135. _DumpDiscInfo();
  2136. _StoreDiscInfo();
  2137. }
  2138. // IDropTarget handling
  2139. // This code forwards to drop target folder for the currently configured burn drive.
  2140. // merged folder hands off to ccdburn because otherwise it'd be doing too much
  2141. // cd burning specific stuff (media detection on drop, etc.)
  2142. HRESULT CCDBurn::_EnsureDropTarget()
  2143. {
  2144. HRESULT hr = S_OK;
  2145. if (!_pdt)
  2146. {
  2147. if (_BurningIsEnabled())
  2148. {
  2149. TCHAR szStaging[MAX_PATH];
  2150. hr = _GetBurnStagingPath(szStaging, ARRAYSIZE(szStaging));
  2151. if (SUCCEEDED(hr))
  2152. {
  2153. LPITEMIDLIST pidl;
  2154. hr = SHILCreateFromPath(szStaging, &pidl, NULL);
  2155. if (SUCCEEDED(hr))
  2156. {
  2157. IShellFolder *psf;
  2158. hr = SHBindToObjectEx(NULL, pidl, NULL, IID_PPV_ARG(IShellFolder, &psf));
  2159. if (SUCCEEDED(hr))
  2160. {
  2161. hr = psf->CreateViewObject(NULL, IID_PPV_ARG(IDropTarget, &_pdt));
  2162. psf->Release();
  2163. }
  2164. ILFree(pidl);
  2165. }
  2166. }
  2167. }
  2168. else
  2169. {
  2170. hr = E_FAIL;
  2171. }
  2172. }
  2173. return hr;
  2174. }
  2175. HRESULT CCDBurn::_GetDropPidl(LPITEMIDLIST *ppidl)
  2176. {
  2177. HRESULT hr;
  2178. if (!_pidl)
  2179. {
  2180. // in the sendto case we aren't called through Initialize, so get default root pidl.
  2181. hr = _GetFolderPidl(ppidl);
  2182. }
  2183. else
  2184. {
  2185. hr = SHILClone(_pidl, ppidl);
  2186. }
  2187. return hr;
  2188. }
  2189. HRESULT CCDBurn::_StagingPidlFromMerged(LPCITEMIDLIST pidlDrop, LPITEMIDLIST *ppidlDest)
  2190. {
  2191. IAugmentedShellFolder *pasf;
  2192. HRESULT hr = SHBindToObjectEx(NULL, pidlDrop, NULL, IID_PPV_ARG(IAugmentedShellFolder, &pasf));
  2193. if (SUCCEEDED(hr))
  2194. {
  2195. hr = E_FAIL;
  2196. DWORD dwNSId;
  2197. GUID guid;
  2198. IShellFolder *psf;
  2199. BOOL fDone = FALSE;
  2200. for (DWORD dwIndex = 0;
  2201. !fDone && SUCCEEDED(pasf->EnumNameSpace(dwIndex, &dwNSId)) && SUCCEEDED(pasf->QueryNameSpace(dwNSId, &guid, &psf));
  2202. dwIndex++)
  2203. {
  2204. if (IsEqualGUID(guid, CLSID_StagingFolder))
  2205. {
  2206. IPersistFolder3 *ppf3;
  2207. hr = psf->QueryInterface(IID_PPV_ARG(IPersistFolder3, &ppf3));
  2208. if (SUCCEEDED(hr))
  2209. {
  2210. PERSIST_FOLDER_TARGET_INFO pfti = {0};
  2211. hr = ppf3->GetFolderTargetInfo(&pfti);
  2212. if (SUCCEEDED(hr))
  2213. {
  2214. *ppidlDest = pfti.pidlTargetFolder;
  2215. }
  2216. ppf3->Release();
  2217. }
  2218. fDone = TRUE;
  2219. }
  2220. psf->Release();
  2221. }
  2222. pasf->Release();
  2223. }
  2224. return hr;
  2225. }
  2226. BOOL CCDBurn::_IsStagingAreaSource(IDataObject *pdtobj, LPCITEMIDLIST pidlDrop)
  2227. {
  2228. BOOL fParent = FALSE; //source is parent of destination
  2229. BOOL fSame = FALSE; //source and destination are the same
  2230. // in UDF case we skip staging area so no need to do this work
  2231. BOOL fUDF = FALSE;
  2232. _GetMediaCapabilities(NULL, &fUDF);
  2233. if (!fUDF)
  2234. {
  2235. LPITEMIDLIST pidlDest;
  2236. if (SUCCEEDED(_StagingPidlFromMerged(pidlDrop, &pidlDest)))
  2237. {
  2238. STGMEDIUM medium;
  2239. LPIDA pida = DataObj_GetHIDA(pdtobj, &medium);
  2240. if (pida)
  2241. {
  2242. LPCITEMIDLIST pidlSource = IDA_GetIDListPtr(pida, -1);
  2243. if (pidlSource)
  2244. {
  2245. if (!ILIsEmpty(pidlSource))
  2246. {
  2247. fSame = ILIsEqual(pidlSource, pidlDest);
  2248. if (!fSame && ILIsParent(pidlSource, pidlDest, FALSE))
  2249. {
  2250. LPCITEMIDLIST pidl;
  2251. for (UINT i = 0; !fSame && !fParent && (pidl = IDA_GetIDListPtr(pida, i)); i++)
  2252. {
  2253. LPITEMIDLIST pidlFull = ILCombine(pidlSource, pidl);
  2254. if (pidlFull)
  2255. {
  2256. fSame = ILIsEqual(pidlFull, pidlDest);
  2257. if (!fSame)
  2258. fParent = ILIsParent(pidlFull, pidlDest, FALSE);
  2259. ILFree(pidlFull);
  2260. }
  2261. }
  2262. }
  2263. }
  2264. else //find folder has full pidls and empty one for a source
  2265. {
  2266. LPCITEMIDLIST pidl;
  2267. for (UINT i = 0; !fSame && !fParent && (pidl = IDA_GetIDListPtr(pida, i)); i++)
  2268. {
  2269. LPITEMIDLIST pidlParent = ILCloneParent(pidl);
  2270. if (pidlParent)
  2271. {
  2272. fSame = ILIsEqual(pidlParent, pidlDest) || ILIsEqual(pidl, pidlDest);
  2273. if (!fSame)
  2274. fParent = ILIsParent(pidl, pidlDest, FALSE);
  2275. ILFree(pidlParent);
  2276. }
  2277. }
  2278. }
  2279. }
  2280. HIDA_ReleaseStgMedium(pida, &medium);
  2281. }
  2282. ILFree(pidlDest);
  2283. }
  2284. }
  2285. if (fSame || fParent)
  2286. {
  2287. UINT idMessage = fSame ? IDS_REASONS_DESTSAMETREE : IDS_REASONS_DESTSUBTREE;
  2288. ShellMessageBox(g_hinst, _hwndBrowser, MAKEINTRESOURCE(idMessage), MAKEINTRESOURCE(IDS_BURN), MB_ICONEXCLAMATION | MB_OK);
  2289. }
  2290. return (fSame || fParent);
  2291. }
  2292. HRESULT CCDBurn::_StorageDrop(IDataObject *pdtobj, BOOL fMove)
  2293. {
  2294. LPITEMIDLIST pidlDrop;
  2295. HRESULT hr = _GetDropPidl(&pidlDrop);
  2296. if (SUCCEEDED(hr))
  2297. {
  2298. if (!_IsStagingAreaSource(pdtobj, pidlDrop))
  2299. {
  2300. IShellItem *psiDest;
  2301. hr = SHCreateShellItem(NULL, NULL, pidlDrop, &psiDest);
  2302. if (SUCCEEDED(hr))
  2303. {
  2304. hr = TransferDataObject(pdtobj, psiDest, fMove ? STGOP_MOVE : STGOP_COPY_PREFERHARDLINK, 0, this);
  2305. psiDest->Release();
  2306. }
  2307. }
  2308. else
  2309. {
  2310. hr = E_FAIL;
  2311. }
  2312. ILFree(pidlDrop);
  2313. }
  2314. return hr;
  2315. }
  2316. HRESULT CCDBurn::DragEnter(IDataObject *pdtobj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
  2317. {
  2318. // lets get the drop object for the folder that is configured for the
  2319. // burn drive. to do this we need to get the staging folder.
  2320. // this also determines if we show up in sendto or not.
  2321. HRESULT hr = _EnsureDropTarget();
  2322. if (SUCCEEDED(hr) && _pdt)
  2323. {
  2324. hr = _pdt->DragEnter(pdtobj, grfKeyState, pt, pdwEffect);
  2325. }
  2326. else
  2327. {
  2328. // there was no drop target, therefore there is no burn drive, therefore we shouldn't
  2329. // offer the ability to drag drop onto our object.
  2330. *pdwEffect = DROPEFFECT_NONE;
  2331. }
  2332. _dwDropEffect = *pdwEffect;
  2333. return hr;
  2334. }
  2335. HRESULT CCDBurn::DragOver(DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
  2336. {
  2337. HRESULT hr = E_FAIL;
  2338. if (_pdt)
  2339. {
  2340. hr = _pdt->DragOver(grfKeyState, pt, pdwEffect);
  2341. _dwDropEffect = *pdwEffect;
  2342. }
  2343. return hr;
  2344. }
  2345. HRESULT CCDBurn::DragLeave(void)
  2346. {
  2347. if (!_pdt)
  2348. return E_FAIL;
  2349. return _pdt->DragLeave();
  2350. }
  2351. void CCDBurn::_FreeDropParams(CDDROPPARAMS *pcddp)
  2352. {
  2353. pcddp->pcdb->Release();
  2354. ATOMICRELEASE(pcddp->pstmDataObj);
  2355. delete pcddp;
  2356. }
  2357. DWORD WINAPI CCDBurn::_DropThread(void *pv)
  2358. {
  2359. CDDROPPARAMS *pcddp = (CDDROPPARAMS*)pv;
  2360. IDataObject *pdtobj;
  2361. if (SUCCEEDED(CoGetInterfaceAndReleaseStream(pcddp->pstmDataObj, IID_PPV_ARG(IDataObject, &pdtobj))))
  2362. {
  2363. pcddp->pcdb->_StorageDrop(pdtobj, pcddp->fMove);
  2364. pdtobj->Release();
  2365. }
  2366. pcddp->pstmDataObj = NULL; // released by CoGetInterfaceAndReleaseStream
  2367. _FreeDropParams(pcddp);
  2368. return 0;
  2369. }
  2370. HRESULT CCDBurn::Drop(IDataObject *pdtobj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
  2371. {
  2372. HRESULT hr = E_OUTOFMEMORY;
  2373. CDDROPPARAMS *pcddp = new CDDROPPARAMS;
  2374. if (pcddp)
  2375. {
  2376. // get the hwnd from the site while we're on this thread so that we
  2377. // don't get SetSite(NULL) before we check it later.
  2378. IOleWindow *pow;
  2379. if (SUCCEEDED(IUnknown_QueryService(_punkSite, SID_STopLevelBrowser, IID_PPV_ARG(IOleWindow, &pow))))
  2380. {
  2381. pow->GetWindow(&_hwndBrowser);
  2382. pow->Release();
  2383. }
  2384. pcddp->pcdb = this;
  2385. AddRef();
  2386. CoMarshalInterThreadInterfaceInStream(IID_IDataObject, pdtobj, &pcddp->pstmDataObj);
  2387. pcddp->fMove = (_dwDropEffect == DROPEFFECT_MOVE);
  2388. if (pcddp->fMove)
  2389. {
  2390. _dwDropEffect = DROPEFFECT_NONE; // other thread will take care of move, so caller should take no action
  2391. }
  2392. *pdwEffect = _dwDropEffect;
  2393. if (SHCreateThread(_DropThread, pcddp, CTF_COINIT, NULL))
  2394. {
  2395. hr = S_OK;
  2396. }
  2397. else
  2398. {
  2399. _FreeDropParams(pcddp);
  2400. hr = E_OUTOFMEMORY;
  2401. }
  2402. }
  2403. DragLeave();
  2404. return hr;
  2405. }
  2406. // Helper function to get an IShellFolder object for the staging folder
  2407. HRESULT CCDBurn::_GetStagingFolder(LPCITEMIDLIST pidlDrive, REFIID riid, void **ppv)
  2408. {
  2409. TCHAR szPath[MAX_PATH];
  2410. HRESULT hr = CCDBurn::_GetBurnStagingPath(szPath, ARRAYSIZE(szPath));
  2411. if (SUCCEEDED(hr))
  2412. {
  2413. // fake up a directory object simple IDLIST
  2414. WIN32_FIND_DATA fd = {0};
  2415. fd.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
  2416. LPITEMIDLIST pidlStg;
  2417. hr = SHSimpleIDListFromFindData(szPath, &fd, &pidlStg);
  2418. if (SUCCEEDED(hr))
  2419. {
  2420. // now initialize the folder with it
  2421. PERSIST_FOLDER_TARGET_INFO pfti = {0};
  2422. pfti.pidlTargetFolder = (LPITEMIDLIST)pidlStg;
  2423. SHTCharToUnicode(szPath, pfti.szTargetParsingName, ARRAYSIZE(pfti.szTargetParsingName));
  2424. pfti.dwAttributes = FILE_ATTRIBUTE_DIRECTORY; // maybe add system?
  2425. pfti.csidl = -1;
  2426. hr = CFSFolder_CreateFolder(NULL, NULL, pidlDrive, &pfti, riid, ppv);
  2427. ILFree(pidlStg);
  2428. }
  2429. }
  2430. return hr;
  2431. }
  2432. // ripped from IMAPI.
  2433. DWORD CCDBurn::_ExecSyncIoctl(HANDLE hDriver, DWORD dwIoctl, void *pbuf, DWORD cbBuf)
  2434. {
  2435. DWORD dwResult = NO_ERROR;
  2436. OVERLAPPED ol = { 0 };
  2437. ol.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  2438. if (ol.hEvent)
  2439. {
  2440. DWORD dwBytes;
  2441. BOOL bStatus = DeviceIoControl(hDriver, dwIoctl, pbuf, cbBuf, pbuf, cbBuf, &dwBytes, &ol);
  2442. if (!bStatus)
  2443. {
  2444. dwResult = GetLastError();
  2445. if (ERROR_IO_PENDING == dwResult)
  2446. {
  2447. bStatus = GetOverlappedResult(hDriver, &ol, &dwBytes, TRUE);
  2448. dwResult = bStatus ? NO_ERROR : GetLastError();
  2449. }
  2450. }
  2451. CloseHandle(ol.hEvent);
  2452. }
  2453. else
  2454. {
  2455. dwResult = ERROR_OUTOFMEMORY;
  2456. }
  2457. return dwResult;
  2458. }
  2459. // {1186654D-47B8-48b9-BEB9-7DF113AE3C67}
  2460. static const GUID IMAPIDeviceInterfaceGUID = { 0x1186654d, 0x47b8, 0x48b9, { 0xbe, 0xb9, 0x7d, 0xf1, 0x13, 0xae, 0x3c, 0x67 } };
  2461. // this is a first approximation to see if the drive is supported or not to avoid loading imapi at boot
  2462. // whenever possible. if this passes, then we still have to use imapi to make sure, but if this returns
  2463. // false, theres no way imapi will support it.
  2464. // note that this mimics the logic in imapi's CMSEnumDiscRecordersObj::Next enumerator function.
  2465. BOOL CCDBurn::_CouldPossiblySupport(LPCWSTR pszVolume)
  2466. {
  2467. // if the user isnt an admin, then these checks wont work.
  2468. // just assume that we could support it, and let imapi do the privileged stuff since its a service.
  2469. // perfwise this isnt such a big hit since the admin home user is the main scenario.
  2470. if (!IsUserAnAdmin())
  2471. return TRUE;
  2472. BOOL fSupported = FALSE;
  2473. HDEVINFO hDevInfo = SetupDiGetClassDevs(&IMAPIDeviceInterfaceGUID, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
  2474. if (INVALID_HANDLE_VALUE != hDevInfo)
  2475. {
  2476. SP_DEVICE_INTERFACE_DATA did = { 0 };
  2477. did.cbSize = sizeof(did);
  2478. for (int i = 0; !fSupported && SetupDiEnumDeviceInterfaces(hDevInfo, 0, &IMAPIDeviceInterfaceGUID, i, &did); i++)
  2479. {
  2480. ULONG cbRequired = 0;
  2481. SetupDiGetDeviceInterfaceDetail(hDevInfo, &did, NULL, 0, &cbRequired, NULL);
  2482. if (cbRequired > 0)
  2483. {
  2484. cbRequired += sizeof(WCHAR);
  2485. PSP_DEVICE_INTERFACE_DETAIL_DATA pdidd = (PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc(LPTR, cbRequired);
  2486. if (pdidd)
  2487. {
  2488. pdidd->cbSize = sizeof(*pdidd);
  2489. SP_DEVINFO_DATA dd = { 0 };
  2490. dd.cbSize = sizeof(dd);
  2491. if (SetupDiGetDeviceInterfaceDetail(hDevInfo, &did, pdidd, cbRequired, NULL, &dd))
  2492. {
  2493. WCHAR szLower[100];
  2494. BOOL fHasFilter = FALSE;
  2495. if (SetupDiGetDeviceRegistryProperty(hDevInfo, &dd, SPDRP_LOWERFILTERS, NULL, (BYTE*)szLower, sizeof(szLower), NULL))
  2496. {
  2497. PCWSTR psz = szLower;
  2498. while (*psz && !fHasFilter)
  2499. {
  2500. if (StrCmpI(psz, L"imapi") == 0)
  2501. {
  2502. fHasFilter = TRUE;
  2503. }
  2504. psz += lstrlenW(psz) + 1;
  2505. }
  2506. }
  2507. if (fHasFilter)
  2508. {
  2509. HANDLE hDriver = CreateFile(pdidd->DevicePath, GENERIC_READ | GENERIC_WRITE,
  2510. FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
  2511. FILE_FLAG_OVERLAPPED, NULL);
  2512. if (INVALID_HANDLE_VALUE != hDriver)
  2513. {
  2514. STORAGE_DEVICE_NUMBER sdn = { 0 };
  2515. if (NO_ERROR == _ExecSyncIoctl(hDriver, IOCTL_STORAGE_GET_DEVICE_NUMBER, &sdn, sizeof(sdn)))
  2516. {
  2517. WCHAR szDevicePath[50];
  2518. wnsprintf(szDevicePath, ARRAYSIZE(szDevicePath), L"\\Device\\CdRom%d", sdn.DeviceNumber);
  2519. fSupported = _DevicePathMatchesVolumeName(szDevicePath, pszVolume);
  2520. }
  2521. CloseHandle(hDriver);
  2522. }
  2523. }
  2524. }
  2525. LocalFree(pdidd);
  2526. }
  2527. }
  2528. }
  2529. SetupDiDestroyDeviceInfoList(hDevInfo);
  2530. }
  2531. return fSupported;
  2532. }
  2533. HRESULT CDBurn_OnDeviceAdded(DWORD dwDriveMask, BOOL fFullRefresh, BOOL fPickNewDrive)
  2534. {
  2535. HRESULT hr = S_OK;
  2536. // only do stuff if the user doesn't have a drive configured already
  2537. TCHAR szDummy[MAX_PATH];
  2538. HRESULT hrCheck = CCDBurn::_GetCurrentBurnVolumeName(szDummy, ARRAYSIZE(szDummy));
  2539. // if hr == E_UNEXPECTED, then there's already a empty string in the registry for the current
  2540. // burn drive. that means the user disabled the functionality so don't put it back.
  2541. if (fFullRefresh || (FAILED(hrCheck) && (hrCheck != E_UNEXPECTED)))
  2542. {
  2543. hr = E_OUTOFMEMORY;
  2544. CCDBurn *pcdb = new CCDBurn();
  2545. if (pcdb)
  2546. {
  2547. // keep track of the fastest drive in the system to default to.
  2548. DWORD dwBestWrite = 0;
  2549. TCHAR szNewBurnVolume[MAX_PATH];
  2550. // only run through this if the device that just got added is a cd.
  2551. // this drive letter stuff is weak but it's what comes from base's notification.
  2552. BOOL fCheck = FALSE;
  2553. for (int i = 0; i < 26; i++)
  2554. {
  2555. TCHAR szDriveLetter[4];
  2556. if (PathBuildRoot(szDriveLetter, i) &&
  2557. (GetDriveType(szDriveLetter) == DRIVE_CDROM))
  2558. {
  2559. TCHAR szVolumeName[MAX_PATH];
  2560. if (SUCCEEDED(CCDBurn::_GetVolumeNameForDriveIndex(i, szVolumeName, ARRAYSIZE(szVolumeName))))
  2561. {
  2562. DWORD dwMaxWrite, dwDriveType;
  2563. // if we already have info on the drive, we don't need to worry about it.
  2564. // if we dont have info, check it.
  2565. // if we're doing a full refresh then always recheck if it wasnt supported before --
  2566. // this could happen if a driver update across a reboot caused a drive to get supported.
  2567. if (FAILED(CCDBurn::_GetCachedDriveInfo(szVolumeName, &dwDriveType, NULL, &dwMaxWrite)) ||
  2568. (fFullRefresh && !SUPPORTED(dwDriveType)))
  2569. {
  2570. if (CCDBurn::_CouldPossiblySupport(szVolumeName))
  2571. {
  2572. // all new cd-rom drives need to be checked with IMAPI.
  2573. fCheck = TRUE;
  2574. }
  2575. // default to unsupported. this is so we don't have to hit IMAPI on
  2576. // the property sheet later.
  2577. CCDBurn::_SetCachedDriveInfo(szVolumeName, DRIVE_NOTSUPPORTED, 0, 0);
  2578. }
  2579. else
  2580. {
  2581. if (SUPPORTED(dwDriveType) && (dwMaxWrite > dwBestWrite))
  2582. {
  2583. // we'll always take the fastest one
  2584. dwBestWrite = dwMaxWrite;
  2585. lstrcpyn(szNewBurnVolume, szVolumeName, ARRAYSIZE(szNewBurnVolume));
  2586. }
  2587. }
  2588. }
  2589. }
  2590. }
  2591. // okay we have to enumerate through IMAPI.
  2592. if (fCheck)
  2593. {
  2594. IDiscMaster *pdm;
  2595. IJolietDiscMaster *pjdm;
  2596. hr = pcdb->_GetDiscMasters(&pdm, &pjdm);
  2597. if (SUCCEEDED(hr))
  2598. {
  2599. IEnumDiscRecorders *penumdr;
  2600. hr = pdm->EnumDiscRecorders(&penumdr);
  2601. if (SUCCEEDED(hr))
  2602. {
  2603. ULONG celt;
  2604. IDiscRecorder *pdr;
  2605. while (S_OK == penumdr->Next(1, &pdr, &celt))
  2606. {
  2607. TCHAR szDevicePath[MAX_PATH];
  2608. if (SUCCEEDED(pcdb->_GetRecorderPath(pdr, szDevicePath, ARRAYSIZE(szDevicePath))))
  2609. {
  2610. DWORD dwMaxWrite, dwDriveType;
  2611. if (SUCCEEDED(pcdb->_GetDiscRecorderInfo(pdr, NULL, &dwMaxWrite, &dwDriveType)))
  2612. {
  2613. TCHAR szVolumeName[MAX_PATH];
  2614. if (SUCCEEDED(pcdb->_GetVolumeNameForDevicePath(szDevicePath, szVolumeName, ARRAYSIZE(szVolumeName))))
  2615. {
  2616. if (dwMaxWrite > dwBestWrite)
  2617. {
  2618. // we'll always take the fastest one
  2619. dwBestWrite = dwMaxWrite;
  2620. lstrcpyn(szNewBurnVolume, szVolumeName, ARRAYSIZE(szNewBurnVolume));
  2621. }
  2622. // default to fastest speed for the drive
  2623. pcdb->_SetCachedDriveInfo(szVolumeName, dwDriveType, WRITESPEED_FASTEST, dwMaxWrite);
  2624. }
  2625. }
  2626. }
  2627. pdr->Release();
  2628. }
  2629. penumdr->Release();
  2630. }
  2631. pdm->Release();
  2632. pjdm->Release();
  2633. }
  2634. }
  2635. if (fPickNewDrive && (dwBestWrite > 0))
  2636. {
  2637. pcdb->_SetCurrentBurnVolumeName(szNewBurnVolume, FALSE);
  2638. }
  2639. pcdb->Release();
  2640. }
  2641. }
  2642. return hr;
  2643. }
  2644. void CCDBurn::_PruneRemovedDevices()
  2645. {
  2646. HKEY hk;
  2647. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_DRIVES, 0, KEY_READ, &hk))
  2648. {
  2649. // since we're deleting as we're moving along, walk backwards.
  2650. DWORD dwLast;
  2651. if (ERROR_SUCCESS == RegQueryInfoKey(hk, NULL, NULL, NULL, &dwLast, NULL, NULL, NULL, NULL, NULL, NULL, NULL))
  2652. {
  2653. TCHAR szVolKey[MAX_PATH];
  2654. for (int i = dwLast - 1; (i >= 0) && ERROR_SUCCESS == RegEnumKey(hk, i, szVolKey, ARRAYSIZE(szVolKey)); i--)
  2655. {
  2656. TCHAR szCachedVol[MAX_PATH];
  2657. lstrcpyn(szCachedVol, L"\\\\?\\", ARRAYSIZE(szCachedVol));
  2658. StrCatBuff(szCachedVol, szVolKey, ARRAYSIZE(szCachedVol));
  2659. StrCatBuff(szCachedVol, L"\\", ARRAYSIZE(szCachedVol));
  2660. int iDrive;
  2661. if (FAILED(CCDBurn::_GetDriveIndexForVolumeName(szCachedVol, &iDrive)))
  2662. {
  2663. // this drive is dead, remove its cached info
  2664. TCHAR szRegPath[MAX_PATH];
  2665. lstrcpyn(szRegPath, REGSTR_PATH_DRIVES, ARRAYSIZE(szRegPath));
  2666. StrCatBuff(szRegPath, L"\\", ARRAYSIZE(szRegPath));
  2667. StrCatBuff(szRegPath, szVolKey, ARRAYSIZE(szRegPath));
  2668. SHDeleteKey(HKEY_CURRENT_USER, szRegPath);
  2669. }
  2670. }
  2671. }
  2672. RegCloseKey(hk);
  2673. }
  2674. }
  2675. HRESULT CDBurn_OnDeviceRemoved(DWORD dwDriveMask)
  2676. {
  2677. HRESULT hr = S_OK;
  2678. // see if the selected drive just got removed.
  2679. TCHAR szVolumeName[MAX_PATH];
  2680. HRESULT hrCheck = CCDBurn::_GetCurrentBurnVolumeName(szVolumeName, ARRAYSIZE(szVolumeName));
  2681. CCDBurn::_PruneRemovedDevices();
  2682. BOOL fFound = FALSE;
  2683. HKEY hk;
  2684. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_DRIVES, 0, KEY_READ, &hk))
  2685. {
  2686. TCHAR szVolKey[MAX_PATH];
  2687. for (int i = 0; ERROR_SUCCESS == RegEnumKey(hk, i, szVolKey, ARRAYSIZE(szVolKey)); i++)
  2688. {
  2689. TCHAR szCachedVol[MAX_PATH];
  2690. lstrcpyn(szCachedVol, L"\\\\?\\", ARRAYSIZE(szCachedVol));
  2691. StrCatBuff(szCachedVol, szVolKey, ARRAYSIZE(szCachedVol));
  2692. StrCatBuff(szCachedVol, L"\\", ARRAYSIZE(szCachedVol));
  2693. int iDrive;
  2694. if (SUCCEEDED(CCDBurn::_GetDriveIndexForVolumeName(szCachedVol, &iDrive)) &&
  2695. SUCCEEDED(hrCheck) && (lstrcmpi(szCachedVol, szVolumeName) == 0))
  2696. {
  2697. // we found the drive that's currently enabled.
  2698. // this means it's still currently mounted.
  2699. // now check if either we dont have a cached index, or if the cached index is still the
  2700. // same as it is now. then we really didn't change.
  2701. DWORD dwIndex, cb = sizeof(dwIndex);
  2702. if ((ERROR_SUCCESS != SHGetValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_CACHEDINDEX, NULL, &dwIndex, &cb)) ||
  2703. (dwIndex == iDrive))
  2704. {
  2705. fFound = TRUE;
  2706. }
  2707. }
  2708. }
  2709. RegCloseKey(hk);
  2710. }
  2711. if (SUCCEEDED(hrCheck) && !fFound)
  2712. {
  2713. // zonk the currently selected drive, we'll pick a new one from the rest.
  2714. // this is all because the drive letter scheme doesn't let us get back to the volume name
  2715. // since the drive letter is gone at this point.
  2716. CCDBurn::_SetCurrentBurnVolumeName(TEXT(""), TRUE);
  2717. hr = CDBurn_OnDeviceAdded(0, FALSE, TRUE);
  2718. }
  2719. return hr;
  2720. }
  2721. HRESULT CDBurn_OnDeviceChange(BOOL fAdd, LPCWSTR pszDrive)
  2722. {
  2723. int iDriveIndex = PathGetDriveNumber(pszDrive);
  2724. if (fAdd)
  2725. CDBurn_OnDeviceAdded(1 << iDriveIndex, FALSE, TRUE);
  2726. else
  2727. CDBurn_OnDeviceRemoved(1 << iDriveIndex);
  2728. return S_OK;
  2729. }
  2730. BOOL CCDBurn::_HasMedia()
  2731. {
  2732. // unfortunately we have to assume there's media unless we find otherwise.
  2733. BOOL fHasMedia = TRUE;
  2734. CCDBurn *pcdb = new CCDBurn();
  2735. if (pcdb)
  2736. {
  2737. IDiscMaster *pdm;
  2738. IJolietDiscMaster *pjdm;
  2739. if (SUCCEEDED(pcdb->_GetDiscMasters(&pdm, &pjdm)))
  2740. {
  2741. IDiscRecorder *pdr;
  2742. if (SUCCEEDED(pcdb->_FindAndSetDefaultRecorder(pdm, FALSE, &pdr)))
  2743. {
  2744. if (SUCCEEDED(pdr->OpenExclusive()))
  2745. {
  2746. long lMediaType, lMediaFlags;
  2747. if (SUCCEEDED(pdr->QueryMediaType(&lMediaType, &lMediaFlags)))
  2748. {
  2749. if (!lMediaType && !lMediaFlags)
  2750. {
  2751. fHasMedia = FALSE;
  2752. }
  2753. }
  2754. pdr->Close();
  2755. }
  2756. pdr->Release();
  2757. }
  2758. pdm->Release();
  2759. pjdm->Release();
  2760. }
  2761. pcdb->Release();
  2762. }
  2763. return fHasMedia;
  2764. }
  2765. // this is called by mountpoint code BEFORE sending off the SHCNE_MEDIA events
  2766. // checking stuff on the media has to be done synchronously because it uses
  2767. // IMAPI and IMAPI can only have one caller at a time.
  2768. // autorun and things responding to SHCNE_MEDIA may also use IMAPI so we need to
  2769. // get this out of the way ASAP when media is inserted.
  2770. HRESULT CDBurn_OnMediaChange(BOOL fInsert, LPCWSTR pszDrive)
  2771. {
  2772. int iCurrent;
  2773. HRESULT hr = CCDBurn::_GetCurrentDriveIndex(&iCurrent);
  2774. if (SUCCEEDED(hr) && (PathGetDriveNumber(pszDrive) == iCurrent))
  2775. {
  2776. if (fInsert)
  2777. {
  2778. CCDBurn::_HandleBookkeeping();
  2779. }
  2780. else if (!CCDBurn::_HasMedia())
  2781. {
  2782. CDBurn_OnEject(NULL, iCurrent);
  2783. }
  2784. }
  2785. return hr;
  2786. }
  2787. HRESULT CDBurn_OnEject(HWND hwnd, INT iDrive)
  2788. {
  2789. int iCurrent;
  2790. HRESULT hr = CCDBurn::_GetCurrentDriveIndex(&iCurrent);
  2791. if (SUCCEEDED(hr))
  2792. {
  2793. CCDBurn *pcdb = new CCDBurn();
  2794. if (pcdb)
  2795. {
  2796. // we need to know whether to put up the dialog or not based on if the last
  2797. // media was writable. we cant check the media now since in the non-MMC2 case
  2798. // the media is already ejected at this point, so we hit up our cache.
  2799. DWORD dwMediaCap;
  2800. DWORD cb = sizeof(dwMediaCap);
  2801. if (ERROR_SUCCESS == SHGetValue(HKEY_CURRENT_USER, REGSTR_PATH_PERMEDIA, REGVALUE_MEDIATYPE, NULL, &dwMediaCap, &cb) &&
  2802. (dwMediaCap & HWDMC_CDRECORDABLE))
  2803. {
  2804. pcdb->_DumpDiscInfo();
  2805. if ((iDrive == iCurrent) && CCDBurn::_StagingAreaHasFiles())
  2806. {
  2807. IPropertyBag *ppb;
  2808. hr = pcdb->_CreateDefaultPropBag(IID_PPV_ARG(IPropertyBag, &ppb));
  2809. if (SUCCEEDED(hr))
  2810. {
  2811. SHPropertyBag_WriteBOOL(ppb, PROPSTR_EJECT, TRUE);
  2812. hr = pcdb->Load(ppb, NULL);
  2813. if (SUCCEEDED(hr))
  2814. {
  2815. CMINVOKECOMMANDINFO cmi = { 0 };
  2816. hr = pcdb->_PrepWiz(&cmi, FALSE, TRUE);
  2817. }
  2818. ppb->Release();
  2819. }
  2820. }
  2821. }
  2822. else
  2823. {
  2824. pcdb->_DumpDiscInfo();
  2825. hr = S_OK;
  2826. }
  2827. pcdb->Release();
  2828. }
  2829. else
  2830. {
  2831. hr = E_OUTOFMEMORY;
  2832. }
  2833. }
  2834. return hr;
  2835. }
  2836. // IOleCommandTarget implementation
  2837. HRESULT CCDBurn::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT* pCmdText)
  2838. {
  2839. HRESULT hr = OLECMDERR_E_UNKNOWNGROUP;
  2840. if (*pguidCmdGroup == CGID_ShellServiceObject)
  2841. {
  2842. // We like Shell Service Object notifications...
  2843. hr = S_OK;
  2844. }
  2845. return hr;
  2846. }
  2847. DWORD WINAPI CCDBurn::_ExecThread(void *pv)
  2848. {
  2849. CCDBurn *pcdb = (CCDBurn *)pv;
  2850. // just in case explorer AV'd while holding the lock, unlock the next time we come up.
  2851. // there's no way to guard against this.
  2852. pcdb->_LockCurrentDrive(FALSE, TRUE);
  2853. // hardware may have been added while we were powered down, and it won't generate
  2854. // a notification event so we have to assume that anything could have changed
  2855. // (inf registration for existing drives too, usually ones that require reboot to update).
  2856. pcdb->_PruneRemovedDevices();
  2857. // save off the currently selected drive and its write speed
  2858. TCHAR szCurrent[MAX_PATH];
  2859. DWORD dwCurWrite;
  2860. HRESULT hrName = pcdb->_GetCurrentBurnVolumeName(szCurrent, ARRAYSIZE(szCurrent));
  2861. if (SUCCEEDED(hrName))
  2862. {
  2863. DWORD dwType;
  2864. hrName = pcdb->_GetCachedDriveInfo(szCurrent, &dwType, &dwCurWrite, NULL);
  2865. // if the drive has become unsupported, we need to drop our currently selected
  2866. // drive.
  2867. if (SUCCEEDED(hrName) && !SUPPORTED(dwType))
  2868. {
  2869. hrName = E_FAIL;
  2870. }
  2871. }
  2872. BOOL fSet = SUCCEEDED(hrName);
  2873. // if it's E_UNEXPECTED then the user has disabled the burning feature completely.
  2874. BOOL fDisabled = (hrName == E_UNEXPECTED);
  2875. // readd devices, syncro
  2876. CDBurn_OnDeviceAdded(0xFFFFFFFF, TRUE, !fSet);
  2877. DWORD dwDriveType;
  2878. if (fDisabled)
  2879. {
  2880. // if we're disabled, stay disabled
  2881. pcdb->_SetCurrentBurnVolumeName(L"", FALSE);
  2882. }
  2883. else if (fSet && SUCCEEDED(pcdb->_GetCachedDriveInfo(szCurrent, &dwDriveType, NULL, NULL)) && SUPPORTED(dwDriveType))
  2884. {
  2885. // if the device we were using before is still supported, use the previous write speed
  2886. pcdb->_SetCachedDriveInfo(szCurrent, DRIVE_USEEXISTING, dwCurWrite, 0);
  2887. }
  2888. if (pcdb->_BurningIsEnabled())
  2889. {
  2890. pcdb->_HandleBookkeeping();
  2891. int iDrive;
  2892. if (SUCCEEDED(pcdb->_GetCurrentDriveIndex(&iDrive)))
  2893. {
  2894. SHSetValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_CACHEDINDEX, REG_DWORD, &iDrive, sizeof(iDrive));
  2895. }
  2896. else
  2897. {
  2898. SHDeleteValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_CACHEDINDEX);
  2899. }
  2900. }
  2901. pcdb->Release();
  2902. return 0;
  2903. }
  2904. HRESULT CCDBurn::Exec(const GUID* pguidCmdGroup, DWORD nCmdID, DWORD nCmdExecOpt, VARIANTARG* pvaIn, VARIANTARG* pvaOut)
  2905. {
  2906. HRESULT hr = OLECMDERR_E_UNKNOWNGROUP;
  2907. if (*pguidCmdGroup == CGID_ShellServiceObject)
  2908. {
  2909. hr = S_OK; // Any ol' notification is ok with us
  2910. // Handle Shell Service Object notifications here.
  2911. switch (nCmdID)
  2912. {
  2913. case SSOCMDID_OPEN:
  2914. // we're on the tray's thread as a service object so lets create our own thread.
  2915. // this is fine since our thread is bound by IOCTLs to the CD-R etc.
  2916. AddRef();
  2917. if (SHCreateThread(_ExecThread, this, CTF_COINIT, NULL))
  2918. break;
  2919. Release();
  2920. break;
  2921. default:
  2922. break;
  2923. }
  2924. }
  2925. return hr;
  2926. }
  2927. HRESULT CCDBurn::GetRecorderDriveLetter(LPWSTR pszDrive, UINT cch)
  2928. {
  2929. if (cch < 4)
  2930. return E_INVALIDARG;
  2931. int iDrive;
  2932. HRESULT hr = _GetCurrentDriveIndex(&iDrive);
  2933. if (SUCCEEDED(hr))
  2934. {
  2935. // pathbuildroot assumes cch >= 4
  2936. hr = PathBuildRoot(pszDrive, iDrive) ? S_OK : E_FAIL;
  2937. }
  2938. return hr;
  2939. }
  2940. // helper for lazy callers within shell32
  2941. STDAPI CDBurn_GetRecorderDriveLetter(LPWSTR pszDrive, UINT cch)
  2942. {
  2943. ICDBurn *pcdb;
  2944. HRESULT hr = CoCreateInstance(CLSID_CDBurn, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(ICDBurn, &pcdb));
  2945. if (SUCCEEDED(hr))
  2946. {
  2947. hr = pcdb->GetRecorderDriveLetter(pszDrive, cch);
  2948. pcdb->Release();
  2949. }
  2950. return hr;
  2951. }
  2952. HRESULT CCDBurn::Burn(HWND hwnd)
  2953. {
  2954. HRESULT hr = InitNew();
  2955. if (SUCCEEDED(hr))
  2956. {
  2957. // do this synchronously, callers will handle putting it on a separate thread.
  2958. // this is easier than making a callback to tell them when its done.
  2959. hr = _WizardThreadProc();
  2960. }
  2961. return hr;
  2962. }
  2963. HRESULT CCDBurn::HasRecordableDrive(BOOL *pfHasRecorder)
  2964. {
  2965. *pfHasRecorder = FALSE;
  2966. HKEY hk;
  2967. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_DRIVES, 0, KEY_READ, &hk))
  2968. {
  2969. TCHAR szVolKey[MAX_PATH];
  2970. for (int i = 0; !*pfHasRecorder && (ERROR_SUCCESS == RegEnumKey(hk, i, szVolKey, ARRAYSIZE(szVolKey))); i++)
  2971. {
  2972. TCHAR szRegPath[MAX_PATH];
  2973. lstrcpyn(szRegPath, REGSTR_PATH_DRIVES, ARRAYSIZE(szRegPath));
  2974. StrCatBuff(szRegPath, L"\\", ARRAYSIZE(szRegPath));
  2975. StrCatBuff(szRegPath, szVolKey, ARRAYSIZE(szRegPath));
  2976. DWORD dwType;
  2977. ULONG cb = sizeof(dwType);
  2978. if (ERROR_SUCCESS == SHGetValue(HKEY_CURRENT_USER, szRegPath, REGVALUE_DRIVETYPE, NULL, &dwType, &cb))
  2979. {
  2980. *pfHasRecorder = SUPPORTED(dwType);
  2981. }
  2982. }
  2983. RegCloseKey(hk);
  2984. }
  2985. return S_OK;
  2986. }
  2987. HRESULT CCDBurn::_DumpDiscInfo()
  2988. {
  2989. SHDeleteKey(HKEY_CURRENT_USER, REGSTR_PATH_PERMEDIA);
  2990. return S_OK;
  2991. }
  2992. HRESULT CCDBurn::_GetDiscInfoUsingIMAPI(IJolietDiscMaster *pjdm, IDiscRecorder *pdr, ULONGLONG *pcbFree)
  2993. {
  2994. HRESULT hr = E_FAIL;
  2995. BYTE bSessions, bLastTrack;
  2996. LONG nBlockBytes;
  2997. ULONG ulStartAddress, ulNextWritable, ulFreeBlocks;
  2998. if (SUCCEEDED(pjdm->GetDataBlockSize(&nBlockBytes)) &&
  2999. SUCCEEDED(pdr->QueryMediaInfo(&bSessions, &bLastTrack, &ulStartAddress, &ulNextWritable, &ulFreeBlocks)))
  3000. {
  3001. hr = S_OK;
  3002. *pcbFree = (ULONGLONG) ulFreeBlocks * nBlockBytes;
  3003. }
  3004. return hr;
  3005. }
  3006. HRESULT CCDBurn::_GetDiscInfoUsingFilesystem(ULONGLONG *pcbTotal, ULONGLONG *pcbFree, BOOL *pfUDF)
  3007. {
  3008. int iCurrent;
  3009. HRESULT hr = _GetCurrentDriveIndex(&iCurrent);
  3010. if (SUCCEEDED(hr))
  3011. {
  3012. *pcbTotal = 0;
  3013. *pcbFree = 0;
  3014. ULARGE_INTEGER ulTotal, ulFree;
  3015. TCHAR szRoot[4];
  3016. if (PathBuildRoot(szRoot, iCurrent) && SHGetDiskFreeSpace(szRoot, &ulFree, &ulTotal, NULL))
  3017. {
  3018. *pcbTotal = ulTotal.QuadPart;
  3019. *pcbFree = ulFree.QuadPart;
  3020. }
  3021. *pfUDF = FALSE;
  3022. TCHAR szFilesystem[30];
  3023. if (GetVolumeInformation(szRoot, NULL, 0, NULL, NULL, NULL, szFilesystem, ARRAYSIZE(szFilesystem)))
  3024. {
  3025. HUSKEY huskeyExclude;
  3026. if (ERROR_SUCCESS == SHRegOpenUSKey(REGSTR_PATH_EXCLUDE, KEY_READ, NULL, &huskeyExclude, FALSE))
  3027. {
  3028. DWORD dwIndex = 0;
  3029. TCHAR szKey[30];
  3030. DWORD cchKey = ARRAYSIZE(szKey);
  3031. while (!*pfUDF && (ERROR_SUCCESS == SHRegEnumUSValue(huskeyExclude, dwIndex, szKey, &cchKey, NULL, NULL, NULL, SHREGENUM_DEFAULT)))
  3032. {
  3033. *pfUDF = (lstrcmpi(szFilesystem, szKey) == 0);
  3034. dwIndex++;
  3035. cchKey = ARRAYSIZE(szKey);
  3036. }
  3037. SHRegCloseUSKey(huskeyExclude);
  3038. }
  3039. }
  3040. }
  3041. return hr;
  3042. }
  3043. HRESULT CDBurn_GetCDInfo(LPCTSTR pszVolume, DWORD *pdwDriveCapabilities, DWORD *pdwMediaCapabilities)
  3044. {
  3045. *pdwDriveCapabilities = 0;
  3046. *pdwMediaCapabilities = 0;
  3047. DWORD dwDriveType;
  3048. HRESULT hr = CCDBurn::_GetCachedDriveInfo(pszVolume, &dwDriveType, NULL, NULL);
  3049. if (SUCCEEDED(hr))
  3050. {
  3051. switch (dwDriveType)
  3052. {
  3053. case RECORDER_CDR:
  3054. *pdwDriveCapabilities = HWDDC_CDROM | HWDDC_CDRECORDABLE;
  3055. break;
  3056. case RECORDER_CDRW:
  3057. *pdwDriveCapabilities = HWDDC_CDROM | HWDDC_CDRECORDABLE | HWDDC_CDREWRITABLE;
  3058. break;
  3059. default:
  3060. *pdwDriveCapabilities = HWDDC_CDROM;
  3061. break;
  3062. }
  3063. DWORD dwMediaCap;
  3064. DWORD cb = sizeof(dwMediaCap);
  3065. if (ERROR_SUCCESS == SHGetValue(HKEY_CURRENT_USER, REGSTR_PATH_PERMEDIA, REGVALUE_MEDIATYPE, NULL, &dwMediaCap, &cb))
  3066. {
  3067. *pdwMediaCapabilities = dwMediaCap;
  3068. }
  3069. }
  3070. return hr;
  3071. }
  3072. void CDBurn_GetUDFState(BOOL *pfUDF)
  3073. {
  3074. *pfUDF = FALSE;
  3075. DWORD dw, cb = sizeof(dw);
  3076. if (ERROR_SUCCESS == SHGetValue(HKEY_CURRENT_USER, REGSTR_PATH_PERMEDIA, REGVALUE_UDF, NULL, &dw, &cb))
  3077. {
  3078. *pfUDF = dw;
  3079. }
  3080. }
  3081. HRESULT CCDBurn::_GetMediaCapabilities(DWORD *pdwCap, BOOL *pfUDF)
  3082. {
  3083. HRESULT hr = S_OK;
  3084. if (pfUDF)
  3085. {
  3086. CDBurn_GetUDFState(pfUDF);
  3087. }
  3088. if (pdwCap)
  3089. {
  3090. *pdwCap = 0;
  3091. TCHAR szVolumeName[MAX_PATH];
  3092. hr = CCDBurn::_GetCurrentBurnVolumeName(szVolumeName, ARRAYSIZE(szVolumeName));
  3093. if (SUCCEEDED(hr))
  3094. {
  3095. DWORD dwDriveCap;
  3096. CDBurn_GetCDInfo(szVolumeName, &dwDriveCap, pdwCap);
  3097. }
  3098. }
  3099. return hr;
  3100. }
  3101. HRESULT CCDBurn::GetMediaCapabilities(DWORD *pdwCap, BOOL *pfUDF)
  3102. {
  3103. return _GetMediaCapabilities(pdwCap, pfUDF);
  3104. }
  3105. HRESULT CCDBurn::_StoreDiscInfo()
  3106. {
  3107. HRESULT hr = E_FAIL;
  3108. BOOL fDone = FALSE;
  3109. int iRetryCount = 0;
  3110. // retry up to a max of 5 times.
  3111. // we can get into a state where we failed to pick up the disc information, if IMAPI
  3112. // is around and in use by somebody else. in that case just wait and loop around until we can
  3113. // get it.
  3114. while (!fDone && (iRetryCount < 5))
  3115. {
  3116. iRetryCount++;
  3117. // these are the values we're going to pick up.
  3118. ULONGLONG cbTotal, cbFree;
  3119. DWORD dwMediaCaps;
  3120. BOOL fUDF;
  3121. hr = E_OUTOFMEMORY;
  3122. CCDBurn *pcdb = new CCDBurn();
  3123. if (pcdb)
  3124. {
  3125. IDiscMaster *pdm;
  3126. IJolietDiscMaster *pjdm;
  3127. hr = pcdb->_GetDiscMasters(&pdm, &pjdm);
  3128. if (SUCCEEDED(hr))
  3129. {
  3130. IDiscRecorder *pdr;
  3131. // dont call SetActiveDiscRecorder unless absolutely necessary -- it returns random errors
  3132. // if there's UDF media.
  3133. hr = pcdb->_FindAndSetDefaultRecorder(pdm, FALSE, &pdr);
  3134. if (SUCCEEDED(hr))
  3135. {
  3136. hr = pdr->OpenExclusive();
  3137. if (SUCCEEDED(hr))
  3138. {
  3139. // don't use the mountpoint layer to determine capabilities.
  3140. dwMediaCaps = HWDMC_CDROM;
  3141. long lMediaType, lMediaFlags;
  3142. hr = pdr->QueryMediaType(&lMediaType, &lMediaFlags);
  3143. if (SUCCEEDED(hr) && !lMediaType && !lMediaFlags)
  3144. {
  3145. hr = E_FAIL;
  3146. }
  3147. if (SUCCEEDED(hr))
  3148. {
  3149. if (lMediaFlags & MEDIA_WRITABLE)
  3150. {
  3151. dwMediaCaps |= HWDMC_CDRECORDABLE;
  3152. }
  3153. if (lMediaFlags & MEDIA_RW)
  3154. {
  3155. dwMediaCaps |= HWDMC_CDREWRITABLE;
  3156. }
  3157. hr = _GetDiscInfoUsingFilesystem(&cbTotal, &cbFree, &fUDF);
  3158. // also adjust the fUDF bit to include unusable media.
  3159. if (lMediaFlags & MEDIA_FORMAT_UNUSABLE_BY_IMAPI)
  3160. {
  3161. fUDF = TRUE;
  3162. }
  3163. if (SUCCEEDED(hr) && (dwMediaCaps & (HWDMC_CDRECORDABLE | HWDMC_CDREWRITABLE)) && !fUDF)
  3164. {
  3165. ULONGLONG cbFreeIMAPI;
  3166. hr = _GetDiscInfoUsingIMAPI(pjdm, pdr, &cbFreeIMAPI);
  3167. if (SUCCEEDED(hr))
  3168. {
  3169. cbTotal += cbFreeIMAPI;
  3170. cbFree += cbFreeIMAPI;
  3171. }
  3172. }
  3173. }
  3174. pdr->Close();
  3175. }
  3176. // pick up the write speed, it might have changed. don't worry about
  3177. // failure since this is a bonus perk anyway.
  3178. DWORD dwMaxWrite;
  3179. TCHAR szDevicePath[MAX_PATH], szVolumeName[MAX_PATH];
  3180. if (SUCCEEDED(_GetDiscRecorderInfo(pdr, NULL, &dwMaxWrite, NULL)) &&
  3181. SUCCEEDED(_GetRecorderPath(pdr, szDevicePath, ARRAYSIZE(szDevicePath))) &&
  3182. SUCCEEDED(_GetVolumeNameForDevicePath(szDevicePath, szVolumeName, ARRAYSIZE(szVolumeName))))
  3183. {
  3184. // update max speed
  3185. _SetCachedDriveInfo(szVolumeName, DRIVE_USEEXISTING, 0, dwMaxWrite);
  3186. }
  3187. pdr->Release();
  3188. }
  3189. pdm->Release();
  3190. pjdm->Release();
  3191. }
  3192. pcdb->Release();
  3193. }
  3194. if (SUCCEEDED(hr))
  3195. {
  3196. SHSetValue(HKEY_CURRENT_USER, REGSTR_PATH_PERMEDIA, REGVALUE_TOTALBYTES, REG_BINARY, &cbTotal, sizeof(cbTotal));
  3197. SHSetValue(HKEY_CURRENT_USER, REGSTR_PATH_PERMEDIA, REGVALUE_FREEBYTES, REG_BINARY, &cbFree, sizeof(cbFree));
  3198. SHSetValue(HKEY_CURRENT_USER, REGSTR_PATH_PERMEDIA, REGVALUE_MEDIATYPE, REG_DWORD, &dwMediaCaps, sizeof(dwMediaCaps));
  3199. DWORD dw = fUDF;
  3200. SHSetValue(HKEY_CURRENT_USER, REGSTR_PATH_PERMEDIA, REGVALUE_UDF, REG_DWORD, &dw, sizeof(dw));
  3201. int iCurrent;
  3202. if (SUCCEEDED(_GetCurrentDriveIndex(&iCurrent)))
  3203. {
  3204. TCHAR szRoot[4];
  3205. TCHAR szVolName[MAX_PATH];
  3206. if (PathBuildRoot(szRoot, iCurrent) &&
  3207. GetVolumeInformation(szRoot, szVolName, ARRAYSIZE(szVolName), NULL, NULL, NULL, NULL, 0))
  3208. {
  3209. UINT cb = (lstrlen(szVolName) + 1) * sizeof(TCHAR);
  3210. SHSetValue(HKEY_CURRENT_USER, REGSTR_PATH_PERMEDIA, REGVALUE_DISCLABEL, REG_SZ, szVolName, cb);
  3211. }
  3212. }
  3213. DWORD dwSet = 1;
  3214. SHSetValue(HKEY_CURRENT_USER, REGSTR_PATH_PERMEDIA, REGVALUE_SET, REG_DWORD, &dwSet, sizeof(dwSet));
  3215. LPITEMIDLIST pidl;
  3216. if (SUCCEEDED(_GetFolderPidl(&pidl)))
  3217. {
  3218. SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_IDLIST, pidl, NULL);
  3219. ILFree(pidl);
  3220. }
  3221. fDone = TRUE;
  3222. }
  3223. else if ((IMAPI_E_STASHINUSE == hr) || // IMAPI is being used by somebody else.
  3224. (IMAPI_E_DEVICE_NOTACCESSIBLE == hr)) // CD has not spun up.
  3225. {
  3226. // wait and try again.
  3227. SHProcessMessagesUntilEvent(NULL, NULL, 5 * 1000); // 5 seconds
  3228. }
  3229. else
  3230. {
  3231. // there was some other error, bail out anyway.
  3232. fDone = TRUE;
  3233. }
  3234. }
  3235. return hr;
  3236. }
  3237. HRESULT CCDBurn::GetSpace(ULONGLONG *pcbTotal, ULONGLONG *pcbFree)
  3238. {
  3239. HRESULT hr = E_FAIL;
  3240. ULONGLONG cbTotal, cbFree;
  3241. DWORD cbReg1 = sizeof(cbTotal), cbReg2 = sizeof(cbFree);
  3242. if ((ERROR_SUCCESS == SHGetValue(HKEY_CURRENT_USER, REGSTR_PATH_PERMEDIA, REGVALUE_TOTALBYTES, NULL, &cbTotal, &cbReg1)) &&
  3243. (ERROR_SUCCESS == SHGetValue(HKEY_CURRENT_USER, REGSTR_PATH_PERMEDIA, REGVALUE_FREEBYTES, NULL, &cbFree, &cbReg2)))
  3244. {
  3245. if (pcbTotal)
  3246. *pcbTotal = cbTotal;
  3247. if (pcbFree)
  3248. *pcbFree = cbFree;
  3249. hr = S_OK;
  3250. }
  3251. return hr;
  3252. }
  3253. HRESULT CCDBurn::InitNew()
  3254. {
  3255. IPropertyBag *ppb;
  3256. // load up the default property bag for peruser perfolder
  3257. // may have problems down the line with thumbs.db being alluser.
  3258. HRESULT hr = _CreateDefaultPropBag(IID_PPV_ARG(IPropertyBag, &ppb));
  3259. if (SUCCEEDED(hr))
  3260. {
  3261. IUnknown_Set((IUnknown**)&_ppb, ppb);
  3262. ppb->Release();
  3263. }
  3264. return hr;
  3265. }
  3266. HRESULT CCDBurn::Load(IPropertyBag *ppb, IErrorLog *pErr)
  3267. {
  3268. IUnknown_Set((IUnknown**)&_ppb, ppb);
  3269. return S_OK;
  3270. }
  3271. STDAPI SHCreateQueryCancelAutoPlayMoniker(IMoniker** ppmoniker); // mtptarun2.cpp
  3272. void CCDBurn::_RegisterAutoplayCanceller()
  3273. {
  3274. IMoniker *pmoniker;
  3275. if (SUCCEEDED(SHCreateQueryCancelAutoPlayMoniker(&pmoniker)))
  3276. {
  3277. IRunningObjectTable *prot;
  3278. if (SUCCEEDED(GetRunningObjectTable(0, &prot)))
  3279. {
  3280. IUnknown *punkThis;
  3281. if (SUCCEEDED(QueryInterface(IID_PPV_ARG(IUnknown, &punkThis))))
  3282. {
  3283. prot->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, punkThis, pmoniker, &_dwROTRegister);
  3284. punkThis->Release();
  3285. }
  3286. prot->Release();
  3287. }
  3288. pmoniker->Release();
  3289. }
  3290. }
  3291. void CCDBurn::_UnregisterAutoplayCanceller()
  3292. {
  3293. if (_dwROTRegister)
  3294. {
  3295. IRunningObjectTable *prot;
  3296. if (SUCCEEDED(GetRunningObjectTable(0, &prot)))
  3297. {
  3298. prot->Revoke(_dwROTRegister);
  3299. _dwROTRegister = 0;
  3300. prot->Release();
  3301. }
  3302. }
  3303. }
  3304. HRESULT CCDBurn::_WizardThreadProc()
  3305. {
  3306. HRESULT hr = E_FAIL;
  3307. BOOL fWizardShown = FALSE;
  3308. // the burningnow check does an additional call into IMAPI -- this may be slow so do it while
  3309. // we're on the background thread instead of the duiview one.
  3310. if (!_IsBurningNow())
  3311. {
  3312. if (_EnterExclusiveBurning())
  3313. {
  3314. _RegisterAutoplayCanceller();
  3315. hr = _ShowWizard();
  3316. if (SUCCEEDED(_GetBurnHR()) && SHPropertyBag_ReadBOOLDefRet(_ppb, PROPSTR_AUTOCLOSE, FALSE))
  3317. {
  3318. // if we auto-closed the wizard, leave this thread going for a few more seconds
  3319. // to cancel any spurious autoplays that come in.
  3320. SHProcessMessagesUntilEvent(NULL, NULL, 3 * 1000);
  3321. }
  3322. _UnregisterAutoplayCanceller();
  3323. fWizardShown = TRUE;
  3324. _LeaveExclusiveBurning();
  3325. }
  3326. }
  3327. if (!fWizardShown && !SHPropertyBag_ReadBOOLDefRet(_ppb, PROPSTR_FAILSILENTLY, FALSE))
  3328. {
  3329. // put up UI so we dont silently fail.
  3330. ShellMessageBox(HINST_THISDLL, NULL, MAKEINTRESOURCE(IDS_BURN_CANTBURN), MAKEINTRESOURCE(IDS_BURN),
  3331. MB_OK | MB_ICONEXCLAMATION);
  3332. }
  3333. return hr;
  3334. }
  3335. DWORD WINAPI CCDBurn::_WizardThreadWrapper(void *pv)
  3336. {
  3337. CCDBurn *pcdb = (CCDBurn*)pv;
  3338. pcdb->_WizardThreadProc();
  3339. pcdb->Release();
  3340. return 0;
  3341. }
  3342. HRESULT CCDBurn::_ShowWizardOnSeparateThread()
  3343. {
  3344. HRESULT hr = S_OK;
  3345. AddRef();
  3346. if (!SHCreateThread(_WizardThreadWrapper, this, CTF_COINIT, NULL))
  3347. {
  3348. Release();
  3349. hr = E_FAIL;
  3350. }
  3351. return hr;
  3352. }
  3353. // match this with below
  3354. #define INDEX_DLG_BURNWIZ_WELCOME 0
  3355. #define INDEX_DLG_BURNWIZ_EJECT 1
  3356. #define INDEX_DLG_BURNWIZ_BURN_PROGRESS 2
  3357. #define INDEX_DLG_BURNWIZ_BURN_SUCCESS 3
  3358. #define INDEX_DLG_BURNWIZ_BURN_FAILURE 4
  3359. #define INDEX_DLG_BURNWIZ_WAITFORMEDIA 5
  3360. #define INDEX_DLG_BURNWIZ_STARTERASE 6
  3361. #define INDEX_DLG_BURNWIZ_ERASE_PROGRESS 7
  3362. #define INDEX_DLG_BURNWIZ_ERASE_SUCCESS 8
  3363. #define INDEX_DLG_BURNWIZ_ERASE_FAILURE 9
  3364. #define INDEX_DLG_BURNWIZ_DISCFULL 10
  3365. #define INDEX_DLG_BURNWIZ_EARLYEXIT 11
  3366. #define INDEX_DLG_BURNWIZ_HDFULL 12
  3367. #define INDEX_DLG_BURNWIZ_NOFILES 13
  3368. const WIZPAGE c_wpPages[] =
  3369. {
  3370. {DLG_BURNWIZ_WELCOME, 0, 0, PSP_HIDEHEADER, CCDBurn::s_WelcomeDlgProc},
  3371. {DLG_BURNWIZ_EJECT, 0, 0, PSP_HIDEHEADER, CCDBurn::s_EjectDlgProc},
  3372. {DLG_BURNWIZ_PROGRESS, IDS_BURNWIZ_PROGRESS_BURN_HEAD, IDS_BURNWIZ_PROGRESS_BURN_SUB, 0, CCDBurn::s_ProgressDlgProc},
  3373. {DLG_BURNWIZ_BURN_SUCCESS, 0, 0, PSP_HIDEHEADER, CCDBurn::s_DoneDlgProc},
  3374. {DLG_BURNWIZ_BURN_FAILURE, 0, 0, PSP_HIDEHEADER, CCDBurn::s_DoneDlgProc},
  3375. {DLG_BURNWIZ_WAITFORMEDIA, IDS_BURNWIZ_WAIT_HEAD, IDS_BURNWIZ_WAIT_SUB, 0, CCDBurn::s_WaitForMediaDlgProc},
  3376. {DLG_BURNWIZ_STARTERASE, 0, 0, PSP_HIDEHEADER, CCDBurn::s_StartEraseDlgProc},
  3377. {DLG_BURNWIZ_PROGRESS, IDS_BURNWIZ_PROGRESS_ERASE_HEAD, IDS_BURNWIZ_PROGRESS_ERASE_SUB, 0, CCDBurn::s_ProgressDlgProc},
  3378. {DLG_BURNWIZ_ERASE_SUCCESS, 0, 0, PSP_HIDEHEADER, CCDBurn::s_DoneDlgProc},
  3379. {DLG_BURNWIZ_ERASE_FAILURE, 0, 0, PSP_HIDEHEADER, CCDBurn::s_DoneDlgProc},
  3380. {DLG_BURNWIZ_DISCFULL, 0, 0, PSP_HIDEHEADER, CCDBurn::s_DiskFullDlgProc},
  3381. {DLG_BURNWIZ_PROGRESS, 0, 0, PSP_HIDEHEADER, CCDBurn::s_EarlyExitDlgProc},
  3382. {DLG_BURNWIZ_HDFULL, 0, 0, PSP_HIDEHEADER, CCDBurn::s_HDFullDlgProc},
  3383. {DLG_BURNWIZ_NOFILES, 0, 0, PSP_HIDEHEADER, CCDBurn::s_NoFilesDlgProc},
  3384. };
  3385. HPROPSHEETPAGE _CreatePropPageFromInfo(const WIZPAGE *pwp, LPARAM lParam)
  3386. {
  3387. PROPSHEETPAGE psp = { 0 };
  3388. psp.dwSize = sizeof(psp);
  3389. psp.hInstance = HINST_THISDLL;
  3390. psp.lParam = lParam;
  3391. psp.dwFlags = PSP_USETITLE | PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE | pwp->dwFlags;
  3392. psp.pszTemplate = MAKEINTRESOURCE(pwp->idPage);
  3393. psp.pfnDlgProc = pwp->dlgproc;
  3394. psp.pszTitle = MAKEINTRESOURCE(IDS_BURN_WIZTITLE);
  3395. psp.pszHeaderTitle = MAKEINTRESOURCE(pwp->idHeading);
  3396. psp.pszHeaderSubTitle = MAKEINTRESOURCE(pwp->idSubHeading);
  3397. return CreatePropertySheetPage(&psp);
  3398. }
  3399. int ReleaseCallback(void *pv, void *)
  3400. {
  3401. IWizardExtension *pwe = (IWizardExtension*)pv;
  3402. IUnknown_SetSite(pwe, NULL);
  3403. pwe->Release();
  3404. return 1;
  3405. }
  3406. HRESULT CCDBurn::_ShowWizard()
  3407. {
  3408. LinkWindow_RegisterClass();
  3409. _fCancelled = FALSE;
  3410. // create the page array
  3411. int nStartPage;
  3412. if (SHPropertyBag_ReadBOOLDefRet(_ppb, PROPSTR_EJECT, FALSE))
  3413. {
  3414. // we want the eject page
  3415. nStartPage = INDEX_DLG_BURNWIZ_EJECT;
  3416. }
  3417. else
  3418. {
  3419. // normal entry point
  3420. if (SHPropertyBag_ReadBOOLDefRet(_ppb, PROPSTR_ERASE, FALSE))
  3421. {
  3422. nStartPage = INDEX_DLG_BURNWIZ_STARTERASE;
  3423. }
  3424. else
  3425. {
  3426. nStartPage = _StagingAreaHasFiles() ? INDEX_DLG_BURNWIZ_WELCOME : INDEX_DLG_BURNWIZ_NOFILES;
  3427. }
  3428. }
  3429. // wtf? if i dont include a propsheet without PSP_HIDEHEADER the sizing gets messed up.
  3430. for (int i = 0; i < ARRAYSIZE(c_wpPages); i++)
  3431. {
  3432. _rgWizPages[i] = _CreatePropPageFromInfo(&c_wpPages[i], (LPARAM)this);
  3433. }
  3434. UINT cTotalExtPages;
  3435. HRESULT hr = _FillExtensionDPA(_rgWizPages + ARRAYSIZE(c_wpPages), ARRAYSIZE(_rgWizPages) - ARRAYSIZE(c_wpPages), &cTotalExtPages);
  3436. if (SUCCEEDED(hr))
  3437. {
  3438. PROPSHEETHEADER psh = { 0 };
  3439. psh.dwSize = sizeof(psh);
  3440. psh.hInstance = HINST_THISDLL;
  3441. psh.dwFlags = PSH_WIZARD | PSH_WIZARD97 | PSH_WATERMARK | PSH_STRETCHWATERMARK | PSH_HEADER | PSH_USEICONID;
  3442. psh.pszbmHeader = MAKEINTRESOURCE(IDB_BURNWIZ_HEADER);
  3443. psh.pszbmWatermark = MAKEINTRESOURCE(IDB_BURNWIZ_WATERMARK);
  3444. psh.pszIcon = MAKEINTRESOURCE(IDI_DRIVECD);
  3445. psh.phpage = _rgWizPages;
  3446. psh.nPages = ARRAYSIZE(c_wpPages) + cTotalExtPages;
  3447. psh.nStartPage = nStartPage;
  3448. PropertySheet(&psh);
  3449. HRESULT hrOp = E_FAIL;
  3450. DWORD dwHR;
  3451. if (SUCCEEDED(SHPropertyBag_ReadDWORD(_ppb, PROPSTR_HR, &dwHR)))
  3452. {
  3453. hrOp = dwHR;
  3454. }
  3455. hr = SUCCEEDED(hrOp) ? S_OK : S_FALSE;
  3456. }
  3457. if (_hdpaExts)
  3458. {
  3459. DPA_DestroyCallback(_hdpaExts, ReleaseCallback, 0);
  3460. }
  3461. s_hwndWiz = NULL;
  3462. // the drive could have been locked after the wait for media page.
  3463. _LockCurrentDrive(FALSE);
  3464. return hr;
  3465. }
  3466. CCDBurn* CCDBurn::s_GetCDBurn(HWND hwnd, UINT uMsg, LPARAM lParam)
  3467. {
  3468. if (uMsg == WM_INITDIALOG)
  3469. {
  3470. PROPSHEETPAGE *ppsp = (PROPSHEETPAGE*)lParam;
  3471. SetWindowLongPtr(hwnd, GWLP_USERDATA, ppsp->lParam);
  3472. return (CCDBurn*)ppsp->lParam;
  3473. }
  3474. return (CCDBurn*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  3475. }
  3476. HFONT GetIntroFont(HWND hwnd)
  3477. {
  3478. static HFONT _hfontIntro = NULL;
  3479. if (!_hfontIntro)
  3480. {
  3481. TCHAR szBuffer[64];
  3482. NONCLIENTMETRICS ncm = { 0 };
  3483. LOGFONT lf;
  3484. ncm.cbSize = sizeof(ncm);
  3485. SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
  3486. lf = ncm.lfMessageFont;
  3487. LoadString(g_hinst, IDS_BURNWIZ_TITLEFONTNAME, lf.lfFaceName, ARRAYSIZE(lf.lfFaceName));
  3488. lf.lfWeight = FW_BOLD;
  3489. LoadString(g_hinst, IDS_BURNWIZ_TITLEFONTSIZE, szBuffer, ARRAYSIZE(szBuffer));
  3490. lf.lfHeight = 0 - (GetDeviceCaps(NULL, LOGPIXELSY) * StrToInt(szBuffer) / 72);
  3491. _hfontIntro = CreateFontIndirect(&lf);
  3492. }
  3493. return _hfontIntro;
  3494. }
  3495. void CCDBurn::_SetNextPage(HWND hwnd, int iIndex)
  3496. {
  3497. PropSheet_SetCurSel(GetParent(hwnd), _rgWizPages[iIndex], -1);
  3498. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, (LPARAM)-1);
  3499. }
  3500. void CCDBurn::_SetUpStartPage(HWND hwnd)
  3501. {
  3502. TCHAR szDiscLabel[JOLIET_MAX_LABEL + 1];
  3503. szDiscLabel[0] = 0;
  3504. SHPropertyBag_ReadStr(_ppb, PROPSTR_DISCLABEL, szDiscLabel, ARRAYSIZE(szDiscLabel));
  3505. SetDlgItemText(hwnd, IDC_BURNWIZ_DISCLABEL, szDiscLabel);
  3506. Edit_LimitText(GetDlgItem(hwnd, IDC_BURNWIZ_DISCLABEL), JOLIET_MAX_LABEL);
  3507. SHLimitInputEditChars(GetDlgItem(hwnd, IDC_BURNWIZ_DISCLABEL), NULL, INVALID_JOLIETNAME_CHARS);
  3508. BOOL fClose = SHPropertyBag_ReadBOOLDefRet(_ppb, PROPSTR_AUTOCLOSE, FALSE);
  3509. Button_SetCheck(GetDlgItem(hwnd, IDC_BURNWIZ_AUTOCLOSEWIZ), fClose ? BST_CHECKED : BST_UNCHECKED);
  3510. }
  3511. void CCDBurn::_LeaveStartPage(HWND hwnd)
  3512. {
  3513. BOOL fClose = (IsDlgButtonChecked(hwnd, IDC_BURNWIZ_AUTOCLOSEWIZ) == BST_CHECKED);
  3514. SHPropertyBag_WriteBOOL(_ppb, PROPSTR_AUTOCLOSE, fClose);
  3515. DWORD dwClose = fClose;
  3516. SHSetValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_AUTOCLOSE, REG_DWORD, &dwClose, sizeof(dwClose));
  3517. }
  3518. #define CDBURNWM_SHOWSHUTDOWNMESSAGE WM_APP
  3519. LRESULT CALLBACK CCDBurn::_WizSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRefData)
  3520. {
  3521. LRESULT lres;
  3522. switch (uMsg)
  3523. {
  3524. case WM_NCDESTROY:
  3525. // Clean up subclass
  3526. RemoveWindowSubclass(hwnd, _WizSubclassProc, 0);
  3527. lres = DefSubclassProc(hwnd, uMsg, wParam, lParam);
  3528. break;
  3529. case WM_QUERYENDSESSION:
  3530. lres = TRUE;
  3531. if (s_fDriveInUse)
  3532. {
  3533. // post so we return to user quickly
  3534. PostMessage(hwnd, CDBURNWM_SHOWSHUTDOWNMESSAGE, 0, 0);
  3535. // always bail if the drive is in use.
  3536. lres = FALSE;
  3537. }
  3538. break;
  3539. case CDBURNWM_SHOWSHUTDOWNMESSAGE:
  3540. ShellMessageBox(HINST_THISDLL, hwnd, MAKEINTRESOURCE(IDS_BURN_CANTSHUTDOWN), MAKEINTRESOURCE(IDS_BURN),
  3541. MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND);
  3542. lres = TRUE;
  3543. break;
  3544. default:
  3545. lres = DefSubclassProc(hwnd, uMsg, wParam, lParam);
  3546. break;
  3547. }
  3548. return lres;
  3549. }
  3550. void CCDBurn::_SetupFirstPage(HWND hwnd, BOOL fSubclass)
  3551. {
  3552. s_hwndWiz = GetParent(hwnd);
  3553. SendDlgItemMessage(hwnd, IDC_BURNWIZ_TITLE, WM_SETFONT, (WPARAM)GetIntroFont(hwnd), 0);
  3554. if (fSubclass)
  3555. {
  3556. SetWindowSubclass(s_hwndWiz, _WizSubclassProc, 0, 0);
  3557. }
  3558. }
  3559. INT_PTR CCDBurn::_WelcomeDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  3560. {
  3561. BOOL fRet = FALSE;
  3562. switch (uMsg)
  3563. {
  3564. case WM_INITDIALOG:
  3565. _SetupFirstPage(hwnd, TRUE);
  3566. fRet = TRUE;
  3567. break;
  3568. case WM_NOTIFY:
  3569. {
  3570. LPNMHDR pnmh = (LPNMHDR)lParam;
  3571. switch (pnmh->code)
  3572. {
  3573. case PSN_SETACTIVE:
  3574. PropSheet_SetWizButtons(pnmh->hwndFrom, PSWIZB_NEXT);
  3575. _SetUpStartPage(hwnd);
  3576. fRet = TRUE;
  3577. break;
  3578. case PSN_WIZNEXT:
  3579. TCHAR szDiscLabel[JOLIET_MAX_LABEL + 1];
  3580. szDiscLabel[0] = 0;
  3581. // GetDlgItemText helpfully returns 0 for error and 0 for the empty string, so dont use
  3582. // its return value.
  3583. GetDlgItemText(hwnd, IDC_BURNWIZ_DISCLABEL, szDiscLabel, ARRAYSIZE(szDiscLabel));
  3584. SHPropertyBag_WriteStr(_ppb, PROPSTR_DISCLABEL, szDiscLabel);
  3585. _SetNextPage(hwnd, INDEX_DLG_BURNWIZ_WAITFORMEDIA);
  3586. fRet = TRUE;
  3587. break;
  3588. case PSN_KILLACTIVE:
  3589. _LeaveStartPage(hwnd);
  3590. break;
  3591. }
  3592. break;
  3593. }
  3594. }
  3595. return fRet;
  3596. }
  3597. INT_PTR CCDBurn::_StartEraseDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  3598. {
  3599. BOOL fRet = FALSE;
  3600. switch (uMsg)
  3601. {
  3602. case WM_INITDIALOG:
  3603. _SetupFirstPage(hwnd, TRUE);
  3604. fRet = TRUE;
  3605. break;
  3606. case WM_NOTIFY:
  3607. {
  3608. LPNMHDR pnmh = (LPNMHDR)lParam;
  3609. switch (pnmh->code)
  3610. {
  3611. case PSN_SETACTIVE:
  3612. PropSheet_SetWizButtons(pnmh->hwndFrom, PSWIZB_NEXT);
  3613. _SetUpStartPage(hwnd);
  3614. fRet = TRUE;
  3615. break;
  3616. case PSN_WIZNEXT:
  3617. // the erase progress page will almost immediately lock the drive -- this call is for
  3618. // consistency and to set the state variable used in shutdown prevention.
  3619. _LockCurrentDrive(TRUE);
  3620. _SetNextPage(hwnd, INDEX_DLG_BURNWIZ_ERASE_PROGRESS);
  3621. fRet = TRUE;
  3622. break;
  3623. case PSN_KILLACTIVE:
  3624. _LeaveStartPage(hwnd);
  3625. break;
  3626. }
  3627. break;
  3628. }
  3629. }
  3630. return fRet;
  3631. }
  3632. INT_PTR CCDBurn::_EjectDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  3633. {
  3634. BOOL fRet = FALSE;
  3635. switch (uMsg)
  3636. {
  3637. case WM_INITDIALOG:
  3638. _SetupFirstPage(hwnd, TRUE);
  3639. fRet = TRUE;
  3640. break;
  3641. case WM_COMMAND:
  3642. switch (GET_WM_COMMAND_ID(wParam, lParam))
  3643. {
  3644. case IDC_BURNWIZ_BURNDATA:
  3645. case IDC_BURNWIZ_CLEAR:
  3646. case IDC_BURNWIZ_EJECT:
  3647. if (IsDlgButtonChecked(hwnd, IDC_BURNWIZ_BURNDATA) == BST_CHECKED)
  3648. {
  3649. PropSheet_SetWizButtons(GetParent(hwnd), PSWIZB_NEXT);
  3650. }
  3651. else
  3652. {
  3653. PropSheet_SetWizButtons(GetParent(hwnd), PSWIZB_FINISH);
  3654. }
  3655. break;
  3656. }
  3657. break;
  3658. case WM_NOTIFY:
  3659. {
  3660. LPNMHDR pnmh = (LPNMHDR)lParam;
  3661. switch (pnmh->code)
  3662. {
  3663. case PSN_SETACTIVE:
  3664. PropSheet_SetWizButtons(pnmh->hwndFrom, PSWIZB_NEXT);
  3665. _SetUpStartPage(hwnd);
  3666. Button_SetCheck(GetDlgItem(hwnd, IDC_BURNWIZ_BURNDATA), BST_CHECKED);
  3667. fRet = TRUE;
  3668. break;
  3669. case PSN_WIZNEXT:
  3670. {
  3671. TCHAR szDiscLabel[JOLIET_MAX_LABEL + 1];
  3672. if (GetDlgItemText(hwnd, IDC_BURNWIZ_DISCLABEL, szDiscLabel, ARRAYSIZE(szDiscLabel)))
  3673. {
  3674. SHPropertyBag_WriteStr(_ppb, PROPSTR_DISCLABEL, szDiscLabel);
  3675. }
  3676. _SetNextPage(hwnd, INDEX_DLG_BURNWIZ_WAITFORMEDIA);
  3677. fRet = TRUE;
  3678. break;
  3679. }
  3680. case PSN_WIZFINISH:
  3681. if (IsDlgButtonChecked(hwnd, IDC_BURNWIZ_CLEAR) == BST_CHECKED)
  3682. {
  3683. CMINVOKECOMMANDINFO cmi = {0};
  3684. cmi.fMask = CMIC_MASK_FLAG_NO_UI;
  3685. _CleanUp(&cmi, TRUE);
  3686. }
  3687. fRet = TRUE;
  3688. break;
  3689. case PSN_KILLACTIVE:
  3690. _LeaveStartPage(hwnd);
  3691. break;
  3692. }
  3693. break;
  3694. }
  3695. }
  3696. return fRet;
  3697. }
  3698. void CCDBurn::_InitTimeStats(BOOL fErase)
  3699. {
  3700. ZeroMemory(&_ts, sizeof(_ts));
  3701. DWORD cb;
  3702. if (fErase)
  3703. {
  3704. DWORD dwEraseTime;
  3705. cb = sizeof(dwEraseTime);
  3706. if (ERROR_SUCCESS != SHGetValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_ERASETIME, NULL, &dwEraseTime, &cb))
  3707. {
  3708. // default to 3 minutes or so.
  3709. dwEraseTime = 180;
  3710. }
  3711. _ts.dwSecErase = dwEraseTime / _dwCurSpeed;
  3712. _ts.dwSecTotal = _ts.dwSecErase;
  3713. }
  3714. else
  3715. {
  3716. _fRecording = FALSE;
  3717. ULONGLONG ullStageRate;
  3718. cb = sizeof(ullStageRate);
  3719. if ((ERROR_SUCCESS != SHGetValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_STAGERATE, NULL, &ullStageRate, &cb)) ||
  3720. (0 == ullStageRate))
  3721. {
  3722. // default to staging approx. 2MB/s.
  3723. ullStageRate = 2000000;
  3724. }
  3725. _ts.dwSecStaging = (DWORD) (_cbStagedSize / ullStageRate);
  3726. ULONGLONG ullBurnRate;
  3727. cb = sizeof(ullBurnRate);
  3728. if ((ERROR_SUCCESS != SHGetValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_BURNRATE, NULL, &ullBurnRate, &cb)) ||
  3729. (0 == ullBurnRate))
  3730. {
  3731. // default, single speed.
  3732. ullBurnRate = 150000;
  3733. }
  3734. _ts.dwSecBurn = (DWORD) (_cbStagedSize / (ullBurnRate * _dwCurSpeed));
  3735. DWORD dwCloseFactor;
  3736. cb = sizeof(dwCloseFactor);
  3737. if (ERROR_SUCCESS != SHGetValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_CLOSEFACTOR, NULL, &dwCloseFactor, &cb))
  3738. {
  3739. // default to ~2 min, single speed.
  3740. dwCloseFactor = 120;
  3741. }
  3742. _ts.dwSecClose = dwCloseFactor / _dwCurSpeed;
  3743. _ts.dwSecTotal = _ts.dwSecStaging + _ts.dwSecBurn + _ts.dwSecClose;
  3744. }
  3745. if (0 == _ts.dwSecTotal)
  3746. _ts.dwSecTotal = 1;
  3747. _dwLastTime = 0;
  3748. _SetEstimatedTime(_ts.dwSecTotal);
  3749. }
  3750. void CCDBurn::_SaveTimeStats(BOOL fErase)
  3751. {
  3752. if (fErase)
  3753. {
  3754. // if we didnt fill in one of our timing fields, IMAPI called us wrong and we throw out all our data.
  3755. if (_ts.dwTickEraseStart && _ts.dwTickEraseEnd)
  3756. {
  3757. DWORD dwEraseTime = (_ts.dwTickEraseEnd - _ts.dwTickEraseStart) / 1000 * _dwCurSpeed;
  3758. SHSetValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_ERASETIME, REG_DWORD, &dwEraseTime, sizeof(dwEraseTime));
  3759. }
  3760. }
  3761. else
  3762. {
  3763. // if we didnt fill in one of our timing fields, IMAPI called us wrong and we throw out all our data.
  3764. if (_ts.dwTickStagingStart && _ts.dwTickStagingEnd &&
  3765. _ts.dwTickBurnStart && _ts.dwTickBurnEnd &&
  3766. _ts.dwTickCloseStart && _ts.dwTickCloseEnd)
  3767. {
  3768. // only tally results from burns of more than 1MB (arbitrary, but good enough).
  3769. // 1MB is about 8s on a 1x drive and 1s on an 8x drive.
  3770. // the main danger is people burning a few text files that total 1k, then the burn phase takes 1 second
  3771. // (rather, the time between our IMAPI notifications is 1s) and we get stuck with some measly transfer rate
  3772. // that doesnt make any sense and makes the next burn's estimated time up in the gazillions of minutes.
  3773. if (_cbStagedSize > 1000000)
  3774. {
  3775. ULONGLONG ullStageRate = _cbStagedSize * 1000 / (_ts.dwTickStagingEnd - _ts.dwTickStagingStart);
  3776. SHSetValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_STAGERATE, REG_BINARY, &ullStageRate, sizeof(ullStageRate));
  3777. ULONGLONG ullBurnRate = _cbStagedSize * 1000 / (_ts.dwTickBurnEnd - _ts.dwTickBurnStart) / _dwCurSpeed;
  3778. SHSetValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_BURNRATE, REG_BINARY, &ullBurnRate, sizeof(ullBurnRate));
  3779. }
  3780. DWORD dwCloseFactor = (_ts.dwTickCloseEnd - _ts.dwTickCloseStart) / 1000 * _dwCurSpeed;
  3781. SHSetValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_CLOSEFACTOR, REG_DWORD, &dwCloseFactor, sizeof(dwCloseFactor));
  3782. }
  3783. }
  3784. }
  3785. void CCDBurn::_ConstructTimeString(DWORD dwEstTime, LPTSTR psz, UINT cch)
  3786. {
  3787. TCHAR szBuf[100];
  3788. if (dwEstTime >= 60)
  3789. {
  3790. LoadString(HINST_THISDLL, IDS_TIMEEST_MINUTES2, szBuf, ARRAYSIZE(szBuf));
  3791. wnsprintf(psz, cch, szBuf, dwEstTime / 60 + 1);
  3792. }
  3793. else
  3794. {
  3795. LoadString(HINST_THISDLL, IDS_TIMEEST_SECONDS2, szBuf, ARRAYSIZE(szBuf));
  3796. wnsprintf(psz, cch, szBuf, (dwEstTime / 5 + 1) * 5); // round off to 5sec increments
  3797. }
  3798. }
  3799. void CCDBurn::_SetEstimatedTime(DWORD dwSeconds)
  3800. {
  3801. _ts.dwSecRemaining = dwSeconds;
  3802. _dwTimeSet = GetTickCount();
  3803. }
  3804. void CCDBurn::_DisplayEstimatedTime(HWND hwnd)
  3805. {
  3806. if (_ts.dwSecRemaining)
  3807. {
  3808. // we know when we last made an estimate, so show time based on that.
  3809. // however, our estimate could have easily been wrong, so skew it so it never quite reaches 0,
  3810. // and instead sit at a few seconds remaining (hopefully for not too long).
  3811. DWORD dwElapsedTime = (GetTickCount() - _dwTimeSet) / 1000;
  3812. DWORD dwEstTime = 0;
  3813. if (_ts.dwSecRemaining > dwElapsedTime + 5)
  3814. {
  3815. dwEstTime = _ts.dwSecRemaining - dwElapsedTime;
  3816. }
  3817. if (!_dwLastTime || (dwEstTime < _dwLastTime))
  3818. {
  3819. TCHAR szTime[100];
  3820. _ConstructTimeString(dwEstTime, szTime, ARRAYSIZE(szTime));
  3821. SetDlgItemText(hwnd, IDC_BURNWIZ_ESTTIME, szTime);
  3822. SendMessage(GetDlgItem(_hwndWizardPage, IDC_BURNWIZ_PROGRESS), PBM_SETPOS, (WPARAM) (PROGRESS_INCREMENTS * (_ts.dwSecTotal - dwEstTime) / _ts.dwSecTotal), 0);
  3823. _dwLastTime = dwEstTime;
  3824. }
  3825. }
  3826. }
  3827. void CCDBurn::_InitProgressPage(HWND hwnd)
  3828. {
  3829. SendMessage(GetDlgItem(hwnd, IDC_BURNWIZ_PROGRESS), PBM_SETRANGE, (WPARAM)0, MAKELPARAM(0, PROGRESS_INCREMENTS));
  3830. SendMessage(GetDlgItem(hwnd, IDC_BURNWIZ_PROGRESS), PBM_SETPOS, (WPARAM)0, 0);
  3831. SetDlgItemText(hwnd, IDC_BURNWIZ_ESTTIME, L"");
  3832. SetDlgItemText(hwnd, IDC_BURNWIZ_STATUSTEXT, L"");
  3833. }
  3834. #define IDT_SHOWTIME 1
  3835. INT_PTR CCDBurn::_ProgressDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  3836. {
  3837. BOOL fRet = FALSE;
  3838. switch (uMsg)
  3839. {
  3840. case WM_NOTIFY:
  3841. {
  3842. LPNMHDR pnmh = (LPNMHDR)lParam;
  3843. switch (pnmh->code)
  3844. {
  3845. case PSN_SETACTIVE:
  3846. _InitProgressPage(hwnd);
  3847. _hwndWizardPage = hwnd;
  3848. PropSheet_SetWizButtons(pnmh->hwndFrom, 0);
  3849. // start up a timer to periodically refresh the time remaining
  3850. _ts.dwSecRemaining = 0;
  3851. SetTimer(hwnd, IDT_SHOWTIME, 1000, NULL);
  3852. AddRef();
  3853. if (!SHCreateThread(SHPropertyBag_ReadBOOLDefRet(_ppb, PROPSTR_ERASE, FALSE) ? _EraseThread : _BurnThread,
  3854. this, CTF_COINIT, NULL))
  3855. {
  3856. Release();
  3857. }
  3858. fRet = TRUE;
  3859. break;
  3860. case PSN_QUERYCANCEL:
  3861. if (IDYES == ShellMessageBox(HINST_THISDLL, hwnd, MAKEINTRESOURCE(IDS_BURN_CONFIRM_CANCEL), MAKEINTRESOURCE(IDS_BURN),
  3862. MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2))
  3863. {
  3864. _fCancelled = TRUE;
  3865. }
  3866. else
  3867. {
  3868. // TRUE means don't cancel
  3869. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, TRUE);
  3870. fRet = TRUE;
  3871. }
  3872. break;
  3873. case PSN_WIZNEXT:
  3874. _PostOperation();
  3875. fRet = TRUE;
  3876. break;
  3877. case PSN_KILLACTIVE:
  3878. KillTimer(hwnd, IDT_SHOWTIME);
  3879. break;
  3880. }
  3881. break;
  3882. }
  3883. case WM_TIMER:
  3884. switch (wParam)
  3885. {
  3886. case IDT_SHOWTIME:
  3887. _DisplayEstimatedTime(hwnd);
  3888. break;
  3889. }
  3890. break;
  3891. }
  3892. return fRet;
  3893. }
  3894. void CCDBurn::_DisplayMediaErrorOnNext(HWND hwnd, UINT idMsg, UINT idMsgInsert)
  3895. {
  3896. WCHAR sz[100];
  3897. LoadString(HINST_THISDLL, idMsg, sz, ARRAYSIZE(sz));
  3898. SetDlgItemText(hwnd, IDC_BURNWIZ_STATUSTEXT, sz);
  3899. int iIndex;
  3900. if (SUCCEEDED(_GetCurrentDriveIndex(&iIndex)) && PathBuildRoot(sz, iIndex))
  3901. {
  3902. LPWSTR pszInsertDisc = ShellConstructMessageString(HINST_THISDLL, MAKEINTRESOURCE(idMsgInsert), sz);
  3903. if (pszInsertDisc)
  3904. {
  3905. SetDlgItemText(hwnd, IDC_BURNWIZ_PLEASEINSERT, pszInsertDisc);
  3906. LocalFree(pszInsertDisc);
  3907. }
  3908. }
  3909. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, -1);
  3910. }
  3911. // to make the wizard happy, we load all of the extensions' pages at the beginning.
  3912. // however, not all will be used, since some behavior is dependent on the media that's
  3913. // inserted -- which can only be known AFTER _WaitForMediaDlgProc.
  3914. void CCDBurn::_PruneExts()
  3915. {
  3916. IDataObject *pdo;
  3917. if (SUCCEEDED(_CreateDataObject(&pdo)))
  3918. {
  3919. int i = DPA_GetPtrCount(_hdpaExts);
  3920. // count down and remove from the end of the DPA.
  3921. while (i--)
  3922. {
  3923. BOOL fKeep = FALSE;
  3924. IWizardExtension *pwe = (IWizardExtension*)DPA_GetPtr(_hdpaExts, i);
  3925. ASSERT(pwe);
  3926. IDropTarget *pdt;
  3927. if (SUCCEEDED(pwe->QueryInterface(IID_PPV_ARG(IDropTarget, &pdt))))
  3928. {
  3929. DWORD dwEffect;
  3930. POINTL pt = { 0 };
  3931. if (SUCCEEDED(pdt->DragEnter(pdo, 0, pt, &dwEffect)))
  3932. {
  3933. if (DROPEFFECT_NONE != dwEffect)
  3934. {
  3935. fKeep = TRUE;
  3936. }
  3937. pdt->DragLeave();
  3938. }
  3939. pdt->Release();
  3940. }
  3941. if (!fKeep)
  3942. {
  3943. DPA_DeletePtr(_hdpaExts, i);
  3944. IUnknown_SetSite(pwe, NULL);
  3945. pwe->Release();
  3946. }
  3947. }
  3948. pdo->Release();
  3949. }
  3950. }
  3951. // timer for our retries
  3952. #define IDT_CLICKNEXT 1
  3953. INT_PTR CCDBurn::_WaitForMediaDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  3954. {
  3955. BOOL fRet = FALSE;
  3956. switch (uMsg)
  3957. {
  3958. case WM_NOTIFY:
  3959. {
  3960. LPNMHDR pnmh = (LPNMHDR)lParam;
  3961. switch (pnmh->code)
  3962. {
  3963. case PSN_SETACTIVE:
  3964. {
  3965. PropSheet_SetWizButtons(pnmh->hwndFrom, PSWIZB_BACK | PSWIZB_NEXT);
  3966. // kick off a trial to see if media is here already
  3967. PropSheet_PressButton(GetParent(hwnd), PSBTN_NEXT);
  3968. // start up a timer too -- we could also register the window for notification
  3969. // but this is a cheap operation and its less code
  3970. SetTimer(hwnd, IDT_CLICKNEXT, 250, NULL);
  3971. fRet = TRUE;
  3972. }
  3973. break;
  3974. case PSN_WIZBACK:
  3975. _SetNextPage(hwnd, SHPropertyBag_ReadBOOLDefRet(_ppb, PROPSTR_EJECT, FALSE) ? INDEX_DLG_BURNWIZ_EJECT : INDEX_DLG_BURNWIZ_WELCOME);
  3976. fRet = TRUE;
  3977. break;
  3978. case PSN_WIZNEXT:
  3979. {
  3980. // used to check if our media-insert thread is done with using IMAPI.
  3981. DWORD dwDummy, cb = sizeof(dwDummy);
  3982. if (ERROR_SUCCESS == SHGetValue(HKEY_CURRENT_USER, REGSTR_PATH_PERMEDIA, REGVALUE_SET, NULL, &dwDummy, &cb))
  3983. {
  3984. DWORD dwCaps;
  3985. BOOL fUDF;
  3986. if (SUCCEEDED(_GetMediaCapabilities(&dwCaps, &fUDF)) && (dwCaps & HWDMC_CDRECORDABLE) && !fUDF)
  3987. {
  3988. _LockCurrentDrive(TRUE);
  3989. _PruneExts();
  3990. SHPropertyBag_WriteDWORD(_ppb, PROPSTR_CURRENTEXT, 1);
  3991. _SetExtPageFromPropBag(hwnd, TRUE);
  3992. }
  3993. else
  3994. {
  3995. _DisplayMediaErrorOnNext(hwnd, IDS_BURN_FAILURE_MEDIUM_INVALIDTYPE, IDS_BURN_INSERTDISCFULL);
  3996. }
  3997. }
  3998. else
  3999. {
  4000. _DisplayMediaErrorOnNext(hwnd, IDS_BURN_FAILURE_MEDIUM_NOTPRESENT, IDS_BURN_INSERTDISC);
  4001. }
  4002. fRet = TRUE;
  4003. break;
  4004. }
  4005. case PSN_KILLACTIVE:
  4006. KillTimer(hwnd, IDT_CLICKNEXT);
  4007. break;
  4008. }
  4009. break;
  4010. }
  4011. case WM_TIMER:
  4012. switch (wParam)
  4013. {
  4014. case IDT_CLICKNEXT:
  4015. PropSheet_PressButton(GetParent(hwnd), PSBTN_NEXT);
  4016. break;
  4017. }
  4018. break;
  4019. }
  4020. return fRet;
  4021. }
  4022. HRESULT CCDBurn::_PostOperation()
  4023. {
  4024. HRESULT hrOp = E_FAIL;
  4025. DWORD dwHR;
  4026. if (SUCCEEDED(SHPropertyBag_ReadDWORD(_ppb, PROPSTR_HR, &dwHR)))
  4027. {
  4028. hrOp = dwHR;
  4029. }
  4030. if (SHPropertyBag_ReadBOOLDefRet(_ppb, PROPSTR_ERASE, FALSE))
  4031. {
  4032. _SetNextPage(_hwndWizardPage, SUCCEEDED(hrOp) ? INDEX_DLG_BURNWIZ_ERASE_SUCCESS : INDEX_DLG_BURNWIZ_ERASE_FAILURE);
  4033. }
  4034. else
  4035. {
  4036. switch (hrOp)
  4037. {
  4038. case IMAPI_E_DISCFULL:
  4039. {
  4040. TCHAR szDiscFull[200];
  4041. LoadString(HINST_THISDLL, IDS_BURN_DISCFULL, szDiscFull, ARRAYSIZE(szDiscFull));
  4042. SHPropertyBag_WriteStr(_ppb, PROPSTR_DISCFULLTEXT, szDiscFull);
  4043. _SetNextPage(_hwndWizardPage, INDEX_DLG_BURNWIZ_DISCFULL);
  4044. break;
  4045. }
  4046. case IMAPI_E_NOTENOUGHDISKFORSTASH:
  4047. _SetNextPage(_hwndWizardPage, INDEX_DLG_BURNWIZ_HDFULL);
  4048. break;
  4049. case HRESULT_FROM_WIN32(ERROR_DISK_FULL):
  4050. // diskfulltext has already been set by _CheckTotal.
  4051. _SetNextPage(_hwndWizardPage, INDEX_DLG_BURNWIZ_DISCFULL);
  4052. break;
  4053. case IMAPI_E_LOSS_OF_STREAMING:
  4054. {
  4055. // slow down the speed by one step
  4056. TCHAR szVolume[MAX_PATH];
  4057. if (SUCCEEDED(_GetCurrentBurnVolumeName(szVolume, ARRAYSIZE(szVolume))))
  4058. {
  4059. DWORD dwCurSpeed, dwMaxSpeed;
  4060. if (SUCCEEDED(_GetCachedDriveInfo(szVolume, NULL, &dwCurSpeed, &dwMaxSpeed)))
  4061. {
  4062. if (WRITESPEED_FASTEST == dwCurSpeed)
  4063. {
  4064. // if we're set at the fastest speed, tone down to dwMaxSpeed
  4065. dwCurSpeed = dwMaxSpeed;
  4066. }
  4067. DWORD dwNewSpeed = 1;
  4068. // find the highest power of 2 smaller than dwSpeed
  4069. while (dwNewSpeed * 2 < dwCurSpeed)
  4070. {
  4071. dwNewSpeed *= 2;
  4072. }
  4073. _SetCachedDriveInfo(szVolume, DRIVE_USEEXISTING, dwNewSpeed, 0);
  4074. }
  4075. }
  4076. _SetNextPage(_hwndWizardPage, INDEX_DLG_BURNWIZ_BURN_FAILURE);
  4077. break;
  4078. }
  4079. case IMAPI_E_CANNOT_WRITE_TO_MEDIA:
  4080. {
  4081. WCHAR szText[300];
  4082. LoadString(HINST_THISDLL, IDS_BURN_CANTWRITETOMEDIA, szText, ARRAYSIZE(szText));
  4083. SHPropertyBag_WriteStr(_ppb, PROPSTR_STATUSTEXT, szText);
  4084. _SetNextPage(_hwndWizardPage, INDEX_DLG_BURNWIZ_BURN_FAILURE);
  4085. }
  4086. default:
  4087. _SetNextPage(_hwndWizardPage, SUCCEEDED(hrOp) ? INDEX_DLG_BURNWIZ_BURN_SUCCESS : INDEX_DLG_BURNWIZ_BURN_FAILURE);
  4088. break;
  4089. }
  4090. }
  4091. return S_OK;
  4092. }
  4093. HRESULT CCDBurn::_GetBurnHR()
  4094. {
  4095. HRESULT hrBurn = E_FAIL;
  4096. DWORD dwHR;
  4097. if (SUCCEEDED(SHPropertyBag_ReadDWORD(_ppb, PROPSTR_HR, &dwHR)))
  4098. {
  4099. hrBurn = dwHR;
  4100. }
  4101. return hrBurn;
  4102. }
  4103. void CCDBurn::_ShowRoxio()
  4104. {
  4105. SHELLEXECUTEINFO sei = {0};
  4106. sei.cbSize = sizeof(sei);
  4107. sei.lpFile = L"http://go.microsoft.com/fwlink/?LinkId=932"; // http://www.roxio.com/
  4108. ShellExecuteEx(&sei); // fully hardcoded
  4109. }
  4110. INT_PTR CCDBurn::_DoneDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4111. {
  4112. BOOL fRet = FALSE;
  4113. switch (uMsg)
  4114. {
  4115. case WM_INITDIALOG:
  4116. SendDlgItemMessage(hwnd, IDC_BURNWIZ_TITLE, WM_SETFONT, (WPARAM)GetIntroFont(hwnd), 0);
  4117. fRet = TRUE;
  4118. break;
  4119. case WM_COMMAND:
  4120. switch (GET_WM_COMMAND_ID(wParam, lParam))
  4121. {
  4122. case IDC_BURNWIZ_BURNAGAIN:
  4123. case IDC_BURNWIZ_CLEAR:
  4124. case IDC_BURNWIZ_EXIT:
  4125. if (IsDlgButtonChecked(hwnd, IDC_BURNWIZ_BURNAGAIN) == BST_CHECKED)
  4126. {
  4127. PropSheet_SetWizButtons(GetParent(hwnd), PSWIZB_NEXT);
  4128. }
  4129. else
  4130. {
  4131. PropSheet_SetWizButtons(GetParent(hwnd), PSWIZB_FINISH);
  4132. }
  4133. break;
  4134. }
  4135. break;
  4136. case WM_NOTIFY:
  4137. {
  4138. LPNMHDR pnmh = (LPNMHDR)lParam;
  4139. switch (pnmh->code)
  4140. {
  4141. case PSN_SETACTIVE:
  4142. EnableWindow(GetDlgItem(GetParent(hwnd), IDCANCEL), FALSE);
  4143. Button_SetCheck(GetDlgItem(hwnd, IDC_BURNWIZ_BURNAGAIN), BST_UNCHECKED);
  4144. PropSheet_SetWizButtons(pnmh->hwndFrom, PSWIZB_FINISH);
  4145. WCHAR szStatus[300];
  4146. if (SUCCEEDED(SHPropertyBag_ReadStr(_ppb, PROPSTR_STATUSTEXT, szStatus, ARRAYSIZE(szStatus))))
  4147. {
  4148. SetDlgItemText(hwnd, IDC_BURNWIZ_STATUSTEXT, szStatus);
  4149. }
  4150. if (SUCCEEDED(_GetBurnHR()))
  4151. {
  4152. if (SHPropertyBag_ReadBOOLDefRet(_ppb, PROPSTR_AUTOCLOSE, FALSE))
  4153. {
  4154. PropSheet_PressButton(GetParent(hwnd), PSBTN_FINISH);
  4155. }
  4156. }
  4157. else
  4158. {
  4159. Button_SetCheck(GetDlgItem(hwnd, IDC_BURNWIZ_BURNAGAIN), BST_UNCHECKED);
  4160. Button_SetCheck(GetDlgItem(hwnd, IDC_BURNWIZ_CLEAR), BST_UNCHECKED);
  4161. Button_SetCheck(GetDlgItem(hwnd, IDC_BURNWIZ_EXIT), BST_CHECKED);
  4162. if (IMAPI_E_LOSS_OF_STREAMING != _GetBurnHR())
  4163. {
  4164. ShowWindow(GetDlgItem(hwnd, IDC_BURNWIZ_LOWERED), FALSE);
  4165. }
  4166. }
  4167. fRet = TRUE;
  4168. break;
  4169. case PSN_WIZNEXT:
  4170. {
  4171. // dump stored info since we're ejecting
  4172. _DumpDiscInfo();
  4173. // eject media
  4174. int iCurrent;
  4175. if (SUCCEEDED(CCDBurn::_GetCurrentDriveIndex(&iCurrent)))
  4176. {
  4177. CMountPoint *pmtpt = CMountPoint::GetMountPoint(iCurrent);
  4178. if (pmtpt)
  4179. {
  4180. pmtpt->Eject(hwnd);
  4181. pmtpt->Release();
  4182. }
  4183. }
  4184. // go back to the beginning
  4185. EnableWindow(GetDlgItem(GetParent(hwnd), IDCANCEL), TRUE);
  4186. _SetNextPage(hwnd, INDEX_DLG_BURNWIZ_WAITFORMEDIA);
  4187. fRet = TRUE;
  4188. break;
  4189. }
  4190. case PSN_WIZFINISH:
  4191. if (!SHPropertyBag_ReadBOOLDefRet(_ppb, PROPSTR_ERASE, FALSE))
  4192. {
  4193. if (SUCCEEDED(_GetBurnHR()) ||
  4194. (pnmh->code == PSN_WIZFINISH) && (IsDlgButtonChecked(hwnd, IDC_BURNWIZ_CLEAR) == BST_CHECKED))
  4195. {
  4196. // clean up staging area, the files are already on the cd.
  4197. CMINVOKECOMMANDINFO cmi = {0};
  4198. cmi.fMask = CMIC_MASK_FLAG_NO_UI;
  4199. _CleanUp(&cmi, FAILED(_GetBurnHR()));
  4200. }
  4201. }
  4202. fRet = TRUE;
  4203. break;
  4204. case NM_CLICK:
  4205. case NM_RETURN:
  4206. switch (pnmh->idFrom)
  4207. {
  4208. case IDC_BURNWIZ_LOWERED:
  4209. {
  4210. SHELLEXECUTEINFO sei = {0};
  4211. sei.cbSize = sizeof(sei);
  4212. sei.lpFile = L"hcp://services/subsite?node=TopLevelBucket_4/Hardware&topic=MS-ITS%3A%25HELP_LOCATION%25%5Ccdmedia.chm%3A%3A/cdmedia_fail2_moreinfo_buffer_underrun.htm&select=TopLevelBucket_4/Hardware/CDs_and_other_storage_devices";
  4213. ShellExecuteEx(&sei); // fully hardcoded
  4214. fRet = TRUE;
  4215. }
  4216. break;
  4217. case IDC_BURNWIZ_ATTRIB:
  4218. _ShowRoxio();
  4219. fRet = TRUE;
  4220. break;
  4221. }
  4222. break;
  4223. }
  4224. break;
  4225. }
  4226. }
  4227. return fRet;
  4228. }
  4229. INT_PTR CCDBurn::_DiskFullDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4230. {
  4231. BOOL fRet = FALSE;
  4232. switch (uMsg)
  4233. {
  4234. case WM_INITDIALOG:
  4235. SendDlgItemMessage(hwnd, IDC_BURNWIZ_TITLE, WM_SETFONT, (WPARAM)GetIntroFont(hwnd), 0);
  4236. fRet = TRUE;
  4237. break;
  4238. case WM_COMMAND:
  4239. switch (GET_WM_COMMAND_ID(wParam, lParam))
  4240. {
  4241. case IDC_BURNWIZ_BURNAGAIN:
  4242. case IDC_BURNWIZ_EXIT:
  4243. if (IsDlgButtonChecked(hwnd, IDC_BURNWIZ_BURNAGAIN) == BST_CHECKED)
  4244. {
  4245. PropSheet_SetWizButtons(GetParent(hwnd), PSWIZB_NEXT);
  4246. }
  4247. else
  4248. {
  4249. PropSheet_SetWizButtons(GetParent(hwnd), PSWIZB_FINISH);
  4250. }
  4251. break;
  4252. }
  4253. break;
  4254. case WM_NOTIFY:
  4255. {
  4256. LPNMHDR pnmh = (LPNMHDR)lParam;
  4257. switch (pnmh->code)
  4258. {
  4259. case PSN_SETACTIVE:
  4260. {
  4261. EnableWindow(GetDlgItem(GetParent(hwnd), IDCANCEL), FALSE);
  4262. PropSheet_SetWizButtons(pnmh->hwndFrom, PSWIZB_FINISH);
  4263. Button_SetCheck(GetDlgItem(hwnd, IDC_BURNWIZ_BURNAGAIN), BST_UNCHECKED);
  4264. Button_SetCheck(GetDlgItem(hwnd, IDC_BURNWIZ_EXIT), BST_CHECKED);
  4265. TCHAR szText[200];
  4266. if (SUCCEEDED(SHPropertyBag_ReadStr(_ppb, PROPSTR_DISCFULLTEXT, szText, ARRAYSIZE(szText))))
  4267. {
  4268. SetDlgItemText(hwnd, IDC_BURNWIZ_STATUSTEXT, szText);
  4269. }
  4270. fRet = TRUE;
  4271. break;
  4272. }
  4273. case PSN_WIZNEXT:
  4274. EnableWindow(GetDlgItem(GetParent(hwnd), IDCANCEL), TRUE);
  4275. _SetNextPage(hwnd, INDEX_DLG_BURNWIZ_WAITFORMEDIA);
  4276. fRet = TRUE;
  4277. break;
  4278. case NM_CLICK:
  4279. case NM_RETURN:
  4280. if (IDC_BURNWIZ_ATTRIB == pnmh->idFrom)
  4281. {
  4282. _ShowRoxio();
  4283. fRet = TRUE;
  4284. }
  4285. break;
  4286. }
  4287. break;
  4288. }
  4289. }
  4290. return fRet;
  4291. }
  4292. // a stub page just to bail on the wizard when an extension says "dont run any more".
  4293. INT_PTR CCDBurn::_EarlyExitDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4294. {
  4295. BOOL fRet = FALSE;
  4296. switch (uMsg)
  4297. {
  4298. case WM_INITDIALOG:
  4299. PropSheet_PressButton(GetParent(hwnd), PSBTN_CANCEL);
  4300. fRet = TRUE;
  4301. break;
  4302. }
  4303. return fRet;
  4304. }
  4305. void CCDBurn::_HDFullSetText(HWND hwnd)
  4306. {
  4307. TCHAR szStashDrive[4] = {0};
  4308. if (FAILED(_GetCurrentStashDrive(szStashDrive, ARRAYSIZE(szStashDrive))))
  4309. {
  4310. // fall back to temp drive if path doesnt exist in registry
  4311. TCHAR szTempPath[MAX_PATH];
  4312. if (GetTempPath(ARRAYSIZE(szTempPath), szTempPath))
  4313. {
  4314. PathStripToRoot(szTempPath);
  4315. StringCchCopy(szStashDrive, ARRAYSIZE(szStashDrive), szTempPath);
  4316. }
  4317. }
  4318. if (szStashDrive[0])
  4319. {
  4320. LPTSTR pszMessage1 = ShellConstructMessageString(HINST_THISDLL, MAKEINTRESOURCE(IDS_BURN_HDFULL1), szStashDrive);
  4321. if (pszMessage1)
  4322. {
  4323. SetDlgItemText(hwnd, IDC_BURNWIZ_STATUSTEXT, pszMessage1);
  4324. LocalFree(pszMessage1);
  4325. }
  4326. // 50 MB overhead fudge factor. this is the best estimate we have.
  4327. ULONGLONG cbStash = _cbStagedSize + 50 * 1024 * 1024;
  4328. ULARGE_INTEGER ulFree;
  4329. if (SHGetDiskFreeSpaceEx(szStashDrive, &ulFree, NULL, NULL) &&
  4330. (ulFree.QuadPart < cbStash))
  4331. {
  4332. TCHAR szNeed[40], szToDelete[40];
  4333. StrFormatByteSize64(cbStash, szNeed, ARRAYSIZE(szNeed));
  4334. StrFormatByteSize64(cbStash - ulFree.QuadPart, szToDelete, ARRAYSIZE(szToDelete));
  4335. LPTSTR pszMessage2 = ShellConstructMessageString(HINST_THISDLL, MAKEINTRESOURCE(IDS_BURN_HDFULL2), szNeed, szStashDrive, szToDelete);
  4336. if (pszMessage2)
  4337. {
  4338. SetDlgItemText(hwnd, IDC_BURNWIZ_STATUSTEXT2, pszMessage2);
  4339. LocalFree(pszMessage2);
  4340. }
  4341. }
  4342. }
  4343. }
  4344. INT_PTR CCDBurn::_HDFullDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4345. {
  4346. BOOL fRet = FALSE;
  4347. switch (uMsg)
  4348. {
  4349. case WM_INITDIALOG:
  4350. SendDlgItemMessage(hwnd, IDC_BURNWIZ_TITLE, WM_SETFONT, (WPARAM)GetIntroFont(hwnd), 0);
  4351. fRet = TRUE;
  4352. break;
  4353. case WM_NOTIFY:
  4354. {
  4355. LPNMHDR pnmh = (LPNMHDR)lParam;
  4356. switch (pnmh->code)
  4357. {
  4358. case PSN_SETACTIVE:
  4359. {
  4360. EnableWindow(GetDlgItem(GetParent(hwnd), IDCANCEL), FALSE);
  4361. PropSheet_SetWizButtons(pnmh->hwndFrom, PSWIZB_FINISH);
  4362. Button_SetCheck(GetDlgItem(hwnd, IDC_BURNWIZ_CLEAR), BST_UNCHECKED);
  4363. Button_SetCheck(GetDlgItem(hwnd, IDC_BURNWIZ_EXIT), BST_CHECKED);
  4364. _HDFullSetText(hwnd);
  4365. fRet = TRUE;
  4366. break;
  4367. }
  4368. case PSN_WIZFINISH:
  4369. if (IsDlgButtonChecked(hwnd, IDC_BURNWIZ_CLEAR) == BST_CHECKED)
  4370. {
  4371. TCHAR szStash[4];
  4372. if (SUCCEEDED(_GetCurrentStashDrive(szStash, ARRAYSIZE(szStash))))
  4373. {
  4374. LaunchDiskCleanup(NULL, DRIVEID(szStash), DISKCLEANUP_NOFLAG);
  4375. }
  4376. }
  4377. fRet = TRUE;
  4378. break;
  4379. case NM_CLICK:
  4380. case NM_RETURN:
  4381. switch (pnmh->idFrom)
  4382. {
  4383. case IDC_BURNWIZ_STATUSTEXT:
  4384. {
  4385. SHELLEXECUTEINFO sei = {0};
  4386. sei.cbSize = sizeof(sei);
  4387. sei.lpFile = L"hcp://services/subsite?node=TopLevelBucket_4/Hardware&topic=MS-ITS%3A%25HELP_LOCATION%25%5Ccdmedia.chm%3A%3A/cdmedia_fail3_moreinfo_disk_full.htm&select=TopLevelBucket_4/Hardware/CDs_and_other_storage_devices";
  4388. ShellExecuteEx(&sei); // fully hardcoded
  4389. fRet = TRUE;
  4390. }
  4391. break;
  4392. case IDC_BURNWIZ_ATTRIB:
  4393. _ShowRoxio();
  4394. fRet = TRUE;
  4395. break;
  4396. }
  4397. break;
  4398. }
  4399. break;
  4400. }
  4401. }
  4402. return fRet;
  4403. }
  4404. INT_PTR CCDBurn::_NoFilesDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4405. {
  4406. BOOL fRet = FALSE;
  4407. switch (uMsg)
  4408. {
  4409. case WM_INITDIALOG:
  4410. _SetupFirstPage(hwnd, FALSE);
  4411. fRet = TRUE;
  4412. break;
  4413. case WM_NOTIFY:
  4414. {
  4415. LPNMHDR pnmh = (LPNMHDR)lParam;
  4416. switch (pnmh->code)
  4417. {
  4418. case PSN_SETACTIVE:
  4419. {
  4420. EnableWindow(GetDlgItem(GetParent(hwnd), IDCANCEL), FALSE);
  4421. PropSheet_SetWizButtons(pnmh->hwndFrom, PSWIZB_FINISH);
  4422. fRet = TRUE;
  4423. break;
  4424. }
  4425. case PSN_WIZFINISH:
  4426. fRet = TRUE;
  4427. break;
  4428. }
  4429. break;
  4430. }
  4431. }
  4432. return fRet;
  4433. }
  4434. HRESULT CCDBurn::DriveMatches(int iDrive)
  4435. {
  4436. HRESULT hr = E_FAIL;
  4437. // check if the drive index matches what we stored off last time.
  4438. // this lets us keep parsing the drive correctly if its been recently unmounted.
  4439. DWORD dwDrive, cb = sizeof(dwDrive);
  4440. if ((ERROR_SUCCESS == SHGetValue(HKEY_CURRENT_USER, REGSTR_PATH_CDBURNING, REGVALUE_CACHEDINDEX, NULL, &dwDrive, &cb)) &&
  4441. (iDrive == dwDrive))
  4442. {
  4443. hr = S_OK;
  4444. }
  4445. return hr;
  4446. }
  4447. HRESULT CCDBurn::_GetPlainCDPidl(LPITEMIDLIST *ppidl)
  4448. {
  4449. *ppidl = NULL;
  4450. HRESULT hr = E_FAIL;
  4451. WCHAR szDrive[4];
  4452. int iCurrent;
  4453. if (SUCCEEDED(_GetCurrentDriveIndex(&iCurrent)) &&
  4454. PathBuildRoot(szDrive, iCurrent))
  4455. {
  4456. hr = ILCreateFromPathEx(szDrive, NULL, ILCFP_FLAG_SKIPJUNCTIONS, ppidl, NULL);
  4457. }
  4458. return hr;
  4459. }
  4460. HRESULT CCDBurn::Bind(LPCITEMIDLIST pidl, IBindCtx *pbc, REFIID riid, void **ppv)
  4461. {
  4462. IShellFolder *psfStg;
  4463. HRESULT hr = _GetStagingFolder(pidl, IID_PPV_ARG(IShellFolder, &psfStg));
  4464. if (SUCCEEDED(hr))
  4465. {
  4466. IAugmentedShellFolder *pasf;
  4467. hr = SHCoCreateInstance(NULL, &CLSID_CDBurnFolder, NULL, IID_PPV_ARG(IAugmentedShellFolder, &pasf));
  4468. if (SUCCEEDED(hr))
  4469. {
  4470. // initialize with its point in the shell namespace
  4471. // NOTE: worry about IPersistFolder3?
  4472. IPersistFolder *ppf;
  4473. hr = pasf->QueryInterface(IID_PPV_ARG(IPersistFolder, &ppf));
  4474. if (SUCCEEDED(hr))
  4475. {
  4476. hr = ppf->Initialize(pidl);
  4477. ppf->Release();
  4478. }
  4479. if (SUCCEEDED(hr))
  4480. {
  4481. IBindCtx *pbcNoForce;
  4482. if (pbc)
  4483. {
  4484. // tack on to existing bind context if available
  4485. pbcNoForce = pbc;
  4486. pbc->AddRef();
  4487. }
  4488. else
  4489. {
  4490. // otherwise make a new one
  4491. hr = CreateBindCtx(0, &pbcNoForce);
  4492. }
  4493. if (SUCCEEDED(hr))
  4494. {
  4495. // this is the drive shellfolder for cd burning --
  4496. // in this case we want to ensure that new files specified by comdlg are created
  4497. // in the staging area, so we tell the drive shellfolder that it can't
  4498. // succeed on parsedisplayname if the file doesnt exist.
  4499. hr = pbcNoForce->RegisterObjectParam(STR_DONT_FORCE_CREATE, psfStg); // just need a non-null object to register
  4500. if (SUCCEEDED(hr))
  4501. {
  4502. LPITEMIDLIST pidlCD;
  4503. hr = _GetPlainCDPidl(&pidlCD);
  4504. if (SUCCEEDED(hr))
  4505. {
  4506. IShellFolder *psf;
  4507. hr = CFSFolder_CreateFolder(NULL, pbcNoForce, pidlCD, NULL, IID_PPV_ARG(IShellFolder, &psf));
  4508. if (SUCCEEDED(hr))
  4509. {
  4510. hr = pasf->AddNameSpace(&CLSID_CDBurn, psf, NULL, ASFF_COMMON);
  4511. psf->Release();
  4512. }
  4513. ILFree(pidlCD);
  4514. }
  4515. // clean up after ourselves
  4516. pbcNoForce->RevokeObjectParam(STR_DONT_FORCE_CREATE);
  4517. }
  4518. pbcNoForce->Release();
  4519. }
  4520. }
  4521. // lets add the namespace that represents the storage
  4522. if (SUCCEEDED(hr))
  4523. {
  4524. hr = pasf->AddNameSpace(&CLSID_StagingFolder, psfStg, NULL, ASFF_DEFNAMESPACE_ALL);
  4525. }
  4526. // tell the namespace its CLSID so we can get the correct views of the
  4527. // web view etc.
  4528. if (SUCCEEDED(hr))
  4529. {
  4530. IPropertyBag *ppb;
  4531. hr = SHCreatePropertyBagOnMemory(STGM_READWRITE, IID_PPV_ARG(IPropertyBag, &ppb));
  4532. if (SUCCEEDED(hr))
  4533. {
  4534. // store the class ID for the CD mastering folder
  4535. SHPropertyBag_WriteGUID(ppb, L"MergedFolder\\CLSID", &CLSID_CDBurn);
  4536. // store the default effect for this folder.
  4537. SHPropertyBag_WriteInt(ppb, L"MergedFolder\\DropEffect", DROPEFFECT_COPY); // sets the default
  4538. // say it's in a shellview.
  4539. SHPropertyBag_WriteBOOL(ppb, L"MergedFolder\\ShellView", TRUE);
  4540. SHLoadFromPropertyBag(pasf, ppb);
  4541. ppb->Release();
  4542. }
  4543. }
  4544. if (SUCCEEDED(hr))
  4545. hr = pasf->QueryInterface(riid, ppv);
  4546. pasf->Release();
  4547. }
  4548. psfStg->Release();
  4549. }
  4550. return hr;
  4551. }
  4552. // IWizardSite
  4553. // note: these two methods change state -- the alternative is to have the
  4554. // extensions themselves manage which extension goes next. we have to track
  4555. // which extension we're in with state because we dont get ownership of the
  4556. // wizard back until the extensions are done.
  4557. STDMETHODIMP CCDBurn::GetNextPage(HPROPSHEETPAGE *phPage)
  4558. {
  4559. DWORD dwExtNum;
  4560. if (SUCCEEDED(SHPropertyBag_ReadDWORD(_ppb, PROPSTR_CURRENTEXT, &dwExtNum)))
  4561. {
  4562. SHPropertyBag_WriteDWORD(_ppb, PROPSTR_CURRENTEXT, dwExtNum + 1);
  4563. }
  4564. return _GetExtPageFromPropBag(FALSE, phPage);
  4565. }
  4566. STDMETHODIMP CCDBurn::GetPreviousPage(HPROPSHEETPAGE *phPage)
  4567. {
  4568. DWORD dwExtNum;
  4569. if (SUCCEEDED(SHPropertyBag_ReadDWORD(_ppb, PROPSTR_CURRENTEXT, &dwExtNum)))
  4570. {
  4571. SHPropertyBag_WriteDWORD(_ppb, PROPSTR_CURRENTEXT, dwExtNum - 1);
  4572. }
  4573. return _GetExtPageFromPropBag(FALSE, phPage);
  4574. }
  4575. HRESULT CCDBurn::_GetExtPage(int nExt, BOOL fNext, HPROPSHEETPAGE *phpage)
  4576. {
  4577. HRESULT hr = E_FAIL;
  4578. // nExt is 1-based
  4579. IWizardExtension *pwe = (IWizardExtension*)DPA_GetPtr(_hdpaExts, nExt - 1);
  4580. if (pwe)
  4581. {
  4582. if (fNext)
  4583. {
  4584. hr = pwe->GetFirstPage(phpage);
  4585. }
  4586. else
  4587. {
  4588. hr = pwe->GetLastPage(phpage);
  4589. }
  4590. }
  4591. return hr;
  4592. }
  4593. HRESULT CCDBurn::_GetExtPageFromPropBag(BOOL fNext, HPROPSHEETPAGE *phpage)
  4594. {
  4595. HRESULT hr = S_OK;
  4596. *phpage = NULL;
  4597. // an extension could have completed, in which case check its return state to see if
  4598. // we should be running more of them.
  4599. DWORD dwState;
  4600. if (SUCCEEDED(SHPropertyBag_ReadDWORD(_ppb, PROPSTR_EXTENSIONCOMPLETIONSTATE, &dwState)))
  4601. {
  4602. if (dwState & CDBE_RET_STOPWIZARD)
  4603. {
  4604. // leave the wizard.
  4605. *phpage = _rgWizPages[INDEX_DLG_BURNWIZ_EARLYEXIT];
  4606. }
  4607. else if (dwState & CDBE_RET_DONTRUNOTHEREXTS)
  4608. {
  4609. // we're done with extensions, go to the burn.
  4610. *phpage = _rgWizPages[INDEX_DLG_BURNWIZ_BURN_PROGRESS];
  4611. }
  4612. }
  4613. if (!*phpage)
  4614. {
  4615. DWORD dwExt;
  4616. hr = SHPropertyBag_ReadDWORD(_ppb, PROPSTR_CURRENTEXT, &dwExt);
  4617. if (SUCCEEDED(hr))
  4618. {
  4619. if ((int)dwExt > DPA_GetPtrCount(_hdpaExts))
  4620. {
  4621. // we're done with extensions, go to the burn.
  4622. *phpage = _rgWizPages[INDEX_DLG_BURNWIZ_BURN_PROGRESS];
  4623. }
  4624. else if (dwExt == 0)
  4625. {
  4626. // we went 'back' through all extensions, put us at the start page.
  4627. int nIndex = SHPropertyBag_ReadBOOLDefRet(_ppb, PROPSTR_ERASE, FALSE) ? INDEX_DLG_BURNWIZ_STARTERASE : INDEX_DLG_BURNWIZ_WELCOME;
  4628. *phpage = _rgWizPages[nIndex];
  4629. }
  4630. else
  4631. {
  4632. hr = _GetExtPage(dwExt, fNext, phpage);
  4633. }
  4634. }
  4635. }
  4636. return hr;
  4637. }
  4638. void CCDBurn::_SetExtPageFromPropBag(HWND hwnd, BOOL fNext)
  4639. {
  4640. HPROPSHEETPAGE hpage;
  4641. if (SUCCEEDED(_GetExtPageFromPropBag(fNext, &hpage)))
  4642. {
  4643. PropSheet_SetCurSel(GetParent(hwnd), hpage, -1);
  4644. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, (LPARAM)-1);
  4645. }
  4646. }
  4647. HRESULT CCDBurn::_TryCLSID(REFCLSID clsid, DWORD dwExtType, REFIID riid, void **ppv)
  4648. {
  4649. *ppv = NULL;
  4650. ICDBurnExt *pcdbe;
  4651. // Use SHExtCoCreateInstance to go through approval checking and app compat checking
  4652. HRESULT hr = SHExtCoCreateInstance2(NULL, &clsid, NULL, CLSCTX_ALL, IID_PPV_ARG(ICDBurnExt, &pcdbe));
  4653. if (SUCCEEDED(hr))
  4654. {
  4655. DWORD dw;
  4656. hr = pcdbe->GetSupportedActionTypes(&dw);
  4657. if (SUCCEEDED(hr))
  4658. {
  4659. if (dw & dwExtType)
  4660. {
  4661. hr = pcdbe->QueryInterface(riid, ppv);
  4662. }
  4663. else
  4664. {
  4665. hr = E_NOTIMPL;
  4666. }
  4667. }
  4668. pcdbe->Release();
  4669. }
  4670. ASSERT(SUCCEEDED(hr) ? (*ppv != NULL) : (*ppv == NULL));
  4671. return hr;
  4672. }
  4673. HRESULT CCDBurn::_TryKey(LPTSTR pszKey, DWORD dwExtType, REFIID riid, void **ppv)
  4674. {
  4675. HRESULT hr = E_FAIL;
  4676. *ppv = NULL;
  4677. TCHAR szFullKey[MAX_PATH];
  4678. lstrcpyn(szFullKey, REGSTR_PATH_HANDLERS, ARRAYSIZE(szFullKey));
  4679. PathAppend(szFullKey, pszKey);
  4680. TCHAR szCLSID[MAX_GUID_STRING_LEN];
  4681. DWORD cbCLSID = sizeof(szCLSID);
  4682. CLSID clsid;
  4683. if ((ERROR_SUCCESS == SHRegGetUSValue(szFullKey, REGVALUE_CLSID, NULL, szCLSID, &cbCLSID, FALSE, NULL, 0)) &&
  4684. GUIDFromString(szCLSID, &clsid))
  4685. {
  4686. hr = _TryCLSID(clsid, dwExtType, riid, ppv);
  4687. }
  4688. ASSERT(SUCCEEDED(hr) ? (*ppv != NULL) : (*ppv == NULL));
  4689. return hr;
  4690. }
  4691. HRESULT CCDBurn::_TestDropEffect(IDropTarget *pdt, IDataObject *pdo, REFIID riid, void **ppv)
  4692. {
  4693. *ppv = NULL;
  4694. DWORD dwEffect;
  4695. POINTL pt = {0};
  4696. HRESULT hr = pdt->DragEnter(pdo, 0, pt, &dwEffect);
  4697. if (SUCCEEDED(hr))
  4698. {
  4699. if (dwEffect != DROPEFFECT_NONE)
  4700. {
  4701. hr = pdt->QueryInterface(riid, ppv);
  4702. }
  4703. else
  4704. {
  4705. hr = E_FAIL;
  4706. }
  4707. pdt->DragLeave();
  4708. }
  4709. ASSERT(SUCCEEDED(hr) ? (*ppv != NULL) : (*ppv == NULL));
  4710. return hr;
  4711. }
  4712. HRESULT CCDBurn::_TryKeyWithDropEffect(LPTSTR pszKey, DWORD dwExtType, IDataObject *pdo, REFIID riid, void **ppv)
  4713. {
  4714. *ppv = NULL;
  4715. IDropTarget *pdt;
  4716. HRESULT hr = _TryKey(pszKey, dwExtType, IID_PPV_ARG(IDropTarget, &pdt));
  4717. if (SUCCEEDED(hr))
  4718. {
  4719. hr = _TestDropEffect(pdt, pdo, riid, ppv);
  4720. pdt->Release();
  4721. }
  4722. ASSERT(SUCCEEDED(hr) ? (*ppv != NULL) : (*ppv == NULL));
  4723. return hr;
  4724. }
  4725. HRESULT CCDBurn::_TryCLSIDWithDropEffect(REFCLSID clsid, DWORD dwExtType, IDataObject *pdo, REFIID riid, void **ppv)
  4726. {
  4727. *ppv = NULL;
  4728. IDropTarget *pdt;
  4729. HRESULT hr = _TryCLSID(clsid, dwExtType, IID_PPV_ARG(IDropTarget, &pdt));
  4730. if (SUCCEEDED(hr))
  4731. {
  4732. hr = _TestDropEffect(pdt, pdo, riid, ppv);
  4733. pdt->Release();
  4734. }
  4735. ASSERT(SUCCEEDED(hr) ? (*ppv != NULL) : (*ppv == NULL));
  4736. return hr;
  4737. }
  4738. void CCDBurn::_AddExtensionToDPA(IWizardExtension *pwe, HPROPSHEETPAGE *rgPages, UINT cNumPages, UINT *pcPagesAdded)
  4739. {
  4740. IUnknown_SetSite(pwe, SAFECAST(this, IWizardSite *));
  4741. BOOL fAdded = FALSE;
  4742. UINT cExtPages;
  4743. if (SUCCEEDED(pwe->AddPages(rgPages + *pcPagesAdded, cNumPages - *pcPagesAdded, &cExtPages)) && cExtPages)
  4744. {
  4745. if (-1 != DPA_AppendPtr(_hdpaExts, pwe))
  4746. {
  4747. fAdded = TRUE;
  4748. *pcPagesAdded += cExtPages;
  4749. pwe->AddRef();
  4750. }
  4751. else
  4752. {
  4753. for (UINT i = 0; i < cExtPages; i++)
  4754. {
  4755. DestroyPropertySheetPage(rgPages[*pcPagesAdded + i]);
  4756. }
  4757. }
  4758. }
  4759. if (!fAdded)
  4760. {
  4761. // if it's in the dpa, it gets the setsite(NULL) later.
  4762. IUnknown_SetSite(pwe, NULL);
  4763. }
  4764. }
  4765. // does the enumRegFlags == SHREGENUM_BOTH case.
  4766. DWORD MySHRegEnumUSKey(HUSKEY hUSKey, DWORD dwIndex, LPWSTR pszName, DWORD *pcchName)
  4767. {
  4768. // start with HKCU if possible.
  4769. DWORD cKeys;
  4770. DWORD dwRet = SHRegQueryInfoUSKey(hUSKey, &cKeys, NULL, NULL, NULL, SHREGENUM_HKCU);
  4771. if (ERROR_SUCCESS == dwRet)
  4772. {
  4773. // HKCU is present.
  4774. if (dwIndex < cKeys)
  4775. {
  4776. // enum from HKCU first
  4777. dwRet = SHRegEnumUSKey(hUSKey, dwIndex, pszName, pcchName, SHREGENUM_HKCU);
  4778. }
  4779. else
  4780. {
  4781. // and next, HKLM
  4782. dwRet = SHRegEnumUSKey(hUSKey, dwIndex - cKeys, pszName, pcchName, SHREGENUM_HKLM);
  4783. }
  4784. }
  4785. else
  4786. {
  4787. // go only with HKLM.
  4788. dwRet = SHRegEnumUSKey(hUSKey, dwIndex, pszName, pcchName, SHREGENUM_HKLM);
  4789. }
  4790. return dwRet;
  4791. }
  4792. HRESULT CCDBurn::_FillExtensionDPA(HPROPSHEETPAGE *rgPages, UINT cNumPages, UINT *pcPagesAdded)
  4793. {
  4794. _hdpaExts = DPA_Create(4);
  4795. HRESULT hr = _hdpaExts ? S_OK : E_OUTOFMEMORY;
  4796. if (SUCCEEDED(hr))
  4797. {
  4798. *pcPagesAdded = 0;
  4799. // first up is the burn audio cd extension
  4800. IWizardExtension *pwe;
  4801. if (SUCCEEDED(_TryCLSID(CLSID_BurnAudioCDExtension, CDBE_TYPE_ALL, IID_PPV_ARG(IWizardExtension, &pwe))))
  4802. {
  4803. _AddExtensionToDPA(pwe, rgPages, cNumPages, pcPagesAdded);
  4804. pwe->Release();
  4805. }
  4806. HUSKEY huskeyHandlers;
  4807. if (ERROR_SUCCESS == SHRegOpenUSKey(REGSTR_PATH_HANDLERS, KEY_READ, NULL, &huskeyHandlers, FALSE))
  4808. {
  4809. DWORD dwIndex = 0;
  4810. TCHAR szKey[50];
  4811. DWORD cchKey = ARRAYSIZE(szKey);
  4812. while (ERROR_SUCCESS == SHRegEnumUSKey(huskeyHandlers, dwIndex, szKey, &cchKey, SHREGENUM_DEFAULT))
  4813. {
  4814. if (SUCCEEDED(_TryKey(szKey, CDBE_TYPE_ALL, IID_PPV_ARG(IWizardExtension, &pwe))))
  4815. {
  4816. _AddExtensionToDPA(pwe, rgPages, cNumPages, pcPagesAdded);
  4817. pwe->Release();
  4818. }
  4819. dwIndex++;
  4820. cchKey = ARRAYSIZE(szKey);
  4821. }
  4822. SHRegCloseUSKey(huskeyHandlers);
  4823. }
  4824. }
  4825. return hr;
  4826. }
  4827. HRESULT CDBurn_GetExtensionObject(DWORD dwExtType, IDataObject *pdo, REFIID riid, void **ppv)
  4828. {
  4829. *ppv = NULL;
  4830. TCHAR szDefault[50];
  4831. DWORD cb = sizeof(szDefault);
  4832. HRESULT hr = (ERROR_SUCCESS == SHRegGetUSValue(REGSTR_PATH_HANDLERS, REGVALUE_FIRSTHANDLER,
  4833. NULL, szDefault, &cb, FALSE, NULL, 0)) ? S_OK : E_FAIL;
  4834. if (SUCCEEDED(hr))
  4835. {
  4836. hr = CCDBurn::_TryKeyWithDropEffect(szDefault, dwExtType, pdo, riid, ppv);
  4837. }
  4838. else
  4839. {
  4840. szDefault[0] = 0;
  4841. }
  4842. // if we're not overridden by the FIRSTHANDLER value, try the burn audio cd extension.
  4843. if (FAILED(hr))
  4844. {
  4845. hr = CCDBurn::_TryCLSIDWithDropEffect(CLSID_BurnAudioCDExtension, dwExtType, pdo, riid, ppv);
  4846. }
  4847. if (FAILED(hr))
  4848. {
  4849. HUSKEY huskeyHandlers;
  4850. if (ERROR_SUCCESS == SHRegOpenUSKey(REGSTR_PATH_HANDLERS, KEY_READ, NULL, &huskeyHandlers, FALSE))
  4851. {
  4852. DWORD dwIndex = 0;
  4853. TCHAR szKey[50];
  4854. DWORD cchKey = ARRAYSIZE(szKey);
  4855. while (FAILED(hr) && (ERROR_SUCCESS == MySHRegEnumUSKey(huskeyHandlers, dwIndex, szKey, &cchKey)))
  4856. {
  4857. if (StrCmpI(szDefault, szKey) != 0)
  4858. {
  4859. hr = CCDBurn::_TryKeyWithDropEffect(szKey, dwExtType, pdo, riid, ppv);
  4860. }
  4861. dwIndex++;
  4862. cchKey = ARRAYSIZE(szKey);
  4863. }
  4864. SHRegCloseUSKey(huskeyHandlers);
  4865. }
  4866. }
  4867. return hr;
  4868. }
  4869. STDMETHODIMP CCDBurn::QueryService(REFGUID guidService, REFIID riid, void **ppv)
  4870. {
  4871. *ppv = NULL;
  4872. HRESULT hr = E_FAIL;
  4873. if (IsEqualGUID(guidService, SID_CDWizardHost))
  4874. {
  4875. if (IsEqualIID(riid, IID_IPropertyBag) && _ppb)
  4876. {
  4877. hr = _ppb->QueryInterface(riid, ppv);
  4878. }
  4879. }
  4880. return hr;
  4881. }
  4882. STDMETHODIMP CCDBurn::AllowAutoPlay(LPCWSTR pszPath, DWORD dwContentType, LPCWSTR pszLabel, DWORD dwSerialNumber)
  4883. {
  4884. HRESULT hr = S_OK; // default to allow autoplay
  4885. int iDrive;
  4886. if (SUCCEEDED(_GetCurrentDriveIndex(&iDrive)) &&
  4887. (iDrive == DRIVEID(pszPath)))
  4888. {
  4889. // while we're registered in the running object table the wizard is always running, so dont autoplay.
  4890. hr = S_FALSE;
  4891. }
  4892. return hr;
  4893. }
  4894. HRESULT CCDBurn::ConfirmOperation(IShellItem *psiSource, IShellItem *psiDest, STGTRANSCONFIRMATION stc, LPCUSTOMCONFIRMATION pcc)
  4895. {
  4896. HRESULT hr = STRESPONSE_CONTINUE; // use default postop handling.
  4897. // null psiitem means this is postop for the entire operation.
  4898. if (psiSource && IsEqualGUID(STCONFIRM_ACCESS_DENIED, stc))
  4899. {
  4900. DWORD dwCaps;
  4901. BOOL fUDF;
  4902. if (SUCCEEDED(_GetMediaCapabilities(&dwCaps, &fUDF)) && fUDF)
  4903. {
  4904. int id = (dwCaps & HWDMC_CDREWRITABLE) ? IDS_BURN_CANTWRITEMEDIACDRW : IDS_BURN_CANTWRITEMEDIACDR;
  4905. ShellMessageBox(HINST_THISDLL, NULL, MAKEINTRESOURCE(id),
  4906. MAKEINTRESOURCE(IDS_BURN), MB_OK | MB_ICONSTOP);
  4907. hr = E_FAIL; // stop the operation
  4908. }
  4909. }
  4910. return hr;
  4911. }
  4912. typedef struct
  4913. {
  4914. WCHAR szExts[MAX_PATH]; // PathMatchSpec list ("*.wma;*.mp3")
  4915. } FILE_EXTS;
  4916. // handles the audio cd burner extensions
  4917. class CBurnAudioCDExtension : public CObjectWithSite,
  4918. public ICDBurnExt,
  4919. public IDropTarget,
  4920. public IWizardExtension,
  4921. public INamespaceWalkCB
  4922. {
  4923. public:
  4924. // IUnknown methods
  4925. STDMETHOD(QueryInterface)(REFIID riid, void **ppvObj);
  4926. STDMETHOD_(ULONG, AddRef)();
  4927. STDMETHOD_(ULONG, Release)();
  4928. // ICDBurnExt methods
  4929. STDMETHOD(GetSupportedActionTypes)(DWORD *pdwActions);
  4930. // IDropTarget methods
  4931. STDMETHOD(DragEnter)(IDataObject *pdtobj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
  4932. STDMETHOD(DragOver)(DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
  4933. { return E_NOTIMPL; }
  4934. STDMETHOD(DragLeave)(void)
  4935. { return E_NOTIMPL; }
  4936. STDMETHOD(Drop)(IDataObject *pdtobj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
  4937. // IWizardExtension
  4938. STDMETHOD(AddPages)(HPROPSHEETPAGE *aPages, UINT cPages, UINT *pnPages);
  4939. STDMETHOD(GetFirstPage)(HPROPSHEETPAGE *phPage);
  4940. STDMETHOD(GetLastPage)(HPROPSHEETPAGE *phPage);
  4941. // INamespaceWalkCB
  4942. STDMETHOD(FoundItem)(IShellFolder *psf, LPCITEMIDLIST pidl);
  4943. STDMETHOD(EnterFolder)(IShellFolder *psf, LPCITEMIDLIST pidl)
  4944. { return S_OK; }
  4945. STDMETHOD(LeaveFolder)(IShellFolder *psf, LPCITEMIDLIST pidl)
  4946. { return S_OK; }
  4947. STDMETHOD(InitializeProgressDialog)(LPWSTR *ppszTitle, LPWSTR *ppszCancel)
  4948. { *ppszTitle = NULL; *ppszCancel = NULL; return E_NOTIMPL; }
  4949. static INT_PTR s_MusicDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4950. { CBurnAudioCDExtension *pwe = s_GetBurnAudioCDExtension(hwnd, uMsg, lParam); return pwe->_MusicDlgProc(hwnd, uMsg, wParam, lParam); }
  4951. private:
  4952. CBurnAudioCDExtension();
  4953. ~CBurnAudioCDExtension();
  4954. LONG _cRef;
  4955. DWORD _cFiles, _cAudioFiles, _cNonAudioFiles; // state vars for walk callback
  4956. BOOL _fBreakOnNonAudioFiles;
  4957. HPROPSHEETPAGE _hpage;
  4958. BOOL _fSelectMusic;
  4959. HDSA _hdsaExtensions; // bunch of FILE_EXTS. we keep them individually for each extension and don't strcat them all
  4960. // together so if one registry entry is hopelessly bad it wont hurt everyone else.
  4961. // hook stuff
  4962. void _AddFileExtsForCLSID(REFCLSID clsid);
  4963. void _AddFileExtsForKey(PCWSTR pszKey);
  4964. void _AddAllExts();
  4965. BOOL _HasAudioExtension(LPCTSTR pszName);
  4966. BOOL _DataObjectHasAllAudioFiles(IDataObject *pdo);
  4967. DWORD _CountOfAudioFilesForHandler(IDataObject *pdo, REFCLSID clsid);
  4968. CLSID _GetDefaultCLSID();
  4969. HRESULT _GetVerbForCLSID(REFCLSID clsid, PWSTR psz, UINT cch);
  4970. BOOL _CanCreate(REFCLSID clsid);
  4971. HRESULT _DropOnHandler(REFCLSID clsid, IDataObject *pdo);
  4972. HRESULT _PickHandler(IDataObject *pdo, CLSID *pclsid);
  4973. // wizard page
  4974. static CBurnAudioCDExtension* s_GetBurnAudioCDExtension(HWND hwnd, UINT uMsg, LPARAM lParam);
  4975. INT_PTR _MusicDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  4976. void _SetCompletionState();
  4977. // "exports"
  4978. friend HRESULT CBurnAudioCDExtension_CreateInstance(IUnknown* punkOuter, REFIID riid, void **ppv);
  4979. };
  4980. CBurnAudioCDExtension::CBurnAudioCDExtension() :
  4981. _cRef(1)
  4982. {
  4983. _fSelectMusic = TRUE;
  4984. }
  4985. CBurnAudioCDExtension::~CBurnAudioCDExtension()
  4986. {
  4987. ASSERT(!_punkSite);
  4988. DSA_Destroy(_hdsaExtensions);
  4989. }
  4990. // IUnknown
  4991. STDMETHODIMP_(ULONG) CBurnAudioCDExtension::AddRef()
  4992. {
  4993. return InterlockedIncrement(&_cRef);
  4994. }
  4995. STDMETHODIMP_(ULONG) CBurnAudioCDExtension::Release()
  4996. {
  4997. ASSERT(0 != _cRef);
  4998. ULONG cRef = InterlockedDecrement(&_cRef);
  4999. if (0 == cRef)
  5000. {
  5001. delete this;
  5002. }
  5003. return cRef;
  5004. }
  5005. HRESULT CBurnAudioCDExtension::QueryInterface(REFIID riid, void **ppv)
  5006. {
  5007. static const QITAB qit[] =
  5008. {
  5009. QITABENT(CBurnAudioCDExtension, ICDBurnExt),
  5010. QITABENT(CBurnAudioCDExtension, IDropTarget),
  5011. QITABENT(CBurnAudioCDExtension, IWizardExtension),
  5012. QITABENT(CBurnAudioCDExtension, IObjectWithSite),
  5013. QITABENT(CBurnAudioCDExtension, INamespaceWalkCB),
  5014. { 0 },
  5015. };
  5016. return QISearch(this, qit, riid, ppv);
  5017. }
  5018. STDAPI CBurnAudioCDExtension_CreateInstance(IUnknown* punkOuter, REFIID riid, void **ppv)
  5019. {
  5020. if (punkOuter)
  5021. return CLASS_E_NOAGGREGATION;
  5022. CBurnAudioCDExtension *pbe = new CBurnAudioCDExtension();
  5023. if (!pbe)
  5024. return E_OUTOFMEMORY;
  5025. HRESULT hr = pbe->QueryInterface(riid, ppv);
  5026. pbe->Release();
  5027. return hr;
  5028. }
  5029. CBurnAudioCDExtension* CBurnAudioCDExtension::s_GetBurnAudioCDExtension(HWND hwnd, UINT uMsg, LPARAM lParam)
  5030. {
  5031. if (uMsg == WM_INITDIALOG)
  5032. {
  5033. PROPSHEETPAGE *ppsp = (PROPSHEETPAGE*)lParam;
  5034. SetWindowLongPtr(hwnd, GWLP_USERDATA, ppsp->lParam);
  5035. return (CBurnAudioCDExtension*)ppsp->lParam;
  5036. }
  5037. return (CBurnAudioCDExtension*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  5038. }
  5039. HRESULT CBurnAudioCDExtension::GetSupportedActionTypes(DWORD *pdwActions)
  5040. {
  5041. *pdwActions = CDBE_TYPE_MUSIC;
  5042. return S_OK;
  5043. }
  5044. void CBurnAudioCDExtension::_AddFileExtsForKey(PCWSTR pszKey)
  5045. {
  5046. ASSERT(_hdsaExtensions);
  5047. FILE_EXTS fileexts;
  5048. DWORD cb = sizeof(fileexts.szExts);
  5049. if (ERROR_SUCCESS == SHRegGetUSValue(pszKey, REGVALUE_FILEEXTS, NULL, fileexts.szExts, &cb, FALSE, NULL, 0))
  5050. {
  5051. DSA_AppendItem(_hdsaExtensions, &fileexts);
  5052. }
  5053. }
  5054. void CBurnAudioCDExtension::_AddFileExtsForCLSID(REFCLSID clsid)
  5055. {
  5056. ASSERT(_hdsaExtensions);
  5057. if (_CanCreate(clsid))
  5058. {
  5059. WCHAR szCLSID[GUIDSTR_MAX];
  5060. SHStringFromGUID(clsid, szCLSID, ARRAYSIZE(szCLSID));
  5061. WCHAR szExtKey[MAX_PATH];
  5062. StrCpyN(szExtKey, REGSTR_PATH_AUDIOEXTS, ARRAYSIZE(szExtKey));
  5063. PathAppend(szExtKey, szCLSID);
  5064. _AddFileExtsForKey(szExtKey);
  5065. }
  5066. }
  5067. void CBurnAudioCDExtension::_AddAllExts()
  5068. {
  5069. HUSKEY huskeyExts;
  5070. if (ERROR_SUCCESS == SHRegOpenUSKey(REGSTR_PATH_AUDIOEXTS, KEY_READ, NULL, &huskeyExts, FALSE))
  5071. {
  5072. DWORD dwIndex = 0;
  5073. WCHAR szCLSID[GUIDSTR_MAX];
  5074. DWORD cchCLSID = ARRAYSIZE(szCLSID);
  5075. while (ERROR_SUCCESS == MySHRegEnumUSKey(huskeyExts, dwIndex, szCLSID, &cchCLSID))
  5076. {
  5077. CLSID clsid;
  5078. if (GUIDFromString(szCLSID, &clsid))
  5079. {
  5080. _AddFileExtsForCLSID(clsid);
  5081. }
  5082. cchCLSID = ARRAYSIZE(szCLSID);
  5083. dwIndex++;
  5084. }
  5085. SHRegCloseUSKey(huskeyExts);
  5086. }
  5087. }
  5088. BOOL CBurnAudioCDExtension::_HasAudioExtension(LPCTSTR pszName)
  5089. {
  5090. // this list of extensions is based on what files the extension can BURN, not just play.
  5091. // (so we cant do a check for generic audio type.)
  5092. BOOL fRet = FALSE;
  5093. if (_hdsaExtensions)
  5094. {
  5095. for (int i = 0; !fRet && (i < DSA_GetItemCount(_hdsaExtensions)); i++)
  5096. {
  5097. FILE_EXTS *pfileexts = (FILE_EXTS *)DSA_GetItemPtr(_hdsaExtensions, i);
  5098. fRet = PathMatchSpec(pszName, pfileexts->szExts);
  5099. }
  5100. }
  5101. return fRet;
  5102. }
  5103. HRESULT CBurnAudioCDExtension::FoundItem(IShellFolder *psf, LPCITEMIDLIST pidl)
  5104. {
  5105. // early-out if we are checking that ALL files are audio files and we've found one that's not.
  5106. if (_fBreakOnNonAudioFiles && (_cNonAudioFiles > 0))
  5107. return E_FAIL;
  5108. // break if we've seen enough files.
  5109. if (_cFiles > 50)
  5110. return E_FAIL;
  5111. _cFiles++;
  5112. TCHAR szName[MAX_PATH];
  5113. HRESULT hr = DisplayNameOf(psf, pidl, SHGDN_INFOLDER | SHGDN_FORPARSING, szName, ARRAYSIZE(szName));
  5114. if (SUCCEEDED(hr))
  5115. {
  5116. if (_HasAudioExtension(szName))
  5117. {
  5118. _cAudioFiles++;
  5119. }
  5120. else
  5121. {
  5122. _cNonAudioFiles++;
  5123. }
  5124. }
  5125. return hr;
  5126. }
  5127. BOOL CBurnAudioCDExtension::_DataObjectHasAllAudioFiles(IDataObject *pdo)
  5128. {
  5129. _cFiles = _cAudioFiles = _cNonAudioFiles = 0;
  5130. _fBreakOnNonAudioFiles = TRUE;
  5131. if (_hdsaExtensions)
  5132. DSA_Destroy(_hdsaExtensions);
  5133. _hdsaExtensions = DSA_Create(sizeof(FILE_EXTS), 4);
  5134. if (_hdsaExtensions)
  5135. {
  5136. _AddAllExts();
  5137. INamespaceWalk *pnsw;
  5138. if (SUCCEEDED(CoCreateInstance(CLSID_NamespaceWalker, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(INamespaceWalk, &pnsw))))
  5139. {
  5140. pnsw->Walk(pdo, NSWF_DONT_ACCUMULATE_RESULT, 4, this);
  5141. pnsw->Release();
  5142. }
  5143. }
  5144. return ((_cFiles > 0) && (_cNonAudioFiles == 0));
  5145. }
  5146. DWORD CBurnAudioCDExtension::_CountOfAudioFilesForHandler(IDataObject *pdo, REFCLSID clsid)
  5147. {
  5148. _cFiles = _cAudioFiles = _cNonAudioFiles = 0;
  5149. if (pdo)
  5150. {
  5151. _fBreakOnNonAudioFiles = FALSE;
  5152. if (_hdsaExtensions)
  5153. DSA_Destroy(_hdsaExtensions);
  5154. _hdsaExtensions = DSA_Create(sizeof(FILE_EXTS), 4);
  5155. if (_hdsaExtensions)
  5156. {
  5157. _AddFileExtsForCLSID(clsid);
  5158. INamespaceWalk *pnsw;
  5159. if (SUCCEEDED(CoCreateInstance(CLSID_NamespaceWalker, NULL, CLSCTX_INPROC, IID_PPV_ARG(INamespaceWalk, &pnsw))))
  5160. {
  5161. pnsw->Walk(pdo, NSWF_DONT_ACCUMULATE_RESULT, 4, this);
  5162. pnsw->Release();
  5163. }
  5164. }
  5165. }
  5166. else
  5167. {
  5168. // if we're not given a data object, we're being polled just to see if we can create
  5169. if (_CanCreate(clsid))
  5170. {
  5171. _cAudioFiles = 1;
  5172. }
  5173. }
  5174. return _cAudioFiles;
  5175. }
  5176. BOOL CBurnAudioCDExtension::_CanCreate(REFCLSID clsid)
  5177. {
  5178. // Use SHExtCoCreateInstance to go through approval checking and app compat checking
  5179. IUnknown *punk;
  5180. HRESULT hr = SHExtCoCreateInstance2(NULL, &clsid, NULL, CLSCTX_ALL, IID_PPV_ARG(IUnknown, &punk));
  5181. if (SUCCEEDED(hr))
  5182. {
  5183. punk->Release();
  5184. }
  5185. return SUCCEEDED(hr);
  5186. }
  5187. // if pdo is NULL, only test which extensions can be cocreated.
  5188. HRESULT CBurnAudioCDExtension::_PickHandler(IDataObject *pdo, CLSID *pclsid)
  5189. {
  5190. HRESULT hr;
  5191. *pclsid = _GetDefaultCLSID();
  5192. if (_CountOfAudioFilesForHandler(pdo, *pclsid) > 0)
  5193. {
  5194. // if the default handler supports any of the files, let it take over and we're done.
  5195. hr = S_OK;
  5196. }
  5197. else
  5198. {
  5199. hr = E_FAIL;
  5200. CLSID clsidBestSoFar;
  5201. DWORD dwCountBestSoFar = 0;
  5202. HUSKEY huskeyExts;
  5203. if (ERROR_SUCCESS == SHRegOpenUSKey(REGSTR_PATH_AUDIOEXTS, KEY_READ, NULL, &huskeyExts, FALSE))
  5204. {
  5205. DWORD dwIndex = 0;
  5206. WCHAR szCLSID[GUIDSTR_MAX];
  5207. DWORD cchKey = ARRAYSIZE(szCLSID);
  5208. while (ERROR_SUCCESS == MySHRegEnumUSKey(huskeyExts, dwIndex, szCLSID, &cchKey))
  5209. {
  5210. CLSID clsidExt;
  5211. if (GUIDFromString(szCLSID, &clsidExt))
  5212. {
  5213. DWORD dwCountExt = _CountOfAudioFilesForHandler(pdo, clsidExt);
  5214. if (dwCountExt > dwCountBestSoFar)
  5215. {
  5216. hr = S_OK;
  5217. dwCountBestSoFar = dwCountExt;
  5218. clsidBestSoFar = clsidExt;
  5219. }
  5220. }
  5221. cchKey = ARRAYSIZE(szCLSID);
  5222. dwIndex++;
  5223. }
  5224. SHRegCloseUSKey(huskeyExts);
  5225. }
  5226. if (SUCCEEDED(hr))
  5227. {
  5228. *pclsid = clsidBestSoFar;
  5229. }
  5230. }
  5231. return hr;
  5232. }
  5233. HRESULT CBurnAudioCDExtension::DragEnter(IDataObject *pdo, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
  5234. {
  5235. *pdwEffect = DROPEFFECT_NONE;
  5236. // on DTC even the default handler may or may not be installed, so do an early check if we can create the object.
  5237. // cache it since this DragEnter is hit determining if the "burn audio cd" task show up.
  5238. static int s_fBurnHandlerAvailable = -1;
  5239. if (s_fBurnHandlerAvailable == -1)
  5240. {
  5241. CLSID clsid;
  5242. if (SUCCEEDED(_PickHandler(NULL, &clsid)))
  5243. {
  5244. s_fBurnHandlerAvailable = 1;
  5245. }
  5246. else
  5247. {
  5248. s_fBurnHandlerAvailable = 0;
  5249. }
  5250. }
  5251. ICDBurnPriv *pcdbp;
  5252. if (s_fBurnHandlerAvailable && SUCCEEDED(SHCoCreateInstance(NULL, &CLSID_CDBurn, NULL, IID_PPV_ARG(ICDBurnPriv, &pcdbp))))
  5253. {
  5254. // mini-hack: we want the web view task "copy to audio cd" to always show up no matter what
  5255. // the current state of the media is, however we only want to show the wizard page if it's blank.
  5256. // so we check against if the wizard is active or not now.
  5257. // this has the added effect of disabling the "copy to audio cd" task if we're burning in
  5258. // the wizard -- which is probably what we want so its okay.
  5259. if (_DataObjectHasAllAudioFiles(pdo))
  5260. {
  5261. BOOL fOnMedia;
  5262. // if we're not running the wizard, go for it.
  5263. // if we are running the wizard, make sure there are no files on the media.
  5264. if ((S_OK != pcdbp->IsWizardUp()) || (SUCCEEDED(pcdbp->GetContentState(NULL, &fOnMedia)) && !fOnMedia))
  5265. {
  5266. *pdwEffect = DROPEFFECT_COPY;
  5267. }
  5268. }
  5269. pcdbp->Release();
  5270. }
  5271. return S_OK;
  5272. }
  5273. CLSID CBurnAudioCDExtension::_GetDefaultCLSID()
  5274. {
  5275. WCHAR szCLSID[GUIDSTR_MAX];
  5276. DWORD cb = sizeof(szCLSID);
  5277. CLSID clsid;
  5278. if ((ERROR_SUCCESS != SHRegGetUSValue(REGSTR_PATH_AUDIOEXTS, L"", NULL, szCLSID, &cb, FALSE, NULL, 0)) ||
  5279. (!GUIDFromString(szCLSID, &clsid)))
  5280. {
  5281. clsid = CLSID_NULL; // default to this, if registry entry is not there or erroneous
  5282. }
  5283. return clsid;
  5284. }
  5285. HRESULT CBurnAudioCDExtension::_GetVerbForCLSID(REFCLSID clsid, PWSTR psz, UINT cch)
  5286. {
  5287. WCHAR szCLSID[GUIDSTR_MAX];
  5288. SHStringFromGUID(clsid, szCLSID, ARRAYSIZE(szCLSID));
  5289. WCHAR szExtensionRegPath[MAX_PATH];
  5290. lstrcpyn(szExtensionRegPath, REGSTR_PATH_AUDIOEXTS, ARRAYSIZE(szExtensionRegPath));
  5291. PathAppend(szExtensionRegPath, szCLSID);
  5292. DWORD cbVerb = cch * sizeof(*psz);
  5293. return (ERROR_SUCCESS == SHRegGetUSValue(szExtensionRegPath, REGVALUE_VERB, NULL, psz, &cbVerb, FALSE, NULL, 0)) ? S_OK : E_FAIL;
  5294. }
  5295. HRESULT CBurnAudioCDExtension::_DropOnHandler(REFCLSID clsid, IDataObject *pdo)
  5296. {
  5297. WCHAR wzVerb[20];
  5298. HRESULT hr = _GetVerbForCLSID(clsid, wzVerb, ARRAYSIZE(wzVerb));
  5299. if (SUCCEEDED(hr))
  5300. {
  5301. IShellExtInit *psei;
  5302. hr = SHExtCoCreateInstance2(NULL, &clsid, NULL, CLSCTX_ALL, IID_PPV_ARG(IShellExtInit, &psei));
  5303. if (SUCCEEDED(hr))
  5304. {
  5305. hr = psei->Initialize(NULL, pdo, NULL);
  5306. if (SUCCEEDED(hr))
  5307. {
  5308. IContextMenu *pcm;
  5309. hr = psei->QueryInterface(IID_PPV_ARG(IContextMenu, &pcm));
  5310. if (SUCCEEDED(hr))
  5311. {
  5312. HMENU hmenu = CreatePopupMenu();
  5313. if (hmenu)
  5314. {
  5315. hr = pcm->QueryContextMenu(hmenu, 0, 0x1, 0x7fff, 0);
  5316. if (SUCCEEDED(hr))
  5317. {
  5318. CMINVOKECOMMANDINFOEX ici = { 0 };
  5319. ici.cbSize = sizeof(CMINVOKECOMMANDINFOEX);
  5320. ici.fMask = CMIC_MASK_UNICODE;
  5321. ici.lpVerbW = wzVerb;
  5322. CHAR szVerbAnsi[20];
  5323. SHTCharToAnsi(wzVerb, szVerbAnsi, ARRAYSIZE(szVerbAnsi));
  5324. ici.lpVerb = szVerbAnsi;
  5325. ici.nShow = SW_NORMAL;
  5326. hr = pcm->InvokeCommand((LPCMINVOKECOMMANDINFO)(&ici));
  5327. }
  5328. DestroyMenu(hmenu);
  5329. }
  5330. else
  5331. {
  5332. hr = E_OUTOFMEMORY;
  5333. }
  5334. pcm->Release();
  5335. }
  5336. }
  5337. psei->Release();
  5338. }
  5339. }
  5340. return hr;
  5341. }
  5342. HRESULT CBurnAudioCDExtension::Drop(IDataObject *pdo, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
  5343. {
  5344. CLSID clsid;
  5345. HRESULT hr = _PickHandler(pdo, &clsid);
  5346. if (SUCCEEDED(hr))
  5347. {
  5348. _DropOnHandler(clsid, pdo);
  5349. }
  5350. return hr;
  5351. }
  5352. HRESULT CBurnAudioCDExtension::GetLastPage(HPROPSHEETPAGE *phPage)
  5353. {
  5354. *phPage = _hpage;
  5355. return S_OK;
  5356. }
  5357. HRESULT CBurnAudioCDExtension::GetFirstPage(HPROPSHEETPAGE *phPage)
  5358. {
  5359. *phPage = _hpage;
  5360. return S_OK;
  5361. }
  5362. HRESULT CBurnAudioCDExtension::AddPages(HPROPSHEETPAGE *aPages, UINT cPages, UINT *pnPages)
  5363. {
  5364. *pnPages = 0;
  5365. WIZPAGE c_wp =
  5366. {DLG_BURNWIZ_MUSIC, IDS_BURNWIZ_MUSIC_HEAD, IDS_BURNWIZ_MUSIC_SUB, 0, CBurnAudioCDExtension::s_MusicDlgProc};
  5367. _hpage = _CreatePropPageFromInfo(&c_wp, (LPARAM)this);
  5368. if (cPages > 0)
  5369. {
  5370. aPages[0] = _hpage;
  5371. *pnPages = 1;
  5372. }
  5373. return S_OK;
  5374. }
  5375. // pushes the return state back to the main wizard
  5376. void CBurnAudioCDExtension::_SetCompletionState()
  5377. {
  5378. IPropertyBag *ppb;
  5379. if (SUCCEEDED(IUnknown_QueryService(_punkSite, SID_CDWizardHost, IID_PPV_ARG(IPropertyBag, &ppb))))
  5380. {
  5381. SHPropertyBag_WriteDWORD(ppb, PROPSTR_EXTENSIONCOMPLETIONSTATE, CDBE_RET_STOPWIZARD);
  5382. ppb->Release();
  5383. }
  5384. }
  5385. INT_PTR CBurnAudioCDExtension::_MusicDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  5386. {
  5387. BOOL fRet = FALSE;
  5388. switch (uMsg)
  5389. {
  5390. case WM_NOTIFY:
  5391. {
  5392. LPNMHDR pnmh = (LPNMHDR)lParam;
  5393. switch (pnmh->code)
  5394. {
  5395. case PSN_SETACTIVE:
  5396. PropSheet_SetWizButtons(pnmh->hwndFrom, PSWIZB_BACK | PSWIZB_NEXT);
  5397. Button_SetCheck(GetDlgItem(hwnd, IDC_BURNWIZ_BURNAUDIO), _fSelectMusic ? BST_CHECKED : BST_UNCHECKED);
  5398. Button_SetCheck(GetDlgItem(hwnd, IDC_BURNWIZ_BURNDATA), _fSelectMusic ? BST_UNCHECKED : BST_CHECKED);
  5399. fRet = TRUE;
  5400. break;
  5401. case PSN_WIZBACK:
  5402. if (_punkSite)
  5403. {
  5404. IWizardSite *pws;
  5405. if (SUCCEEDED(_punkSite->QueryInterface(IID_PPV_ARG(IWizardSite, &pws))))
  5406. {
  5407. HPROPSHEETPAGE hpage;
  5408. if (SUCCEEDED(pws->GetPreviousPage(&hpage)))
  5409. {
  5410. PropSheet_SetCurSel(GetParent(hwnd), hpage, -1);
  5411. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, (LPARAM)-1);
  5412. }
  5413. pws->Release();
  5414. }
  5415. }
  5416. fRet = TRUE;
  5417. break;
  5418. case PSN_WIZNEXT:
  5419. if (IsDlgButtonChecked(hwnd, IDC_BURNWIZ_BURNAUDIO) == BST_CHECKED)
  5420. {
  5421. IDataObject *pdo;
  5422. if (SUCCEEDED(_CreateDataObject(&pdo)))
  5423. {
  5424. POINTL pt = {0};
  5425. if (SUCCEEDED(Drop(pdo, 0, pt, NULL)))
  5426. {
  5427. _SetCompletionState();
  5428. }
  5429. pdo->Release();
  5430. }
  5431. }
  5432. if (_punkSite)
  5433. {
  5434. IWizardSite *pws;
  5435. if (SUCCEEDED(_punkSite->QueryInterface(IID_PPV_ARG(IWizardSite, &pws))))
  5436. {
  5437. HPROPSHEETPAGE hpage;
  5438. if (SUCCEEDED(pws->GetNextPage(&hpage)))
  5439. {
  5440. PropSheet_SetCurSel(GetParent(hwnd), hpage, -1);
  5441. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, (LPARAM)-1);
  5442. }
  5443. pws->Release();
  5444. }
  5445. }
  5446. fRet = TRUE;
  5447. break;
  5448. case PSN_KILLACTIVE:
  5449. _fSelectMusic = (IsDlgButtonChecked(hwnd, IDC_BURNWIZ_BURNAUDIO) == BST_CHECKED);
  5450. break;
  5451. }
  5452. break;
  5453. }
  5454. }
  5455. return fRet;
  5456. }