@@ -129,28 +129,30 @@ bool CustomSubExplorerCommand::Accept(bool multipleFiles, FileType fileType, con
129129}
130130
131131IFACEMETHODIMP CustomSubExplorerCommand::GetIcon (_In_opt_ IShellItemArray* items, _Outptr_result_nullonfailure_ PWSTR* icon) {
132- * icon = nullptr ;
132+ wil::assign_null_to_opt_param ( icon) ;
133133
134- if (m_theme_type == ThemeType::Dark && !_icon_dark.empty ()) {
135- auto iconPath = wil::make_cotaskmem_string_nothrow (_icon_dark.c_str ());
136- RETURN_IF_NULL_ALLOC (iconPath);
137- *icon = iconPath.release ();
138- return S_OK;
134+ std::wstring_view iconPath{ m_theme_type == ThemeType::Dark && _icon_dark.empty () ? _icon: _icon_dark };
135+ if (iconPath.find (L" %" ) != std::string::npos)
136+ {
137+ wil::unique_cotaskmem_string path{};
138+ if (S_OK == wil::ExpandEnvironmentStringsW (iconPath.data (), path))
139+ {
140+ *icon=path.release ();
141+ return S_OK;
142+ }
139143 }
140-
141- // TODO light or default
142- if (!_icon.empty ()) {
143- auto iconPath = wil::make_cotaskmem_string_nothrow (_icon.c_str ());
144- RETURN_IF_NULL_ALLOC (iconPath);
145- *icon = iconPath.release ();
144+ else if (!iconPath.empty ())
145+ {
146+ auto path{ wil::make_cotaskmem_string (iconPath.data (), iconPath.size ()) };
147+ *icon=path.release ();
146148 return S_OK;
147149 }
148150
149151 return BaseExplorerCommand::GetIcon (items, icon);
150152}
151153
152154IFACEMETHODIMP CustomSubExplorerCommand::GetTitle (_In_opt_ IShellItemArray* items, _Outptr_result_nullonfailure_ PWSTR* name) {
153- * name = nullptr ;
155+ wil::assign_null_to_opt_param ( name) ;
154156 auto title = wil::make_cotaskmem_string_nothrow (_title.c_str ());
155157 RETURN_IF_NULL_ALLOC (title);
156158 *name = title.release ();
@@ -199,21 +201,20 @@ IFACEMETHODIMP CustomSubExplorerCommand::Invoke(_In_opt_ IShellItemArray* select
199201 }
200202 std::wstring param =PathHelper::simpleFormat (paramView, replacements);
201203
202- // TODO
203- std::wstring workingDirectory{ _working_directory };
204+ std::wstring workingDirectory{ _working_directory.find (L" %" ) == std::string::npos ?_working_directory : wil::ExpandEnvironmentStringsW (_working_directory.c_str ()).get () };
204205 if (workingDirectory.empty ()) {
205206 workingDirectory = parentPath;
206207 }
207208 else {
208209 PathHelper::replaceAll (workingDirectory, PARAM_PARENT, replacements[PARAM_PARENT]);
209210 PathHelper::replaceAll (workingDirectory, PARAM_PATH0, replacements[PARAM_PATH0]);
210211 }
212+ DEBUG_LOG (L" CustomSubExplorerCommand::Invoke menu={}, workingDirectoryPath={}" , _title, workingDirectory);
213+
214+ const std::wstring exePath{ _exe.find (L" %" ) == std::string::npos ? _exe : wil::ExpandEnvironmentStringsW (_exe.c_str ()).get () };
215+ DEBUG_LOG (L" CustomSubExplorerCommand::Invoke menu={}, exePath={}, param={}" , _title, exePath, param);
211216
212- const auto workingDirectoryPath = wil::ExpandEnvironmentStringsW (workingDirectory.c_str ());
213- DEBUG_LOG (L" CustomSubExplorerCommand::Invoke menu={}, workingDirectoryPath={}" , _title, workingDirectoryPath.get ());
214- const auto exePath = wil::ExpandEnvironmentStringsW (_exe.c_str ());
215- DEBUG_LOG (L" CustomSubExplorerCommand::Invoke menu={}, exePath={}, param={}" , _title, exePath.get (), param);
216- ShellExecute (parent, L" open" , exePath.get (), param.c_str (), workingDirectoryPath.get (), _show_window_flag + 1 );
217+ ShellExecute (parent, L" open" , exePath.c_str (), param.c_str (), workingDirectory.c_str (), _show_window_flag + 1 );
217218 }
218219 }
219220 else if (count > 1 && _accept_multiple_files_flag == FILES_EACH) {
@@ -254,7 +255,7 @@ void CustomSubExplorerCommand::Execute(HWND parent, const std::wstring& path) {
254255 std::wstring param = PathHelper::simpleFormat (_param, replacements);
255256
256257 // TODO
257- std::wstring workingDirectory{ _working_directory };
258+ std::wstring workingDirectory{ _working_directory. find ( L" % " ) == std::string::npos?_working_directory: wil::ExpandEnvironmentStringsW (_working_directory. c_str ()). get () };
258259 if (workingDirectory.empty ()) {
259260 workingDirectory = file.parent_path ().wstring ();
260261 }
@@ -265,9 +266,8 @@ void CustomSubExplorerCommand::Execute(HWND parent, const std::wstring& path) {
265266 PathHelper::replaceAll (workingDirectory, PARAM_PATH0, replacements[PARAM_PATH]);
266267 }
267268
268- const auto workingDirectoryPath = wil::ExpandEnvironmentStringsW (workingDirectory.c_str ());
269- DEBUG_LOG (L" CustomSubExplorerCommand::Invoke menu={}, workingDirectoryPath={}" , _title, workingDirectoryPath.get ());
270- const auto exePath = wil::ExpandEnvironmentStringsW (_exe.c_str ());
271- DEBUG_LOG (L" CustomSubExplorerCommand::Invoke menu={}, exe={}, param={}" , _title, exePath.get (), param);
272- ShellExecute (parent, L" open" , exePath.get (), param.c_str (), workingDirectoryPath.get (), _show_window_flag + 1 );
269+ const std::wstring exePath{ _exe.find (L" %" ) == std::string::npos? _exe : wil::ExpandEnvironmentStringsW (_exe.c_str ()).get () };
270+ DEBUG_LOG (L" CustomSubExplorerCommand::Invoke menu={}, exe={}, param={}" , _title, exePath, param);
271+
272+ ShellExecute (parent, L" open" , exePath.c_str (), param.c_str (), workingDirectory.c_str (), _show_window_flag + 1 );
273273}
0 commit comments