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.

118 lines
3.3 KiB

  1. #include "precomp.hxx"
  2. #pragma hdrstop
  3. #include "util.h"
  4. #include "dll.h"
  5. #include "resource.h"
  6. class CMyDocsCopyHook : public ICopyHook
  7. {
  8. public:
  9. CMyDocsCopyHook();
  10. // IUnknown
  11. STDMETHOD(QueryInterface)(REFIID riid, void **ppv);
  12. STDMETHOD_(ULONG, AddRef)();
  13. STDMETHOD_(ULONG, Release)();
  14. // ICopyHook
  15. STDMETHOD_(UINT,CopyCallback)(HWND hwnd, UINT wFunc, UINT wFlags,
  16. LPCTSTR pszSrcFile, DWORD dwSrcAttribs,
  17. LPCTSTR pszDestFile, DWORD dwDestAttribs);
  18. private:
  19. ~CMyDocsCopyHook();
  20. LONG _cRef;
  21. };
  22. STDMETHODIMP CMyDocsCopyHook::QueryInterface(REFIID riid, void **ppv)
  23. {
  24. static const QITAB qit[] = {
  25. QITABENT(CMyDocsCopyHook, ICopyHook), // IID_ICopyHook
  26. { 0 },
  27. };
  28. return QISearch(this, qit, riid, ppv);
  29. }
  30. STDMETHODIMP_ (ULONG) CMyDocsCopyHook::AddRef()
  31. {
  32. return InterlockedIncrement(&_cRef);
  33. }
  34. STDMETHODIMP_ (ULONG) CMyDocsCopyHook::Release()
  35. {
  36. ASSERT( 0 != _cRef );
  37. ULONG cRef = InterlockedDecrement(&_cRef);
  38. if ( 0 == cRef )
  39. {
  40. delete this;
  41. }
  42. return cRef;
  43. }
  44. CMyDocsCopyHook::CMyDocsCopyHook() : _cRef(1)
  45. {
  46. DllAddRef();
  47. }
  48. CMyDocsCopyHook::~CMyDocsCopyHook()
  49. {
  50. DllRelease();
  51. }
  52. // ICopyHook methods
  53. UINT CMyDocsCopyHook::CopyCallback(HWND hwnd, UINT wFunc, UINT wFlags,
  54. LPCTSTR pszSrcFile, DWORD dwSrcAttribs,
  55. LPCTSTR pszDestFile, DWORD dwDestAttribs)
  56. {
  57. UINT uRes = IDYES;
  58. if ((wFunc == FO_COPY) || (wFunc == FO_MOVE))
  59. {
  60. TCHAR szPersonal[MAX_PATH];
  61. if (S_OK == SHGetFolderPath(NULL, CSIDL_PERSONAL | CSIDL_FLAG_DONT_VERIFY, NULL, SHGFP_TYPE_CURRENT, szPersonal) &&
  62. lstrcmpi(pszSrcFile, szPersonal) == 0)
  63. {
  64. // the source is the personal directory, now check if the
  65. // destination is on the desktop...
  66. DWORD dwRes = IsPathGoodMyDocsPath(hwnd, pszDestFile);
  67. if (dwRes == PATH_IS_NONEXISTENT)
  68. {
  69. StrCpyN(szPersonal, pszDestFile, ARRAYSIZE(szPersonal));
  70. if (PathRemoveFileSpec(szPersonal))
  71. {
  72. dwRes = IsPathGoodMyDocsPath(hwnd, szPersonal);
  73. }
  74. }
  75. if (dwRes == PATH_IS_DESKTOP)
  76. {
  77. // keep the user from moving the personal folder to the desktop
  78. TCHAR szVerb[ 32 ];
  79. LoadString(g_hInstance, (wFunc == FO_COPY) ? IDS_COPY : IDS_MOVE, szVerb, ARRAYSIZE(szVerb));
  80. uRes = IDNO;
  81. GetFolderDisplayName(CSIDL_PERSONAL, szPersonal, ARRAYSIZE(szPersonal));
  82. ShellMessageBox(g_hInstance, hwnd,
  83. (LPTSTR)IDS_NODRAG_DESKTOP_NOT_HIDDEN, szPersonal,
  84. MB_OK | MB_ICONSTOP, szPersonal, szVerb);
  85. }
  86. }
  87. }
  88. return uRes;
  89. }
  90. HRESULT CMyDocsCopyHook_CreateInstance(IUnknown *punkOuter, IUnknown **ppunk, LPCOBJECTINFO poi)
  91. {
  92. CMyDocsCopyHook * pMDCH = new CMyDocsCopyHook();
  93. if (pMDCH)
  94. {
  95. *ppunk = SAFECAST(pMDCH, ICopyHook*);
  96. return S_OK;
  97. }
  98. *ppunk = NULL;
  99. return E_OUTOFMEMORY;
  100. }