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.

182 lines
4.7 KiB

  1. // PropShellExt.cpp : Implementation of CW3extApp and DLL registration.
  2. #include "stdafx.h"
  3. #include "w3ext.h"
  4. #include "PropShellExt.h"
  5. /////////////////////////////////////////////////////////////////////////////
  6. //
  7. // IShellExtInit Implementation.
  8. STDMETHODIMP
  9. CPropShellExt::Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hKeyID)
  10. {
  11. if (pDataObj == NULL)
  12. {
  13. ATLASSERT(FALSE);
  14. return (E_INVALIDARG);
  15. }
  16. FORMATETC f = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  17. STGMEDIUM m;
  18. HRESULT hr = pDataObj->GetData(&f, &m);
  19. if (FAILED(hr))
  20. {
  21. return(hr);
  22. }
  23. if (1 == DragQueryFile((HDROP)m.hGlobal, (UINT)(-1), NULL,0))
  24. {
  25. TCHAR szFileName[MAX_PATH];
  26. DragQueryFile((HDROP)m.hGlobal, 0, szFileName, sizeof(szFileName) / sizeof(TCHAR));
  27. SHFILEINFO shfi;
  28. SHGetFileInfo(szFileName, 0, &shfi, sizeof(SHFILEINFO), SHGFI_ATTRIBUTES);
  29. if ( (shfi.dwAttributes & (SFGAO_LINK | SFGAO_REMOVABLE)) == 0
  30. && (shfi.dwAttributes & SFGAO_FILESYSTEM) != 0
  31. )
  32. {
  33. int drive_number, drive_type;
  34. TCHAR szRoot[4];
  35. if ( -1 != (drive_number = PathGetDriveNumber(szFileName))
  36. && NULL != PathBuildRoot(szRoot, drive_number)
  37. && DRIVE_REMOTE != (drive_type = GetDriveType(szRoot))
  38. && DRIVE_NO_ROOT_DIR != drive_type
  39. )
  40. {
  41. StrCpy(m_szFileName, szFileName);
  42. }
  43. else
  44. {
  45. hr = E_FAIL;
  46. }
  47. }
  48. else
  49. {
  50. hr = E_FAIL;
  51. }
  52. }
  53. ReleaseStgMedium(&m);
  54. return hr;
  55. }
  56. STDMETHODIMP
  57. CPropShellExt::AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
  58. {
  59. // We only add the page if the user has admin priviliges in the metabase.
  60. // The only way to check it now is to try to write something.
  61. // Test key is /LM/W3SVC.
  62. CMetabasePath path(SZ_MBN_WEB);
  63. CMetaKey key(LOCAL_KEY, path,
  64. METADATA_PERMISSION_READ | METADATA_PERMISSION_WRITE
  65. );
  66. if (key.Succeeded() && SUCCEEDED(key.SetValue(MD_ISM_ACCESS_CHECK, 0x0000FFFF)))
  67. {
  68. m_psW3ShellExtProp.SetParentExt(this);
  69. HPROPSHEETPAGE hpage = m_psW3ShellExtProp.Create();
  70. ASSERT(hpage != NULL);
  71. if (NULL != hpage)
  72. {
  73. AddRef();
  74. if (!lpfnAddPage(hpage, lParam))
  75. {
  76. DestroyPropertySheetPage(hpage);
  77. }
  78. }
  79. }
  80. return key.QueryResult();
  81. }
  82. STDMETHODIMP
  83. CPropShellExt::ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE lpfnReplaceWith, LPARAM lParam)
  84. {
  85. return E_FAIL;
  86. }
  87. BOOL
  88. RecursiveCheckVRoots(CMetaEnumerator& en, LPCTSTR meta_path, LPCTSTR folder_path)
  89. {
  90. BOOL shared = FALSE;
  91. CString vrpath;
  92. BOOL bInheritOverride = FALSE;
  93. if (SUCCEEDED(en.QueryValue(MD_VR_PATH, vrpath, &bInheritOverride, meta_path)))
  94. {
  95. if (vrpath.CompareNoCase(folder_path) == 0)
  96. {
  97. return TRUE;
  98. }
  99. }
  100. CString vdir;
  101. while (SUCCEEDED(en.Next(vdir, meta_path)) && !shared)
  102. {
  103. CString next_vdir;
  104. if (meta_path != NULL)
  105. next_vdir += meta_path;
  106. next_vdir += vdir;
  107. next_vdir += SZ_MBN_SEP_STR;
  108. en.Push();
  109. en.Reset();
  110. shared = RecursiveCheckVRoots(en, next_vdir, folder_path);
  111. en.Pop();
  112. }
  113. return shared;
  114. }
  115. BOOL IsFolderShared(LPCTSTR path)
  116. {
  117. BOOL shared = FALSE;
  118. CMetaEnumerator en(LOCAL_KEY, CMetabasePath(SZ_MBN_WEB));
  119. if (en.Succeeded())
  120. {
  121. DWORD di;
  122. int i = -1;
  123. CString inst;
  124. HRESULT hr = S_OK;
  125. while (SUCCEEDED(hr) && !shared)
  126. {
  127. if (SUCCEEDED(hr = en.Next(di, inst)))
  128. {
  129. CMetabasePath meta_path(TRUE, SZ_MBN_WEB, inst, SZ_MBN_ROOT);
  130. CMetaEnumerator en(LOCAL_KEY, meta_path);
  131. ASSERT(en.Succeeded());
  132. if (en.Succeeded())
  133. {
  134. shared = RecursiveCheckVRoots(en, NULL, path);
  135. }
  136. }
  137. }
  138. }
  139. return shared;
  140. }
  141. UINT
  142. CPropShellExt::CopyCallback(
  143. HWND hwnd,
  144. UINT wFunc,
  145. UINT wFlags,
  146. LPCTSTR pszSrcFile,
  147. DWORD dwSrcAttribs,
  148. LPCTSTR pszDestFile,
  149. DWORD dwDestAttribs
  150. )
  151. {
  152. UINT rc = IDYES;
  153. if ((dwSrcAttribs & FILE_ATTRIBUTE_DIRECTORY) != 0)
  154. {
  155. switch (wFunc)
  156. {
  157. case FO_DELETE:
  158. case FO_MOVE:
  159. case FO_RENAME:
  160. if (IsFolderShared(pszSrcFile))
  161. {
  162. CString cap, msg;
  163. cap.LoadString(_Module.GetResourceInstance(), IDS_PAGE_TITLE);
  164. msg.Format(_Module.GetResourceInstance(), IDS_CONFIRM_OPERATION, pszSrcFile);
  165. rc = MessageBox(hwnd, msg, cap, MB_YESNOCANCEL|MB_ICONQUESTION);
  166. }
  167. break;
  168. }
  169. }
  170. return rc;
  171. }