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.

2781 lines
76 KiB

  1. #include "shellprv.h"
  2. #pragma hdrstop
  3. #include "shitemid.h"
  4. #include "ids.h"
  5. #include <ntddcdrm.h>
  6. #include "shpriv.h"
  7. #include "hwcmmn.h"
  8. #include "mtptl.h"
  9. #include "cdburn.h"
  10. #ifdef DEBUG
  11. DWORD CMtPtLocal::_cMtPtLocal = 0;
  12. DWORD CVolume::_cVolume = 0;
  13. #endif
  14. const static WCHAR g_szCrossProcessCacheVolumeKey[] = TEXT("CPC\\Volume");
  15. CRegSupport CMtPtLocal::_rsVolumes;
  16. HRESULT CMtPtLocal::SetLabel(HWND hwnd, LPCTSTR pszLabel)
  17. {
  18. HRESULT hr = E_FAIL;
  19. TraceMsg(TF_MOUNTPOINT, "CMtPtLocal::SetLabel: for '%s'", _GetNameDebug());
  20. if (SetVolumeLabel(_GetNameForFctCall(), pszLabel))
  21. {
  22. TraceMsg(TF_MOUNTPOINT, " 'SetVolumeLabel' succeeded");
  23. if ( !_fVolumePoint )
  24. {
  25. RSSetTextValue(NULL, TEXT("_LabelFromReg"), pszLabel,
  26. REG_OPTION_NON_VOLATILE);
  27. }
  28. if (!_CanUseVolume())
  29. {
  30. // we notify for only the current drive (no folder mounted drive)
  31. SHChangeNotify(SHCNE_RENAMEFOLDER, SHCNF_PATH, _GetName(),
  32. _GetName());
  33. }
  34. hr = S_OK;
  35. }
  36. else
  37. {
  38. DWORD dwErr = GetLastError();
  39. switch (dwErr)
  40. {
  41. case ERROR_SUCCESS:
  42. break;
  43. case ERROR_ACCESS_DENIED:
  44. hr = S_FALSE; // don't have permission, shouldn't put them back into editing mode
  45. ShellMessageBox(HINST_THISDLL, hwnd, MAKEINTRESOURCE( IDS_ACCESSDENIED ),
  46. MAKEINTRESOURCE( IDS_TITLE_VOLUMELABELBAD ),
  47. MB_OK | MB_ICONSTOP | MB_SETFOREGROUND);
  48. break;
  49. case ERROR_WRITE_PROTECT:
  50. hr = S_FALSE; // can't write, shouldn't put them back into editing mode
  51. ShellMessageBox(HINST_THISDLL, hwnd, MAKEINTRESOURCE( IDS_WRITEPROTECTED ),
  52. MAKEINTRESOURCE( IDS_TITLE_VOLUMELABELBAD ),
  53. MB_OK | MB_ICONSTOP | MB_SETFOREGROUND);
  54. break;
  55. case ERROR_LABEL_TOO_LONG:
  56. ShellMessageBox(HINST_THISDLL, hwnd, MAKEINTRESOURCE( IDS_ERR_VOLUMELABELBAD ),
  57. MAKEINTRESOURCE( IDS_TITLE_VOLUMELABELBAD ),
  58. MB_OK | MB_ICONSTOP | MB_SETFOREGROUND);
  59. break;
  60. case ERROR_UNRECOGNIZED_VOLUME:
  61. hr = S_FALSE; // can't write, shouldn't put them back into editing mode
  62. ShellMessageBox(HINST_THISDLL, hwnd, MAKEINTRESOURCE( IDS_ERR_VOLUMEUNFORMATTED ),
  63. MAKEINTRESOURCE( IDS_TITLE_VOLUMELABELBAD ),
  64. MB_OK | MB_ICONSTOP | MB_SETFOREGROUND);
  65. break;
  66. default:
  67. ShellMessageBox(HINST_THISDLL, hwnd, MAKEINTRESOURCE( IDS_BADLABEL ),
  68. MAKEINTRESOURCE( IDS_TITLE_VOLUMELABELBAD ),
  69. MB_OK | MB_ICONSTOP | MB_SETFOREGROUND);
  70. break;
  71. }
  72. TraceMsg(TF_MOUNTPOINT, " 'SetVolumeLabel' failed");
  73. }
  74. return hr;
  75. }
  76. HRESULT CMtPtLocal::SetDriveLabel(HWND hwnd, LPCTSTR pszLabel)
  77. {
  78. HRESULT hr = E_FAIL;
  79. if ((_IsFloppy() || !_IsMediaPresent()) && _IsMountedOnDriveLetter())
  80. {
  81. // we rename the drive not the media
  82. TCHAR szSubKey[MAX_PATH];
  83. hr = StringCchPrintf(szSubKey, ARRAYSIZE(szSubKey),
  84. TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\DriveIcons\\%c\\DefaultLabel"),
  85. _GetNameFirstCharUCase());
  86. if (SUCCEEDED(hr))
  87. {
  88. hr = RegSetValueString(HKEY_LOCAL_MACHINE, szSubKey, NULL, pszLabel) ? S_OK : E_FAIL;
  89. if (SUCCEEDED(hr))
  90. {
  91. LocalFree(_pszLegacyRegLabel); // may be NULL
  92. _pszLegacyRegLabel = *pszLabel ? StrDup(pszLabel) : NULL; // empty string resets
  93. SHChangeNotify(SHCNE_RENAMEFOLDER, SHCNF_PATH, _GetName(), _GetName());
  94. }
  95. }
  96. }
  97. else
  98. {
  99. hr = SetLabel(hwnd, pszLabel);
  100. }
  101. return hr;
  102. }
  103. HRESULT CMtPtLocal::GetLabelNoFancy(LPTSTR pszLabel, DWORD cchLabel)
  104. {
  105. HRESULT hr = S_OK;
  106. if (!_GetGVILabelOrMixedCaseFromReg(pszLabel, cchLabel))
  107. {
  108. *pszLabel = 0;
  109. // Propagate failure code out for caller
  110. hr = E_FAIL;
  111. }
  112. return hr;
  113. }
  114. BOOL _ShowUglyDriveNames()
  115. {
  116. static BOOL s_fShowUglyDriveNames = (BOOL)42; // Preload some value to say lets calculate...
  117. if (s_fShowUglyDriveNames == (BOOL)42)
  118. {
  119. int iACP;
  120. TCHAR szTemp[MAX_PATH]; // Nice large buffer
  121. if (GetLocaleInfo(GetUserDefaultLCID(), LOCALE_IDEFAULTANSICODEPAGE, szTemp, ARRAYSIZE(szTemp)))
  122. {
  123. iACP = StrToInt(szTemp);
  124. // per Samer Arafeh, show ugly name for 1256 (Arabic ACP)
  125. if (iACP == 1252 || iACP == 1254 || iACP == 1255 || iACP == 1257 || iACP == 1258)
  126. goto TryLoadString;
  127. else
  128. s_fShowUglyDriveNames = TRUE;
  129. }
  130. else
  131. {
  132. TryLoadString:
  133. // All indications are that we can use pretty drive names.
  134. // Double-check that the localizers didn't corrupt the chars.
  135. LoadString(HINST_THISDLL, IDS_DRIVES_UGLY_TEST, szTemp, ARRAYSIZE(szTemp));
  136. // If the characters did not come through properly set ugly mode...
  137. s_fShowUglyDriveNames = (szTemp[0] != 0x00BC || szTemp[1] != 0x00BD);
  138. }
  139. }
  140. return s_fShowUglyDriveNames;
  141. }
  142. BOOL CMtPtLocal::_HasAutorunLabel()
  143. {
  144. BOOL fRet = FALSE;
  145. if (_CanUseVolume())
  146. {
  147. fRet = BOOLFROMPTR(_pvol->pszAutorunLabel) &&
  148. *(_pvol->pszAutorunLabel);
  149. }
  150. return fRet;
  151. }
  152. BOOL CMtPtLocal::_HasAutorunIcon()
  153. {
  154. BOOL fRet = FALSE;
  155. if (_CanUseVolume())
  156. {
  157. fRet = BOOLFROMPTR(_pvol->pszAutorunIconLocation) &&
  158. *(_pvol->pszAutorunIconLocation);
  159. }
  160. return fRet;
  161. }
  162. void CMtPtLocal::_GetAutorunLabel(LPWSTR pszLabel, DWORD cchLabel)
  163. {
  164. ASSERT(_CanUseVolume());
  165. StringCchCopy(pszLabel, cchLabel, _pvol->pszAutorunLabel);
  166. }
  167. HRESULT CMtPtLocal::GetLabel(LPTSTR pszLabel, DWORD cchLabel)
  168. {
  169. HRESULT hr = S_OK;
  170. BOOL fFoundIt = FALSE;
  171. // Autorun first
  172. // Fancy icon (Autoplay) second
  173. // True label from drive for non-removable
  174. // Legacy drive icons third
  175. // Regular last
  176. if (_HasAutorunLabel())
  177. {
  178. _GetAutorunLabel(pszLabel, cchLabel);
  179. fFoundIt = TRUE;
  180. }
  181. if (!fFoundIt)
  182. {
  183. if (!_IsFloppy())
  184. {
  185. if (!_GetGVILabelOrMixedCaseFromReg(pszLabel, cchLabel))
  186. {
  187. *pszLabel = 0;
  188. }
  189. else
  190. {
  191. if (*pszLabel)
  192. {
  193. fFoundIt = TRUE;
  194. }
  195. }
  196. }
  197. }
  198. if (!fFoundIt)
  199. {
  200. fFoundIt = _GetLegacyRegLabel(pszLabel, cchLabel);
  201. }
  202. if (!fFoundIt)
  203. {
  204. if (!_IsFloppy())
  205. {
  206. if (_CanUseVolume())
  207. {
  208. if (_pvol->pszLabelFromService)
  209. {
  210. if (SUCCEEDED(SHLoadIndirectString(_pvol->pszLabelFromService, pszLabel,
  211. cchLabel, NULL)))
  212. {
  213. fFoundIt = TRUE;
  214. }
  215. else
  216. {
  217. *pszLabel = 0;
  218. }
  219. }
  220. }
  221. }
  222. }
  223. if (!fFoundIt)
  224. {
  225. if (_CanUseVolume() && (HWDTS_CDROM == _pvol->dwDriveType))
  226. {
  227. fFoundIt = _GetCDROMName(pszLabel, cchLabel);
  228. }
  229. }
  230. if (!fFoundIt)
  231. {
  232. if (_IsFloppy())
  233. {
  234. // For some weird reason we have wo sets of "ugly" name for floppies,
  235. // the other is in GetTypeString
  236. UINT id;
  237. if (_IsFloppy35())
  238. {
  239. id = _ShowUglyDriveNames() ? IDS_35_FLOPPY_DRIVE_UGLY : IDS_35_FLOPPY_DRIVE;
  240. }
  241. else
  242. {
  243. id = _ShowUglyDriveNames() ? IDS_525_FLOPPY_DRIVE_UGLY : IDS_525_FLOPPY_DRIVE;
  244. }
  245. LoadString(HINST_THISDLL, id, pszLabel, cchLabel);
  246. }
  247. else
  248. {
  249. // Cook up a default name
  250. GetTypeString(pszLabel, cchLabel);
  251. }
  252. }
  253. return hr;
  254. }
  255. HRESULT CMtPtLocal::Eject(HWND hwnd)
  256. {
  257. TCHAR szNameForError[MAX_DISPLAYNAME];
  258. GetDisplayName(szNameForError, ARRAYSIZE(szNameForError));
  259. return _Eject(hwnd, szNameForError);
  260. }
  261. BOOL CMtPtLocal::HasMedia()
  262. {
  263. return _IsMediaPresent();
  264. }
  265. BOOL CMtPtLocal::IsFormatted()
  266. {
  267. return _IsFormatted();
  268. }
  269. BOOL CMtPtLocal::IsMounted()
  270. {
  271. BOOL fRet;
  272. if (_pvol)
  273. {
  274. if (_pvol->dwVolumeFlags & HWDVF_STATE_DISMOUNTED)
  275. {
  276. fRet = FALSE;
  277. }
  278. else
  279. {
  280. fRet = TRUE;
  281. }
  282. }
  283. else
  284. {
  285. // Assume true. Code that will call this will do so mainly to go
  286. // around the caching done in _pvol.
  287. fRet = TRUE;
  288. }
  289. return fRet;
  290. }
  291. BOOL CMtPtLocal::IsEjectable()
  292. {
  293. BOOL fIsEjectable = FALSE;
  294. if (_IsCDROM())
  295. {
  296. fIsEjectable = TRUE;
  297. }
  298. else
  299. {
  300. // Floppies are not Software ejectable
  301. if (_IsStrictRemovable())
  302. {
  303. fIsEjectable = TRUE;
  304. }
  305. else
  306. {
  307. if (_IsFloppy())
  308. {
  309. if (_CanUseVolume() && (HWDDC_FLOPPYSOFTEJECT & _pvol->dwDriveCapability))
  310. {
  311. if (_IsMediaPresent())
  312. {
  313. fIsEjectable = TRUE;
  314. }
  315. }
  316. }
  317. }
  318. }
  319. if (fIsEjectable)
  320. {
  321. if (_CanUseVolume())
  322. {
  323. if (HWDDC_NOSOFTEJECT & _pvol->dwDriveCapability)
  324. {
  325. fIsEjectable = FALSE;
  326. }
  327. }
  328. }
  329. return fIsEjectable;
  330. }
  331. HRESULT CMtPtLocal::GetCDInfo(DWORD* pdwDriveCapabilities, DWORD* pdwMediaCapabilities)
  332. {
  333. HRESULT hr;
  334. *pdwDriveCapabilities = 0;
  335. *pdwMediaCapabilities = 0;
  336. if (_IsCDROM())
  337. {
  338. if (_CanUseVolume())
  339. {
  340. if (HWDDC_CAPABILITY_SUPPORTDETECTION & _pvol->dwDriveCapability)
  341. {
  342. *pdwDriveCapabilities = (_pvol->dwDriveCapability & HWDDC_CDTYPEMASK);
  343. if (HWDMC_WRITECAPABILITY_SUPPORTDETECTION & _pvol->dwMediaCap)
  344. {
  345. *pdwMediaCapabilities = (_pvol->dwMediaCap & HWDMC_CDTYPEMASK);
  346. }
  347. hr = S_OK;
  348. }
  349. else
  350. {
  351. // in the case where we really dont know, see if the IMAPI info cached in the
  352. // registry has what we want.
  353. hr = CDBurn_GetCDInfo(_pvol->pszVolumeGUID, pdwDriveCapabilities, pdwMediaCapabilities);
  354. }
  355. }
  356. else
  357. {
  358. hr = S_FALSE;
  359. }
  360. }
  361. else
  362. {
  363. hr = E_FAIL;
  364. }
  365. return hr;
  366. }
  367. // Put all these together
  368. BOOL CMtPtLocal::_IsDVDDisc()
  369. {
  370. BOOL fRet = FALSE;
  371. if (_CanUseVolume())
  372. {
  373. if (HWDMC_HASDVDMOVIE & _pvol->dwMediaCap)
  374. {
  375. fRet = TRUE;
  376. }
  377. }
  378. // else In safe boot we don't care about Audio Disc
  379. return fRet;
  380. }
  381. BOOL CMtPtLocal::_IsRemovableDevice()
  382. {
  383. BOOL fRet = FALSE;
  384. if (_CanUseVolume())
  385. {
  386. if (HWDDC_REMOVABLEDEVICE & _pvol->dwDriveCapability)
  387. {
  388. fRet = TRUE;
  389. }
  390. }
  391. return fRet;
  392. }
  393. // We keep the functionality we had before: a drive is Autorun only if it has
  394. // a Autorun.inf in the root when inserted. If it acquires one after, too bad.
  395. BOOL CMtPtLocal::_IsAutorun()
  396. {
  397. BOOL fRet = FALSE;
  398. if (_CanUseVolume())
  399. {
  400. if ((HWDMC_HASAUTORUNINF & _pvol->dwMediaCap) &&
  401. (HWDMC_HASAUTORUNCOMMAND & _pvol->dwMediaCap) &&
  402. !(HWDMC_HASUSEAUTOPLAY & _pvol->dwMediaCap))
  403. {
  404. fRet = TRUE;
  405. }
  406. }
  407. else
  408. {
  409. WCHAR szAutorun[MAX_PATH];
  410. DWORD dwErrMode = SetErrorMode(SEM_FAILCRITICALERRORS);
  411. if (SUCCEEDED(StringCchCopy(szAutorun, ARRAYSIZE(szAutorun), _GetNameForFctCall())))
  412. {
  413. if (SUCCEEDED(StringCchCat(szAutorun, ARRAYSIZE(szAutorun), TEXT("autorun.inf"))))
  414. {
  415. if (-1 != GetFileAttributes(szAutorun))
  416. {
  417. fRet = TRUE;
  418. }
  419. }
  420. }
  421. SetErrorMode(dwErrMode);
  422. }
  423. return fRet;
  424. }
  425. // try to rename it
  426. BOOL CMtPtLocal::_IsAudioDisc()
  427. {
  428. BOOL fRet = FALSE;
  429. if (_CanUseVolume())
  430. {
  431. if (HWDMC_HASAUDIOTRACKS & _pvol->dwMediaCap)
  432. {
  433. fRet = TRUE;
  434. }
  435. }
  436. // else In safe boot we don't care about Audio Disc
  437. return fRet;
  438. }
  439. LPCTSTR CMtPtLocal::_GetNameForFctCall()
  440. {
  441. LPCTSTR psz;
  442. if (_CanUseVolume())
  443. {
  444. psz = _pvol->pszVolumeGUID;
  445. }
  446. else
  447. {
  448. psz = _szName;
  449. }
  450. return psz;
  451. }
  452. HRESULT CMtPtLocal::_Eject(HWND hwnd, LPTSTR pszMountPointNameForError)
  453. {
  454. HRESULT hr = E_FAIL;
  455. #ifndef _WIN64
  456. // NTRAID#NTBUG9-093957-2000/09/08-StephStm Code temporarily disabled for Win64
  457. // MCI is not 64bit ready. It crashes.
  458. // We do this check to see if the CD will accept an IOCTL to eject it.
  459. // Old CD drives do not. On W2K ssince the IOCTL was not implemented they use
  460. // to all say 'no'. I assumne that on ia64 machine they will have recent CD
  461. // drives. I call the IOCTL for them. It works now, and it's certainly better
  462. // than the crash we get using MCI, worst come to worst it will silently fail.
  463. if (IsEjectable())
  464. {
  465. #endif //_WIN64
  466. // it is a protect mode drive that we can tell directly...
  467. if (_IsCDROM())
  468. {
  469. HANDLE h = _GetHandleReadRead();
  470. if (INVALID_HANDLE_VALUE != h)
  471. {
  472. DWORD dwReturned;
  473. DeviceIoControl(h, IOCTL_DISK_EJECT_MEDIA, NULL, 0, NULL, 0,
  474. &dwReturned, NULL);
  475. CloseHandle(h);
  476. }
  477. hr = S_OK;
  478. }
  479. else
  480. {
  481. // For removable drives, we want to do all the calls on a single
  482. // handle, thus we can't do lots of calls to DeviceIoControl.
  483. // Instead, use the helper routines to do our work...
  484. // Don't bring up any error message if the user already chose to abort.
  485. BOOL fAborted = FALSE;
  486. BOOL fFailed = TRUE;
  487. HANDLE h = _GetHandleWithAccessAndShareMode(GENERIC_READ,
  488. FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE);
  489. if (INVALID_HANDLE_VALUE != h)
  490. {
  491. DWORD dwReturned;
  492. _RETRY_LOCK_VOLUME_:
  493. // Now try to lock the drive...
  494. //
  495. // In theory, if no filesystem was mounted, the IOCtl command could go
  496. // to the device, which would fail with ERROR_INVALID_FUNCTION. If that
  497. // occured, we would still want to proceed, since the device might still
  498. // be able to handle the IOCTL_DISK_EJECT_MEDIA command below.
  499. //
  500. if (!DeviceIoControl(h, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0,
  501. &dwReturned, NULL) && (GetLastError() != ERROR_INVALID_FUNCTION))
  502. {
  503. // So we can't lock the drive, bring up a message box to see if user
  504. // wants to
  505. // 1. Abort.
  506. // 2. Retry to lock the drive.
  507. // 3. Dismount anyway.
  508. WCHAR szLabelForMessage[MAX_LABEL];
  509. szLabelForMessage[0] = 0;
  510. if (_CanUseVolume() && (_pvol->pszLabelFromService))
  511. {
  512. StringCchCopy(szLabelForMessage, ARRAYSIZE(szLabelForMessage), _pvol->pszLabelFromService);
  513. }
  514. if (!(szLabelForMessage[0]))
  515. {
  516. GetTypeString(szLabelForMessage, ARRAYSIZE(szLabelForMessage));
  517. LPTSTR psz = ShellConstructMessageString(HINST_THISDLL, MAKEINTRESOURCE(IDS_VOL_FORMAT),
  518. szLabelForMessage, _GetNameFirstCharUCase());
  519. if (psz)
  520. {
  521. StringCchCopy(szLabelForMessage, ARRAYSIZE(szLabelForMessage), psz);
  522. LocalFree(psz);
  523. }
  524. else
  525. {
  526. StringCchCopy(szLabelForMessage, ARRAYSIZE(szLabelForMessage), pszMountPointNameForError);
  527. }
  528. }
  529. int iRet = ShellMessageBox(HINST_THISDLL, hwnd, MAKEINTRESOURCE( IDS_UNMOUNT_TEXT ),
  530. pszMountPointNameForError, MB_CANCELTRYCONTINUE | MB_ICONWARNING | MB_SETFOREGROUND,
  531. szLabelForMessage);
  532. switch (iRet)
  533. {
  534. case IDCANCEL:
  535. // we did not fail, we aborted the format
  536. fFailed = FALSE;
  537. fAborted = TRUE;
  538. break;
  539. case IDCONTINUE:
  540. // send FSCTL_DISMOUNT_VOLUME
  541. if (!DeviceIoControl(h, FSCTL_DISMOUNT_VOLUME, NULL, 0, NULL, 0, &dwReturned, NULL))
  542. {
  543. TraceMsg(TF_WARNING, "FSCTL_DISMOUNT_VOLUME failed with error %d.", GetLastError());
  544. fFailed = TRUE;
  545. break;
  546. }
  547. // We sucessfully dismounted the volume, so the h we have is not valid anymore. We
  548. // therefore close it and start the process all over again, hoping to lock the volume before
  549. // anyone re-opens a handle to it
  550. //
  551. // (fall through)
  552. case IDTRYAGAIN:
  553. goto _RETRY_LOCK_VOLUME_;
  554. }
  555. }
  556. else
  557. {
  558. ASSERT(!fAborted); // should not have aborted if we got this far...
  559. fFailed = FALSE;
  560. }
  561. if (!fFailed && !fAborted)
  562. {
  563. PREVENT_MEDIA_REMOVAL pmr;
  564. pmr.PreventMediaRemoval = FALSE;
  565. // tell the drive to allow removal, then eject
  566. if (!DeviceIoControl(h, IOCTL_STORAGE_MEDIA_REMOVAL, &pmr, sizeof(pmr), NULL, 0, &dwReturned, NULL) ||
  567. !DeviceIoControl(h, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &dwReturned, NULL))
  568. {
  569. ShellMessageBox(HINST_THISDLL, hwnd, MAKEINTRESOURCE( IDS_EJECT_TEXT ),
  570. MAKEINTRESOURCE( IDS_EJECT_TITLE ),
  571. MB_OK | MB_ICONSTOP | MB_SETFOREGROUND, pszMountPointNameForError);
  572. }
  573. else
  574. {
  575. hr = S_OK;
  576. }
  577. }
  578. CloseHandle(h);
  579. }
  580. if (fFailed)
  581. {
  582. ShellMessageBox(HINST_THISDLL, hwnd, MAKEINTRESOURCE( IDS_UNMOUNT_TEXT ),
  583. MAKEINTRESOURCE( IDS_UNMOUNT_TITLE ),
  584. MB_OK | MB_ICONSTOP | MB_SETFOREGROUND, pszMountPointNameForError);
  585. }
  586. }
  587. #ifndef _WIN64
  588. }
  589. else
  590. {
  591. // Is this needed anymore?
  592. // See comment above for why this is ifdef'ed out on Win64
  593. // (stephstm) only works for drive mounted on letter
  594. TCHAR szMCI[128];
  595. hr = StringCchPrintf(szMCI, ARRAYSIZE(szMCI), TEXT("Open %c: type cdaudio alias foo shareable"),
  596. _GetNameFirstCharUCase());
  597. if (SUCCEEDED(hr))
  598. {
  599. if (mciSendString(szMCI, NULL, 0, 0L) == MMSYSERR_NOERROR)
  600. {
  601. mciSendString(TEXT("set foo door open"), NULL, 0, 0L);
  602. mciSendString(TEXT("close foo"), NULL, 0, 0L);
  603. hr = S_OK;
  604. }
  605. }
  606. }
  607. #endif //_WIN64
  608. return hr;
  609. }
  610. ///////////////////////////////////////////////////////////////////////////////
  611. // New //////////////////////////////////////////////////////////////////////
  612. ///////////////////////////////////////////////////////////////////////////////
  613. BOOL CMtPtLocal::_GetFileAttributes(DWORD* pdwAttrib)
  614. {
  615. BOOL fRet = FALSE;
  616. BOOL fDoRead = FALSE;
  617. *pdwAttrib = -1;
  618. if (_CanUseVolume() && !_IsFloppy())
  619. {
  620. if (_IsMediaPresent() && _IsFormatted())
  621. {
  622. if (_IsReadOnly())
  623. {
  624. // The file attrib we received at the begginning should be
  625. // valid, do not touch the drive for nothing
  626. *pdwAttrib = _pvol->dwRootAttributes;
  627. fRet = TRUE;
  628. }
  629. else
  630. {
  631. fDoRead = TRUE;
  632. }
  633. }
  634. }
  635. else
  636. {
  637. fDoRead = TRUE;
  638. }
  639. if (fDoRead)
  640. {
  641. DWORD dw = GetFileAttributes(_GetNameForFctCall());
  642. if (-1 != dw)
  643. {
  644. *pdwAttrib = dw;
  645. fRet = TRUE;
  646. }
  647. }
  648. return fRet;
  649. }
  650. // { DRIVE_ISCOMPRESSIBLE | DRIVE_LFN | DRIVE_SECURITY }
  651. int CMtPtLocal::_GetGVIDriveFlags()
  652. {
  653. int iFlags = 0;
  654. DWORD dwFileSystemFlags = 0;
  655. DWORD dwMaxFileNameLen = 13;
  656. if (_CanUseVolume() && (_pvol->dwVolumeFlags & HWDVF_STATE_SUPPORTNOTIFICATION))
  657. {
  658. if (_IsMediaPresent() && _IsFormatted())
  659. {
  660. // No check for _IsReadOnly, we'll be notified if there's a format
  661. dwFileSystemFlags = _pvol->dwFileSystemFlags;
  662. dwMaxFileNameLen = _pvol->dwMaxFileNameLen;
  663. }
  664. }
  665. else
  666. {
  667. if (!GetVolumeInformation(_GetNameForFctCall(), NULL, 0, NULL,
  668. &dwMaxFileNameLen, &dwFileSystemFlags, NULL, NULL))
  669. {
  670. // Just make sure
  671. dwMaxFileNameLen = 13;
  672. }
  673. }
  674. // The file attrib we received at the begginning should be
  675. // valid, do not touch the drive for nothing
  676. if (dwFileSystemFlags & FS_FILE_COMPRESSION)
  677. {
  678. iFlags |= DRIVE_ISCOMPRESSIBLE;
  679. }
  680. // Volume supports long filename (greater than 8.3)?
  681. if (dwMaxFileNameLen > 12)
  682. {
  683. iFlags |= DRIVE_LFN;
  684. }
  685. // Volume supports security?
  686. if (dwFileSystemFlags & FS_PERSISTENT_ACLS)
  687. {
  688. iFlags |= DRIVE_SECURITY;
  689. }
  690. return iFlags;
  691. }
  692. BOOL CMtPtLocal::_GetGVILabel(LPTSTR pszLabel, DWORD cchLabel)
  693. {
  694. BOOL fRet = FALSE;
  695. *pszLabel = 0;
  696. if (_CanUseVolume() && (_pvol->dwVolumeFlags & HWDVF_STATE_SUPPORTNOTIFICATION))
  697. {
  698. if (_IsMediaPresent() && _IsFormatted())
  699. {
  700. // No check for _IsReadOnly, we'll be notified if there's a change
  701. // of label
  702. fRet = SUCCEEDED(StringCchCopy(pszLabel, cchLabel, _pvol->pszLabel));
  703. }
  704. }
  705. else
  706. {
  707. fRet = GetVolumeInformation(_GetNameForFctCall(), pszLabel, cchLabel,
  708. NULL, NULL, NULL, NULL, NULL);
  709. }
  710. return fRet;
  711. }
  712. BOOL CMtPtLocal::_GetSerialNumber(DWORD* pdwSerialNumber)
  713. {
  714. BOOL fRet = FALSE;
  715. if (_CanUseVolume() && (_pvol->dwVolumeFlags & HWDVF_STATE_SUPPORTNOTIFICATION))
  716. {
  717. if (_IsMediaPresent() && _IsFormatted())
  718. {
  719. *pdwSerialNumber = _pvol->dwSerialNumber;
  720. fRet = TRUE;
  721. }
  722. }
  723. else
  724. {
  725. fRet = GetVolumeInformation(_GetNameForFctCall(), NULL, 0,
  726. pdwSerialNumber, NULL, NULL, NULL, NULL);
  727. }
  728. return fRet;
  729. }
  730. BOOL CMtPtLocal::_GetGVILabelOrMixedCaseFromReg(LPTSTR pszLabel, DWORD cchLabel)
  731. {
  732. BOOL fRet = FALSE;
  733. *pszLabel = 0;
  734. fRet = _GetGVILabel(pszLabel, cchLabel);
  735. if (fRet)
  736. {
  737. WCHAR szLabelFromReg[MAX_LABEL];
  738. // Do we already have a label from the registry for this volume?
  739. // (the user may have renamed this drive)
  740. if (_GetLabelFromReg(szLabelFromReg, ARRAYSIZE(szLabelFromReg)) &&
  741. szLabelFromReg[0])
  742. {
  743. // Yes
  744. // Do they match (only diff in case)
  745. if (lstrcmpi(szLabelFromReg, pszLabel) == 0)
  746. {
  747. // Yes
  748. StringCchCopy(pszLabel, cchLabel, szLabelFromReg);
  749. }
  750. }
  751. }
  752. return fRet;
  753. }
  754. BOOL CMtPtLocal::_GetFileSystemFlags(DWORD* pdwFlags)
  755. {
  756. BOOL fRet = FALSE;
  757. DWORD dwFileSystemFlags = 0;
  758. *pdwFlags = 0;
  759. if (_CanUseVolume() && (_pvol->dwVolumeFlags & HWDVF_STATE_SUPPORTNOTIFICATION))
  760. {
  761. if (_IsMediaPresent() && _IsFormatted())
  762. {
  763. // No check for _IsReadOnly, we'll be notified if there's a
  764. // format oper.
  765. *pdwFlags = _pvol->dwFileSystemFlags;
  766. fRet = TRUE;
  767. }
  768. }
  769. else
  770. {
  771. if (GetVolumeInformation(_GetNameForFctCall(), NULL, 0, NULL,
  772. NULL, pdwFlags, NULL, NULL))
  773. {
  774. fRet = TRUE;
  775. }
  776. }
  777. return fRet;
  778. }
  779. BOOL CMtPtLocal::_GetFileSystemName(LPTSTR pszFileSysName, DWORD cchFileSysName)
  780. {
  781. BOOL fRet = FALSE;
  782. *pszFileSysName = 0;
  783. if (_CanUseVolume() && (_pvol->dwVolumeFlags & HWDVF_STATE_SUPPORTNOTIFICATION))
  784. {
  785. if (_IsMediaPresent() && _IsFormatted())
  786. {
  787. fRet = SUCCEEDED(StringCchCopy(pszFileSysName, cchFileSysName,
  788. _pvol->pszFileSystem));
  789. }
  790. }
  791. else
  792. {
  793. if (GetVolumeInformation(_GetNameForFctCall(),
  794. NULL,
  795. 0,
  796. NULL,
  797. NULL,
  798. NULL,
  799. pszFileSysName,
  800. cchFileSysName))
  801. {
  802. fRet = TRUE;
  803. }
  804. }
  805. return fRet;
  806. }
  807. struct CDROMICONS
  808. {
  809. DWORD dwCap;
  810. UINT iIcon;
  811. UINT iName;
  812. };
  813. // Go from most wonderful caps to less wonderful (according to stepshtm)
  814. // Keep in order, it is verrrrry important
  815. const CDROMICONS rgMediaPresent[] =
  816. {
  817. // Specfic content
  818. { HWDMC_HASDVDMOVIE, -IDI_AP_VIDEO, 0}, // we display the DVD media icon,
  819. // since it will most likely be
  820. // replaced by an icon from the DVD itself
  821. { HWDMC_HASAUDIOTRACKS | HWDMC_HASDATATRACKS, -IDI_MEDIACDAUDIOPLUS, 0},
  822. { HWDMC_HASAUDIOTRACKS, -IDI_CDAUDIO, 0 },
  823. { HWDMC_HASAUTORUNINF, -IDI_DRIVECD, 0 },
  824. // Specific media
  825. { HWDMC_WRITECAPABILITY_SUPPORTDETECTION | HWDMC_DVDRAM, -IDI_MEDIADVDRAM, 0 },
  826. { HWDMC_WRITECAPABILITY_SUPPORTDETECTION | HWDMC_DVDRECORDABLE, -IDI_MEDIADVDR, 0 },
  827. { HWDMC_WRITECAPABILITY_SUPPORTDETECTION | HWDMC_DVDREWRITABLE, -IDI_MEDIADVDRW, 0 },
  828. { HWDMC_WRITECAPABILITY_SUPPORTDETECTION | HWDMC_DVDROM, -IDI_MEDIADVDROM, 0 },
  829. { HWDMC_WRITECAPABILITY_SUPPORTDETECTION | HWDMC_CDREWRITABLE, -IDI_MEDIACDRW, 0 },
  830. { HWDMC_WRITECAPABILITY_SUPPORTDETECTION | HWDMC_CDRECORDABLE, -IDI_MEDIACDR, 0 },
  831. { HWDMC_WRITECAPABILITY_SUPPORTDETECTION | HWDMC_CDROM, -IDI_MEDIACDROM, 0 },
  832. };
  833. // Keep in order, it is verrrrry important
  834. const CDROMICONS rgNoMedia[] =
  835. {
  836. { HWDMC_WRITECAPABILITY_SUPPORTDETECTION | HWDDC_DVDRAM, -IDI_DRIVECD, IDS_DRIVES_DVDRAM },
  837. { HWDMC_WRITECAPABILITY_SUPPORTDETECTION | HWDDC_DVDRECORDABLE, -IDI_DRIVECD, IDS_DRIVES_DVDR },
  838. { HWDMC_WRITECAPABILITY_SUPPORTDETECTION | HWDDC_DVDREWRITABLE, -IDI_DRIVECD, IDS_DRIVES_DVDRW },
  839. { HWDMC_WRITECAPABILITY_SUPPORTDETECTION | HWDDC_DVDROM | HWDDC_CDREWRITABLE, -IDI_DRIVECD, IDS_DRIVES_DVDCDRW },
  840. { HWDMC_WRITECAPABILITY_SUPPORTDETECTION | HWDDC_DVDROM | HWDDC_CDRECORDABLE, -IDI_DRIVECD, IDS_DRIVES_DVDCDR },
  841. { HWDMC_WRITECAPABILITY_SUPPORTDETECTION | HWDDC_DVDROM, -IDI_DVDDRIVE, IDS_DRIVES_DVD },
  842. { HWDMC_WRITECAPABILITY_SUPPORTDETECTION | HWDDC_CDREWRITABLE, -IDI_DRIVECD, IDS_DRIVES_CDRW },
  843. { HWDMC_WRITECAPABILITY_SUPPORTDETECTION | HWDDC_CDRECORDABLE, -IDI_DRIVECD, IDS_DRIVES_CDR },
  844. { HWDMC_WRITECAPABILITY_SUPPORTDETECTION | HWDDC_CDROM, -IDI_DRIVECD, IDS_DRIVES_CDROM },
  845. };
  846. UINT _GetCDROMIconFromArray(DWORD dwCap, const CDROMICONS* prgcdromicons,
  847. DWORD ccdromicons)
  848. {
  849. UINT iIcon = 0;
  850. for (DWORD dw = 0; dw < ccdromicons; ++dw)
  851. {
  852. if ((prgcdromicons[dw].dwCap & dwCap) == prgcdromicons[dw].dwCap)
  853. {
  854. iIcon = prgcdromicons[dw].iIcon;
  855. break;
  856. }
  857. }
  858. return iIcon;
  859. }
  860. UINT _GetCDROMNameFromArray(DWORD dwCap)
  861. {
  862. UINT iName = 0;
  863. for (DWORD dw = 0; dw < ARRAYSIZE(rgNoMedia); ++dw)
  864. {
  865. if ((rgNoMedia[dw].dwCap & dwCap) == rgNoMedia[dw].dwCap)
  866. {
  867. iName = rgNoMedia[dw].iName;
  868. break;
  869. }
  870. }
  871. return iName;
  872. }
  873. UINT CMtPtLocal::_GetCDROMIcon()
  874. {
  875. int iIcon;
  876. if (_IsMediaPresent())
  877. {
  878. ASSERT(_CanUseVolume());
  879. iIcon = _GetCDROMIconFromArray(_pvol->dwMediaCap, rgMediaPresent,
  880. ARRAYSIZE(rgMediaPresent));
  881. if (!iIcon)
  882. {
  883. iIcon = -IDI_DRIVECD;
  884. }
  885. }
  886. else
  887. {
  888. ASSERT(_CanUseVolume());
  889. iIcon = _GetCDROMIconFromArray(_pvol->dwDriveCapability, rgNoMedia,
  890. ARRAYSIZE(rgNoMedia));
  891. if (!iIcon)
  892. {
  893. // No media generic CD icon
  894. iIcon = -IDI_DRIVECD;
  895. }
  896. }
  897. return iIcon;
  898. }
  899. BOOL CMtPtLocal::_GetCDROMName(LPWSTR pszName, DWORD cchName)
  900. {
  901. BOOL fRet = FALSE;
  902. *pszName = 0;
  903. if (!_IsMediaPresent())
  904. {
  905. ASSERT(_CanUseVolume());
  906. UINT iName = _GetCDROMNameFromArray(_pvol->dwDriveCapability);
  907. if (iName)
  908. {
  909. fRet = LoadString(HINST_THISDLL, iName, pszName, cchName);
  910. }
  911. }
  912. return fRet;
  913. }
  914. UINT CMtPtLocal::_GetAutorunIcon(LPTSTR pszModule, DWORD cchModule)
  915. {
  916. int iIcon = -1;
  917. ASSERT(_CanUseVolume());
  918. if (_pvol->pszAutorunIconLocation)
  919. {
  920. if (SUCCEEDED(StringCchCopy(pszModule, cchModule, _GetName())))
  921. {
  922. if (SUCCEEDED(StringCchCat(pszModule, cchModule, _pvol->pszAutorunIconLocation)))
  923. {
  924. iIcon = PathParseIconLocation(pszModule);
  925. }
  926. }
  927. }
  928. return iIcon;
  929. }
  930. UINT CMtPtLocal::GetIcon(LPTSTR pszModule, DWORD cchModule)
  931. {
  932. UINT iIcon = -IDI_DRIVEUNKNOWN;
  933. *pszModule = 0;
  934. if (_CanUseVolume())
  935. {
  936. // Autorun first
  937. // Fancy icon (Autoplay) second
  938. // Legacy drive icons last
  939. if (_HasAutorunIcon())
  940. {
  941. iIcon = _GetAutorunIcon(pszModule, cchModule);
  942. }
  943. if (-IDI_DRIVEUNKNOWN == iIcon)
  944. {
  945. // Try fancy icon
  946. if (!_IsFloppy())
  947. {
  948. if (_IsMediaPresent())
  949. {
  950. if (_pvol->pszIconFromService)
  951. {
  952. if (FAILED(StringCchCopy(pszModule, cchModule, _pvol->pszIconFromService)))
  953. {
  954. *pszModule = 0;
  955. }
  956. }
  957. }
  958. else
  959. {
  960. if (_pvol->pszNoMediaIconFromService)
  961. {
  962. if (FAILED(StringCchCopy(pszModule, cchModule, _pvol->pszNoMediaIconFromService)))
  963. {
  964. *pszModule = 0;
  965. }
  966. }
  967. else
  968. {
  969. if (_pvol->pszIconFromService)
  970. {
  971. if (FAILED(StringCchCopy(pszModule, cchModule, _pvol->pszIconFromService)))
  972. {
  973. *pszModule = 0;
  974. }
  975. }
  976. }
  977. }
  978. if (*pszModule)
  979. {
  980. iIcon = PathParseIconLocation(pszModule);
  981. }
  982. }
  983. if (-IDI_DRIVEUNKNOWN == iIcon)
  984. {
  985. if (_pszLegacyRegIcon)
  986. {
  987. if (*_pszLegacyRegIcon)
  988. {
  989. if (SUCCEEDED(StringCchCopy(pszModule, cchModule, _pszLegacyRegIcon)))
  990. {
  991. iIcon = PathParseIconLocation(pszModule);
  992. }
  993. }
  994. else
  995. {
  996. *pszModule = 0;
  997. }
  998. }
  999. else
  1000. {
  1001. if (_CanUseVolume() && (HWDTS_CDROM == _pvol->dwDriveType))
  1002. {
  1003. iIcon = _GetCDROMIcon();
  1004. *pszModule = 0;
  1005. }
  1006. }
  1007. }
  1008. if (-IDI_DRIVEUNKNOWN == iIcon)
  1009. {
  1010. switch (_pvol->dwDriveType)
  1011. {
  1012. case HWDTS_FLOPPY35:
  1013. {
  1014. iIcon = II_DRIVE35;
  1015. break;
  1016. }
  1017. case HWDTS_FIXEDDISK:
  1018. {
  1019. iIcon = II_DRIVEFIXED;
  1020. break;
  1021. }
  1022. case HWDTS_CDROM:
  1023. {
  1024. iIcon = II_DRIVECD;
  1025. break;
  1026. }
  1027. case HWDTS_REMOVABLEDISK:
  1028. {
  1029. iIcon = II_DRIVEREMOVE;
  1030. break;
  1031. }
  1032. case HWDTS_FLOPPY525:
  1033. {
  1034. iIcon = II_DRIVE525;
  1035. break;
  1036. }
  1037. default:
  1038. {
  1039. iIcon = -IDI_DRIVEUNKNOWN;
  1040. break;
  1041. }
  1042. }
  1043. }
  1044. }
  1045. }
  1046. else
  1047. {
  1048. iIcon = CMountPoint::GetSuperPlainDriveIcon(_szName, GetDriveType(_GetName()));
  1049. }
  1050. if (*pszModule)
  1051. TraceMsg(TF_MOUNTPOINT, "CMtPtLocal::GetIcon: for '%s', chose '%s', '%d'", _GetNameDebug(), pszModule, iIcon);
  1052. else
  1053. TraceMsg(TF_MOUNTPOINT, "CMtPtLocal::GetIcon: for '%s', chose '%d'", _GetNameDebug(), iIcon);
  1054. return iIcon;
  1055. }
  1056. HRESULT CMtPtLocal::GetAssocSystemElement(IAssociationElement **ppae)
  1057. {
  1058. PCWSTR psz = NULL;
  1059. if (_IsFixedDisk())
  1060. psz = L"Drive.Fixed";
  1061. else if (_IsFloppy())
  1062. psz = L"Drive.Floppy";
  1063. else if (_IsCDROM())
  1064. psz = L"Drive.CDROM";
  1065. else if (_IsStrictRemovable())
  1066. psz = L"Drive.Removable";
  1067. if (psz)
  1068. return AssocElemCreateForClass(&CLSID_AssocSystemElement, psz, ppae);
  1069. return E_FAIL;
  1070. }
  1071. int CMtPtLocal::GetDriveFlags()
  1072. {
  1073. UINT uDriveFlags = 0;
  1074. // Is this a CD/DVD of some sort?
  1075. if (_IsCDROM())
  1076. {
  1077. // Yes
  1078. LPCTSTR pszSubKey = NULL;
  1079. if (_IsAudioDisc())
  1080. {
  1081. uDriveFlags |= DRIVE_AUDIOCD;
  1082. pszSubKey = TEXT("AudioCD\\shell");
  1083. }
  1084. else if (_IsDVDDisc())
  1085. {
  1086. uDriveFlags |= DRIVE_DVD;
  1087. pszSubKey = TEXT("DVD\\shell");
  1088. }
  1089. // Set the AutoOpen stuff, if applicable
  1090. if (pszSubKey)
  1091. {
  1092. TCHAR ach[80];
  1093. DWORD cb = sizeof(ach);
  1094. ach[0] = 0;
  1095. // get the default verb for Audio CD/DVD
  1096. if (ERROR_SUCCESS == SHRegGetValue(HKEY_CLASSES_ROOT, pszSubKey, NULL, SRRF_RT_REG_SZ, NULL, ach, &cb))
  1097. {
  1098. // we should only set AUTOOPEN if there is a default verb on Audio CD/DVD
  1099. if (ach[0])
  1100. uDriveFlags |= DRIVE_AUTOOPEN;
  1101. }
  1102. }
  1103. }
  1104. else
  1105. {
  1106. // No, by default every drive type is ShellOpen, except CD-ROMs
  1107. uDriveFlags |= DRIVE_SHELLOPEN;
  1108. }
  1109. if (_IsAutorun())
  1110. {
  1111. uDriveFlags |= DRIVE_AUTORUN;
  1112. //FEATURE should we set AUTOOPEN based on a flag in the AutoRun.inf???
  1113. uDriveFlags |= DRIVE_AUTOOPEN;
  1114. }
  1115. return uDriveFlags;
  1116. }
  1117. void CMtPtLocal::GetTypeString(LPTSTR pszType, DWORD cchType)
  1118. {
  1119. int iID;
  1120. *pszType = 0;
  1121. if (_CanUseVolume())
  1122. {
  1123. switch (_pvol->dwDriveType)
  1124. {
  1125. case HWDTS_FLOPPY35:
  1126. if (_ShowUglyDriveNames())
  1127. {
  1128. iID = IDS_DRIVES_DRIVE35_UGLY;
  1129. }
  1130. else
  1131. {
  1132. iID = IDS_DRIVES_DRIVE35;
  1133. }
  1134. break;
  1135. case HWDTS_FLOPPY525:
  1136. if (_ShowUglyDriveNames())
  1137. {
  1138. iID = IDS_DRIVES_DRIVE525_UGLY;
  1139. }
  1140. else
  1141. {
  1142. iID = IDS_DRIVES_DRIVE525;
  1143. }
  1144. break;
  1145. case HWDTS_REMOVABLEDISK:
  1146. iID = IDS_DRIVES_REMOVABLE;
  1147. break;
  1148. case HWDTS_FIXEDDISK:
  1149. iID = IDS_DRIVES_FIXED;
  1150. break;
  1151. case HWDTS_CDROM:
  1152. iID = IDS_DRIVES_CDROM;
  1153. break;
  1154. }
  1155. }
  1156. else
  1157. {
  1158. UINT uDriveType = GetDriveType(_GetNameForFctCall());
  1159. switch (uDriveType)
  1160. {
  1161. case DRIVE_REMOVABLE:
  1162. iID = IDS_DRIVES_REMOVABLE;
  1163. break;
  1164. case DRIVE_REMOTE:
  1165. iID = IDS_DRIVES_NETDRIVE;
  1166. break;
  1167. case DRIVE_CDROM:
  1168. iID = IDS_DRIVES_CDROM;
  1169. break;
  1170. case DRIVE_RAMDISK:
  1171. iID = IDS_DRIVES_RAMDISK;
  1172. break;
  1173. case DRIVE_FIXED:
  1174. default:
  1175. iID = IDS_DRIVES_FIXED;
  1176. break;
  1177. }
  1178. }
  1179. LoadString(HINST_THISDLL, iID, pszType, cchType);
  1180. }
  1181. DWORD CMtPtLocal::GetShellDescriptionID()
  1182. {
  1183. DWORD dwShellDescrID;
  1184. if (_CanUseVolume())
  1185. {
  1186. switch (_pvol->dwDriveType)
  1187. {
  1188. case HWDTS_FLOPPY35:
  1189. dwShellDescrID = SHDID_COMPUTER_DRIVE35;
  1190. break;
  1191. case HWDTS_FLOPPY525:
  1192. dwShellDescrID = SHDID_COMPUTER_DRIVE525;
  1193. break;
  1194. case HWDTS_REMOVABLEDISK:
  1195. dwShellDescrID = SHDID_COMPUTER_REMOVABLE;
  1196. break;
  1197. case HWDTS_FIXEDDISK:
  1198. dwShellDescrID = SHDID_COMPUTER_FIXED;
  1199. break;
  1200. case HWDTS_CDROM:
  1201. dwShellDescrID = SHDID_COMPUTER_CDROM;
  1202. break;
  1203. default:
  1204. dwShellDescrID = SHDID_COMPUTER_OTHER;
  1205. break;
  1206. }
  1207. }
  1208. else
  1209. {
  1210. UINT uDriveType = GetDriveType(_GetNameForFctCall());
  1211. switch (uDriveType)
  1212. {
  1213. case DRIVE_REMOVABLE:
  1214. dwShellDescrID = SHDID_COMPUTER_REMOVABLE;
  1215. break;
  1216. case DRIVE_CDROM:
  1217. dwShellDescrID = SHDID_COMPUTER_CDROM;
  1218. break;
  1219. case DRIVE_FIXED:
  1220. dwShellDescrID = SHDID_COMPUTER_FIXED;
  1221. break;
  1222. case DRIVE_RAMDISK:
  1223. dwShellDescrID = SHDID_COMPUTER_RAMDISK;
  1224. break;
  1225. case DRIVE_NO_ROOT_DIR:
  1226. case DRIVE_UNKNOWN:
  1227. default:
  1228. dwShellDescrID = SHDID_COMPUTER_OTHER;
  1229. break;
  1230. }
  1231. }
  1232. return dwShellDescrID;
  1233. }
  1234. ///////////////////////////////////////////////////////////////////////////////
  1235. // DeviceIoControl stuff
  1236. ///////////////////////////////////////////////////////////////////////////////
  1237. HANDLE CMtPtLocal::_GetHandleWithAccessAndShareMode(DWORD dwDesiredAccess, DWORD dwShareMode)
  1238. {
  1239. HANDLE handle = INVALID_HANDLE_VALUE;
  1240. WCHAR szVolumeGUIDWOSlash[50];
  1241. DWORD dwFileAttributes = 0;
  1242. if (_CanUseVolume())
  1243. {
  1244. StringCchCopy(szVolumeGUIDWOSlash, ARRAYSIZE(szVolumeGUIDWOSlash),
  1245. _pvol->pszVolumeGUID);
  1246. PathRemoveBackslash(szVolumeGUIDWOSlash);
  1247. }
  1248. else
  1249. {
  1250. // Go for VolumeGUID first
  1251. if (GetVolumeNameForVolumeMountPoint(_GetName(), szVolumeGUIDWOSlash,
  1252. ARRAYSIZE(szVolumeGUIDWOSlash)))
  1253. {
  1254. PathRemoveBackslash(szVolumeGUIDWOSlash);
  1255. }
  1256. else
  1257. {
  1258. // Probably a floppy, which cannot be mounted on a folder
  1259. StringCchCopy(szVolumeGUIDWOSlash, ARRAYSIZE(szVolumeGUIDWOSlash),
  1260. TEXT("\\\\.\\A:"));
  1261. szVolumeGUIDWOSlash[4] = _GetNameFirstCharUCase();
  1262. }
  1263. }
  1264. return CreateFile(szVolumeGUIDWOSlash, dwDesiredAccess, dwShareMode, NULL, OPEN_EXISTING, dwFileAttributes, NULL);
  1265. }
  1266. // On NT, when use GENERIC_READ (as opposed to 0) in the CreateFile call, we
  1267. // get a handle to the filesystem (CDFS), not the device itself. But we can't
  1268. // change DriveIOCTL to do this, since that causes the floppy disks to spin
  1269. // up, and we don't want to do that.
  1270. HANDLE CMtPtLocal::_GetHandleReadRead()
  1271. {
  1272. return _GetHandleWithAccessAndShareMode(GENERIC_READ, FILE_SHARE_READ);
  1273. }
  1274. BOOL CMtPtLocal::_CanUseVolume()
  1275. {
  1276. // This is used in ASSERTs, do not add code that would introduce a side
  1277. // effect in debug only (stephstm)
  1278. // For Dismounted volumes, we want the code to take the alternate code
  1279. // path. The volume, when ready to be re-mounted, will be remounted
  1280. // until some code tries to access it. So using the alternate code path
  1281. // will try to remount it, if it's ready it will get remounted, the Shell
  1282. // Service will get an event, and we'll remove the DISMOUNTED bit.
  1283. return (_pvol && !(_pvol->dwVolumeFlags & HWDVF_STATE_ACCESSDENIED) &&
  1284. !(_pvol->dwVolumeFlags & HWDVF_STATE_DISMOUNTED));
  1285. }
  1286. HRESULT CMtPtLocal::_InitWithVolume(LPCWSTR pszMtPt, CVolume* pvol)
  1287. {
  1288. HRESULT hr = StringCchCopy(_szName, ARRAYSIZE(_szName), pszMtPt);
  1289. if (SUCCEEDED(hr))
  1290. {
  1291. pvol->AddRef();
  1292. _pvol = pvol;
  1293. PathAddBackslash(_szName);
  1294. _fMountedOnDriveLetter = _IsDriveLetter(pszMtPt);
  1295. RSInitRoot(HKEY_CURRENT_USER, REGSTR_MTPT_ROOTKEY2, _pvol->pszKeyName,
  1296. REG_OPTION_NON_VOLATILE);
  1297. RSSetTextValue(NULL, TEXT("BaseClass"), TEXT("Drive"));
  1298. _InitAutorunInfo();
  1299. if (_CanUseVolume())
  1300. {
  1301. if (HWDMC_HASDESKTOPINI & _pvol->dwMediaCap)
  1302. {
  1303. // we need to listen to change notify to know when this guys will change
  1304. _UpdateCommentFromDesktopINI();
  1305. }
  1306. }
  1307. _InitLegacyRegIconAndLabelHelper();
  1308. }
  1309. return hr;
  1310. }
  1311. // These can only be mounted on drive letter
  1312. HRESULT CMtPtLocal::_Init(LPCWSTR pszMtPt)
  1313. {
  1314. HRESULT hr;
  1315. ASSERT(_IsDriveLetter(pszMtPt));
  1316. if (GetLogicalDrives() & (1 << DRIVEID(pszMtPt)))
  1317. {
  1318. _fMountedOnDriveLetter = TRUE;
  1319. hr = StringCchCopy(_szName, ARRAYSIZE(_szName), pszMtPt);
  1320. if (SUCCEEDED(hr))
  1321. {
  1322. PathAddBackslash(_szName);
  1323. _GetNameFirstXChar(_szNameNoVolume, ARRAYSIZE(_szNameNoVolume));
  1324. RSInitRoot(HKEY_CURRENT_USER, REGSTR_MTPT_ROOTKEY2, _szNameNoVolume,
  1325. REG_OPTION_NON_VOLATILE);
  1326. RSSetTextValue(NULL, TEXT("BaseClass"), TEXT("Drive"));
  1327. _InitAutorunInfo();
  1328. }
  1329. }
  1330. else
  1331. {
  1332. hr = E_FAIL;
  1333. }
  1334. return hr;
  1335. }
  1336. void CMtPtLocal::_InitLegacyRegIconAndLabelHelper()
  1337. {
  1338. CMountPoint::_InitLegacyRegIconAndLabel(_HasAutorunIcon(),
  1339. _HasAutorunLabel());
  1340. }
  1341. void CMtPtLocal::StoreIconForUpdateImage(int iImage)
  1342. {
  1343. if (_CanUseVolume())
  1344. {
  1345. _pvol->iShellImageForUpdateImage = iImage;
  1346. }
  1347. }
  1348. void CMtPtLocal::_InitAutorunInfo()
  1349. {
  1350. if (_Shell32LoadedInDesktop())
  1351. {
  1352. BOOL fAutorun = FALSE;
  1353. if (!_CanUseVolume())
  1354. {
  1355. if (_IsAutorun())
  1356. {
  1357. fAutorun = TRUE;
  1358. }
  1359. }
  1360. if (!fAutorun && !_fVolumePoint)
  1361. {
  1362. // Make sure to delete the shell key
  1363. RSDeleteSubKey(TEXT("Shell"));
  1364. }
  1365. }
  1366. }
  1367. // Equivalent of GetDriveType API
  1368. int CMtPtLocal::_GetDriveType()
  1369. {
  1370. int iDriveType = DRIVE_NO_ROOT_DIR;
  1371. if (_CanUseVolume())
  1372. {
  1373. switch (_pvol->dwDriveType)
  1374. {
  1375. case HWDTS_FLOPPY35:
  1376. case HWDTS_FLOPPY525:
  1377. case HWDTS_REMOVABLEDISK:
  1378. iDriveType = DRIVE_REMOVABLE;
  1379. break;
  1380. case HWDTS_FIXEDDISK:
  1381. iDriveType = DRIVE_FIXED;
  1382. break;
  1383. case HWDTS_CDROM:
  1384. iDriveType = DRIVE_CDROM;
  1385. break;
  1386. }
  1387. }
  1388. else
  1389. {
  1390. iDriveType = GetDriveType(_GetNameForFctCall());
  1391. }
  1392. return iDriveType;
  1393. }
  1394. #define VALID_VOLUME_PREFIX TEXT("\\\\?\\Volume")
  1395. // static
  1396. HRESULT CMtPtLocal::_CreateVolume(VOLUMEINFO* pvolinfo, CVolume** ppvolNew)
  1397. {
  1398. ASSERT(_csDL.IsInside());
  1399. HRESULT hr;
  1400. if (!StrCmpN(pvolinfo->pszVolumeGUID, VALID_VOLUME_PREFIX, ARRAYSIZE(VALID_VOLUME_PREFIX) - 1))
  1401. {
  1402. CVolume* pvol = new CVolume();
  1403. *ppvolNew = NULL;
  1404. if (pvol)
  1405. {
  1406. // The next four strings shouyld always be set to something
  1407. pvol->pszDeviceIDVolume = StrDup(pvolinfo->pszDeviceIDVolume);
  1408. pvol->pszVolumeGUID = StrDup(pvolinfo->pszVolumeGUID);
  1409. pvol->pszLabel = StrDup(pvolinfo->pszLabel);
  1410. pvol->pszFileSystem = StrDup(pvolinfo->pszFileSystem);
  1411. // The following five strings are optional
  1412. if (pvolinfo->pszAutorunIconLocation)
  1413. {
  1414. pvol->pszAutorunIconLocation = StrDup(pvolinfo->pszAutorunIconLocation);
  1415. }
  1416. if (pvolinfo->pszAutorunLabel)
  1417. {
  1418. pvol->pszAutorunLabel = StrDup(pvolinfo->pszAutorunLabel);
  1419. }
  1420. if (pvolinfo->pszIconLocationFromService)
  1421. {
  1422. pvol->pszIconFromService = StrDup(pvolinfo->pszIconLocationFromService);
  1423. }
  1424. if (pvolinfo->pszNoMediaIconLocationFromService)
  1425. {
  1426. pvol->pszNoMediaIconFromService = StrDup(pvolinfo->pszNoMediaIconLocationFromService);
  1427. }
  1428. if (pvolinfo->pszLabelFromService)
  1429. {
  1430. pvol->pszLabelFromService = StrDup(pvolinfo->pszLabelFromService);
  1431. }
  1432. if (pvol->pszDeviceIDVolume && pvol->pszVolumeGUID && pvol->pszLabel &&
  1433. pvol->pszFileSystem)
  1434. {
  1435. pvol->dwState = pvolinfo->dwState;
  1436. pvol->dwVolumeFlags = pvolinfo->dwVolumeFlags;
  1437. pvol->dwDriveType = pvolinfo->dwDriveType;
  1438. pvol->dwDriveCapability = pvolinfo->dwDriveCapability;
  1439. pvol->dwFileSystemFlags = pvolinfo->dwFileSystemFlags;
  1440. pvol->dwMaxFileNameLen = pvolinfo->dwMaxFileNameLen;
  1441. pvol->dwRootAttributes = pvolinfo->dwRootAttributes;
  1442. pvol->dwSerialNumber = pvolinfo->dwSerialNumber;
  1443. pvol->dwDriveState = pvolinfo->dwDriveState;
  1444. pvol->dwMediaState = pvolinfo->dwMediaState;
  1445. pvol->dwMediaCap = pvolinfo->dwMediaCap;
  1446. if (_hdpaVolumes && (-1 != DPA_AppendPtr(_hdpaVolumes, pvol)))
  1447. {
  1448. pvol->pszKeyName = pvol->pszVolumeGUID + OFFSET_GUIDWITHINVOLUMEGUID;
  1449. pvol->AddRef();
  1450. *ppvolNew = pvol;
  1451. hr = S_OK;
  1452. }
  1453. else
  1454. {
  1455. hr = E_OUTOFMEMORY;
  1456. }
  1457. }
  1458. else
  1459. {
  1460. hr = E_OUTOFMEMORY;
  1461. }
  1462. if (FAILED(hr))
  1463. {
  1464. delete pvol;
  1465. }
  1466. }
  1467. else
  1468. {
  1469. hr = E_OUTOFMEMORY;
  1470. }
  1471. }
  1472. else
  1473. {
  1474. hr = E_FAIL;
  1475. }
  1476. return hr;
  1477. }
  1478. // this helper function will hit the drive to see if media is present.
  1479. // should only be used for drives that don't support the HWDVF_STATE_SUPPORTNOTIFICATION
  1480. BOOL CMtPtLocal::_ForceCheckMediaPresent()
  1481. {
  1482. BOOL bRet = FALSE; // assume no media present
  1483. HANDLE hDevice = _GetHandleWithAccessAndShareMode(GENERIC_READ,
  1484. FILE_SHARE_READ | FILE_SHARE_WRITE);
  1485. if (hDevice != INVALID_HANDLE_VALUE)
  1486. {
  1487. DWORD dwDummy;
  1488. // call the ioctl to verify media presence
  1489. if (DeviceIoControl(hDevice,
  1490. IOCTL_STORAGE_CHECK_VERIFY,
  1491. NULL,
  1492. 0,
  1493. NULL,
  1494. 0,
  1495. &dwDummy,
  1496. NULL))
  1497. {
  1498. bRet = TRUE;
  1499. }
  1500. CloseHandle(hDevice);
  1501. }
  1502. return bRet;
  1503. }
  1504. BOOL CMtPtLocal::_IsMediaPresent()
  1505. {
  1506. BOOL bRet;
  1507. if (!_CanUseVolume() || !(_pvol->dwVolumeFlags & HWDVF_STATE_SUPPORTNOTIFICATION))
  1508. {
  1509. // if the drive dosen't support notification, we need to ping it now
  1510. bRet = _ForceCheckMediaPresent();
  1511. }
  1512. else
  1513. {
  1514. bRet = (HWDMS_PRESENT & _pvol->dwMediaState);
  1515. }
  1516. return bRet;
  1517. }
  1518. BOOL CMtPtLocal::_IsFormatted()
  1519. {
  1520. BOOL bRet = FALSE;
  1521. if (!_CanUseVolume() || !(_pvol->dwVolumeFlags & HWDVF_STATE_SUPPORTNOTIFICATION))
  1522. {
  1523. // if the drive dosen't support notification, we need to ping it now
  1524. bRet = GetVolumeInformation(_GetNameForFctCall(),
  1525. NULL,
  1526. 0,
  1527. NULL,
  1528. NULL,
  1529. NULL,
  1530. NULL,
  1531. NULL);
  1532. }
  1533. else
  1534. {
  1535. bRet = (_IsMediaPresent() && (HWDMS_FORMATTED & _pvol->dwMediaState));
  1536. }
  1537. return bRet;
  1538. }
  1539. BOOL CMtPtLocal::_IsReadOnly()
  1540. {
  1541. ASSERT(_CanUseVolume());
  1542. ASSERT(_IsMediaPresent()); // does not make sense otherwise
  1543. BOOL fRet = FALSE;
  1544. if (_IsCDROM() &&
  1545. (
  1546. (HWDMC_WRITECAPABILITY_SUPPORTDETECTION & _pvol->dwMediaState) &&
  1547. (
  1548. (HWDMC_CDROM & _pvol->dwMediaCap) ||
  1549. (HWDMC_DVDROM & _pvol->dwMediaCap)
  1550. )
  1551. )
  1552. )
  1553. {
  1554. fRet = TRUE;
  1555. }
  1556. else
  1557. {
  1558. // We could optimize by checking if the floppy is write protected. But
  1559. // it might not be worth it.
  1560. fRet = FALSE;
  1561. }
  1562. return fRet;
  1563. }
  1564. BOOL CMtPtLocal::_IsMountedOnDriveLetter()
  1565. {
  1566. return _fMountedOnDriveLetter;
  1567. }
  1568. CMtPtLocal::CMtPtLocal()
  1569. {
  1570. #ifdef DEBUG
  1571. ++_cMtPtLocal;
  1572. #endif
  1573. }
  1574. CMtPtLocal::~CMtPtLocal()
  1575. {
  1576. if (_pvol)
  1577. {
  1578. _pvol->Release();
  1579. }
  1580. #ifdef DEBUG
  1581. --_cMtPtLocal;
  1582. #endif
  1583. }
  1584. // static
  1585. HRESULT CMtPtLocal::_CreateMtPtLocal(LPCWSTR pszMountPoint)
  1586. {
  1587. ASSERT(_csDL.IsInside());
  1588. HRESULT hr;
  1589. CMtPtLocal* pmtptl = new CMtPtLocal();
  1590. if (pmtptl)
  1591. {
  1592. int iDrive = DRIVEID(pszMountPoint);
  1593. if (_rgMtPtDriveLetterLocal[iDrive])
  1594. {
  1595. _rgMtPtDriveLetterLocal[iDrive]->Release();
  1596. _rgMtPtDriveLetterLocal[iDrive] = NULL;
  1597. }
  1598. hr = pmtptl->_Init(pszMountPoint);
  1599. if (SUCCEEDED(hr))
  1600. {
  1601. // Yes
  1602. _rgMtPtDriveLetterLocal[iDrive] = pmtptl;
  1603. }
  1604. else
  1605. {
  1606. delete pmtptl;
  1607. }
  1608. }
  1609. else
  1610. {
  1611. hr = E_OUTOFMEMORY;
  1612. }
  1613. return hr;
  1614. }
  1615. HRESULT CMtPtLocal::GetMountPointName(LPWSTR pszMountPoint, DWORD cchMountPoint)
  1616. {
  1617. return StringCchCopy(pszMountPoint, cchMountPoint, _GetName());
  1618. }
  1619. // static
  1620. HRESULT CMtPtLocal::_CreateMtPtLocalWithVolume(LPCWSTR pszMountPoint,
  1621. CVolume* pvol)
  1622. {
  1623. ASSERT(_csDL.IsInside());
  1624. HRESULT hr;
  1625. CMtPtLocal* pmtptlNew = new CMtPtLocal();
  1626. if (pmtptlNew)
  1627. {
  1628. // Is it a drive letter only?
  1629. if (_IsDriveLetter(pszMountPoint))
  1630. {
  1631. // Yes
  1632. int iDrive = DRIVEID(pszMountPoint);
  1633. if (_rgMtPtDriveLetterLocal[iDrive])
  1634. {
  1635. _rgMtPtDriveLetterLocal[iDrive]->Release();
  1636. _rgMtPtDriveLetterLocal[iDrive] = NULL;
  1637. }
  1638. }
  1639. else
  1640. {
  1641. _RemoveLocalMountPoint(pszMountPoint);
  1642. }
  1643. hr = pmtptlNew->_InitWithVolume(pszMountPoint, pvol);
  1644. if (SUCCEEDED(hr))
  1645. {
  1646. // Is it a drive letter only?
  1647. if (_IsDriveLetter(pszMountPoint))
  1648. {
  1649. // Yes
  1650. int iDrive = DRIVEID(pszMountPoint);
  1651. _rgMtPtDriveLetterLocal[iDrive] = pmtptlNew;
  1652. }
  1653. else
  1654. {
  1655. hr = _StoreMtPtMOF(pmtptlNew);
  1656. }
  1657. }
  1658. if (FAILED(hr))
  1659. {
  1660. delete pmtptlNew;
  1661. }
  1662. }
  1663. else
  1664. {
  1665. hr = E_OUTOFMEMORY;
  1666. }
  1667. return hr;
  1668. }
  1669. // static
  1670. HRESULT CMtPtLocal::_CreateMtPtLocalFromVolumeGuid(LPCWSTR pszVolumeGuid, CMountPoint ** ppmtpt )
  1671. {
  1672. ASSERT(_csDL.IsInside());
  1673. HRESULT hr;
  1674. CMtPtLocal* pmtptlNew = new CMtPtLocal();
  1675. Assert(NULL != ppmtpt);
  1676. *ppmtpt = (CMountPoint*)pmtptlNew;
  1677. if (pmtptlNew)
  1678. {
  1679. ASSERT(NULL == pmtptlNew->_pvol);
  1680. hr = StringCchCopy(pmtptlNew->_szName, ARRAYSIZE(pmtptlNew->_szName), pszVolumeGuid);
  1681. if (SUCCEEDED(hr))
  1682. {
  1683. pmtptlNew->RSInitRoot(HKEY_CURRENT_USER, REGSTR_MTPT_ROOTKEY2, pmtptlNew->_szName,
  1684. REG_OPTION_NON_VOLATILE);
  1685. PathAddBackslash(pmtptlNew->_szName);
  1686. pmtptlNew->_fMountedOnDriveLetter = FALSE;
  1687. pmtptlNew->_fVolumePoint = TRUE;
  1688. pmtptlNew->_InitAutorunInfo();
  1689. }
  1690. }
  1691. else
  1692. {
  1693. hr = E_OUTOFMEMORY;
  1694. }
  1695. return hr;
  1696. }
  1697. // static
  1698. CVolume* CMtPtLocal::_GetVolumeByMtPt(LPCWSTR pszMountPoint)
  1699. {
  1700. ASSERT(_csDL.IsInside());
  1701. CVolume* pvol = NULL;
  1702. WCHAR szVolumeGUID[50];
  1703. if (_fLocalDrivesInited)
  1704. {
  1705. if (GetVolumeNameForVolumeMountPoint(pszMountPoint, szVolumeGUID,
  1706. ARRAYSIZE(szVolumeGUID)))
  1707. {
  1708. DWORD c = DPA_GetPtrCount(_hdpaVolumes);
  1709. for (DWORD dw = 0; dw < c; ++dw)
  1710. {
  1711. pvol = (CVolume*)DPA_GetPtr(_hdpaVolumes, dw);
  1712. if (pvol)
  1713. {
  1714. if (!lstrcmpi(pvol->pszVolumeGUID, szVolumeGUID))
  1715. {
  1716. pvol->AddRef();
  1717. break;
  1718. }
  1719. else
  1720. {
  1721. pvol = NULL;
  1722. }
  1723. }
  1724. }
  1725. }
  1726. }
  1727. return pvol;
  1728. }
  1729. // static
  1730. CVolume* CMtPtLocal::_GetVolumeByID(LPCWSTR pszDeviceIDVolume)
  1731. {
  1732. ASSERT(_csDL.IsInside());
  1733. CVolume* pvol = NULL;
  1734. if (_hdpaVolumes)
  1735. {
  1736. DWORD c = DPA_GetPtrCount(_hdpaVolumes);
  1737. for (DWORD dw = 0; dw < c; ++dw)
  1738. {
  1739. pvol = (CVolume*)DPA_GetPtr(_hdpaVolumes, dw);
  1740. if (pvol)
  1741. {
  1742. if (!lstrcmpi(pvol->pszDeviceIDVolume, pszDeviceIDVolume))
  1743. {
  1744. pvol->AddRef();
  1745. break;
  1746. }
  1747. else
  1748. {
  1749. pvol = NULL;
  1750. }
  1751. }
  1752. }
  1753. }
  1754. return pvol;
  1755. }
  1756. // static
  1757. CVolume* CMtPtLocal::_GetAndRemoveVolumeByID(LPCWSTR pszDeviceIDVolume)
  1758. {
  1759. CVolume* pvol = NULL;
  1760. _csDL.Enter();
  1761. if (_hdpaVolumes)
  1762. {
  1763. DWORD c = DPA_GetPtrCount(_hdpaVolumes);
  1764. for (int i = c - 1; i >= 0; --i)
  1765. {
  1766. pvol = (CVolume*)DPA_GetPtr(_hdpaVolumes, i);
  1767. if (pvol)
  1768. {
  1769. if (!lstrcmpi(pvol->pszDeviceIDVolume, pszDeviceIDVolume))
  1770. {
  1771. // Do not AddRef
  1772. DPA_DeletePtr(_hdpaVolumes, i);
  1773. break;
  1774. }
  1775. else
  1776. {
  1777. pvol = NULL;
  1778. }
  1779. }
  1780. }
  1781. }
  1782. _csDL.Leave();
  1783. return pvol;
  1784. }
  1785. // static
  1786. HRESULT CMtPtLocal::_GetAndRemoveVolumeAndItsMtPts(LPCWSTR pszDeviceIDVolume,
  1787. CVolume** ppvol, HDPA hdpaMtPts)
  1788. {
  1789. _csDL.Enter();
  1790. CVolume* pvol = _GetAndRemoveVolumeByID(pszDeviceIDVolume);
  1791. if (pvol)
  1792. {
  1793. for (DWORD dw = 0; dw < 26; ++dw)
  1794. {
  1795. CMtPtLocal* pmtptl = (CMtPtLocal*)_rgMtPtDriveLetterLocal[dw];
  1796. if (pmtptl && pmtptl->_pvol)
  1797. {
  1798. if (pmtptl->_pvol == pvol)
  1799. {
  1800. _rgMtPtDriveLetterLocal[dw] = 0;
  1801. DPA_AppendPtr(hdpaMtPts, pmtptl);
  1802. break;
  1803. }
  1804. }
  1805. }
  1806. _csLocalMtPtHDPA.Enter();
  1807. if (_hdpaMountPoints)
  1808. {
  1809. DWORD c = DPA_GetPtrCount(_hdpaMountPoints);
  1810. for (int i = c - 1; i >= 0; --i)
  1811. {
  1812. CMtPtLocal* pmtptl = (CMtPtLocal*)DPA_GetPtr(_hdpaMountPoints, i);
  1813. if (pmtptl && pmtptl->_pvol)
  1814. {
  1815. if (pmtptl->_pvol == pvol)
  1816. {
  1817. DPA_DeletePtr(_hdpaMountPoints, i);
  1818. DPA_AppendPtr(hdpaMtPts, pmtptl);
  1819. }
  1820. }
  1821. }
  1822. }
  1823. _csLocalMtPtHDPA.Leave();
  1824. }
  1825. *ppvol = pvol;
  1826. _csDL.Leave();
  1827. return S_OK;
  1828. }
  1829. BOOL CMtPtLocal::_IsMiniMtPt()
  1830. {
  1831. return !_CanUseVolume();
  1832. }
  1833. HKEY CMtPtLocal::GetRegKey()
  1834. {
  1835. TraceMsg(TF_MOUNTPOINT, "CMtPtLocal::GetRegKey: for '%s'", _GetNameDebug());
  1836. if (_IsAutoRunDrive())
  1837. {
  1838. _ProcessAutoRunFile();
  1839. }
  1840. return RSDuplicateRootKey();
  1841. }
  1842. DWORD CMtPtLocal::_GetRegVolumeGen()
  1843. {
  1844. ASSERT(_CanUseVolume());
  1845. DWORD dwGen;
  1846. if (!_rsVolumes.RSGetDWORDValue(_pvol->pszVolumeGUID + OFFSET_GUIDWITHINVOLUMEGUID, TEXT("Generation"), &dwGen))
  1847. {
  1848. dwGen = 0;
  1849. }
  1850. return dwGen;
  1851. }
  1852. BOOL CMtPtLocal::_NeedToRefresh()
  1853. {
  1854. ASSERT(_csDL.IsInside());
  1855. ASSERT(!_Shell32LoadedInDesktop());
  1856. BOOL fNeedToRefresh = FALSE;
  1857. if (_CanUseVolume())
  1858. {
  1859. DWORD dwRegVolumeGeneration = _GetRegVolumeGen();
  1860. if (dwRegVolumeGeneration != _pvol->dwGeneration)
  1861. {
  1862. // Remove it so that new mtpts do not get it.
  1863. CVolume* pvolnew;
  1864. CVolume* pvol = _GetAndRemoveVolumeByID(_pvol->pszDeviceIDVolume);
  1865. if (pvol)
  1866. {
  1867. // Release our cache ref count
  1868. pvol->Release();
  1869. }
  1870. // Replace the volume
  1871. if (SUCCEEDED(CMtPtLocal::_CreateVolumeFromReg(_pvol->pszDeviceIDVolume,
  1872. &pvolnew)))
  1873. {
  1874. pvolnew->Release();
  1875. }
  1876. fNeedToRefresh = TRUE;
  1877. }
  1878. }
  1879. return fNeedToRefresh;
  1880. }
  1881. // static
  1882. HRESULT CMtPtLocal::_CreateVolumeFromVOLUMEINFO2(VOLUMEINFO2* pvolinfo2, CVolume** ppvolNew)
  1883. {
  1884. VOLUMEINFO volinfo = {0};
  1885. volinfo.pszDeviceIDVolume = pvolinfo2->szDeviceIDVolume;
  1886. volinfo.pszVolumeGUID = pvolinfo2->szVolumeGUID;
  1887. volinfo.pszLabel = pvolinfo2->szLabel;
  1888. volinfo.pszFileSystem = pvolinfo2->szFileSystem;
  1889. volinfo.dwState = pvolinfo2->dwState;
  1890. volinfo.dwVolumeFlags = pvolinfo2->dwVolumeFlags;
  1891. volinfo.dwDriveType = pvolinfo2->dwDriveType;
  1892. volinfo.dwDriveCapability = pvolinfo2->dwDriveCapability;
  1893. volinfo.dwFileSystemFlags = pvolinfo2->dwFileSystemFlags;
  1894. volinfo.dwMaxFileNameLen = pvolinfo2->dwMaxFileNameLen;
  1895. volinfo.dwRootAttributes = pvolinfo2->dwRootAttributes;
  1896. volinfo.dwSerialNumber = pvolinfo2->dwSerialNumber;
  1897. volinfo.dwDriveState = pvolinfo2->dwDriveState;
  1898. volinfo.dwMediaState = pvolinfo2->dwMediaState;
  1899. volinfo.dwMediaCap = pvolinfo2->dwMediaCap;
  1900. if (-1 != pvolinfo2->oAutorunIconLocation)
  1901. {
  1902. volinfo.pszAutorunIconLocation = pvolinfo2->szOptionalStrings +
  1903. pvolinfo2->oAutorunIconLocation;
  1904. }
  1905. if (-1 != pvolinfo2->oAutorunLabel)
  1906. {
  1907. volinfo.pszAutorunLabel = pvolinfo2->szOptionalStrings +
  1908. pvolinfo2->oAutorunLabel;
  1909. }
  1910. if (-1 != pvolinfo2->oIconLocationFromService)
  1911. {
  1912. volinfo.pszIconLocationFromService = pvolinfo2->szOptionalStrings +
  1913. pvolinfo2->oIconLocationFromService;
  1914. }
  1915. if (-1 != pvolinfo2->oNoMediaIconLocationFromService)
  1916. {
  1917. volinfo.pszNoMediaIconLocationFromService = pvolinfo2->szOptionalStrings +
  1918. pvolinfo2->oNoMediaIconLocationFromService;
  1919. }
  1920. if (-1 != pvolinfo2->oLabelFromService)
  1921. {
  1922. volinfo.pszLabelFromService = pvolinfo2->szOptionalStrings +
  1923. pvolinfo2->oLabelFromService;
  1924. }
  1925. return _CreateVolume(&volinfo, ppvolNew);
  1926. }
  1927. // static
  1928. HRESULT CMtPtLocal::_CreateVolumeFromRegHelper(LPCWSTR pszGUID, CVolume** ppvolNew)
  1929. {
  1930. ASSERT(!_Shell32LoadedInDesktop());
  1931. ASSERT(_csDL.IsInside());
  1932. HRESULT hr;
  1933. DWORD cbSize = MAX_VOLUMEINFO2;
  1934. PBYTE pb = (PBYTE)LocalAlloc(LPTR, cbSize);
  1935. if (pb)
  1936. {
  1937. if (_rsVolumes.RSGetBinaryValue(pszGUID, TEXT("Data"), pb, &cbSize))
  1938. {
  1939. DWORD dwGen;
  1940. if (_rsVolumes.RSGetDWORDValue(pszGUID, TEXT("Generation"), &dwGen))
  1941. {
  1942. VOLUMEINFO2* pvolinfo2 = (VOLUMEINFO2*)pb;
  1943. hr = _CreateVolumeFromVOLUMEINFO2(pvolinfo2, ppvolNew);
  1944. if (SUCCEEDED(hr))
  1945. {
  1946. (*ppvolNew)->dwGeneration = dwGen;
  1947. }
  1948. }
  1949. else
  1950. {
  1951. hr = E_FAIL;
  1952. }
  1953. }
  1954. else
  1955. {
  1956. hr = E_FAIL;
  1957. }
  1958. LocalFree(pb);
  1959. }
  1960. else
  1961. {
  1962. hr = E_OUTOFMEMORY;
  1963. }
  1964. return hr;
  1965. }
  1966. // static
  1967. HRESULT CMtPtLocal::_CreateVolumeFromReg(LPCWSTR pszDeviceIDVolume, CVolume** ppvolNew)
  1968. {
  1969. ASSERT(!_Shell32LoadedInDesktop());
  1970. ASSERT(_csDL.IsInside());
  1971. HRESULT hr;
  1972. WCHAR szDeviceIDWithSlash[MAX_PATH];
  1973. WCHAR szVolumeGUID[50];
  1974. hr = StringCchCopy(szDeviceIDWithSlash, ARRAYSIZE(szDeviceIDWithSlash),
  1975. pszDeviceIDVolume);
  1976. if (SUCCEEDED(hr))
  1977. {
  1978. if (PathAddBackslash(szDeviceIDWithSlash))
  1979. {
  1980. if (GetVolumeNameForVolumeMountPoint(szDeviceIDWithSlash,
  1981. szVolumeGUID, ARRAYSIZE(szVolumeGUID)))
  1982. {
  1983. LPWSTR pszGUID = &(szVolumeGUID[OFFSET_GUIDWITHINVOLUMEGUID]);
  1984. hr = _CreateVolumeFromRegHelper(pszGUID, ppvolNew);
  1985. }
  1986. else
  1987. {
  1988. hr = E_FAIL;
  1989. }
  1990. }
  1991. else
  1992. {
  1993. hr = E_FAIL;
  1994. }
  1995. }
  1996. return hr;
  1997. }
  1998. // static
  1999. HRESULT CMtPtLocal::_UpdateVolumeRegInfo(VOLUMEINFO* pvolinfo)
  2000. {
  2001. ASSERT(_Shell32LoadedInDesktop());
  2002. ASSERT(_csDL.IsInside());
  2003. HRESULT hr;
  2004. DWORD cbSize = MAX_VOLUMEINFO2;
  2005. PBYTE pb = (PBYTE)LocalAlloc(LPTR, cbSize);
  2006. if (pb)
  2007. {
  2008. DWORD dwGen;
  2009. VOLUMEINFO2* pvolinfo2 = (VOLUMEINFO2*)pb;
  2010. // Get the Generation
  2011. if (!_rsVolumes.RSGetDWORDValue(
  2012. pvolinfo->pszVolumeGUID + OFFSET_GUIDWITHINVOLUMEGUID, TEXT("Generation"),
  2013. &dwGen))
  2014. {
  2015. dwGen = 0;
  2016. }
  2017. ++dwGen;
  2018. ASSERT(pvolinfo->pszDeviceIDVolume);
  2019. ASSERT(pvolinfo->pszVolumeGUID);
  2020. ASSERT(pvolinfo->pszLabel);
  2021. ASSERT(pvolinfo->pszFileSystem);
  2022. hr = StringCchCopy(pvolinfo2->szDeviceIDVolume, ARRAYSIZE(pvolinfo2->szDeviceIDVolume),
  2023. pvolinfo->pszDeviceIDVolume);
  2024. if (SUCCEEDED(hr))
  2025. {
  2026. hr = StringCchCopy(pvolinfo2->szVolumeGUID, ARRAYSIZE(pvolinfo2->szVolumeGUID),
  2027. pvolinfo->pszVolumeGUID);
  2028. }
  2029. if (SUCCEEDED(hr))
  2030. {
  2031. StringCchCopy(pvolinfo2->szLabel, ARRAYSIZE(pvolinfo2->szLabel),
  2032. pvolinfo->pszLabel);
  2033. StringCchCopy(pvolinfo2->szFileSystem, ARRAYSIZE(pvolinfo2->szFileSystem),
  2034. pvolinfo->pszFileSystem);
  2035. pvolinfo2->dwState = pvolinfo->dwState;
  2036. pvolinfo2->dwVolumeFlags = pvolinfo->dwVolumeFlags;
  2037. pvolinfo2->dwDriveType = pvolinfo->dwDriveType;
  2038. pvolinfo2->dwDriveCapability = pvolinfo->dwDriveCapability;
  2039. pvolinfo2->dwFileSystemFlags = pvolinfo->dwFileSystemFlags;
  2040. pvolinfo2->dwMaxFileNameLen = pvolinfo->dwMaxFileNameLen;
  2041. pvolinfo2->dwRootAttributes = pvolinfo->dwRootAttributes;
  2042. pvolinfo2->dwSerialNumber = pvolinfo->dwSerialNumber;
  2043. pvolinfo2->dwDriveState = pvolinfo->dwDriveState;
  2044. pvolinfo2->dwMediaState = pvolinfo->dwMediaState;
  2045. pvolinfo2->dwMediaCap = pvolinfo->dwMediaCap;
  2046. pvolinfo2->oAutorunIconLocation = -1;
  2047. pvolinfo2->oAutorunLabel = -1;
  2048. pvolinfo2->oIconLocationFromService = -1;
  2049. pvolinfo2->oNoMediaIconLocationFromService = -1;
  2050. pvolinfo2->oLabelFromService = -1;
  2051. LPWSTR pszNext = pvolinfo2->szOptionalStrings;
  2052. size_t cchLeft = (cbSize - sizeof(*pvolinfo2) +
  2053. sizeof(pvolinfo2->szOptionalStrings)) / sizeof(WCHAR);
  2054. size_t cchLeftBeginWith = cchLeft;
  2055. // The following five strings are optional
  2056. if (pvolinfo->pszAutorunIconLocation)
  2057. {
  2058. pvolinfo2->oAutorunIconLocation = (DWORD)(cchLeftBeginWith - cchLeft);
  2059. hr = StringCchCopyEx(pszNext, cchLeft, pvolinfo->pszAutorunIconLocation, &pszNext, &cchLeft, 0);
  2060. ++pszNext;
  2061. --cchLeft;
  2062. }
  2063. if (SUCCEEDED(hr) && pvolinfo->pszAutorunLabel)
  2064. {
  2065. pvolinfo2->oAutorunLabel = (DWORD)(cchLeftBeginWith - cchLeft);
  2066. hr = StringCchCopyEx(pszNext, cchLeft, pvolinfo->pszAutorunLabel, &pszNext, &cchLeft, 0);
  2067. ++pszNext;
  2068. --cchLeft;
  2069. }
  2070. if (SUCCEEDED(hr) && pvolinfo->pszIconLocationFromService)
  2071. {
  2072. pvolinfo2->oIconLocationFromService = (DWORD)(cchLeftBeginWith - cchLeft);
  2073. hr = StringCchCopyEx(pszNext, cchLeft, pvolinfo->pszIconLocationFromService, &pszNext, &cchLeft, 0);
  2074. ++pszNext;
  2075. --cchLeft;
  2076. }
  2077. if (SUCCEEDED(hr) && pvolinfo->pszNoMediaIconLocationFromService)
  2078. {
  2079. pvolinfo2->oNoMediaIconLocationFromService = (DWORD)(cchLeftBeginWith - cchLeft);
  2080. hr = StringCchCopyEx(pszNext, cchLeft, pvolinfo->pszNoMediaIconLocationFromService, &pszNext, &cchLeft, 0);
  2081. ++pszNext;
  2082. --cchLeft;
  2083. }
  2084. if (SUCCEEDED(hr) && pvolinfo->pszLabelFromService)
  2085. {
  2086. pvolinfo2->oLabelFromService = (DWORD)(cchLeftBeginWith - cchLeft);
  2087. hr = StringCchCopyEx(pszNext, cchLeft, pvolinfo->pszLabelFromService, &pszNext, &cchLeft, 0);
  2088. // Remove one for the null terminator
  2089. --cchLeft;
  2090. }
  2091. if (SUCCEEDED(hr))
  2092. {
  2093. if (_rsVolumes.RSSetBinaryValue(pvolinfo->pszVolumeGUID + OFFSET_GUIDWITHINVOLUMEGUID,
  2094. TEXT("Data"), pb, cbSize - (cchLeft * sizeof(WCHAR)), REG_OPTION_VOLATILE))
  2095. {
  2096. if (_rsVolumes.RSSetDWORDValue(pvolinfo->pszVolumeGUID + OFFSET_GUIDWITHINVOLUMEGUID,
  2097. TEXT("Generation"), dwGen))
  2098. {
  2099. hr = S_OK;
  2100. }
  2101. else
  2102. {
  2103. hr = E_FAIL;
  2104. }
  2105. }
  2106. else
  2107. {
  2108. hr = E_FAIL;
  2109. }
  2110. }
  2111. if (FAILED(hr))
  2112. {
  2113. _rsVolumes.RSDeleteSubKey(pvolinfo->pszVolumeGUID + OFFSET_GUIDWITHINVOLUMEGUID);
  2114. }
  2115. }
  2116. LocalFree(pb);
  2117. }
  2118. else
  2119. {
  2120. hr = E_OUTOFMEMORY;
  2121. }
  2122. return hr;
  2123. }
  2124. // static
  2125. HRESULT CMtPtLocal::_UpdateVolumeRegInfo2(VOLUMEINFO2* pvolinfo2)
  2126. {
  2127. ASSERT(_Shell32LoadedInDesktop());
  2128. ASSERT(_csDL.IsInside());
  2129. HRESULT hr;
  2130. DWORD dwGen;
  2131. // Get the Generation
  2132. if (!_rsVolumes.RSGetDWORDValue(
  2133. pvolinfo2->szVolumeGUID + OFFSET_GUIDWITHINVOLUMEGUID, TEXT("Generation"),
  2134. &dwGen))
  2135. {
  2136. dwGen = 0;
  2137. }
  2138. ++dwGen;
  2139. if (_rsVolumes.RSSetBinaryValue(pvolinfo2->szVolumeGUID + OFFSET_GUIDWITHINVOLUMEGUID,
  2140. TEXT("Data"), (PBYTE)pvolinfo2, pvolinfo2->cbSize, REG_OPTION_VOLATILE))
  2141. {
  2142. if (_rsVolumes.RSSetDWORDValue(pvolinfo2->szVolumeGUID + OFFSET_GUIDWITHINVOLUMEGUID,
  2143. TEXT("Generation"), dwGen))
  2144. {
  2145. hr = S_OK;
  2146. }
  2147. else
  2148. {
  2149. hr = E_FAIL;
  2150. }
  2151. }
  2152. else
  2153. {
  2154. hr = E_FAIL;
  2155. }
  2156. if (FAILED(hr))
  2157. {
  2158. _rsVolumes.RSDeleteSubKey(pvolinfo2->szVolumeGUID + OFFSET_GUIDWITHINVOLUMEGUID);
  2159. }
  2160. return hr;
  2161. }
  2162. //static
  2163. BOOL CMtPtLocal::Initialize()
  2164. {
  2165. _rsVolumes.RSInitRoot(HKEY_CURRENT_USER, REGSTR_MTPT_ROOTKEY2,
  2166. g_szCrossProcessCacheVolumeKey, REG_OPTION_VOLATILE);
  2167. return TRUE;
  2168. }
  2169. void CMtPtLocal::FinalCleanUp()
  2170. {
  2171. if (_Shell32LoadedInDesktop())
  2172. {
  2173. _rsVolumes.RSDeleteKey();
  2174. }
  2175. }
  2176. static const TWODWORDS arcontenttypemappings[] =
  2177. {
  2178. { HWDMC_HASAUTORUNINF, ARCONTENT_AUTORUNINF },
  2179. { HWDMC_HASAUDIOTRACKS, ARCONTENT_AUDIOCD },
  2180. { HWDMC_HASDVDMOVIE, ARCONTENT_DVDMOVIE },
  2181. };
  2182. static const TWODWORDS arblankmediamappings[] =
  2183. {
  2184. { HWDMC_CDRECORDABLE, ARCONTENT_BLANKCD },
  2185. { HWDMC_CDREWRITABLE, ARCONTENT_BLANKCD },
  2186. { HWDMC_DVDRECORDABLE, ARCONTENT_BLANKDVD },
  2187. { HWDMC_DVDREWRITABLE, ARCONTENT_BLANKDVD },
  2188. };
  2189. DWORD CMtPtLocal::_GetAutorunContentType()
  2190. {
  2191. DWORD dwRet = 0;
  2192. if (_CanUseVolume())
  2193. {
  2194. dwRet = _DoDWORDMapping(_pvol->dwMediaCap, arcontenttypemappings,
  2195. ARRAYSIZE(arcontenttypemappings), TRUE);
  2196. if (_pvol->dwMediaState & HWDMS_FORMATTED)
  2197. {
  2198. dwRet |= ARCONTENT_UNKNOWNCONTENT;
  2199. }
  2200. else
  2201. {
  2202. ASSERT(!dwRet);
  2203. DWORD dwDriveCapabilities;
  2204. DWORD dwMediaCapabilities;
  2205. if (_IsCDROM())
  2206. {
  2207. if (SUCCEEDED(CDBurn_GetCDInfo(_pvol->pszVolumeGUID, &dwDriveCapabilities, &dwMediaCapabilities)))
  2208. {
  2209. dwRet = _DoDWORDMapping(dwMediaCapabilities, arblankmediamappings,
  2210. ARRAYSIZE(arblankmediamappings), TRUE);
  2211. }
  2212. }
  2213. }
  2214. }
  2215. else
  2216. {
  2217. // If there's no _pvol, we care only about autorun.inf
  2218. if (_IsAutorun())
  2219. {
  2220. dwRet = ARCONTENT_AUTORUNINF;
  2221. }
  2222. if (_IsFormatted())
  2223. {
  2224. dwRet |= ARCONTENT_UNKNOWNCONTENT;
  2225. }
  2226. }
  2227. return dwRet;
  2228. }
  2229. // static
  2230. BOOL CMtPtLocal::IsVolume(LPCWSTR pszDeviceID)
  2231. {
  2232. BOOL fRet = FALSE;
  2233. _csDL.Enter();
  2234. CVolume* pvol = _GetVolumeByID(pszDeviceID);
  2235. if (pvol)
  2236. {
  2237. fRet = TRUE;
  2238. pvol->Release();
  2239. }
  2240. _csDL.Leave();
  2241. return fRet;
  2242. }
  2243. static const TWODWORDS drivetypemappings[] =
  2244. {
  2245. { HWDTS_FLOPPY35 , DT_FLOPPY35 },
  2246. { HWDTS_FLOPPY525 , DT_FLOPPY525 },
  2247. { HWDTS_REMOVABLEDISK, DT_REMOVABLEDISK },
  2248. { HWDTS_FIXEDDISK , DT_FIXEDDISK },
  2249. { HWDTS_CDROM , DT_CDROM },
  2250. };
  2251. static const TWODWORDS drivetypemappingusingGDT[] =
  2252. {
  2253. { DRIVE_REMOVABLE , DT_REMOVABLEDISK },
  2254. { DRIVE_FIXED , DT_FIXEDDISK },
  2255. { DRIVE_RAMDISK , DT_FIXEDDISK },
  2256. { DRIVE_CDROM , DT_CDROM },
  2257. };
  2258. static const TWODWORDS cdtypemappings[] =
  2259. {
  2260. { HWDDC_CDROM , DT_CDROM },
  2261. { HWDDC_CDRECORDABLE , DT_CDR },
  2262. { HWDDC_CDREWRITABLE , DT_CDRW },
  2263. { HWDDC_DVDROM , DT_DVDROM },
  2264. { HWDDC_DVDRECORDABLE, DT_DVDR },
  2265. { HWDDC_DVDREWRITABLE, DT_DVDRW },
  2266. { HWDDC_DVDRAM , DT_DVDRAM },
  2267. };
  2268. DWORD CMtPtLocal::_GetMTPTDriveType()
  2269. {
  2270. DWORD dwRet = 0;
  2271. if (_CanUseVolume())
  2272. {
  2273. dwRet = _DoDWORDMapping(_pvol->dwDriveType, drivetypemappings,
  2274. ARRAYSIZE(drivetypemappings), TRUE);
  2275. if (DT_CDROM == dwRet)
  2276. {
  2277. DWORD dwDriveCapabilities;
  2278. DWORD dwMediaCapabilities;
  2279. if (SUCCEEDED(CDBurn_GetCDInfo(_pvol->pszVolumeGUID, &dwDriveCapabilities, &dwMediaCapabilities)))
  2280. {
  2281. dwRet |= _DoDWORDMapping(dwDriveCapabilities, cdtypemappings,
  2282. ARRAYSIZE(cdtypemappings), TRUE);
  2283. }
  2284. }
  2285. }
  2286. else
  2287. {
  2288. dwRet = _DoDWORDMapping(GetDriveType(_GetNameForFctCall()), drivetypemappingusingGDT,
  2289. ARRAYSIZE(drivetypemappingusingGDT), FALSE);
  2290. }
  2291. return dwRet;
  2292. }
  2293. /* TBD
  2294. CT_UNKNOWNCONTENT 0x00000008
  2295. CT_AUTOPLAYMUSIC 0x00000100
  2296. CT_AUTOPLAYPIX 0x00000200
  2297. CT_AUTOPLAYMOVIE 0x00000400*/
  2298. static const TWODWORDS contenttypemappings[] =
  2299. {
  2300. { HWDMC_HASAUTORUNINF, CT_AUTORUNINF },
  2301. { HWDMC_HASAUDIOTRACKS, CT_CDAUDIO },
  2302. { HWDMC_HASDVDMOVIE, CT_DVDMOVIE },
  2303. };
  2304. static const TWODWORDS blankmediamappings[] =
  2305. {
  2306. { HWDMC_CDRECORDABLE, CT_BLANKCDR },
  2307. { HWDMC_CDREWRITABLE, CT_BLANKCDRW },
  2308. { HWDMC_DVDRECORDABLE, CT_BLANKDVDR },
  2309. { HWDMC_DVDREWRITABLE, CT_BLANKDVDRW },
  2310. };
  2311. DWORD CMtPtLocal::_GetMTPTContentType()
  2312. {
  2313. DWORD dwRet = 0;
  2314. if (_CanUseVolume())
  2315. {
  2316. dwRet = _DoDWORDMapping(_pvol->dwMediaCap, contenttypemappings,
  2317. ARRAYSIZE(contenttypemappings), TRUE);
  2318. if (!(_pvol->dwMediaState & HWDMS_FORMATTED))
  2319. {
  2320. ASSERT(!dwRet);
  2321. DWORD dwDriveCapabilities;
  2322. DWORD dwMediaCapabilities;
  2323. if (_IsCDROM())
  2324. {
  2325. if (SUCCEEDED(CDBurn_GetCDInfo(_pvol->pszVolumeGUID, &dwDriveCapabilities, &dwMediaCapabilities)))
  2326. {
  2327. dwRet = _DoDWORDMapping(dwMediaCapabilities, blankmediamappings,
  2328. ARRAYSIZE(blankmediamappings), TRUE);
  2329. }
  2330. }
  2331. }
  2332. else
  2333. {
  2334. dwRet |= CT_UNKNOWNCONTENT;
  2335. }
  2336. }
  2337. else
  2338. {
  2339. // If there's no _pvol, we care only about autorun.inf
  2340. if (_IsAutorun())
  2341. {
  2342. dwRet = CT_AUTORUNINF;
  2343. }
  2344. if (_IsFormatted())
  2345. {
  2346. dwRet |= CT_UNKNOWNCONTENT;
  2347. }
  2348. }
  2349. return dwRet;
  2350. }