diff --git a/.gitignore b/.gitignore index 892d71e..e4b5a5a 100644 --- a/.gitignore +++ b/.gitignore @@ -264,3 +264,5 @@ __pycache__/ # Visual Studio Code .vscode/ +enc_temp_folder/ + diff --git a/CommandTrayHost/CommandTrayHost.cpp b/CommandTrayHost/CommandTrayHost.cpp index 83f87f4..c975f69 100644 --- a/CommandTrayHost/CommandTrayHost.cpp +++ b/CommandTrayHost/CommandTrayHost.cpp @@ -991,7 +991,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) LOGMESSAGE(L"%x Clicked. %d %d\n", nID, menu_idx, submenu_idx); nlohmann::json& js = (*global_configs_pointer)[menu_idx]; cache_config_cursor = menu_idx; - if (submenu_idx < 3) + if (submenu_idx == 0) + { + open_path(js); + } + else if (submenu_idx == 1) + { + select_file(js); + } + else if (submenu_idx == 2) { show_hide_toggle(js); } diff --git a/CommandTrayHost/configure.cpp b/CommandTrayHost/configure.cpp index c3df606..b0f895e 100644 --- a/CommandTrayHost/configure.cpp +++ b/CommandTrayHost/configure.cpp @@ -2406,9 +2406,9 @@ void get_command_submenu(std::vector& outVcHmenu) { uSubFlags |= MF_CHECKED; } - AppendMenu(hSubMenu, uSubFlags, WM_TASKBARNOTIFY_MENUITEM_COMMAND_BASE + i * 0x10 + 0, + AppendMenu(hSubMenu, uSubFlags&(~MF_GRAYED), WM_TASKBARNOTIFY_MENUITEM_COMMAND_BASE + i * 0x10 + 0, utf8_to_wstring(truncate(itm["path"], cmd_menu_max_length)).c_str()); - AppendMenu(hSubMenu, uSubFlags, WM_TASKBARNOTIFY_MENUITEM_COMMAND_BASE + i * 0x10 + 1, + AppendMenu(hSubMenu, uSubFlags&(~MF_GRAYED), WM_TASKBARNOTIFY_MENUITEM_COMMAND_BASE + i * 0x10 + 1, utf8_to_wstring(truncate(itm["cmd"], cmd_menu_max_length)).c_str()); //AppendMenu(hSubMenu, uSubFlags, WM_TASKBARNOTIFY_MENUITEM_COMMAND_BASE + i * 0x10 + 2, //utf8_to_wstring(itm["working_directory"]).c_str()); @@ -3113,6 +3113,47 @@ void left_click_toggle() } } +void open_path(nlohmann::json& jsp) +{ + std::wstring cmd = utf8_to_wstring(jsp["cmd"]), path = utf8_to_wstring(jsp["path"]); + path = get_abs_path(path, cmd); + ShellExecute(NULL, NULL, path.c_str(), NULL, NULL, SW_SHOWNORMAL); +} + +void select_file(nlohmann::json& jsp) +{ + std::wstring cmd = utf8_to_wstring(jsp["cmd"]), path = utf8_to_wstring(jsp["path"]); + path = get_abs_path(path, cmd); + TCHAR commandLine[MAX_PATH * 128]; + + if (NULL != PathCombine(commandLine, path.c_str(), cmd.c_str())) + { + //_wsystem((std::wstring(L"explorer /select,") + commandLine).c_str()); + if (1) + { + TCHAR commandPath[MAX_PATH * 128]; + StringCchCopy(commandPath, MAX_PATH * 128, commandLine); + PathRemoveFileSpec(commandPath); + LOGMESSAGE("!!\n%s %s", commandPath, commandLine); + HRESULT hr; + hr = CoInitializeEx(0, COINIT_MULTITHREADED); + + ITEMIDLIST* folder = ILCreateFromPath(commandPath); + std::vector v; + v.push_back(ILCreateFromPath(commandLine)); + + SHOpenFolderAndSelectItems(folder, v.size(), const_cast(v.data()), 0); + + for (auto idl : v) + { + ILFree(const_cast(idl)); + } + ILFree(folder); + if (SUCCEEDED(hr)) ::CoUninitialize(); + } + } +} + void show_hide_toggle(nlohmann::json& jsp) { if (jsp["running"] == false)return; diff --git a/CommandTrayHost/configure.h b/CommandTrayHost/configure.h index 8f3141a..18f9107 100644 --- a/CommandTrayHost/configure.h +++ b/CommandTrayHost/configure.h @@ -51,6 +51,8 @@ int init_global(HANDLE&, HICON&); void create_process(nlohmann::json& jsp, const HANDLE&, bool runas_admin = false, bool log_crontab = false); void show_hide_toggle(nlohmann::json& jsp); +void open_path(nlohmann::json& jsp); +void select_file(nlohmann::json& jsp); void disable_enable_menu(nlohmann::json& jsp, HANDLE, bool runas_admin = false); BOOL undock_window(int idx); diff --git a/CommandTrayHost/stdafx.h b/CommandTrayHost/stdafx.h index b20885b..d5ba479 100644 --- a/CommandTrayHost/stdafx.h +++ b/CommandTrayHost/stdafx.h @@ -33,6 +33,8 @@ #include // CComPtr #include +#include + #ifdef _DEBUG_PROCESS_TREE #include #endif diff --git a/CommandTrayHost/utils.cpp b/CommandTrayHost/utils.cpp index 02bd4e9..e0baed4 100644 --- a/CommandTrayHost/utils.cpp +++ b/CommandTrayHost/utils.cpp @@ -63,9 +63,29 @@ std::string wstring_to_utf8(const std::wstring& str) extern TCHAR szPathToExeDir[MAX_PATH * 10]; -std::wstring get_abs_path(const std::wstring& path_wstring, const std::wstring& cmd_wstring) { +/*std::wstring get_abs_path_old(const std::wstring& path_wstring, const std::wstring& cmd_wstring) { if (0 == path_wstring.compare(0, 2, L"..") || (path_wstring == L"" && 0 == cmd_wstring.compare(0, 2, L".."))) { TCHAR abs_path[MAX_PATH * 128]; // 这个必须要求是可写的字符串,不能是const的。 + if (NULL == PathCombine(abs_path, szPathToExeDir, path_wstring.c_str())) + { + LOGMESSAGE(L"Copy CTH path failed\n"); + msg_prompt(L"PathCombine Failed", L"Error", MB_OK | MB_ICONERROR); + } + return abs_path; + } + return path_wstring; +}*/ + +std::wstring get_abs_path(const std::wstring& path_wstring, const std::wstring& cmd_wstring) +{ + TCHAR abs_path[MAX_PATH * 128]; // 这个必须要求是可写的字符串,不能是const的。 + if (NULL == PathCombine(abs_path, path_wstring.c_str(), cmd_wstring.c_str())) + { + LOGMESSAGE(L"Copy CTH path failed\n"); + msg_prompt(L"PathCombine Failed", L"Error", MB_OK | MB_ICONERROR); + } + if (NULL == StrChr(abs_path, ':')) + { if (NULL == PathCombine(abs_path, szPathToExeDir, path_wstring.c_str())) { LOGMESSAGE(L"Copy CTH path failed\n");