mirror of
https://github.com/yuanyuanxiang/SimpleRemoter.git
synced 2026-01-21 23:13:08 +08:00
Improve: ExpandDirectories after GetForegroundSelectedFiles
This commit is contained in:
@@ -619,7 +619,7 @@ VOID CScreenManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
|||||||
}
|
}
|
||||||
if (SendClientClipboard(ulLength > 1))
|
if (SendClientClipboard(ulLength > 1))
|
||||||
break;
|
break;
|
||||||
files = GetForegroundSelectedFiles();
|
files = GetForegroundSelectedFiles(result);
|
||||||
if (!files.empty()) {
|
if (!files.empty()) {
|
||||||
char h[100] = {};
|
char h[100] = {};
|
||||||
memcpy(h, szBuffer + 1, ulLength - 1);
|
memcpy(h, szBuffer + 1, ulLength - 1);
|
||||||
@@ -631,7 +631,7 @@ VOID CScreenManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
|||||||
memcpy(szBuffer + 1, str.data(), str.size());
|
memcpy(szBuffer + 1, str.data(), str.size());
|
||||||
SendData(szBuffer, 1 + str.size());
|
SendData(szBuffer, 1 + str.size());
|
||||||
SAFE_DELETE_ARRAY(szBuffer);
|
SAFE_DELETE_ARRAY(szBuffer);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case COMMAND_SCREEN_SET_CLIPBOARD: {
|
case COMMAND_SCREEN_SET_CLIPBOARD: {
|
||||||
|
|||||||
@@ -12,41 +12,93 @@
|
|||||||
#pragma comment(lib, "ole32.lib")
|
#pragma comment(lib, "ole32.lib")
|
||||||
#pragma comment(lib, "oleaut32.lib")
|
#pragma comment(lib, "oleaut32.lib")
|
||||||
|
|
||||||
static std::vector<std::string> GetDesktopSelectedFiles()
|
void ExpandDirectory(const std::string& dir, std::vector<std::string>& result) {
|
||||||
|
std::string searchPath = dir + "\\*";
|
||||||
|
WIN32_FIND_DATAA fd;
|
||||||
|
HANDLE hFind = FindFirstFileA(searchPath.c_str(), &fd);
|
||||||
|
|
||||||
|
if (hFind == INVALID_HANDLE_VALUE) return;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (strcmp(fd.cFileName, ".") == 0 || strcmp(fd.cFileName, "..") == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::string fullPath = dir + "\\" + fd.cFileName;
|
||||||
|
result.push_back(fullPath); // 文件和目录都加入
|
||||||
|
|
||||||
|
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||||
|
ExpandDirectory(fullPath, result); // 递归
|
||||||
|
}
|
||||||
|
} while (FindNextFileA(hFind, &fd));
|
||||||
|
|
||||||
|
FindClose(hFind);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> ExpandDirectories(const std::vector<std::string>& selected) {
|
||||||
|
std::vector<std::string> result;
|
||||||
|
|
||||||
|
for (const auto& path : selected) {
|
||||||
|
DWORD attr = GetFileAttributesA(path.c_str());
|
||||||
|
if (attr == INVALID_FILE_ATTRIBUTES) continue;
|
||||||
|
|
||||||
|
result.push_back(path); // 先加入自身
|
||||||
|
|
||||||
|
if (attr & FILE_ATTRIBUTE_DIRECTORY) {
|
||||||
|
ExpandDirectory(path, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::vector<std::string> GetDesktopSelectedFiles(int& result)
|
||||||
{
|
{
|
||||||
CComPtr<IShellWindows> pShellWindows;
|
CComPtr<IShellWindows> pShellWindows;
|
||||||
if (FAILED(pShellWindows.CoCreateInstance(CLSID_ShellWindows)))
|
if (FAILED(pShellWindows.CoCreateInstance(CLSID_ShellWindows))) {
|
||||||
|
result = 101;
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
CComVariant vLoc(CSIDL_DESKTOP);
|
CComVariant vLoc(CSIDL_DESKTOP);
|
||||||
CComVariant vEmpty;
|
CComVariant vEmpty;
|
||||||
long lhwnd;
|
long lhwnd;
|
||||||
CComPtr<IDispatch> pDisp;
|
CComPtr<IDispatch> pDisp;
|
||||||
|
|
||||||
if (FAILED(pShellWindows->FindWindowSW(&vLoc, &vEmpty, SWC_DESKTOP, &lhwnd, SWFO_NEEDDISPATCH, &pDisp)))
|
if (FAILED(pShellWindows->FindWindowSW(&vLoc, &vEmpty, SWC_DESKTOP, &lhwnd, SWFO_NEEDDISPATCH, &pDisp))) {
|
||||||
|
result = 102;
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
CComQIPtr<IServiceProvider> pServiceProvider(pDisp);
|
CComQIPtr<IServiceProvider> pServiceProvider(pDisp);
|
||||||
if (!pServiceProvider)
|
if (!pServiceProvider) {
|
||||||
|
result = 103;
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
CComPtr<IShellBrowser> pShellBrowser;
|
CComPtr<IShellBrowser> pShellBrowser;
|
||||||
if (FAILED(pServiceProvider->QueryService(SID_STopLevelBrowser, IID_IShellBrowser, (void**)&pShellBrowser)))
|
if (FAILED(pServiceProvider->QueryService(SID_STopLevelBrowser, IID_IShellBrowser, (void**)&pShellBrowser))) {
|
||||||
|
result = 104;
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
CComPtr<IShellView> pShellView;
|
CComPtr<IShellView> pShellView;
|
||||||
if (FAILED(pShellBrowser->QueryActiveShellView(&pShellView)))
|
if (FAILED(pShellBrowser->QueryActiveShellView(&pShellView))) {
|
||||||
|
result = 105;
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
CComPtr<IDataObject> pDataObject;
|
CComPtr<IDataObject> pDataObject;
|
||||||
if (FAILED(pShellView->GetItemObject(SVGIO_SELECTION, IID_IDataObject, (void**)&pDataObject)))
|
if (FAILED(pShellView->GetItemObject(SVGIO_SELECTION, IID_IDataObject, (void**)&pDataObject))) {
|
||||||
|
result = 106;
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
FORMATETC fmt = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
|
FORMATETC fmt = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
|
||||||
STGMEDIUM stg = {};
|
STGMEDIUM stg = {};
|
||||||
|
|
||||||
if (FAILED(pDataObject->GetData(&fmt, &stg)))
|
if (FAILED(pDataObject->GetData(&fmt, &stg))) {
|
||||||
|
result = 107;
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> vecFiles;
|
std::vector<std::string> vecFiles;
|
||||||
HDROP hDrop = (HDROP)GlobalLock(stg.hGlobal);
|
HDROP hDrop = (HDROP)GlobalLock(stg.hGlobal);
|
||||||
@@ -65,11 +117,13 @@ static std::vector<std::string> GetDesktopSelectedFiles()
|
|||||||
}
|
}
|
||||||
ReleaseStgMedium(&stg);
|
ReleaseStgMedium(&stg);
|
||||||
|
|
||||||
|
vecFiles = ExpandDirectories(vecFiles);
|
||||||
return vecFiles;
|
return vecFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> GetForegroundSelectedFiles()
|
std::vector<std::string> GetForegroundSelectedFiles(int& result)
|
||||||
{
|
{
|
||||||
|
result = 0;
|
||||||
HRESULT hrInit = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
HRESULT hrInit = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
||||||
bool bNeedUninit = SUCCEEDED(hrInit);
|
bool bNeedUninit = SUCCEEDED(hrInit);
|
||||||
|
|
||||||
@@ -90,7 +144,7 @@ std::vector<std::string> GetForegroundSelectedFiles()
|
|||||||
|
|
||||||
if (hFore == hDesktop || hFore == hWorkerW) {
|
if (hFore == hDesktop || hFore == hWorkerW) {
|
||||||
if (bNeedUninit) CoUninitialize();
|
if (bNeedUninit) CoUninitialize();
|
||||||
return GetDesktopSelectedFiles();
|
return GetDesktopSelectedFiles(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否是资源管理器窗口
|
// 检查是否是资源管理器窗口
|
||||||
@@ -99,6 +153,7 @@ std::vector<std::string> GetForegroundSelectedFiles()
|
|||||||
|
|
||||||
if (strcmp(szClass, "CabinetWClass") != 0 && strcmp(szClass, "ExploreWClass") != 0) {
|
if (strcmp(szClass, "CabinetWClass") != 0 && strcmp(szClass, "ExploreWClass") != 0) {
|
||||||
if (bNeedUninit) CoUninitialize();
|
if (bNeedUninit) CoUninitialize();
|
||||||
|
result = 1;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,6 +161,7 @@ std::vector<std::string> GetForegroundSelectedFiles()
|
|||||||
CComPtr<IShellWindows> pShellWindows;
|
CComPtr<IShellWindows> pShellWindows;
|
||||||
if (FAILED(pShellWindows.CoCreateInstance(CLSID_ShellWindows))) {
|
if (FAILED(pShellWindows.CoCreateInstance(CLSID_ShellWindows))) {
|
||||||
if (bNeedUninit) CoUninitialize();
|
if (bNeedUninit) CoUninitialize();
|
||||||
|
result = 2;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,16 +186,22 @@ std::vector<std::string> GetForegroundSelectedFiles()
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
CComPtr<IDispatch> pDoc;
|
CComPtr<IDispatch> pDoc;
|
||||||
if (FAILED(pBrowser->get_Document(&pDoc)) || !pDoc)
|
if (FAILED(pBrowser->get_Document(&pDoc)) || !pDoc) {
|
||||||
|
result = 3;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
CComQIPtr<IShellFolderViewDual> pView(pDoc);
|
CComQIPtr<IShellFolderViewDual> pView(pDoc);
|
||||||
if (!pView)
|
if (!pView) {
|
||||||
|
result = 4;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
CComPtr<FolderItems> pItems;
|
CComPtr<FolderItems> pItems;
|
||||||
if (FAILED(pView->SelectedItems(&pItems)) || !pItems)
|
if (FAILED(pView->SelectedItems(&pItems)) || !pItems) {
|
||||||
|
result = 5;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
long nItems = 0;
|
long nItems = 0;
|
||||||
pItems->get_Count(&nItems);
|
pItems->get_Count(&nItems);
|
||||||
@@ -169,6 +231,7 @@ std::vector<std::string> GetForegroundSelectedFiles()
|
|||||||
|
|
||||||
if (bNeedUninit) CoUninitialize();
|
if (bNeedUninit) CoUninitialize();
|
||||||
|
|
||||||
|
vecFiles = ExpandDirectories(vecFiles);
|
||||||
return vecFiles;
|
return vecFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,4 +42,4 @@ std::vector<char> BuildMultiStringPath(const std::vector<std::string>& paths);
|
|||||||
|
|
||||||
std::vector<std::string> ParseMultiStringPath(const char* buffer, size_t size);
|
std::vector<std::string> ParseMultiStringPath(const char* buffer, size_t size);
|
||||||
|
|
||||||
std::vector<std::string> GetForegroundSelectedFiles();
|
std::vector<std::string> GetForegroundSelectedFiles(int &result);
|
||||||
|
|||||||
@@ -4347,6 +4347,19 @@ void CMy2015RemoteDlg::RemoveRemoteWindow(HWND wnd)
|
|||||||
LeaveCriticalSection(&m_cs);
|
LeaveCriticalSection(&m_cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMy2015RemoteDlg::UpdateActiveRemoteSession(CDialogBase *sess){
|
||||||
|
EnterCriticalSection(&m_cs);
|
||||||
|
m_pActiveSession = sess;
|
||||||
|
LeaveCriticalSection(&m_cs);
|
||||||
|
}
|
||||||
|
|
||||||
|
CDialogBase* CMy2015RemoteDlg::GetActiveRemoteSession() {
|
||||||
|
EnterCriticalSection(&m_cs);
|
||||||
|
auto sess = m_pActiveSession;
|
||||||
|
LeaveCriticalSection(&m_cs);
|
||||||
|
return sess;
|
||||||
|
}
|
||||||
|
|
||||||
LRESULT CALLBACK CMy2015RemoteDlg::LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
|
LRESULT CALLBACK CMy2015RemoteDlg::LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
if (g_2015RemoteDlg == NULL)
|
if (g_2015RemoteDlg == NULL)
|
||||||
@@ -4431,7 +4444,7 @@ LRESULT CALLBACK CMy2015RemoteDlg::LowLevelKeyboardProc(int nCode, WPARAM wParam
|
|||||||
HWND hFore = ::GetForegroundWindow();
|
HWND hFore = ::GetForegroundWindow();
|
||||||
operateWnd = g_2015RemoteDlg->GetRemoteWindow(hFore);
|
operateWnd = g_2015RemoteDlg->GetRemoteWindow(hFore);
|
||||||
if (!operateWnd)
|
if (!operateWnd)
|
||||||
g_2015RemoteDlg->m_pActiveSession = nullptr;
|
g_2015RemoteDlg->UpdateActiveRemoteSession(nullptr);
|
||||||
}
|
}
|
||||||
// 检测 Ctrl+V
|
// 检测 Ctrl+V
|
||||||
else if ((GetAsyncKeyState(VK_CONTROL) & 0x8000) && pKey->vkCode == 'V') {
|
else if ((GetAsyncKeyState(VK_CONTROL) & 0x8000) && pKey->vkCode == 'V') {
|
||||||
@@ -4447,6 +4460,7 @@ LRESULT CALLBACK CMy2015RemoteDlg::LowLevelKeyboardProc(int nCode, WPARAM wParam
|
|||||||
// [1] 本地 -> 远程
|
// [1] 本地 -> 远程
|
||||||
int result;
|
int result;
|
||||||
auto files = GetClipboardFiles(result);
|
auto files = GetClipboardFiles(result);
|
||||||
|
if (files.empty()) files = GetForegroundSelectedFiles(result);
|
||||||
if (!files.empty()) {
|
if (!files.empty()) {
|
||||||
// 获取远程目录
|
// 获取远程目录
|
||||||
auto str = BuildMultiStringPath(files);
|
auto str = BuildMultiStringPath(files);
|
||||||
@@ -4479,8 +4493,12 @@ LRESULT CALLBACK CMy2015RemoteDlg::LowLevelKeyboardProc(int nCode, WPARAM wParam
|
|||||||
Mprintf("【Ctrl+V】 本地剪贴板没有文本或文件: %d \n", result);
|
Mprintf("【Ctrl+V】 本地剪贴板没有文本或文件: %d \n", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (g_2015RemoteDlg->m_pActiveSession && operateWnd) {
|
} else if (g_2015RemoteDlg->GetActiveRemoteSession() && operateWnd) {
|
||||||
auto screen = (CScreenSpyDlg*)(g_2015RemoteDlg->m_pActiveSession);
|
auto screen = (CScreenSpyDlg*)(g_2015RemoteDlg->GetActiveRemoteSession());
|
||||||
|
if (!screen) {
|
||||||
|
Mprintf("【Ctrl+V】 [远程 -> 本地] 远程桌面窗口状态已经失效\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (!screen->m_bIsCtrl) {
|
if (!screen->m_bIsCtrl) {
|
||||||
Mprintf("【Ctrl+V】 [远程 -> 本地] 窗口不是控制状态: %s\n", screen->m_IPAddress);
|
Mprintf("【Ctrl+V】 [远程 -> 本地] 窗口不是控制状态: %s\n", screen->m_IPAddress);
|
||||||
break;
|
break;
|
||||||
@@ -4494,7 +4512,7 @@ LRESULT CALLBACK CMy2015RemoteDlg::LowLevelKeyboardProc(int nCode, WPARAM wParam
|
|||||||
EmptyClipboard();
|
EmptyClipboard();
|
||||||
CloseClipboard();
|
CloseClipboard();
|
||||||
}
|
}
|
||||||
if (g_2015RemoteDlg->m_pActiveSession->m_ContextObject->Send2Client(bToken, sizeof(bToken)))
|
if (screen->m_ContextObject->Send2Client(bToken, sizeof(bToken)))
|
||||||
Sleep(200);
|
Sleep(200);
|
||||||
Mprintf("【Ctrl+V】 从远程拷贝到本地 \n");
|
Mprintf("【Ctrl+V】 从远程拷贝到本地 \n");
|
||||||
} else {
|
} else {
|
||||||
@@ -4512,7 +4530,7 @@ LRESULT CALLBACK CMy2015RemoteDlg::LowLevelKeyboardProc(int nCode, WPARAM wParam
|
|||||||
LRESULT CMy2015RemoteDlg::OnSessionActivatedMsg(WPARAM wParam, LPARAM lParam)
|
LRESULT CMy2015RemoteDlg::OnSessionActivatedMsg(WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
CDialogBase* pSession = reinterpret_cast<CDialogBase*>(wParam);
|
CDialogBase* pSession = reinterpret_cast<CDialogBase*>(wParam);
|
||||||
m_pActiveSession = pSession;
|
UpdateActiveRemoteSession(pSession);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -279,6 +279,8 @@ public:
|
|||||||
CDialogBase* GetRemoteWindow(CDialogBase* dlg);
|
CDialogBase* GetRemoteWindow(CDialogBase* dlg);
|
||||||
void RemoveRemoteWindow(HWND wnd);
|
void RemoveRemoteWindow(HWND wnd);
|
||||||
CDialogBase* m_pActiveSession = nullptr; // 当前活动会话窗口指针 / NULL 表示无
|
CDialogBase* m_pActiveSession = nullptr; // 当前活动会话窗口指针 / NULL 表示无
|
||||||
|
void UpdateActiveRemoteSession(CDialogBase* sess);
|
||||||
|
CDialogBase* GetActiveRemoteSession();
|
||||||
afx_msg LRESULT OnSessionActivatedMsg(WPARAM wParam, LPARAM lParam);
|
afx_msg LRESULT OnSessionActivatedMsg(WPARAM wParam, LPARAM lParam);
|
||||||
static LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
|
static LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
|
||||||
HHOOK g_hKeyboardHook = NULL;
|
HHOOK g_hKeyboardHook = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user