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
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-05 14:22:12 +01:00
1 parent ca4e85826f
commit ab83f5d685
3 files changed
+87 -45

No files matched your search

+77 -37
View File
@@ -30,10 +30,67 @@ static UINT indicators[] = {
#define MAX_SEND_BUFFER 65535
#define MAX_RECV_BUFFER 65535
// 静态成员变量定义 - 历史路径记录
CString CFileManagerDlg::s_strLocalHistoryPath;
std::map<uint64_t, CString> 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<CString> CFileManagerDlg::LoadTransferHistory(bool bLocal, uint64_t clientID)
{
std::vector<CString> 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<CString> 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<CString> 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<char> packet;
packet.push_back(CMD_DOWN_FILES_V2);
+6 -4
View File
@@ -289,10 +289,12 @@ private:
void CollectFilesRecursive(const std::string& dirPath, std::vector<std::string>& files);
float m_fScalingFactor;
// 历史路径记录(静态,跨实例共享)
static CString s_strLocalHistoryPath;
static std::map<uint64_t, CString> s_mapRemoteHistoryPath;
static CLock s_lockHistory; // 保护历史路径的锁
// 传输目录历史:持久化在 THIS_CFG 的 [file_history] 节,MRU 列表最多 kTransferHistoryMax 条。
// 只有真正发起过文件传输的目录才记录(单纯浏览目录不算),见 RecordTransferHistory。
enum { kTransferHistoryMax = 10 };
static std::vector<CString> 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;
+4 -4
View File
@@ -1872,10 +1872,10 @@ IOCP
<< 移除=<< 移除
插件列表为空,无法创建触发器=外掛列表為空,無法建立觸發器
请先选择至少一个插件=請先選擇至少一個外掛
没有本地历史记录=没有本地历史记录
历史目录不存在: %s=历史目录不存在: %s
无法识别远程主机=无法识别远程主机
没有远程历史记录=没有远程历史记录
没有本地历史记录=沒有本機歷史記錄
历史目录不存在: %s=歷史目錄不存在: %s
无法识别远程主机=無法識別遠端主機
没有远程历史记录=沒有遠端歷史記錄
算法自适应=算法自适应
; Build Dialog - Traditional Chinese Translation
; Format: Simplified Chinese=Traditional Chinese