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.

659 lines
22 KiB

  1. #ifndef _MTPT_H
  2. #define _MTPT_H
  3. #include "regsprtb.h"
  4. #include "hwcmmn.h"
  5. #include "dpa.h"
  6. #include <dbt.h>
  7. #define REGSTR_MTPT_ROOTKEY2 TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MountPoints2")
  8. /////////////////////////////////////////////////////////////////////////////
  9. // Assumptions
  10. /////////////////////////////////////////////////////////////////////////////
  11. // 1- Floppies (3.5" and 5.25") are always FAT
  12. // 2- FAT does not support compression
  13. // 3- DRIVE_CDROM == CDFS or UDF for File system
  14. // 4- CDFS or UDF does not support compression
  15. //
  16. /////////////////////////////////////////////////////////////////////////////
  17. #define DT_FIXEDDISK 0x00000001
  18. #define DT_FLOPPY35 0x00000004
  19. #define DT_FLOPPY525 0x00000008
  20. #define DT_CDROM 0x00000020
  21. #define DT_CDR 0x00000040
  22. #define DT_CDRW 0x00000080
  23. #define DT_DVDROM 0x00000100
  24. #define DT_DVDRAM 0x00000200
  25. #define DT_DVDR 0x00000400
  26. #define DT_DVDRW 0x00000800
  27. #define DT_REMOVABLEDISK 0x00001000
  28. #define DT_REMOTE 0x00002000
  29. #define DT_ANYTYPE 0x0000FFFF
  30. #define DT_ANYFLOPPYDRIVES ( DT_FLOPPY35 | \
  31. DT_FLOPPY525 )
  32. #define DT_ANYCDDRIVES ( DT_CDROM | \
  33. DT_CDR | \
  34. DT_CDRW | \
  35. DT_DVDROM | \
  36. DT_DVDRAM | \
  37. DT_DVDR | \
  38. DT_DVDRW )
  39. #define DT_ANYDVDDRIVES ( DT_DVDROM | \
  40. DT_DVDRAM | \
  41. DT_DVDR | \
  42. DT_DVDRW )
  43. #define DT_ANYWRITABLECDDRIVES ( DT_CDR | \
  44. DT_CDRW )
  45. #define DT_ANYWRITABLEDVDDRIVES ( DT_DVDR | \
  46. DT_DVDRW )
  47. #define DT_ANYREMOVABLEMEDIADRIVES ( DT_ANYCDDRIVES | \
  48. DT_ANYFLOPPYDRIVES | \
  49. DT_REMOVABLEDISK )
  50. #define DT_ANYLOCALDRIVES ( DT_ANYREMOVABLEMEDIADRIVES | \
  51. DT_FIXEDDISK )
  52. #define AUTORUNFLAG_MEDIAARRIVAL 0x00000001
  53. #define AUTORUNFLAG_MTPTARRIVAL 0x00000002
  54. #define AUTORUNFLAG_MENUINVOKED 0x00000004
  55. // put in shell32\shellprv.h
  56. #define TF_MOUNTPOINT 0x08000000
  57. #define MAX_DISPLAYNAME MAX_PATH
  58. #define MAX_MTPTCOMMENT MAX_PATH
  59. #define OFFSET_GUIDWITHINVOLUMEGUID (sizeof("\\\\?\\Volume") - 1)
  60. class CMountPoint;
  61. class CMtPtLocal;
  62. class CMtPtRemote;
  63. class CCriticalSection : CRITICAL_SECTION
  64. {
  65. public:
  66. BOOL Init()
  67. {
  68. // need to use InitializeCriticalSectionAndSpinCount since we are called during process attach
  69. if (InitializeCriticalSectionAndSpinCount(this, 0))
  70. {
  71. _fInited = TRUE;
  72. }
  73. #ifdef DEBUG
  74. _dwThreadIDThatShouldNotTryToEnter = 0;
  75. _fFakeEntered = FALSE;
  76. #endif
  77. return _fInited;
  78. }
  79. void Enter()
  80. {
  81. #ifdef DEBUG
  82. if (_dwThreadIDThatShouldNotTryToEnter)
  83. {
  84. ASSERT(_dwThreadIDThatShouldNotTryToEnter != GetCurrentThreadId());
  85. }
  86. #endif
  87. if (!_fShuttingDown)
  88. {
  89. if (_fInited)
  90. {
  91. EnterCriticalSection(this);
  92. }
  93. }
  94. }
  95. void Leave()
  96. {
  97. if (!_fShuttingDown)
  98. {
  99. if (_fInited)
  100. {
  101. LeaveCriticalSection(this);
  102. }
  103. }
  104. }
  105. void Delete()
  106. {
  107. if (_fInited)
  108. {
  109. _fInited = FALSE;
  110. DeleteCriticalSection(this);
  111. }
  112. }
  113. BOOL IsInitialized()
  114. {
  115. return _fInited;
  116. }
  117. BOOL _fInited;
  118. BOOL _fShuttingDown;
  119. #ifdef DEBUG
  120. BOOL IsInside()
  121. {
  122. ASSERT(_fInited);
  123. return _fFakeEntered || (OwningThread == UlongToHandle(GetCurrentThreadId()));
  124. }
  125. void FakeEnter()
  126. {
  127. ASSERT(_fInited);
  128. // See the comment in CMountPoint::_InitLocalDriveHelper where we use this fct.
  129. // Basically the cirtiical section should already be entered. This will not
  130. // verify that it's entered by the thread that launched us, but it will verify
  131. // that at least one thread entered it.
  132. ASSERT(OwningThread);
  133. _fFakeEntered = TRUE;
  134. }
  135. void FakeLeave()
  136. {
  137. ASSERT(_fInited);
  138. ASSERT(OwningThread);
  139. _fFakeEntered = FALSE;
  140. }
  141. void SetThreadIDToCheckForEntrance(DWORD dwThreadID)
  142. {
  143. _dwThreadIDThatShouldNotTryToEnter = dwThreadID;
  144. }
  145. DWORD _dwThreadIDThatShouldNotTryToEnter;
  146. BOOL _fFakeEntered;
  147. #endif
  148. };
  149. typedef enum
  150. {
  151. APS_RESET = 0,
  152. APS_DID_SNIFF = 0x0001,
  153. // APS_
  154. } APSTATEF;
  155. typedef enum
  156. {
  157. CTI_PIX = 0,
  158. CTI_MUSIC,
  159. CTI_VIDEO,
  160. CTI_MIXCONTENT,
  161. _CTI_TOTAL_COUNT_
  162. } CONTENTTYPE_INDEX;
  163. class CAutoPlayParams
  164. {
  165. public:
  166. CAutoPlayParams(LPCWSTR pszDrive, CMountPoint* pMtPt, DWORD dwAutorunFlags);
  167. ~CAutoPlayParams() { ATOMICRELEASE(_pdo); }
  168. PCWSTR Drive() { return _pszDrive; }
  169. CMountPoint *MountPoint() { return _pmtpt; }
  170. CMtPtLocal *MountPointLocal() { return _pmtptl; }
  171. DWORD DriveType() { return _dwDriveType; }
  172. HRESULT DataObject(IDataObject **ppdo)
  173. {
  174. HRESULT hr = _InitObjects(NULL);
  175. *ppdo = _pdo;
  176. if (SUCCEEDED(hr))
  177. _pdo->AddRef();
  178. return hr;
  179. }
  180. BOOL IsContentTypePresent(DWORD dwContentType);
  181. DWORD ContentType();
  182. void ForceSniff();
  183. protected: // methods
  184. BOOL _ShouldSniffDrive(BOOL fCheckHandlerDefaults);
  185. void _TrySniff();
  186. HRESULT _Sniff(DWORD *pdwFound);
  187. HRESULT _AddWalkToDataObject(INamespaceWalk* pnsw);
  188. HRESULT _InitObjects(IShellFolder **ppsf);
  189. protected: // members
  190. DWORD _state; // APSTATEF
  191. DWORD _dwDriveType;
  192. DWORD _dwContentType;
  193. DWORD _dwAutorunFlags;
  194. PCWSTR _pszDrive;
  195. CMountPoint *_pmtpt;
  196. CMtPtLocal* _pmtptl;
  197. IDataObject *_pdo;
  198. public:
  199. BOOL _fCheckAlwaysDoThisCheckBox;
  200. };
  201. #define AUTORUN_CONDITION_FCT(a) static BOOL (a)(HWND hwndForeground, CAutoPlayParams *papp);
  202. class CMountPoint : public CRegSupport
  203. {
  204. ///////////////////////////////////////////////////////////////////////////////
  205. // Management (mtptmgmt.cpp)
  206. ///////////////////////////////////////////////////////////////////////////////
  207. public:
  208. static CMountPoint* GetMountPoint(LPCTSTR pszMountPoint,
  209. BOOL fCreateNew = TRUE);
  210. static CMountPoint* GetSimulatedMountPointFromVolumeGuid(
  211. LPCTSTR pszVolumeGuid );
  212. static CMountPoint* GetMountPoint(int iDrive, BOOL fCreateNew = TRUE,
  213. BOOL fOKToHitNet = TRUE);
  214. static DWORD GetDrivesMask();
  215. static void HandleMountPointNetEvent(LPCWSTR pszDrive, BOOL fArrival);
  216. static DWORD WINAPI HandleMountPointLocalEventThreadProc(void* pv);
  217. static void HandleMountPointLocalEvent(LPCWSTR pszDrive, BOOL fArrival,
  218. BOOL fMediaEvent);
  219. static void OnNetShareArrival(LPCWSTR pszDrive);
  220. static void OnNetShareRemoval(LPCWSTR pszDrive);
  221. static void OnMediaArrival(LPCWSTR pszDrive);
  222. static void OnMountPointArrival(LPCWSTR pszDrive);
  223. static void OnMediaRemoval(LPCWSTR pszDrive);
  224. static void OnMountPointRemoval(LPCWSTR pszDrive);
  225. static void FinalCleanUp();
  226. static BOOL Initialize();
  227. static void NotifyUnavailableNetDriveGone(LPCWSTR pszMountPoint);
  228. static void NotifyReconnectedNetDrive(LPCWSTR pszMountPoint);
  229. ///////////////////////////////////////////////////////////////////////////////
  230. // Public methods
  231. ///////////////////////////////////////////////////////////////////////////////
  232. public:
  233. HRESULT GetDisplayName(LPTSTR pszName, DWORD cchName);
  234. HRESULT GetComment(LPTSTR pszComment, DWORD cchComment);
  235. virtual HRESULT GetLabel(LPTSTR pszLabel, DWORD cchLabel) = 0;
  236. virtual HRESULT GetLabelNoFancy(LPTSTR pszLabel, DWORD cchLabel) = 0;
  237. virtual HRESULT SetLabel(HWND hwnd, LPCTSTR pszLabel) = 0;
  238. virtual HRESULT SetDriveLabel(HWND hwnd, LPCTSTR pszLabel)
  239. { return SetLabel(hwnd, pszLabel); }
  240. virtual HRESULT GetRemotePath(LPWSTR pszPath, DWORD cchPath) = 0;
  241. BOOL GetFileSystemName(LPTSTR pszFileSysName, DWORD cchFileSysName);
  242. virtual void GetTypeString(LPTSTR pszType, DWORD cchType) = 0;
  243. DWORD GetAttributes();
  244. DWORD GetClusterSize();
  245. virtual int GetDriveFlags() = 0;
  246. int GetVolumeFlags();
  247. virtual UINT GetIcon(LPTSTR pszModule, DWORD cchModule) = 0;
  248. virtual HRESULT GetAssocSystemElement(IAssociationElement **ppae) = 0;
  249. virtual DWORD GetShellDescriptionID() = 0;
  250. virtual HKEY GetRegKey() = 0;
  251. BOOL IsStrictRemovable();
  252. BOOL IsFixedDisk();
  253. BOOL IsRemote();
  254. BOOL IsCDROM();
  255. BOOL IsAudioCD();
  256. BOOL IsAudioCDNoData();
  257. BOOL IsDVD();
  258. BOOL IsDVDRAMMedia();
  259. BOOL IsFormattable();
  260. BOOL IsNTFS();
  261. BOOL IsCompressible();
  262. BOOL IsCompressed();
  263. BOOL IsSupportingSparseFile();
  264. BOOL IsContentIndexed();
  265. BOOL IsSlow();
  266. BOOL IsFloppy();
  267. BOOL IsRemovableDevice();
  268. // Don't call this on net drive for nothing
  269. virtual BOOL IsMounted() { return TRUE; }
  270. virtual BOOL IsFormatted() = 0;
  271. virtual BOOL IsAutoRunDrive() { return FALSE; }
  272. virtual BOOL IsEjectable() { return FALSE; }
  273. virtual BOOL HasMedia() { return TRUE; }
  274. void SetAutorunStatus(BYTE* rgb, DWORD cbSize);
  275. // Returns E_FAIL if not applicable
  276. // Returns S_FALSE if cannot determine capabilities for drive
  277. virtual HRESULT GetCDInfo(DWORD* pdwDriveCapabilities, DWORD* pdwMediaCapabilities)
  278. { return E_FAIL; }
  279. // remote only
  280. virtual BOOL IsUnavailableNetDrive() { return FALSE; }
  281. virtual BOOL IsDisconnectedNetDrive() { return FALSE; }
  282. // local only
  283. virtual HRESULT Eject(HWND hwnd) { return E_FAIL; }
  284. virtual HRESULT ChangeNotifyRegisterAlias(void) = 0;
  285. virtual void StoreIconForUpdateImage(int iImage) { }
  286. static void HandleWMDeviceChange(ULONG_PTR code, DEV_BROADCAST_HDR *pbh);
  287. static void GetTypeString(int iDrive, LPTSTR pszType, DWORD cchType);
  288. static void DoAutorunPrompt(WPARAM iDrive);
  289. static void DoAutorun(LPCWSTR pszDrive, DWORD dwAutorunFlags);
  290. static void _DoAutorunHelper(CAutoPlayParams *papp);
  291. static HRESULT _Sniff(LPCWSTR pszDeviceIDVolume, LPCWSTR pszDrive, DWORD *pdwFound);
  292. static void WantAutorunUI(LPCWSTR pszDrive);
  293. static BOOL _AppAllowsAutoRun(HWND hwndApp, CMountPoint* pmtpt);
  294. static HRESULT _QueryRunningObject(CMountPoint* pmtpt, DWORD dwAutorunContentType, BOOL* pfAllow);
  295. AUTORUN_CONDITION_FCT(_acShiftKeyDown);
  296. AUTORUN_CONDITION_FCT(_acCurrentDesktopIsActiveConsole);
  297. AUTORUN_CONDITION_FCT(_acDriveIsMountedOnDriveLetter);
  298. AUTORUN_CONDITION_FCT(_acDriveIsRestricted);
  299. AUTORUN_CONDITION_FCT(_acHasAutorunCommand);
  300. AUTORUN_CONDITION_FCT(_acHasUseAutoPLAY);
  301. AUTORUN_CONDITION_FCT(_acForegroundAppAllowsAutorun);
  302. AUTORUN_CONDITION_FCT(_acQueryCancelAutoplayAllowsAutorun);
  303. AUTORUN_CONDITION_FCT(_acUserHasSelectedApplication);
  304. AUTORUN_CONDITION_FCT(_acShellIsForegroundApp);
  305. AUTORUN_CONDITION_FCT(_acOSIsServer);
  306. AUTORUN_CONDITION_FCT(_acIsDockedLaptop);
  307. AUTORUN_CONDITION_FCT(_acDriveIsFormatted);
  308. AUTORUN_CONDITION_FCT(_acShellExecuteDriveAutorunINF);
  309. AUTORUN_CONDITION_FCT(_acAlwaysReturnsTRUE);
  310. AUTORUN_CONDITION_FCT(_acPromptUser);
  311. AUTORUN_CONDITION_FCT(_acIsMixedContent);
  312. AUTORUN_CONDITION_FCT(_acExecuteAutoplayDefault);
  313. AUTORUN_CONDITION_FCT(_acWasjustDocked);
  314. AUTORUN_CONDITION_FCT(_acShouldSniff);
  315. AUTORUN_CONDITION_FCT(_acAddAutoplayVerb);
  316. AUTORUN_CONDITION_FCT(_acDirectXAppRunningFullScreen);
  317. static BOOL _ExecuteHelper(LPCWSTR pszHandler, LPCWSTR pszContentTypeHandler,
  318. CAutoPlayParams *papp, DWORD dwMtPtContentType);
  319. static UINT GetSuperPlainDriveIcon(LPCWSTR pszDrive, UINT uDriveType);
  320. static BOOL _CanRegister();
  321. // returns DT_* defined above
  322. virtual DWORD _GetMTPTDriveType() = 0;
  323. // returns CT_* defined above
  324. virtual DWORD _GetMTPTContentType() = 0;
  325. ///////////////////////////////////////////////////////////////////////////////
  326. //
  327. ///////////////////////////////////////////////////////////////////////////////
  328. protected:
  329. virtual BOOL _IsFloppy() { return FALSE; }
  330. virtual BOOL _IsFloppy35() { return FALSE; }
  331. virtual BOOL _IsFloppy525() { return FALSE; }
  332. virtual BOOL _IsCDROM() { return FALSE; }
  333. virtual BOOL _IsStrictRemovable() { return FALSE; }
  334. virtual BOOL _IsAutorun() = 0;
  335. virtual BOOL _IsFormattable() { return FALSE; }
  336. virtual BOOL _IsAudioCD() { return FALSE; }
  337. virtual BOOL _IsAudioCDNoData() { return FALSE; }
  338. virtual BOOL _IsDVD() { return FALSE; }
  339. virtual BOOL _IsFixedDisk() { return FALSE; }
  340. virtual BOOL _IsDVDRAMMedia() { return FALSE; }
  341. virtual BOOL _IsRemovableDevice() { return FALSE; }
  342. BOOL _IsAutoRunDrive();
  343. BOOL _ProcessAutoRunFile();
  344. HRESULT _CopyInvokeVerbKey(LPCWSTR pszProgID, LPCWSTR pszVerb);
  345. HRESULT _AddAutoplayVerb();
  346. static BOOL _IsDriveLetter(LPCWSTR pszDrive);
  347. // Helpers
  348. void _QualifyCommandToDrive(LPTSTR pszCommand, DWORD cchCommand);
  349. virtual BOOL _NeedToRefresh() { return FALSE; }
  350. public:
  351. // Should be accessed only by CMtPt_... fcts
  352. BOOL _IsLFN();
  353. BOOL _IsSecure();
  354. virtual BOOL _IsSlow() { return FALSE; }
  355. private:
  356. ///////////////////////////////////////////////////////////////////////////////
  357. //
  358. ///////////////////////////////////////////////////////////////////////////////
  359. protected:
  360. virtual BOOL _IsAudioDisc() { return FALSE; }
  361. virtual BOOL _IsRemote() { return FALSE; }
  362. BOOL _GetLegacyRegLabel(LPTSTR pszLabel, DWORD cchLabel);
  363. void _UpdateCommentFromDesktopINI();
  364. void _InitLegacyRegIconAndLabel(BOOL fUseAutorunIcon, BOOL fUseAutorunLabel);
  365. virtual BOOL _IsMountedOnDriveLetter() = 0;
  366. ///////////////////////////////////////////////////////////////////////////////
  367. // Management (mtptmgmt.cpp)
  368. ///////////////////////////////////////////////////////////////////////////////
  369. public:
  370. // Drive Letter (DL)
  371. static CMountPoint* _GetMountPointDL(int iDrive, BOOL fCreateNew);
  372. // Mounted On Folder (MOF)
  373. static CMtPtLocal* _GetStoredMtPtMOF(LPTSTR pszPathWithBackslash);
  374. static BOOL _StoreMtPtMOF(CMtPtLocal* pMtPt);
  375. static CMtPtLocal* _GetStoredMtPtMOFFromHDPA(LPTSTR pszPathWithBackslash);
  376. protected:
  377. // Helpers
  378. static BOOL _IsNetDriveLazyLoadNetDLLs(int iDrive);
  379. static HRESULT _InitLocalDrives();
  380. static HRESULT _InitNetDrives();
  381. static HRESULT _InitNetDrivesHelper(DWORD dwScope);
  382. static HRESULT _ReInitNetDrives();
  383. static HRESULT _EnumVolumes(IHardwareDevices* pihwdevs);
  384. static HRESULT _EnumMountPoints(IHardwareDevices* pihwdevs);
  385. static HRESULT _DeleteVolumeInfo();
  386. static HRESULT _DeleteLocalMtPts();
  387. static HRESULT _GetMountPointsForVolume(LPCWSTR pszDeviceIDVolume,
  388. HDPA hdpaMtPts);
  389. static HRESULT _MediaArrivalRemovalHelper(LPCWSTR pszDeviceIDVolume,
  390. BOOL fArrived);
  391. static HRESULT _RemoveLocalMountPoint(LPCWSTR pszMountPoint);
  392. static HRESULT _RemoveNetMountPoint(LPCWSTR pszMountPoint);
  393. static BOOL _LocalDriveIsCoveredByNetDrive(LPCWSTR pszDriveLetter);
  394. static BOOL _CheckLocalMtPtsMOF(LPCWSTR pszMountPoint);
  395. public:
  396. static BOOL _StripToClosestMountPoint(LPCTSTR pszSource, LPTSTR pszDest,
  397. DWORD cchDest);
  398. public:
  399. static HRESULT _InitLocalDriveHelper();
  400. ///////////////////////////////////////////////////////////////////////////////
  401. // Miscellaneous helpers
  402. ///////////////////////////////////////////////////////////////////////////////
  403. protected:
  404. virtual LPCTSTR _GetNameForFctCall();
  405. virtual BOOL _GetFileAttributes(DWORD* pdwAttrib) = 0;
  406. virtual BOOL _GetFileSystemName(LPTSTR pszFileSysName, DWORD cchFileSysName) = 0;
  407. virtual BOOL _GetGVILabelOrMixedCaseFromReg(LPTSTR pszLabel, DWORD cchLabel) = 0;
  408. virtual BOOL _GetGVILabel(LPTSTR pszLabel, DWORD cchLabel) = 0;
  409. virtual BOOL _GetSerialNumber(DWORD* pdwSerialNumber) = 0;
  410. virtual BOOL _GetFileSystemFlags(DWORD* pdwFlags) = 0;
  411. virtual int _GetGVIDriveFlags() = 0;
  412. virtual int _GetDriveType() = 0;
  413. virtual DWORD _GetAutorunContentType() = 0;
  414. TCHAR _GetNameFirstCharUCase();
  415. LPTSTR _GetNameFirstXChar(LPTSTR pszBuffer, int c);
  416. LPCTSTR _GetName();
  417. LPCTSTR _GetNameDebug();
  418. BOOL _GetLabelFromReg(LPWSTR psz, DWORD cch);
  419. BOOL _GetLabelFromDesktopINI(LPWSTR psz, DWORD cch);
  420. CMountPoint();
  421. public:
  422. ULONG AddRef();
  423. ULONG Release();
  424. ///////////////////////////////////////////////////////////////////////////////
  425. //
  426. ///////////////////////////////////////////////////////////////////////////////
  427. static HRESULT _VolumeAddedOrUpdated(BOOL fAdded,
  428. VOLUMEINFO2* pvolinfo2);
  429. static HRESULT _VolumeRemoved(LPCWSTR pszDeviceIDVolume);
  430. static HRESULT _VolumeMountingEvent(LPCWSTR pszDeviceIDVolume,
  431. DWORD dwEvent);
  432. static HRESULT _MountPointAdded(LPCWSTR pszMountPoint,
  433. LPCWSTR pszDeviceIDVolume);
  434. static HRESULT _MountPointRemoved(LPCWSTR pszMountPoint);
  435. static HRESULT RegisterForHardwareNotifications();
  436. static HRESULT HandleDeviceQueryRemove();
  437. static DWORD WINAPI _RegisterThreadProc(void* pv);
  438. static void CALLBACK _EventAPCProc(ULONG_PTR ulpParam);
  439. static DWORD CALLBACK _EventProc(void* pv);
  440. ///////////////////////////////////////////////////////////////////////////////
  441. // Data
  442. ///////////////////////////////////////////////////////////////////////////////
  443. protected:
  444. // Only mtpt, volume, drive real data shared by derived objs
  445. WCHAR _szName[MAX_PATH];
  446. LPWSTR _pszLegacyRegIcon;
  447. LPWSTR _pszLegacyRegLabel;
  448. BOOL _fAutorunFileProcessed;
  449. // Static, non-mtpt related stuff
  450. LONG _cRef;
  451. static CCriticalSection _csLocalMtPtHDPA;
  452. static CCriticalSection _csDL;
  453. static HDPA _hdpaMountPoints;
  454. static HDPA _hdpaVolumes;
  455. static HDPA _hdpaShares;
  456. static DWORD _dwAdviseToken;
  457. // optimization we have an array for the volumes mounted on drive letters
  458. static CMtPtLocal* _rgMtPtDriveLetterLocal[];
  459. static CMtPtRemote* _rgMtPtDriveLetterNet[];
  460. static BOOL _fNetDrivesInited;
  461. static BOOL _fLocalDrivesInited;
  462. static BOOL _fNoVolLocalDrivesInited;
  463. static DWORD _dwTickCountTriedAndFailed;
  464. // Constructor/destructor of _hwdevcb will NOT get called
  465. static BOOL _fShuttingDown;
  466. // Watch out! No constructor nor destructor called on the next members
  467. static CRegSupport _rsMtPtsLocalDL;
  468. static CRegSupport _rsMtPtsLocalMOF;
  469. static CRegSupport _rsMtPtsRemote;
  470. static DWORD _dwRemoteDriveAutorun;
  471. static HANDLE _hThreadSCN;
  472. static DWORD _dwRememberedNetDrivesMask;
  473. public:
  474. static BOOL _fCanRegisterWithShellService;
  475. };
  476. STDAPI MountPoint_RegisterChangeNotifyAlias(int iDrive);
  477. BOOL _Shell32LoadedInDesktop();
  478. struct TWODWORDS
  479. {
  480. DWORD dwLeft;
  481. DWORD dwRight;
  482. };
  483. DWORD _DoDWORDMapping(DWORD dwLeft, const TWODWORDS* rgtwodword, DWORD ctwodword, BOOL fORed);
  484. class PNPNOTIFENTRY : public CRefCounted
  485. {
  486. public:
  487. HDEVNOTIFY hdevnotify;
  488. BOOL fStopSniffing;
  489. HANDLE hThread;
  490. };
  491. // everything is only the things we care about
  492. #define DRIVEHAS_EVERYTHING (CT_AUTOPLAYMUSIC | CT_AUTOPLAYPIX | CT_AUTOPLAYMOVIE)
  493. class CSniffDrive : public INamespaceWalkCB
  494. {
  495. public:
  496. CSniffDrive();
  497. ~CSniffDrive();
  498. // IUnknown methods
  499. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  500. STDMETHODIMP_(ULONG) AddRef()
  501. {
  502. // stack created
  503. return 3;
  504. }
  505. STDMETHODIMP_(ULONG) Release()
  506. {
  507. // stack created
  508. return 2;
  509. }
  510. // INamespaceWalkCB
  511. STDMETHODIMP FoundItem(IShellFolder *psf, LPCITEMIDLIST pidl);
  512. STDMETHODIMP EnterFolder(IShellFolder *psf, LPCITEMIDLIST pidl);
  513. STDMETHODIMP LeaveFolder(IShellFolder *psf, LPCITEMIDLIST pidl);
  514. STDMETHODIMP InitializeProgressDialog(LPWSTR *ppszTitle, LPWSTR *ppszCancel);
  515. DWORD Found() {return _dwFound;}
  516. // CSniffDrive
  517. static HRESULT Init(HANDLE hThreadSCN);
  518. static HRESULT InitNotifyWindow(HWND hwnd);
  519. static HRESULT CleanUp();
  520. static HRESULT HandleNotif(HDEVNOTIFY hdevnotify);
  521. static void CALLBACK _RegisterForNotifsHelper(ULONG_PTR ul);
  522. static void CALLBACK _UnregisterForNotifsHelper(ULONG_PTR ul);
  523. HRESULT RegisterForNotifs(LPCWSTR pszDeviceIDVolume);
  524. HRESULT UnregisterForNotifs();
  525. private: // methods
  526. BOOL _FoundEverything();
  527. private: // members
  528. DWORD _dwFound;
  529. PNPNOTIFENTRY* _pne;
  530. public:
  531. static HANDLE _hThreadSCN;
  532. static CDPA<PNPNOTIFENTRY> _dpaNotifs;
  533. static HWND _hwndNotify;
  534. };
  535. #endif //_MTPT_H