From e2655276107cd38d0eabf59941a23d9869abb9d8 Mon Sep 17 00:00:00 2001 From: yuanyuanxiang <962914132@qq.com> Date: Sun, 6 Dec 2026 16:42:33 +0100 Subject: [PATCH] Feature: show transfer history in the file manager path dropdown The path combo only listed folders browsed in the current session and picking an entry did not navigate; transfer history was reachable only through the history button, which always jumped to the newest entry. Both path combos now load the [file_history] MRU list (max 10) after each drive-list reset, with duplicate paths skipped. The current folder still sits at index 0, and SetCurrentPathInCombo deletes stale copies before inserting. CBN_SELENDOK navigates as soon as the user picks an entry; CBN_SELCHANGE was avoided because it fires on every arrow-key move and would flood the remote side with list requests. With the list dropped, Enter is left to the combo so keyboard selection works too. A local entry that no longer exists restores the combo text and shows the existing "history folder not exist" message. For new clients, TOKEN_FILE_LIST_ERROR now re-enables and clears the remote pane instead of leaving it greyed out; a new translated message reports the path. The dialog resource doubles both dropdown heights (44->88 and 58->116 DLU) so about six rows are visible instead of three. Builds: Debug x64 server. Not runtime-tested against a live client. Co-Authored-By: deepseek-flash --- server/2015Remote/2015Remote.rc | Bin 181092 -> 181094 bytes server/2015Remote/FileManagerDlg.cpp | 170 ++++++++++++++++++++++++++- server/2015Remote/FileManagerDlg.h | 14 +++ server/2015Remote/lang/de_DE.ini | 1 + server/2015Remote/lang/en_US.ini | 1 + server/2015Remote/lang/zh_TW.ini | 1 + 6 files changed, 182 insertions(+), 5 deletions(-) diff --git a/server/2015Remote/2015Remote.rc b/server/2015Remote/2015Remote.rc index 5ff58d70b13059df04bec844004cc5d771f47e8c..c27187d0ba9e51fa7f1ca4ce1d8b3bbe33798eb2 100644 GIT binary patch delta 41 xcmaFT#{H~~dqbZWvjv02=80aSOss|sh74wtCwg6PZt!hy@MYZI;LG%+6aY4z4)Xv2 delta 55 zcmV-70LcI5h706|3$Tt#0W_1bYb%qmnjDkxOp>!`OFjVsHIt7@*^^H143l8!DucL9 Nhqz4vx42CLu64Sz7}Wp( diff --git a/server/2015Remote/FileManagerDlg.cpp b/server/2015Remote/FileManagerDlg.cpp index 8555584..57d8755 100644 --- a/server/2015Remote/FileManagerDlg.cpp +++ b/server/2015Remote/FileManagerDlg.cpp @@ -116,6 +116,59 @@ void CFileManagerDlg::RecordTransferHistory() PushTransferHistory(false, GetClientID(), m_Remote_Path); } +// 把历史传输目录追加到路径下拉框尾部(MRU 顺序,最多 kTransferHistoryMax 条), +// 已在列表里的路径跳过,避免与本次会话浏览过的目录重复。 +// 用 InsertString 而不是 AddString:CB_INSERTSTRING 不受 CBS_SORT 影响, +// 能保持“当前目录/浏览顺序在顶部”的既有排列。 +void CFileManagerDlg::AppendTransferHistoryToCombo(bool bLocal) +{ + CComboBox& combo = bLocal ? m_Local_Directory_ComboBox : m_Remote_Directory_ComboBox; + std::vector history = LoadTransferHistory(bLocal, bLocal ? 0 : GetClientID()); + + int added = 0; + for (const CString& path : history) { + if (added >= kTransferHistoryMax) + break; + if (path.IsEmpty()) + continue; + + bool exists = false; + for (int i = 0; i < combo.GetCount(); ++i) { + CString item; + combo.GetLBText(i, item); + bool same = bLocal ? (TrimTrailingSep(item).CompareNoCase(TrimTrailingSep(path)) == 0) + : (TrimTrailingSep(item) == TrimTrailingSep(path)); + if (same) { + exists = true; + break; + } + } + if (exists) + continue; + + combo.InsertString(combo.GetCount(), path); + ++added; + } +} + +// 导航到新目录时把当前路径放到下拉框顶部:同一目录(本地忽略大小写、远程区分大小写, +// 与传输历史的去重规则一致)只保留一条,避免历史项与浏览项重复出现。 +void CFileManagerDlg::SetCurrentPathInCombo(bool bLocal, const CString& path) +{ + CComboBox& combo = bLocal ? m_Local_Directory_ComboBox : m_Remote_Directory_ComboBox; + CString key = TrimTrailingSep(path); + for (int i = combo.GetCount() - 1; i >= 0; --i) { + CString item; + combo.GetLBText(i, item); + bool same = bLocal ? (TrimTrailingSep(item).CompareNoCase(key) == 0) + : (TrimTrailingSep(item) == key); + if (same) + combo.DeleteString(i); + } + combo.InsertString(0, path); + combo.SetCurSel(0); +} + // 获取有效的客户端ID:基类已经覆盖 m_ClientID + ctx->GetClientID()(含 auth 后钉的值), // 这里仅在它们都拿不到时(老客户端没走 auth)通过 IP 反查主连接做兜底。 uint64_t CFileManagerDlg::GetClientID() const @@ -247,6 +300,8 @@ BEGIN_MESSAGE_MAP(CFileManagerDlg, CDialog) ON_COMMAND(IDT_REMOTE_HOME, OnRemoteHome) ON_COMMAND(IDT_REMOTE_SEARCH, OnRemoteSearch) ON_COMMAND(IDT_REMOTE_HISTORY, OnRemoteHistory) + ON_CBN_SELENDOK(IDC_LOCAL_PATH, OnCbnSelendokLocalPath) + ON_CBN_SELENDOK(IDC_REMOTE_PATH, OnCbnSelendokRemotePath) ON_COMMAND(IDM_TRANSFER, OnTransfer) ON_COMMAND(IDM_RENAME, OnRename) ON_NOTIFY(LVN_ENDLABELEDIT, IDC_LIST_LOCAL, OnEndlabeleditListLocal) @@ -527,6 +582,7 @@ void CFileManagerDlg::FixedLocalDriveList() // 重置本地当前路径 m_Local_Path = ""; m_Local_Directory_ComboBox.ResetContent(); + AppendTransferHistoryToCombo(true); ShowMessage(_TRF("本地:装载目录 %s 完成"), m_Local_Path); } @@ -607,8 +663,7 @@ void CFileManagerDlg::FixedLocalFileList(CString directory) return; } - m_Local_Directory_ComboBox.InsertStringL(0, m_Local_Path); - m_Local_Directory_ComboBox.SetCurSel(0); + SetCurrentPathInCombo(true, m_Local_Path); // 重建标题 m_list_local.DeleteAllItems(); @@ -875,6 +930,22 @@ BOOL CFileManagerDlg::PreTranslateMessage(MSG* pMsg) if (pMsg->wParam == VK_ESCAPE) return true; if (pMsg->wParam == VK_RETURN) { + // 下拉列表展开时,回车交给组合框自己处理:它会提交高亮项并触发 + // CBN_SELENDOK。若在这里抢走,会按文件列表的选中行导航,而不是下拉项。 + // 焦点可能在组合框、编辑框,或独立于对话框的 ComboLBox 下拉列表上。 + auto comboHandlesEnter = [&pMsg](CComboBox& combo) -> bool { + if (!combo.GetDroppedState()) + return false; + if (pMsg->hwnd == combo.m_hWnd || ::IsChild(combo.m_hWnd, pMsg->hwnd)) + return true; + COMBOBOXINFO cbi = { sizeof(cbi) }; + return combo.GetComboBoxInfo(&cbi) && cbi.hwndList && + pMsg->hwnd == cbi.hwndList; + }; + if (comboHandlesEnter(m_Local_Directory_ComboBox) || + comboHandlesEnter(m_Remote_Directory_ComboBox)) + return __super::PreTranslateMessage(pMsg); + if ( pMsg->hwnd == m_list_local.m_hWnd || pMsg->hwnd == ((CEdit*)m_Local_Directory_ComboBox.GetWindow(GW_CHILD))->m_hWnd @@ -1026,7 +1097,11 @@ void CFileManagerDlg::FixedRemoteDriveList() } // 重置远程当前路径 m_Remote_Path = ""; + m_LastGoodRemotePath.Empty(); + m_bIgnoreLegacyEmptyList = false; + m_dwIgnoreLegacyUntil = 0; m_Remote_Directory_ComboBox.ResetContent(); + AppendTransferHistoryToCombo(false); ShowMessage(_TRF("远程:装载目录 %s 完成"), m_Remote_Path); } @@ -1100,6 +1175,15 @@ void CFileManagerDlg::OnReceiveComplete() break; } case TOKEN_FILE_LIST: // 文件列表 + // 新客户端列目录失败时先发 TOKEN_FILE_LIST_ERROR,再补一个 1 字节的兼容 + // 空列表;后者不能当成功处理,否则会覆盖错误状态并显示成空目录。 + if (m_bIgnoreLegacyEmptyList) { + m_bIgnoreLegacyEmptyList = false; + // 只吞紧随错误包之后的兼容空列表;超时说明是后续的新请求。 + if (GetTickCount() <= m_dwIgnoreLegacyUntil && + m_ContextObject->m_DeCompressionBuffer.GetBufferLen() <= 1) + break; + } try { FixedRemoteFileList ( @@ -1122,6 +1206,36 @@ void CFileManagerDlg::OnReceiveComplete() Mprintf("[ERROR] Other exception\n"); } break; + case TOKEN_FILE_LIST_ERROR: { // 新客户端:列目录失败(路径不存在/无权限) + // 请求前列表被禁用,失败时不会走 FixedRemoteFileList 的恢复逻辑;这里必须 + // 解除禁用,并回到最近一次成功列出的目录,否则上传/新建会落到失效路径上。 + LPBYTE buf = m_ContextObject->m_DeCompressionBuffer.GetBuffer(0); + ULONG len = m_ContextObject->m_DeCompressionBuffer.GetBufferLen(); + DWORD err = 0; + if (len >= 5) memcpy(&err, buf + 1, sizeof(err)); + const CString failedPath = m_Remote_Path; + Mprintf("[FileList] open %s failed, win32err=%u\n", (LPCSTR)failedPath, err); + + if (!m_LastGoodRemotePath.IsEmpty() && + m_LastGoodRemotePath.CompareNoCase(failedPath) != 0) { + // 列表内容和元数据都还是上一个成功目录的,直接恢复路径和选中项。 + m_Remote_Path = m_LastGoodRemotePath; + SetCurrentPathInCombo(false, m_Remote_Path); + m_list_remote.EnableWindow(TRUE); + } else { + // 没有可回退的目录,或是刷新当前目录失败:回到驱动器列表,避免 + // 继续在失效路径上操作。 + FixedRemoteDriveList(); + m_list_remote.EnableWindow(TRUE); + } + // 客户端随后补发的兼容空列表要吞掉;放最后是因为 FixedRemoteDriveList + // 会清掉这个标志。 + m_bIgnoreLegacyEmptyList = true; + m_dwIgnoreLegacyUntil = GetTickCount() + 3000; + // FixedRemoteDriveList 会写“装载目录完成”,错误提示必须放在它之后。 + ShowMessage(_TRF("远程目录打开失败: %s"), failedPath); + break; + } case TOKEN_FILE_SIZE: // 传输文件时的第一个数据包,文件大小,及文件名 CreateLocalRecvFile(); break; @@ -1204,7 +1318,7 @@ void CFileManagerDlg::OnReceiveComplete() void CFileManagerDlg::GetRemoteFileList(CString directory) { m_bRemoteSearchResults = false; - m_RemoteMeta.clear(); + // 不在请求前清空 m_RemoteMeta:列目录失败时要保留上一个目录的列表与元数据。 // 导航到目录时停止正在进行的远程搜索 if (m_bSearching) { @@ -1253,8 +1367,7 @@ void CFileManagerDlg::GetRemoteFileList(CString directory) m_ContextObject->Send2Client(bPacket, PacketSize); LocalFree(bPacket); - m_Remote_Directory_ComboBox.InsertStringL(0, m_Remote_Path); - m_Remote_Directory_ComboBox.SetCurSel(0); + SetCurrentPathInCombo(false, m_Remote_Path); // 得到返回数据前禁窗口 m_list_remote.EnableWindow(FALSE); @@ -1620,6 +1733,7 @@ void CFileManagerDlg::FixedRemoteFileList(BYTE *pbBuffer, DWORD dwBufferLen) m_list_remote.SetRedraw(TRUE); // 恢复窗口 m_list_remote.EnableWindow(TRUE); + m_LastGoodRemotePath = m_Remote_Path; ShowMessage(_TRF("远程:装载目录 %s 完成"), m_Remote_Path); } @@ -2159,6 +2273,52 @@ void CFileManagerDlg::OnRemoteHistory() GetRemoteFileList("."); } +// 下拉框选中目录即跳转(历史项与本次浏览过的目录都适用)。 +// 用 CBN_SELENDOK 而不是 CBN_SELCHANGE:后者在用户用方向键浏览下拉列表时 +// 每移动一项就触发一次,会造成远程目录请求连续发送。 +void CFileManagerDlg::OnCbnSelendokLocalPath() +{ + int sel = m_Local_Directory_ComboBox.GetCurSel(); + if (sel == CB_ERR) + return; + + CString path; + m_Local_Directory_ComboBox.GetLBText(sel, path); + if (path.IsEmpty()) + return; + + // 历史项可能指向已删除/已拔出的目录,先确认存在(与 OnLocalHistory 一致) + if (GetFileAttributesA(path) == INVALID_FILE_ATTRIBUTES) { + ShowMessage(_TRF("历史目录不存在: %s"), path); + // 把下拉框恢复成当前实际目录,否则之后在路径框回车会带着失效目录导航 + if (m_Local_Path.IsEmpty()) { + m_Local_Directory_ComboBox.SetCurSel(-1); + m_Local_Directory_ComboBox.SetWindowText(""); + } else { + SetCurrentPathInCombo(true, m_Local_Path); + } + return; + } + + m_Local_Path = path; + FixedLocalFileList("."); +} + +void CFileManagerDlg::OnCbnSelendokRemotePath() +{ + int sel = m_Remote_Directory_ComboBox.GetCurSel(); + if (sel == CB_ERR) + return; + + CString path; + m_Remote_Directory_ComboBox.GetLBText(sel, path); + if (path.IsEmpty()) + return; + + m_Remote_Path = path; + GetRemoteFileList("."); +} + void CFileManagerDlg::OnLocalView() { // TODO: Add your command handler code here diff --git a/server/2015Remote/FileManagerDlg.h b/server/2015Remote/FileManagerDlg.h index 22d6c33..0a66c07 100644 --- a/server/2015Remote/FileManagerDlg.h +++ b/server/2015Remote/FileManagerDlg.h @@ -283,6 +283,8 @@ protected: afx_msg void OnRemoteHome(); afx_msg void OnRemoteSearch(); afx_msg void OnRemoteHistory(); + afx_msg void OnCbnSelendokLocalPath(); + afx_msg void OnCbnSelendokRemotePath(); afx_msg void OnTransferV2ToRemote(); // V2: 本地文件传输到远程 afx_msg void OnTransferV2ToLocal(); // V2: 远程文件传输到本地 //}}AFX_MSG @@ -324,6 +326,18 @@ private: static void PushTransferHistory(bool bLocal, uint64_t clientID, const CString& path); void RecordTransferHistory(); + // 历史传输目录同时反映到路径下拉框:打开对话框/回到驱动器列表时追加到列表尾部, + // 用户选中的下拉项直接跳转(CBN_SELENDOK),原有“当前目录在顶部、输入路径回车跳转”不变。 + void AppendTransferHistoryToCombo(bool bLocal); + void SetCurrentPathInCombo(bool bLocal, const CString& path); + + // 远程列目录失败恢复:新客户端报 TOKEN_FILE_LIST_ERROR 后还会补一个 1 字节的 + // 兼容空列表,必须吞掉;失败时回到最近一次成功列出的目录,避免上传/新建落到 + // 已失效的路径上。 + CString m_LastGoodRemotePath; + bool m_bIgnoreLegacyEmptyList = false; + DWORD m_dwIgnoreLegacyUntil = 0; + // 获取有效的客户端ID(优先用 m_ClientID,否则通过 IP 找主连接) uint64_t GetClientID() const; public: diff --git a/server/2015Remote/lang/de_DE.ini b/server/2015Remote/lang/de_DE.ini index a16d01b..e2c9cc0 100644 --- a/server/2015Remote/lang/de_DE.ini +++ b/server/2015Remote/lang/de_DE.ini @@ -1881,6 +1881,7 @@ IOCP ûÓб¾µØÀúʷ¼Ç¼=Kein lokaler Verlauf ÀúʷĿ¼²»´æÔÚ: %s=Verlaufsordner existiert nicht: %s +Զ³ÌĿ¼´ò¿ªʧ°Ü: %s=Remote-Ordner konnte nicht geoeffnet werden: %s Î޷¨ʶ±ðԶ³ÌÖ÷»ú=Unbekannte Remote-Maschine ûÓÐԶ³ÌÀúʷ¼Ç¼=Kein Remote-Verlauf Ë㷨×ÔÊÊӦ=Algorithmus adaptiv diff --git a/server/2015Remote/lang/en_US.ini b/server/2015Remote/lang/en_US.ini index 3dde512..4d9506e 100644 --- a/server/2015Remote/lang/en_US.ini +++ b/server/2015Remote/lang/en_US.ini @@ -1881,6 +1881,7 @@ IOCP ûÓб¾µØÀúʷ¼Ç¼=No local history ÀúʷĿ¼²»´æÔÚ: %s=History folder not exist: %s +Զ³ÌĿ¼´ò¿ªʧ°Ü: %s=Failed to open remote folder: %s Î޷¨ʶ±ðԶ³ÌÖ÷»ú=Unknown remote machine ûÓÐԶ³ÌÀúʷ¼Ç¼=No remote history Ë㷨×ÔÊÊӦ=Algorithm Adaptive diff --git a/server/2015Remote/lang/zh_TW.ini b/server/2015Remote/lang/zh_TW.ini index d882d2b..1159884 100644 --- a/server/2015Remote/lang/zh_TW.ini +++ b/server/2015Remote/lang/zh_TW.ini @@ -1874,6 +1874,7 @@ IOCP ÇëÏÈѡÔñÖÁÉÙһ¸ö²å¼þ=ՈÏÈßx“ñÖÁÉÙһ‚€Íâ’ì ûÓб¾µØÀúʷ¼Ç¼=›]Óб¾™Cšvʷӛä› ÀúʷĿ¼²»´æÔÚ: %s=švʷĿ䛲»´æÔÚ: %s +Զ³ÌĿ¼´ò¿ªʧ°Ü: %s=ßh¶ËĿä›é_†¢ʧ”¡: %s Î޷¨ʶ±ðԶ³ÌÖ÷»ú=Ÿo·¨×R„eßh¶ËÖ÷™C ûÓÐԶ³ÌÀúʷ¼Ç¼=›]ÓÐßh¶˚vʷӛä› Ë㷨×ÔÊÊӦ=Ë㷨×ÔÊÊӦ