Changeset 722


Ignore:
Timestamp:
12/6/2008 1:35:24 AM (6 years ago)
Author:
lowjoel
Message:

Instead of hardcoding strings, I'm going to use resources to embed the different localisations, and calling LoadString? to retrieve the strings. This allows for internationalisation/localisation of the Shell extension text as well.

Location:
branches/eraser6/ShellExt
Files:
2 edited

Legend:

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

    r720 r722  
    180180        if (applicableActions & ACTION_ERASE) 
    181181        { 
    182             InsertMenu    (hSubmenu, ACTION_ERASE, MF_BYPOSITION, uID++,                _T("&Erase")); 
     182            InsertMenu(hSubmenu, ACTION_ERASE, MF_BYPOSITION, uID++, 
     183                LoadString(IDS_ACTION_ERASE).c_str());              //Erase 
    183184            VerbMenuIndices.push_back(ACTION_ERASE); 
    184185        } 
    185186        if (applicableActions & ACTION_ERASE_ON_RESTART) 
    186187        { 
    187             InsertMenu    (hSubmenu, ACTION_ERASE_ON_RESTART, MF_BYPOSITION, uID++,     _T("Erase on &Restart")); 
     188            InsertMenu(hSubmenu, ACTION_ERASE_ON_RESTART, MF_BYPOSITION, uID++, 
     189                LoadString(IDS_ACTION_ERASERESTART).c_str());       //Erase on Restart 
    188190            VerbMenuIndices.push_back(ACTION_ERASE_ON_RESTART); 
    189191        } 
    190192        if (applicableActions & ACTION_ERASE_UNUSED_SPACE) 
    191193        { 
    192             InsertMenu    (hSubmenu, ACTION_ERASE_UNUSED_SPACE, MF_BYPOSITION, uID++,   _T("Erase &Unused Space")); 
     194            InsertMenu(hSubmenu, ACTION_ERASE_UNUSED_SPACE, MF_BYPOSITION, uID++, 
     195                LoadString(IDS_ACTION_ERASEUNUSEDSPACE).c_str());   //Erase Unused Space 
    193196            VerbMenuIndices.push_back(ACTION_ERASE_UNUSED_SPACE); 
    194197        } 
     
    202205            } 
    203206 
    204             InsertMenu    (hSubmenu, ACTION_SECURE_MOVE, MF_BYPOSITION, uID++,          _T("Secure &Move")); 
     207            InsertMenu(hSubmenu, ACTION_SECURE_MOVE, MF_BYPOSITION, uID++, 
     208                LoadString(IDS_ACTION_SECUREMOVE).c_str());         //Secure Move 
    205209            VerbMenuIndices.push_back(ACTION_SECURE_MOVE); 
    206210        } 
     
    351355                                       LPSTR pszName, UINT cchMax) 
    352356    { 
    353         USES_CONVERSION; 
    354  
    355         //Check idCmd, it must be 0 or 1 since we have two menu items. 
    356         if (idCmd > 2) 
    357             return E_INVALIDARG; 
    358  
    359         //If Explorer is asking for a help string, copy our string into the supplied buffer. 
     357        //We only know how to handle help string requests. 
    360358        if (!(uFlags & GCS_HELPTEXT)) 
    361359            return E_INVALIDARG; 
    362360 
    363         static LPCTSTR szErase        = _T("Erases the currently selected file\r\n"); 
    364         static LPCTSTR szEraseUnunsed = _T("Erases the currently selected drive's unused disk space\r\n"); 
    365         LPCTSTR pszText = (0 == idCmd) ? szErase : szEraseUnunsed; 
    366  
     361        //Get the command string for the given id 
     362        if (idCmd > VerbMenuIndices.size()) 
     363            return E_INVALIDARG; 
     364 
     365        std::wstring commandString; 
     366        switch (VerbMenuIndices[idCmd]) 
     367        { 
     368        case ACTION_ERASE: 
     369        case ACTION_ERASE_ON_RESTART: 
     370        case ACTION_ERASE_UNUSED_SPACE: 
     371        case ACTION_SECURE_MOVE: 
     372 
     373        default: 
     374            //We don't know what action this is: return E_INVALIDARG. 
     375            return E_INVALIDARG; 
     376        } 
     377 
     378        //Return the help string to Explorer. 
    367379        if (uFlags & GCS_UNICODE) 
    368             //We need to cast pszName to a Unicode string, and then use the Unicode string copy API. 
    369             lstrcpynW((LPWSTR)pszName, T2CW(pszText), cchMax); 
     380            wcscpy_s(reinterpret_cast<wchar_t*>(pszName), cchMax, commandString.c_str()); 
    370381        else 
    371             //Use the ANSI string copy API to return the help string. 
    372             lstrcpynA(pszName, T2CA(pszText), cchMax); 
     382        { 
     383            size_t convCount = 0; 
     384            wcstombs_s(&convCount, pszName, cchMax, commandString.c_str(), commandString.length()); 
     385        } 
    373386 
    374387        return S_OK; 
    375388    } 
    376  
    377     /* 
    378     usage: Eraser <action> <arguments> 
    379     where action is 
    380     addtask                 Adds tasks to the current task list. 
    381     querymethods            Lists all registered Erasure methods. 
    382  
    383     global parameters: 
    384     --quiet, -q             Do not create a Console window to display progress. 
    385  
    386     parameters for addtask: 
    387     eraser addtask --method=<methodGUID> (--recycled | --unused=<volume> |  --dir=<directory> | [file1 [file2 [...]]]) 
    388     --method, -m            The Erasure method to use. 
    389     --recycled, -r          Erases files and folders in the recycle bin 
    390     --unused, -u            Erases unused space in the volume. 
    391     optional arguments: --unused=<drive>[,clusterTips] 
    392     clusterTips     If specified, the drive's files will have their cluster tips 
    393     erased. 
    394     --dir, --directory, -d  Erases files and folders in the directory 
    395     optional arguments: --dir=<directory>[,e=excludeMask][,i=includeMask][,delete] 
    396     excludeMask     A wildcard expression for files and folders to exclude. 
    397     includeMask     A wildcard expression for files and folders to include. 
    398     The include mask is applied before the exclude mask. 
    399     delete          Deletes the folder at the end of the erasure if specified. 
    400     file1 ... fileN         The list of files to erase. 
    401  
    402     parameters for querymethods: 
    403     eraser querymethods 
    404  
    405     no parameters to set. 
    406  
    407     All arguments are case sensitive. 
    408  
    409     */   
    410389 
    411390    HRESULT CCtxMenu::InvokeCommand(LPCMINVOKECOMMANDINFO pCmdInfo) 
     
    583562    } 
    584563 
     564    std::wstring CCtxMenu::LoadString(UINT stringID) 
     565    { 
     566        //Get a pointer to the buffer containing the string (we're copying it anyway) 
     567        wchar_t* buffer = NULL; 
     568        DWORD lastCount = ::LoadString(theApp.m_hInstance, stringID, 
     569            reinterpret_cast<wchar_t*>(&buffer), 0); 
     570 
     571        if (lastCount > 0) 
     572            return std::wstring(buffer, lastCount); 
     573        return std::wstring(); 
     574    } 
     575 
    585576    std::wstring CCtxMenu::GetHKeyPath(HKEY handle) 
    586577    { 
  • branches/eraser6/ShellExt/CtxMenu.h

    r720 r722  
    8383        Actions GetApplicableActions(); 
    8484 
     85        static std::wstring LoadString(UINT stringID); 
    8586        static std::wstring GetHKeyPath(HKEY handle); 
    8687        static MENUITEMINFO* GetSeparator(); 
Note: See TracChangeset for help on using the changeset viewer.