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
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-12-06 21:32:14 +01:00
1 parent 4bc51d2498
commit e265527610
6 files changed
+182 -5

No files matched your search

+165 -5
View File
@@ -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<CString> 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