@@ -65,17 +65,19 @@ namespace pboman3 {
6565
6666 if (sel == SelectionMode::Files) {
6767 if (selectedPaths_->size () == 1 ) {
68- TCHAR textItem1[] = " Unpack to..." ;
68+ TCHAR textItem1[] = L " Unpack to..." ;
6969 insertMenuItem (idCmdFirst + idUnpackWithPrompt, textItem1);
7070
71- string textItem2 = " Unpack as \" " + selectedPaths_->at (0 )
72- .filename ().replace_extension ().string () + " \" " ;
71+ wstring textItem2 = L" Unpack as \" " + selectedPaths_->at (0 )
72+ .filename ().replace_extension ().wstring () +
73+ L" \" " ;
7374 insertMenuItem (idCmdFirst + idUnpackToCwd, textItem2.data ());
7475 } else {
75- TCHAR textItem1[] = " Unpack to..." ;
76+ TCHAR textItem1[] = L " Unpack to..." ;
7677 insertMenuItem (idCmdFirst + idUnpackWithPrompt, textItem1);
7778
78- string textItem2 = " Unpack in \" " + selectedPaths_->at (0 ).parent_path ().filename ().string () + " \" " ;
79+ wstring textItem2 = L" Unpack in \" " + selectedPaths_->at (0 ).parent_path ().filename ().wstring () +
80+ L" \" " ;
7981 insertMenuItem (idCmdFirst + idUnpackToCwd, textItem2.data ());
8082 }
8183
@@ -84,16 +86,17 @@ namespace pboman3 {
8486 hr = MAKE_HRESULT (SEVERITY_SUCCESS, 0 , static_cast <USHORT>(lastUsedMenuIndex + 1 ));
8587 } else if (sel == SelectionMode::Folders) {
8688 if (selectedPaths_->size () == 1 ) {
87- TCHAR textItem1[] = " Pack to..." ;
89+ TCHAR textItem1[] = L " Pack to..." ;
8890 insertMenuItem (idCmdFirst + idPackWithPrompt, textItem1);
8991
90- string textItem2 = " Pack as \" " + selectedPaths_->at (0 ).filename ().string () + " .pbo\" " ;
92+ wstring textItem2 = L " Pack as \" " + selectedPaths_->at (0 ).filename ().wstring () + L " .pbo\" " ;
9193 insertMenuItem (idCmdFirst + idPackToCwd, textItem2.data ());
9294 } else {
93- TCHAR textItem3[] = " Pack to..." ;
95+ TCHAR textItem3[] = L " Pack to..." ;
9496 insertMenuItem (idCmdFirst + idPackWithPrompt, textItem3);
9597
96- string textItem4 = " Pack in \" " + selectedPaths_->at (0 ).parent_path ().filename ().string () + " \" " ;
98+ wstring textItem4 = L" Pack in \" " + selectedPaths_->at (0 ).parent_path ().filename ().wstring () +
99+ L" \" " ;
97100 insertMenuItem (idCmdFirst + idPackToCwd, textItem4.data ());
98101 }
99102
@@ -111,31 +114,52 @@ namespace pboman3 {
111114
112115 HRESULT hr = E_FAIL;
113116
114- if (pici->cbSize == sizeof CMINVOKECOMMANDINFOEX
115- && pici->fMask & CMIC_MASK_UNICODE) {
117+ UWORD idCmd = -1 ;
118+ path directory;
119+ if (pici->cbSize == sizeof CMINVOKECOMMANDINFOEX && pici->fMask & CMIC_MASK_UNICODE) {
116120 const auto piciw = reinterpret_cast <CMINVOKECOMMANDINFOEX*>(pici);
121+ // click on a Desktop item or on an item in Explorer right pane
117122 if (HIWORD (piciw->lpVerbW ) == 0 ) {
123+ // means piciw contains idCmd, otherwise would mean pici contains a verb
124+ idCmd = LOWORD (piciw->lpVerb );
125+ directory.append (wstring (piciw->lpDirectoryW , lstrlen (piciw->lpDirectoryW )));
126+ }
127+ } else {
128+ // click on a folder in Explorer left pane
129+ if (HIWORD (pici->lpVerb ) == 0 ) {
118130 // means pici contains idCmd, otherwise would mean pici contains a verb
119- const auto idCmd = LOWORD (pici->lpVerb );
120- switch (idCmd) {
121- case idUnpackWithPrompt:
122- hr = executable_->unpackFiles (pici->lpDirectory , *selectedPaths_);
123- break ;
124- case idUnpackToCwd:
125- hr = executable_->unpackFiles (pici->lpDirectory , *selectedPaths_, pici->lpDirectory );
126- break ;
127- case idPackWithPrompt:
128- hr = executable_->packFolders (pici->lpDirectory , *selectedPaths_);
129- break ;
130- case idPackToCwd:
131- hr = executable_->packFolders (pici->lpDirectory , *selectedPaths_, pici->lpDirectory );
132- break ;
133- default :
134- break ;
131+ idCmd = LOWORD (pici->lpVerb );
132+ if (pici->lpDirectory ) {
133+ directory.append (string (pici->lpDirectory , strlen (pici->lpDirectory )));
134+ } else {
135+ if (selectedPaths_->size () == 1
136+ && is_directory (selectedPaths_->at (0 ))
137+ && selectedPaths_->at (0 ).has_parent_path ()) {
138+ directory = selectedPaths_->at (0 ).parent_path ();
139+ } else {
140+ idCmd = -1 ;
141+ }
135142 }
136143 }
137144 }
138145
146+ switch (idCmd) {
147+ case idUnpackWithPrompt:
148+ hr = executable_->unpackFiles (directory, *selectedPaths_);
149+ break ;
150+ case idUnpackToCwd:
151+ hr = executable_->unpackFiles (directory, *selectedPaths_, directory);
152+ break ;
153+ case idPackWithPrompt:
154+ hr = executable_->packFolders (directory, *selectedPaths_);
155+ break ;
156+ case idPackToCwd:
157+ hr = executable_->packFolders (directory, *selectedPaths_, directory);
158+ break ;
159+ default :
160+ break ;
161+ }
162+
139163 return hr;
140164 }
141165
@@ -229,15 +253,15 @@ namespace pboman3 {
229253 }
230254
231255 void ContextMenu::insertRootItem (HMENU hmenu, UINT indexMenu) const {
232- const MENUITEMINFO menu = makeRootItem (PBOM_PROJECT_NAME, subMenu_);
256+ const MENUITEMINFO menu = makeRootItem (W ( PBOM_PROJECT_NAME) , subMenu_);
233257 InsertMenuItem (hmenu, indexMenu, TRUE , &menu);
234258 }
235259
236260 shared_ptr<MenuIcon> ContextMenu::loadRootIcon () const {
237- const string exePath = Registry::getExecutablePath ();
261+ const wstring exePath = Registry::getExecutablePath ();
238262 if (exePath.empty () || !is_regular_file (exePath))
239263 return nullptr ;
240264
241- return make_shared<MenuIcon>(exePath. data () );
265+ return make_shared<MenuIcon>(exePath);
242266 }
243267}
0 commit comments