Source code of Windows XP (NT5)
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.

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