Feature: add a remote Open command with large-file confirmation
Add an Open item atop the remote file list context menu: a single file is pulled back and previewed through the existing flow, a single folder navigates into its subdirectory, and multi-selection disables it. Files over the 8 MiB preview limit ask for confirmation; once confirmed the explicit-open path relaxes the size gate, hash query, total timeout and cache eviction so even very large files transfer and open. Double-click preview behavior is unchanged. Localize the new menu item and dialog in en_US/zh_TW/de_DE. Co-Authored-By: Qoder
This commit is contained in:
1 parent
ee20326bbf
commit
bdf85a82cd
8 files changed
+94
-18
No files matched your search
@@ -257,6 +257,7 @@ BEGIN_MESSAGE_MAP(CFileManagerDlg, CDialog)
|
||||
ON_COMMAND(IDM_LOCAL_OPEN, OnLocalOpen)
|
||||
ON_COMMAND(IDM_REMOTE_OPEN_SHOW, OnRemoteOpenShow)
|
||||
ON_COMMAND(IDM_REMOTE_OPEN_HIDE, OnRemoteOpenHide)
|
||||
ON_COMMAND(IDM_REMOTE_OPEN_PREVIEW, OnRemoteOpenPreview)
|
||||
ON_NOTIFY(NM_RCLICK, IDC_LIST_LOCAL, OnRclickListLocal)
|
||||
ON_NOTIFY(NM_RCLICK, IDC_LIST_REMOTE, OnRclickListRemote)
|
||||
ON_MESSAGE(WM_MY_MESSAGE, OnMyMessage)
|
||||
@@ -1342,7 +1343,7 @@ void CFileManagerDlg::OpenLocalPath(const CString& path)
|
||||
}
|
||||
}
|
||||
|
||||
void CFileManagerDlg::BeginRemotePreview(const CString& fullPath)
|
||||
void CFileManagerDlg::BeginRemotePreview(const CString& fullPath, bool allowLarge)
|
||||
{
|
||||
if (THIS_CFG.GetInt("settings", "PreviewEnabled", 1) == 0)
|
||||
return;
|
||||
@@ -1371,7 +1372,7 @@ void CFileManagerDlg::BeginRemotePreview(const CString& fullPath)
|
||||
}
|
||||
Mprintf("[Preview] begin full=%s size=%llu mtime=%llu\n",
|
||||
(LPCSTR)fullPath, (unsigned long long)meta.size, (unsigned long long)meta.mtimeMs);
|
||||
if (meta.size > FILE_PREVIEW_MAX_BYTES) {
|
||||
if (meta.size > FILE_PREVIEW_MAX_BYTES && !allowLarge) {
|
||||
CString msg;
|
||||
msg.FormatL("文件较大,不支持预览:%s(%llu MB,上限 %u MB)",
|
||||
fullPath, (unsigned long long)(meta.size / 1024 / 1024),
|
||||
@@ -1381,7 +1382,10 @@ void CFileManagerDlg::BeginRemotePreview(const CString& fullPath)
|
||||
}
|
||||
|
||||
// P2:支持哈希查询的客户端先取当前内容的 SHA-256,命中已有缓存即可不传输。
|
||||
if (mainCtx->SupportsFileHash()) {
|
||||
// 显式打开的超大文件跳过哈希查询(客户端把 maxBytes 钳到预览上限,会回 TOO_LARGE),
|
||||
// 直接走 P1(size+mtime)传输。
|
||||
if (mainCtx->SupportsFileHash() &&
|
||||
!(allowLarge && meta.size > FILE_PREVIEW_MAX_BYTES)) {
|
||||
if (!m_pendingHash.fullPath.IsEmpty()) {
|
||||
::MessageBox(m_hWnd, _TR("正在预览另一个文件,请稍候"),
|
||||
_TR("提示"), MB_OK | MB_ICONINFORMATION);
|
||||
@@ -1406,11 +1410,12 @@ void CFileManagerDlg::BeginRemotePreview(const CString& fullPath)
|
||||
return;
|
||||
}
|
||||
|
||||
ContinueRemotePreview(fullPath, meta.size, meta.mtimeMs, std::string());
|
||||
ContinueRemotePreview(fullPath, meta.size, meta.mtimeMs, std::string(), allowLarge);
|
||||
}
|
||||
|
||||
void CFileManagerDlg::ContinueRemotePreview(const CString& fullPath, uint64_t size,
|
||||
uint64_t mtimeMs, const std::string& sha256)
|
||||
uint64_t mtimeMs, const std::string& sha256,
|
||||
bool allowLarge)
|
||||
{
|
||||
uint64_t clientID = GetClientID();
|
||||
std::string remotePath((LPCSTR)fullPath);
|
||||
@@ -1421,7 +1426,7 @@ void CFileManagerDlg::ContinueRemotePreview(const CString& fullPath, uint64_t si
|
||||
std::string outPath, error, cachedSha;
|
||||
CFilePreviewMgr::PrepareResult pr = CFilePreviewMgr::Instance().Prepare(
|
||||
clientID, clientKey, remotePath, basename, size, mtimeMs,
|
||||
sha256, m_hWnd, outPath, error, &cachedSha);
|
||||
sha256, m_hWnd, outPath, error, &cachedSha, allowLarge);
|
||||
Mprintf("[Preview] prepare result=%d out=%s err=%s sha=%s\n",
|
||||
(int)pr, outPath.c_str(), error.c_str(), sha256.c_str());
|
||||
|
||||
@@ -3669,10 +3674,58 @@ void CFileManagerDlg::OnRclickListRemote(NMHDR* pNMHDR, LRESULT* pResult)
|
||||
pM->EnableMenuItem(IDM_TRANSFER_S, MF_BYCOMMAND | MF_GRAYED); // 远程列表不能上传到远程
|
||||
|
||||
pM->EnableMenuItem(IDM_REFRESH, MF_BYCOMMAND | MF_ENABLED);
|
||||
|
||||
// "打开":置于"传输"上方。单选可用(文件→本地预览,文件夹→进入子目录),多选/零选禁用。
|
||||
// 运行时插入到位置 0,不改 .rc 与既有位置索引;上面的启用/禁用逻辑已执行完毕,不受影响。
|
||||
pM->InsertMenu(0, MF_BYPOSITION | MF_STRING, IDM_REMOTE_OPEN_PREVIEW, _TR("打开(&O)"));
|
||||
pM->EnableMenuItem(IDM_REMOTE_OPEN_PREVIEW, MF_BYCOMMAND |
|
||||
(pListCtrl->GetSelectedCount() == 1 ? MF_ENABLED : MF_GRAYED));
|
||||
|
||||
pM->TrackPopupMenu(TPM_LEFTALIGN, p.x, p.y, this);
|
||||
*pResult = 0;
|
||||
}
|
||||
|
||||
// 远程右键"打开":单选文件→本地预览(超阈值二次确认后允许大文件);单选文件夹→进入子目录。
|
||||
void CFileManagerDlg::OnRemoteOpenPreview()
|
||||
{
|
||||
if (m_list_remote.GetSelectedCount() != 1) return;
|
||||
int nItem = m_list_remote.GetSelectionMark();
|
||||
if (nItem < 0) return;
|
||||
|
||||
// 文件夹:与双击一致,进入子目录。
|
||||
if (m_list_remote.GetItemData(nItem) == 1) {
|
||||
GetRemoteFileList();
|
||||
return;
|
||||
}
|
||||
|
||||
// 文件:构造完整路径(搜索结果第 3 列是目录,普通列表用当前远程目录)。
|
||||
CString name = m_list_remote.GetItemText(nItem, 0);
|
||||
CString full;
|
||||
if (m_bRemoteSearchResults) {
|
||||
full = m_list_remote.GetItemText(nItem, 3);
|
||||
if (!full.IsEmpty() && full.Right(1) != "\\") full += "\\";
|
||||
full += name;
|
||||
} else {
|
||||
full = m_Remote_Path + name;
|
||||
}
|
||||
|
||||
// 超阈值:二次确认。确认后即使很大也传回本机并打开。
|
||||
bool allowLarge = false;
|
||||
RemoteMeta meta;
|
||||
if (GetRemoteFileMeta(full, meta) && meta.size > FILE_PREVIEW_MAX_BYTES) {
|
||||
CString msg;
|
||||
msg.FormatL("文件较大:%s(%llu MB,超过 %u MB 预览上限)。\n"
|
||||
"仍要传输到本机并打开吗?大文件传输可能耗时较长。",
|
||||
full, (unsigned long long)(meta.size / 1024 / 1024),
|
||||
(unsigned)(FILE_PREVIEW_MAX_BYTES / 1024 / 1024));
|
||||
if (::MessageBox(m_hWnd, msg, _TR("确认"), MB_YESNO | MB_ICONWARNING) != IDYES)
|
||||
return;
|
||||
allowLarge = true;
|
||||
}
|
||||
|
||||
BeginRemotePreview(full, allowLarge);
|
||||
}
|
||||
|
||||
bool CFileManagerDlg::MakeSureDirectoryPathExists(LPCTSTR pszDirPath)
|
||||
{
|
||||
LPTSTR p, pszDirCopy;
|
||||
|
||||
Reference in new issue
Block a user