Fix: Decode remote file-list names/paths from GBK/UTF-8 on non-Chinese systems
The Windows ghost client lists directories with FindFirstFileA, so remote file names arrive as GBK/936 bytes. Both file-manager dialogs wrote them back through ANSI InsertItem/SetItemText, which re-converts through CP_ACP and garbles Chinese names when the operator machine runs a non-Chinese ACP. Decode the name/path from the client encoding (GBK for Windows, UTF-8 for LNX/MAC, chosen by RES_CLIENT_TYPE) and write the text via LVM_SETITEMTEXTW, keeping the icon through an empty InsertItem - the same pattern used for the process list, window list and client-list path. Co-Authored-By: deepseek-v4-pro
This commit is contained in:
1 parent
f3a8406050
commit
1a9312d2d1
2 files changed
+71
-9
No files matched your search
@@ -223,6 +223,27 @@ int GetIconIndex(LPCTSTR lpFileName, DWORD dwFileAttributes)
|
||||
return index;
|
||||
}
|
||||
|
||||
// 远程文件名/路径编码按 clientType 判定:Windows 走 A 接口(FindFirstFileA)=GBK/936,
|
||||
// LNX/MAC 文件系统天然 UTF-8(同 McpServer.cpp::BuildListFiles)。这里用 LVM_SETITEMTEXTW
|
||||
// 直接写宽字符串,绕开 ANSI→CP_ACP 回转,即使服务端运行在非中文 ACP 上中文名也能正常显示。
|
||||
static void SetFileTextItem(CListCtrl& list, int iItem, int iSubItem, const char* sz, UINT cp)
|
||||
{
|
||||
std::wstring w;
|
||||
if (sz && sz[0]) {
|
||||
int wlen = MultiByteToWideChar(cp, 0, sz, -1, NULL, 0);
|
||||
if (wlen > 1) {
|
||||
w.resize(wlen - 1);
|
||||
MultiByteToWideChar(cp, 0, sz, -1, &w[0], wlen);
|
||||
}
|
||||
}
|
||||
LVITEMW lv = {};
|
||||
lv.mask = LVIF_TEXT;
|
||||
lv.iItem = iItem;
|
||||
lv.iSubItem = iSubItem;
|
||||
lv.pszText = w.empty() ? const_cast<LPWSTR>(L"") : &w[0];
|
||||
::SendMessageW(list.GetSafeHwnd(), LVM_SETITEMTEXTW, (WPARAM)iItem, (LPARAM)&lv);
|
||||
}
|
||||
|
||||
BOOL CFileManagerDlg::OnInitDialog()
|
||||
{
|
||||
__super::OnInitDialog();
|
||||
@@ -1104,6 +1125,9 @@ void CFileManagerDlg::OnDblclkListRemote(NMHDR* pNMHDR, LRESULT* pResult)
|
||||
|
||||
void CFileManagerDlg::FixedRemoteFileList(BYTE *pbBuffer, DWORD dwBufferLen)
|
||||
{
|
||||
CString clientType = m_ContextObject->GetAdditionalData(RES_CLIENT_TYPE);
|
||||
UINT cp = (clientType == _T("LNX") || clientType == _T("MAC")) ? CP_UTF8 : 936;
|
||||
|
||||
// 重新设置ImageList
|
||||
SHFILEINFO sfi = {};
|
||||
HIMAGELIST hImageListLarge = (HIMAGELIST)SHGetFileInfo(NULL, 0, &sfi,sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_LARGEICON);
|
||||
@@ -1151,7 +1175,8 @@ void CFileManagerDlg::FixedRemoteFileList(BYTE *pbBuffer, DWORD dwBufferLen)
|
||||
pszFileName = ++pList;
|
||||
|
||||
if (bIsInsert) {
|
||||
nItem = m_list_remote.InsertItem(nItemIndex++, pszFileName, GetIconIndex(pszFileName, nType));
|
||||
nItem = m_list_remote.InsertItem(nItemIndex++, "", GetIconIndex(pszFileName, nType));
|
||||
SetFileTextItem(m_list_remote, nItem, 0, pszFileName, cp);
|
||||
m_list_remote.SetItemData(nItem, nType == FILE_ATTRIBUTE_DIRECTORY);
|
||||
SHFILEINFO sfi = {};
|
||||
SHGetFileInfo(pszFileName, FILE_ATTRIBUTE_NORMAL | nType, &sfi,sizeof(SHFILEINFO), SHGFI_TYPENAME | SHGFI_USEFILEATTRIBUTES);
|
||||
@@ -1184,6 +1209,9 @@ void CFileManagerDlg::FixedRemoteFileList(BYTE *pbBuffer, DWORD dwBufferLen)
|
||||
|
||||
void CFileManagerDlg::FixedRemoteSearchFileList(BYTE *pbBuffer, DWORD dwBufferLen)
|
||||
{
|
||||
CString clientType = m_ContextObject->GetAdditionalData(RES_CLIENT_TYPE);
|
||||
UINT cp = (clientType == _T("LNX") || clientType == _T("MAC")) ? CP_UTF8 : 936;
|
||||
|
||||
// 第一批结果到达时,初始化搜索列表
|
||||
if (!m_bSearching) {
|
||||
m_bSearching = true;
|
||||
@@ -1241,7 +1269,8 @@ void CFileManagerDlg::FixedRemoteSearchFileList(BYTE *pbBuffer, DWORD dwBufferLe
|
||||
}
|
||||
}
|
||||
|
||||
int nItem = m_list_remote.InsertItem(m_nSearchResultCount, csFileName, nIcon);
|
||||
int nItem = m_list_remote.InsertItem(m_nSearchResultCount, "", nIcon);
|
||||
SetFileTextItem(m_list_remote, nItem, 0, csFileName, cp);
|
||||
m_list_remote.SetItemData(nItem, nType == FILE_ATTRIBUTE_DIRECTORY);
|
||||
|
||||
pList += lstrlen(pszFullPath) + 1;
|
||||
@@ -1261,7 +1290,7 @@ void CFileManagerDlg::FixedRemoteSearchFileList(BYTE *pbBuffer, DWORD dwBufferLe
|
||||
m_list_remote.SetItemText(nItem, 2, time.FormatL("%Y-%m-%d %H:%M"));
|
||||
|
||||
// 路径
|
||||
m_list_remote.SetItemText(nItem, 3, csDir);
|
||||
SetFileTextItem(m_list_remote, nItem, 3, csDir, cp);
|
||||
|
||||
pList += 16;
|
||||
m_nSearchResultCount++;
|
||||
|
||||
Reference in new issue
Block a user