From ab83f5d6858eb98e4ae30892d20afb3c4fc3ea95 Mon Sep 17 00:00:00 2001 From: yuanyuanxiang <962914132@qq.com> Date: Thu, 5 Nov 2026 14:11:17 +0100 Subject: [PATCH] Feature: persist file manager transfer history History used to jump to the last directory merely visited, and lived only in memory. Now it is recorded only when a transfer actually starts (the four copy/transfer handlers) and persisted as an MRU list of the last 10 directories in THIS_CFG [file_history], keyed "local" plus one key per clientID. Paths are stored verbatim; '|' joins the list. The history handlers read the head of that list; the rest is kept for the future dropdown. Also translated the four zh_TW status messages, which were still simplified copies. Server-only; no protocol or client change. Co-Authored-By: deepseek-flash --- server/2015Remote/FileManagerDlg.cpp | 114 ++++++++++++++++++--------- server/2015Remote/FileManagerDlg.h | 10 ++- server/2015Remote/lang/zh_TW.ini | 8 +- 3 files changed, 87 insertions(+), 45 deletions(-) diff --git a/server/2015Remote/FileManagerDlg.cpp b/server/2015Remote/FileManagerDlg.cpp index 89c5273..20a32a7 100644 --- a/server/2015Remote/FileManagerDlg.cpp +++ b/server/2015Remote/FileManagerDlg.cpp @@ -30,10 +30,67 @@ static UINT indicators[] = { #define MAX_SEND_BUFFER 65535 #define MAX_RECV_BUFFER 65535 -// 静态成员变量定义 - 历史路径记录 -CString CFileManagerDlg::s_strLocalHistoryPath; -std::map CFileManagerDlg::s_mapRemoteHistoryPath; -CLock CFileManagerDlg::s_lockHistory; +// 传输目录历史:本地用 "local" 作键,远程用 clientID 十进制作键(见 [file_history] 节)。 +// 只记录真正发起过传输的目录,纯浏览不记录。 +static std::string HistoryKey(bool bLocal, uint64_t clientID) +{ + return bLocal ? "local" : std::to_string(clientID); +} + +// 比较用的规范化:去掉尾部分隔符(保留根目录本身,如 "C:"、"/")。 +static CString TrimTrailingSep(const CString& path) +{ + CString s = path; + while (s.GetLength() > 1 && (s.Right(1) == "\\" || s.Right(1) == "/")) + s.Delete(s.GetLength() - 1); + return s; +} + +std::vector CFileManagerDlg::LoadTransferHistory(bool bLocal, uint64_t clientID) +{ + std::vector out; + if (!bLocal && clientID == 0) + return out; + + std::string raw = THIS_CFG.GetStr("file_history", HistoryKey(bLocal, clientID)); + for (auto& s : StringToVector(raw, '|')) { + if (!s.empty()) + out.push_back(CString(s.c_str())); + } + return out; +} + +void CFileManagerDlg::PushTransferHistory(bool bLocal, uint64_t clientID, const CString& path) +{ + if (path.IsEmpty() || (!bLocal && clientID == 0)) + return; + + CString key = TrimTrailingSep(path); + // 原样保存(含尾部分隔符),恢复时可直接列目录 + std::string raw = path.GetString(); + // 路径含分隔符会破坏历史格式,跳过不记(与 CInputDialog::SaveHistory 的约定一致) + if (raw.find('|') != std::string::npos) + return; + int n = 1; + for (auto& p : LoadTransferHistory(bLocal, clientID)) { + bool same = bLocal ? (TrimTrailingSep(p).CompareNoCase(key) == 0) + : (TrimTrailingSep(p) == key); + if (same) + continue; + if (n++ >= kTransferHistoryMax) + break; + raw += '|'; + raw += p.GetString(); + } + THIS_CFG.SetStr("file_history", HistoryKey(bLocal, clientID), raw); +} + +// 只有真正发起文件传输时才调用(本地/远程当前目录各记一条) +void CFileManagerDlg::RecordTransferHistory() +{ + PushTransferHistory(true, 0, m_Local_Path); + PushTransferHistory(false, GetClientID(), m_Remote_Path); +} // 获取有效的客户端ID:基类已经覆盖 m_ClientID + ctx->GetClientID()(含 auth 后钉的值), // 这里仅在它们都拿不到时(老客户端没走 auth)通过 IP 反查主连接做兜底。 @@ -542,12 +599,6 @@ void CFileManagerDlg::FixedLocalFileList(CString directory) } ShowMessage(_TRF("本地:装载目录 %s 完成"), m_Local_Path); - - // 记录本地历史路径 - if (m_Local_Path.GetLength() > 0) { - CAutoCLock lock(s_lockHistory); - s_strLocalHistoryPath = m_Local_Path; - } } void CFileManagerDlg::DropItemOnList(CListCtrl* pDragList, CListCtrl* pDropList) @@ -1102,13 +1153,6 @@ void CFileManagerDlg::GetRemoteFileList(CString directory) m_Remote_Directory_ComboBox.InsertStringL(0, m_Remote_Path); m_Remote_Directory_ComboBox.SetCurSel(0); - // 记录远程历史路径(按客户端ID区分) - uint64_t clientID = GetClientID(); - if (m_Remote_Path.GetLength() > 0 && clientID != 0) { - CAutoCLock lock(s_lockHistory); - s_mapRemoteHistoryPath[clientID] = m_Remote_Path; - } - // 得到返回数据前禁窗口 m_list_remote.EnableWindow(FALSE); m_ProgressCtrl->SetPos(0); @@ -1689,18 +1733,14 @@ void CFileManagerDlg::OnRemoteSearch() void CFileManagerDlg::OnLocalHistory() { - // 跳转到上次打开的本地文件夹 - CString historyPath; - { - CAutoCLock lock(s_lockHistory); - historyPath = s_strLocalHistoryPath; - } - - if (historyPath.IsEmpty()) { + // 跳转到上次真正传输过文件的本地目录(MRU 首项) + std::vector history = LoadTransferHistory(true, 0); + if (history.empty()) { ShowMessage(_TR("没有本地历史记录")); return; } + CString historyPath = history.front(); // 检查目录是否存在 if (GetFileAttributesA(historyPath) == INVALID_FILE_ATTRIBUTES) { ShowMessage(_TRF("历史目录不存在: %s"), historyPath); @@ -1713,28 +1753,20 @@ void CFileManagerDlg::OnLocalHistory() void CFileManagerDlg::OnRemoteHistory() { - // 跳转到上次打开的远程文件夹(按客户端ID区分) + // 跳转到上次真正传输过文件的远程目录(按客户端ID区分) uint64_t clientID = GetClientID(); if (clientID == 0) { ShowMessage(_TR("无法识别远程主机")); return; } - CString historyPath; - { - CAutoCLock lock(s_lockHistory); - auto it = s_mapRemoteHistoryPath.find(clientID); - if (it != s_mapRemoteHistoryPath.end()) { - historyPath = it->second; - } - } - - if (historyPath.IsEmpty()) { + std::vector history = LoadTransferHistory(false, clientID); + if (history.empty()) { ShowMessage(_TR("没有远程历史记录")); return; } - m_Remote_Path = historyPath; + m_Remote_Path = history.front(); GetRemoteFileList("."); } @@ -2016,6 +2048,7 @@ void CFileManagerDlg::OnLocalCopy() MessageBoxAPI_L(m_hWnd, "文件夹为空", "警告", MB_OK|MB_ICONWARNING); return; } + RecordTransferHistory(); EnableControl(FALSE); SendUploadJob(); } @@ -2117,6 +2150,10 @@ void CFileManagerDlg::OnRemoteCopy() m_Remote_Download_Job.AddTail(file); } //EO while(pos) -- at this point we have deleted the moving items and stored them in memory + if (!m_Remote_Download_Job.IsEmpty()) { + RecordTransferHistory(); + } + // 发送第一个下载任务 SendDownloadJob(); } @@ -3356,6 +3393,7 @@ void CFileManagerDlg::OnTransferV2ToRemote() if (mainCtx) { std::string remoteDir = m_Remote_Path.GetString(); g_2015RemoteDlg->SendFilesToClientV2(mainCtx, files, remoteDir); + RecordTransferHistory(); ShowMessage(_TRF("V2传输已启动,共 %d 个文件 -> %s"), (int)files.size(), remoteDir.c_str()); } else { ShowMessage(_TRF("找不到主连接: clientID %llu"), clientID); @@ -3391,6 +3429,8 @@ void CFileManagerDlg::OnTransferV2ToLocal() return; } + RecordTransferHistory(); + // 构建命令包: [cmd:1][targetDir\0][file1\0][file2\0]...[fileN\0][\0] std::vector packet; packet.push_back(CMD_DOWN_FILES_V2); diff --git a/server/2015Remote/FileManagerDlg.h b/server/2015Remote/FileManagerDlg.h index a345e4e..876fcbe 100644 --- a/server/2015Remote/FileManagerDlg.h +++ b/server/2015Remote/FileManagerDlg.h @@ -289,10 +289,12 @@ private: void CollectFilesRecursive(const std::string& dirPath, std::vector& files); float m_fScalingFactor; - // 历史路径记录(静态,跨实例共享) - static CString s_strLocalHistoryPath; - static std::map s_mapRemoteHistoryPath; - static CLock s_lockHistory; // 保护历史路径的锁 + // 传输目录历史:持久化在 THIS_CFG 的 [file_history] 节,MRU 列表最多 kTransferHistoryMax 条。 + // 只有真正发起过文件传输的目录才记录(单纯浏览目录不算),见 RecordTransferHistory。 + enum { kTransferHistoryMax = 10 }; + static std::vector LoadTransferHistory(bool bLocal, uint64_t clientID); + static void PushTransferHistory(bool bLocal, uint64_t clientID, const CString& path); + void RecordTransferHistory(); // 获取有效的客户端ID(优先用 m_ClientID,否则通过 IP 找主连接) uint64_t GetClientID() const; diff --git a/server/2015Remote/lang/zh_TW.ini b/server/2015Remote/lang/zh_TW.ini index 5023fdd..5fb117e 100644 --- a/server/2015Remote/lang/zh_TW.ini +++ b/server/2015Remote/lang/zh_TW.ini @@ -1872,10 +1872,10 @@ IOCP << ÒƳý=<< ÒƳý ²å¼þÁбíΪ¿գ¬Î޷¨´´½¨´¥·¢Æ÷=Íâ’ìÁбížé¿գ¬Ÿo·¨½¨Á¢Ó|°lÆ÷ ÇëÏÈѡÔñÖÁÉÙһ¸ö²å¼þ=ՈÏÈßx“ñÖÁÉÙһ‚€Íâ’ì -ûÓб¾µØÀúʷ¼Ç¼=ûÓб¾µØÀúʷ¼Ç¼ -ÀúʷĿ¼²»´æÔÚ: %s=ÀúʷĿ¼²»´æÔÚ: %s -Î޷¨ʶ±ðԶ³ÌÖ÷»ú=Î޷¨ʶ±ðԶ³ÌÖ÷»ú -ûÓÐԶ³ÌÀúʷ¼Ç¼=ûÓÐԶ³ÌÀúʷ¼Ç¼ +ûÓб¾µØÀúʷ¼Ç¼=›]Óб¾™Cšvʷӛä› +ÀúʷĿ¼²»´æÔÚ: %s=švʷĿ䛲»´æÔÚ: %s +Î޷¨ʶ±ðԶ³ÌÖ÷»ú=Ÿo·¨×R„eßh¶ËÖ÷™C +ûÓÐԶ³ÌÀúʷ¼Ç¼=›]ÓÐßh¶˚vʷӛä› Ë㷨×ÔÊÊӦ=Ë㷨×ÔÊÊӦ ; Build Dialog - Traditional Chinese Translation ; Format: Simplified Chinese=Traditional Chinese