Changeset 716


Ignore:
Timestamp:
12/5/2008 12:58:12 PM (6 years ago)
Author:
lowjoel
Message:

-Replaced the CEraserLPVERBS constants with an Actions enumeration
-Only display relevant actions when a recycle bin context menu is requested (unused space is irrelevant here)

Location:
branches/eraser6/ShellExt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/ShellExt/CtxMenu.cpp

    r715 r716  
    4646    }; 
    4747 
     48    struct KEY_NODE_INFORMATION 
     49    { 
     50        LARGE_INTEGER LastWriteTime; 
     51        ULONG TitleIndex; 
     52        ULONG ClassOffset; 
     53        ULONG ClassLength; 
     54        ULONG NameLength; 
     55        WCHAR Name[1]; 
     56    }; 
     57 
    4858    typedef NTSTATUS (*pZwQueryKey)(HANDLE KeyHandle, KEY_INFORMATION_CLASS KeyInformationClass, 
    4959        PVOID KeyInformation, ULONG Length, PULONG ResultLength); 
     
    116126        if (FAILED(pDataObj->GetData(&fmt, &stg))) 
    117127            //Nope! Return an "invalid argument" error back to Explorer. 
    118             return S_OK; 
     128            return E_INVALIDARG; 
    119129 
    120130        //Get a pointer to the actual data. 
     
    166176        //Create the submenu, following the order defined in the CEraserLPVERB enum, creating 
    167177        //only items which are applicable. 
    168         CEraserLPVERBS applicableVerbs = GetApplicableActions(); 
     178        Actions applicableActions = GetApplicableActions(); 
    169179        VerbMenuIndices.clear(); 
    170         if (applicableVerbs & CERASER_ERASE) 
    171         { 
    172             InsertMenu    (hSubmenu, CERASER_ERASE, MF_BYPOSITION, uID++,               _T("&Erase")); 
    173             VerbMenuIndices.push_back(CERASER_ERASE); 
    174         } 
    175         if (applicableVerbs & CERASER_ERASE_ON_RESTART) 
    176         { 
    177             InsertMenu    (hSubmenu, CERASER_ERASE_ON_RESTART, MF_BYPOSITION, uID++,    _T("Erase on &Restart")); 
    178             VerbMenuIndices.push_back(CERASER_ERASE_ON_RESTART); 
    179         } 
    180         if (applicableVerbs & CERASER_ERASE_UNUSED_SPACE) 
    181         { 
    182             InsertMenu    (hSubmenu, CERASER_ERASE_UNUSED_SPACE, MF_BYPOSITION, uID++,  _T("Erase &Unused Space")); 
    183             VerbMenuIndices.push_back(CERASER_ERASE_UNUSED_SPACE); 
     180        if (applicableActions & ACTION_ERASE) 
     181        { 
     182            InsertMenu    (hSubmenu, ACTION_ERASE, MF_BYPOSITION, uID++,                _T("&Erase")); 
     183            VerbMenuIndices.push_back(ACTION_ERASE); 
     184        } 
     185        if (applicableActions & ACTION_ERASE_ON_RESTART) 
     186        { 
     187            InsertMenu    (hSubmenu, ACTION_ERASE_ON_RESTART, MF_BYPOSITION, uID++, _T("Erase on &Restart")); 
     188            VerbMenuIndices.push_back(ACTION_ERASE_ON_RESTART); 
     189        } 
     190        if (applicableActions & ACTION_ERASE_UNUSED_SPACE) 
     191        { 
     192            InsertMenu    (hSubmenu, ACTION_ERASE_UNUSED_SPACE, MF_BYPOSITION, uID++,   _T("Erase &Unused Space")); 
     193            VerbMenuIndices.push_back(ACTION_ERASE_UNUSED_SPACE); 
    184194        } 
    185195        //------------------------------------------------------------------------- 
    186         if (applicableVerbs & CERASER_SECURE_MOVE) 
     196        if (applicableActions & ACTION_SECURE_MOVE) 
    187197        { 
    188198            if (uID - uidFirstCmd > 0) 
    189                 InsertMenuItem(hSubmenu, CERASER_SEPERATOR_1, TRUE, GetSeparator()); 
    190             InsertMenu    (hSubmenu, CERASER_SECURE_MOVE, MF_BYPOSITION, uID++,         _T("Secure &Move")); 
    191             VerbMenuIndices.push_back(CERASER_SECURE_MOVE); 
     199                InsertMenuItem(hSubmenu, 0, FALSE, GetSeparator()); 
     200            InsertMenu    (hSubmenu, ACTION_SECURE_MOVE, MF_BYPOSITION, uID++,          _T("Secure &Move")); 
     201            VerbMenuIndices.push_back(ACTION_SECURE_MOVE); 
    192202        } 
    193203 
     
    319329            return false; 
    320330 
    321         /*Handle<HFONT> font = CreateFontIndirect(&logFont); 
    322         SelectObject(hdc, font);*/ 
    323331        SIZE textSize; 
    324332        if (!GetTextExtentPoint32(hdc, m_szMenuTitle, static_cast<DWORD>(wcslen(m_szMenuTitle)), &textSize)) 
     
    342350 
    343351        //Check idCmd, it must be 0 or 1 since we have two menu items. 
    344         if ( idCmd > 2 ) 
     352        if (idCmd > 2) 
    345353            return E_INVALIDARG; 
    346354 
     
    413421        switch (VerbMenuIndices[LOWORD(pCmdInfo->lpVerb)]) 
    414422        { 
    415         case CERASER_ERASE: 
     423        case ACTION_ERASE: 
    416424            { 
    417425                //Add Task command. 
     
    446454            } 
    447455            // NOT IMPLEMENTED METHODS 
    448             case CERASER_ERASE_ON_RESTART: 
     456            case ACTION_ERASE_ON_RESTART: 
    449457            { 
    450458                MessageBox (pCmdInfo->hwnd, szMsg, _T("Eraser v6 - Shell Extention Query"), MB_ICONINFORMATION ); 
     
    534542    } 
    535543 
    536     CCtxMenu::CEraserLPVERBS CCtxMenu::GetApplicableActions() 
    537     { 
    538         unsigned result = CERASER_ERASE | CERASER_ERASE_ON_RESTART | CERASER_SECURE_MOVE | 
    539             CERASER_ERASE_UNUSED_SPACE; 
    540  
    541         //Check if this is a context menu (as in, user-invoked) or a drag-and-drop 
    542         //operation. The latter only allows for Secure Move. 
    543         if (!m_szDestinationDirectory.empty()) 
    544             result = CERASER_SECURE_MOVE; 
    545  
     544    CCtxMenu::Actions CCtxMenu::GetApplicableActions() 
     545    { 
     546        unsigned result = 0; 
     547         
     548        //First decide the actions which are applicable to the current invocation 
     549        //reason. 
     550        switch (InvokeReason) 
     551        { 
     552        case INVOKEREASON_RECYCLEBIN: 
     553            result |= ACTION_ERASE | ACTION_ERASE_ON_RESTART; 
     554            break; 
     555        case INVOKEREASON_FILEFOLDER: 
     556            result |= ACTION_ERASE | ACTION_ERASE_ON_RESTART | ACTION_ERASE_UNUSED_SPACE; 
     557        case INVOKEREASON_DRAGDROP: 
     558            result |= ACTION_SECURE_MOVE; 
     559        } 
     560 
     561        //Remove actions that don't apply to the current invocation reason. 
    546562        for (std::list<std::wstring>::const_iterator i = m_szSelectedFiles.begin(); 
    547563            i != m_szSelectedFiles.end(); ++i) 
     
    556572                sizeof(volumeName) / sizeof(volumeName[0]))) 
    557573            { 
    558                 result &= ~CERASER_ERASE_UNUSED_SPACE; 
    559             } 
    560         } 
    561  
    562         return static_cast<CEraserLPVERBS>(result); 
     574                result &= ~ACTION_ERASE_UNUSED_SPACE; 
     575            } 
     576        } 
     577 
     578        return static_cast<Actions>(result); 
    563579    } 
    564580 
     
    567583        ZwQueryKey = reinterpret_cast<pZwQueryKey>(GetProcAddress( 
    568584            LoadLibrary(L"Ntdll.dll"), "ZwQueryKey")); 
    569         ULONG keyInfoSize = sizeof(KEY_BASIC_INFORMATION); 
    570         KEY_BASIC_INFORMATION* keyInfo = NULL; 
     585        ULONG keyInfoSize = sizeof(KEY_NODE_INFORMATION); 
     586        KEY_NODE_INFORMATION* keyInfo = NULL; 
    571587        NTSTATUS queryResult = ERROR_MORE_DATA; 
    572588 
     
    574590        { 
    575591            delete[] keyInfo; 
    576             keyInfo = reinterpret_cast<KEY_BASIC_INFORMATION*>( 
     592            keyInfo = reinterpret_cast<KEY_NODE_INFORMATION*>( 
    577593                new char[keyInfoSize += 512]); 
    578594            ::ZeroMemory(keyInfo, keyInfoSize); 
    579             queryResult = ZwQueryKey(handle, KeyBasicInformation, keyInfo, 
     595            queryResult = ZwQueryKey(handle, KeyNodeInformation, keyInfo, 
    580596                keyInfoSize, &keyInfoSize); 
    581597        } 
    582598 
    583         std::wstring result(keyInfo->Name, keyInfoSize - 
    584             sizeof(KEY_BASIC_INFORMATION) + 1); 
     599        std::wstring result(keyInfo->Name); 
    585600        delete[] keyInfo; 
    586601        return result; 
  • branches/eraser6/ShellExt/CtxMenu.h

    r715 r716  
    5757        }; 
    5858 
    59         enum CEraserLPVERBS 
     59        enum Actions 
    6060        { 
    61             CERASER_ERASE               = 1 << 0, 
    62             CERASER_ERASE_ON_RESTART    = 1 << 1, 
    63             CERASER_ERASE_UNUSED_SPACE  = 1 << 2, 
    64             CERASER_SEPERATOR_1, 
    65             CERASER_SECURE_MOVE         = 1 << 3, 
     61            ACTION_ERASE                = 1 << 0, 
     62            ACTION_ERASE_ON_RESTART     = 1 << 1, 
     63            ACTION_ERASE_UNUSED_SPACE   = 1 << 2, 
     64            ACTION_SEPERATOR_1, 
     65            ACTION_SECURE_MOVE          = 1 << 3, 
    6666        }; 
    6767 
     
    8181        bool OnDrawItem(HDC hdc, RECT rect, UINT action, UINT state); 
    8282 
    83         CEraserLPVERBS GetApplicableActions(); 
     83        Actions GetApplicableActions(); 
    8484 
    8585        static std::wstring GetHKeyPath(HKEY handle); 
     
    9595        string_list m_szSelectedFiles; 
    9696        string_type m_szDestinationDirectory; 
    97         std::vector<CEraserLPVERBS> VerbMenuIndices; 
     97        std::vector<Actions> VerbMenuIndices; 
    9898 
    9999        static const wchar_t* m_szMenuTitle; 
Note: See TracChangeset for help on using the changeset viewer.