Skip to content

Commit

Permalink
fix #36 & #34
Browse files Browse the repository at this point in the history
  • Loading branch information
rexdf committed Dec 15, 2018
1 parent de26246 commit f1e17d4
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,5 @@ __pycache__/
# Visual Studio Code
.vscode/

enc_temp_folder/

10 changes: 9 additions & 1 deletion CommandTrayHost/CommandTrayHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
45 changes: 43 additions & 2 deletions CommandTrayHost/configure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2406,9 +2406,9 @@ void get_command_submenu(std::vector<HMENU>& 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());
Expand Down Expand Up @@ -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<LPITEMIDLIST> v;
v.push_back(ILCreateFromPath(commandLine));

SHOpenFolderAndSelectItems(folder, v.size(), const_cast<LPCITEMIDLIST*>(v.data()), 0);

for (auto idl : v)
{
ILFree(const_cast<LPITEMIDLIST>(idl));
}
ILFree(folder);
if (SUCCEEDED(hr)) ::CoUninitialize();
}
}
}

void show_hide_toggle(nlohmann::json& jsp)
{
if (jsp["running"] == false)return;
Expand Down
2 changes: 2 additions & 0 deletions CommandTrayHost/configure.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions CommandTrayHost/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <atlbase.h> // CComPtr
#include <ShlDisp.h>

#include <Shlobj.h>

#ifdef _DEBUG_PROCESS_TREE
#include <TlHelp32.h>
#endif
Expand Down
22 changes: 21 additions & 1 deletion CommandTrayHost/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit f1e17d4

Please sign in to comment.