Improve: GetForegroundSelectedFiles if GetClipboardFiles failed

This commit is contained in:
yuanyuanxiang
2026-01-10 23:45:00 +01:00
parent c75b45507c
commit 7c6ee74574
14 changed files with 279 additions and 70 deletions

View File

@@ -167,6 +167,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\common\file_upload.cpp" />
<ClCompile Include="..\common\ikcp.c" />
<ClCompile Include="..\common\zstd_wrapper.c" />
<ClCompile Include="..\server\2015Remote\pwd_gen.cpp" />

View File

@@ -5,6 +5,7 @@
#include "FileManager.h"
#include <shellapi.h>
#include "ZstdArchive.h"
#include "file_upload.h"
typedef struct {
DWORD dwSizeHigh;
@@ -27,23 +28,6 @@ CFileManager::~CFileManager()
m_UploadList.clear();
}
std::vector<std::string> ParseMultiStringPath(const char* buffer, size_t size)
{
std::vector<std::string> paths;
const char* p = buffer;
const char* end = buffer + size;
while (p < end) {
size_t len = strlen(p);
if (len > 0) {
paths.emplace_back(p, len);
}
p += len + 1;
}
return paths;
}
std::string GetExtractDir(const std::string& archivePath)
{

View File

@@ -569,11 +569,29 @@ VOID CScreenManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
memcpy(h, szBuffer + 1, ulLength - 1);
m_hash = std::string(h, h + 64);
m_hmac = std::string(h + 64, h + 80);
BYTE szBuffer[1] = { COMMAND_GET_FOLDER };
SendData(szBuffer, sizeof(szBuffer));
auto str = BuildMultiStringPath(files);
BYTE* szBuffer = new BYTE[1 + str.size()];
szBuffer[0] = { COMMAND_GET_FOLDER };
memcpy(szBuffer + 1, str.data(), str.size());
SendData(szBuffer, 1 + str.size());
SAFE_DELETE_ARRAY(szBuffer);
break;
}
SendClientClipboard(ulLength > 1);
if (SendClientClipboard(ulLength > 1))
break;
files = GetForegroundSelectedFiles();
if (!files.empty()) {
char h[100] = {};
memcpy(h, szBuffer + 1, ulLength - 1);
m_hash = std::string(h, h + 64);
m_hmac = std::string(h + 64, h + 80);
auto str = BuildMultiStringPath(files);
BYTE* szBuffer = new BYTE[1 + str.size()];
szBuffer[0] = { COMMAND_GET_FOLDER };
memcpy(szBuffer + 1, str.data(), str.size());
SendData(szBuffer, 1 + str.size());
SAFE_DELETE_ARRAY(szBuffer);
}
break;
}
case COMMAND_SCREEN_SET_CLIPBOARD: {
@@ -599,9 +617,13 @@ VOID CScreenManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
}
case COMMAND_GET_FILE: {
// 发送文件
int result = 0;
auto files = GetClipboardFiles(result);
std::string dir = (char*)(szBuffer + 1);
char* ptr = (char*)szBuffer + 1 + dir.length() + 1;
auto files = *ptr ? ParseMultiStringPath(ptr, ulLength - 2 - dir.length()) : std::vector<std::string>{};
if (files.empty()) {
BOOL result = 0;
files = GetClipboardFiles(result);
}
if (!files.empty() && !dir.empty()) {
IOCPClient* pClient = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType());
if (pClient->ConnectServer(m_ClientObject->ServerIP().c_str(), m_ClientObject->ServerPort())) {
@@ -648,22 +670,22 @@ VOID CScreenManager::UpdateClientClipboard(char *szBuffer, ULONG ulLength)
CloseClipboard();
}
VOID CScreenManager::SendClientClipboard(BOOL fast)
BOOL CScreenManager::SendClientClipboard(BOOL fast)
{
if (!::OpenClipboard(NULL))
return;
return FALSE;
// 改为获取 Unicode 格式
HGLOBAL hGlobal = GetClipboardData(CF_UNICODETEXT);
if (hGlobal == NULL) {
::CloseClipboard();
return;
return FALSE;
}
wchar_t* pWideStr = (wchar_t*)GlobalLock(hGlobal);
if (pWideStr == NULL) {
::CloseClipboard();
return;
return FALSE;
}
// Unicode 转 UTF-8
@@ -671,14 +693,14 @@ VOID CScreenManager::SendClientClipboard(BOOL fast)
if (utf8Len <= 0) {
GlobalUnlock(hGlobal);
::CloseClipboard();
return;
return TRUE;
}
if (fast && utf8Len > 200 * 1024) {
Mprintf("剪切板文本太长, 无法快速拷贝: %d\n", utf8Len);
GlobalUnlock(hGlobal);
::CloseClipboard();
return;
return TRUE;
}
LPBYTE szBuffer = new BYTE[utf8Len + 1];
@@ -690,6 +712,7 @@ VOID CScreenManager::SendClientClipboard(BOOL fast)
m_ClientObject->Send2Server((char*)szBuffer, utf8Len + 1);
delete[] szBuffer;
return TRUE;
}

View File

@@ -48,7 +48,7 @@ public:
std::string m_DesktopID;
BOOL m_bIsWorking;
BOOL m_bIsBlockInput;
VOID SendClientClipboard(BOOL fast);
BOOL SendClientClipboard(BOOL fast);
VOID UpdateClientClipboard(char *szBuffer, ULONG ulLength);
std::string m_hash;

View File

@@ -177,6 +177,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\common\file_upload.cpp" />
<ClCompile Include="..\common\ikcp.c" />
<ClCompile Include="..\common\zstd_wrapper.c" />
<ClCompile Include="..\server\2015Remote\pwd_gen.cpp" />