Changeset 2120 for trunk/eraser
- Timestamp:
- 5/15/2010 11:35:15 AM (3 years ago)
- Location:
- trunk/eraser/Eraser.Shell
- Files:
-
- 2 edited
-
CtxMenu.cpp (modified) (6 diffs)
-
CtxMenu.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser/Eraser.Shell/CtxMenu.cpp
r2119 r2120 170 170 return E_INVALIDARG; 171 171 172 //Sanity check - make sure there is at least one filename. 173 UINT uNumFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); 174 if (!uNumFiles) 175 { 176 GlobalUnlock(stg.hGlobal); 177 ReleaseStgMedium(&stg); 178 return E_INVALIDARG; 179 } 180 181 //Collect all the files which have been selected. 182 HRESULT hr = S_OK; 183 WCHAR buffer[MAX_PATH] = {0}; 184 for (UINT i = 0; i < uNumFiles; i++) 185 { 186 UINT charsWritten = DragQueryFile(hDrop, i, buffer, sizeof(buffer) / sizeof(buffer[0])); 187 if (!charsWritten) 188 { 189 hr = E_INVALIDARG; 190 continue; 191 } 192 193 SelectedFiles.push_back(std::wstring(buffer, charsWritten)); 194 } 172 //Assign the list of files selected. 173 SelectedFiles.swap(GetHDropPaths(hDrop)); 195 174 196 175 //Clean up. 197 176 GlobalUnlock(stg.hGlobal); 198 177 ReleaseStgMedium(&stg); 199 return hr;178 return SelectedFiles.empty() ? E_INVALIDARG : S_OK; 200 179 } 201 180 … … 303 282 VerbMenuIndices.push_back(ACTION_SECURE_MOVE); 304 283 } 284 if (applicableActions & ACTION_SECURE_PASTE) 285 { 286 VerbMenuIndices.push_back(ACTION_SECURE_PASTE); 287 } 305 288 306 289 //Insert the submenu into the Context menu provided by Explorer. … … 308 291 MENUITEMINFO mii = { sizeof(MENUITEMINFO) }; 309 292 mii.wID = uID++; 310 mii.fMask = MIIM_SUBMENU | MIIM_STRING | MIIM_ID; 311 mii.hSubMenu = hSubmenu; 312 mii.dwTypeData = const_cast<wchar_t*>(MenuTitle); 293 mii.fMask = MIIM_STRING | MIIM_ID; 294 if (InvokeReason != INVOKEREASON_DIRECTORY_BACKGROUND) 295 { 296 mii.fMask |= MIIM_SUBMENU; 297 mii.hSubMenu = hSubmenu; 298 mii.dwTypeData = const_cast<wchar_t*>(MenuTitle); 299 } 300 else 301 { 302 mii.dwTypeData = L"E&raser Secure Paste"; 303 } 304 313 305 MenuID = mii.wID; 314 306 … … 567 559 break; 568 560 561 case ACTION_SECURE_PASTE: 562 { 563 //Set the destination for the paste operation. 564 commandLine += L"\"/destination=" + DragDropDestinationDirectory + L"\""; 565 566 //Query the files from the clipboard. 567 std::vector<std::wstring> paths; 568 if (OpenClipboard(NULL)) 569 { 570 HDROP fileHandle = reinterpret_cast<HDROP>(GetClipboardData(CF_HDROP)); 571 if (fileHandle) 572 SelectedFiles = GetHDropPaths(fileHandle); 573 574 EmptyClipboard(); 575 CloseClipboard(); 576 } 577 } 578 break; 579 569 580 default: 570 581 if (!(pCmdInfo->fMask & CMIC_MASK_FLAG_NO_UI)) … … 642 653 if (OpenClipboard(NULL)) 643 654 { 655 const UINT preferredDropEffect = RegisterClipboardFormat(L"Preferred DropEffect"); 656 bool hasFiles = false; 657 bool hasDropEffect = false; 658 DWORD dropEffect = DROPEFFECT_NONE; 659 644 660 UINT clipboardFormat = 0; 645 661 while ((clipboardFormat = EnumClipboardFormats(clipboardFormat)) != 0) 662 { 646 663 if (clipboardFormat == CF_HDROP) 647 break; 648 649 if (clipboardFormat != CF_HDROP) 664 hasFiles = true; 665 else if (clipboardFormat == preferredDropEffect) 666 { 667 hasDropEffect = true; 668 HGLOBAL hGlobal = GetClipboardData(preferredDropEffect); 669 DWORD* data = reinterpret_cast<DWORD*>(GlobalLock(hGlobal)); 670 671 if (data) 672 { 673 dropEffect = *data; 674 GlobalUnlock(hGlobal); 675 } 676 } 677 } 678 679 if (!hasFiles || hasDropEffect && dropEffect != DROPEFFECT_MOVE) 650 680 result &= ~ACTION_SECURE_PASTE; 651 681 CloseClipboard(); … … 830 860 &buffer.front()); 831 861 return keyInfo->Name; 862 } 863 864 std::list<std::wstring> CCtxMenu::GetHDropPaths(HDROP hDrop) 865 { 866 //Sanity check - make sure there is at least one filename. 867 UINT uNumFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); 868 if (!uNumFiles) 869 return std::list<std::wstring>(); 870 871 //Collect all the files which have been selected. 872 HRESULT hr = S_OK; 873 WCHAR buffer[MAX_PATH] = {0}; 874 std::list<std::wstring> result; 875 for (UINT i = 0; i < uNumFiles; i++) 876 { 877 UINT charsWritten = DragQueryFile(hDrop, i, buffer, sizeof(buffer) / sizeof(buffer[0])); 878 if (!charsWritten) 879 { 880 hr = E_INVALIDARG; 881 continue; 882 } 883 884 result.push_back(std::wstring(buffer, charsWritten)); 885 } 886 887 return result; 832 888 } 833 889 -
trunk/eraser/Eraser.Shell/CtxMenu.h
r2119 r2120 87 87 static std::wstring FormatError(DWORD lastError = static_cast<DWORD>(-1)); 88 88 static std::wstring GetHKeyPath(HKEY handle); 89 static std::list<std::wstring> GetHDropPaths(HDROP hDrop); 89 90 90 91 static bool IsUserAdmin();
Note: See TracChangeset
for help on using the changeset viewer.
