From 4bc51d24988a7e8de694c24848bacbda6cdc2153 Mon Sep 17 00:00:00 2001 From: yuanyuanxiang <962914132@qq.com> Date: Sat, 5 Dec 2026 17:46:16 +0100 Subject: [PATCH] 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 caps the first-packet size gate at the confirmed size and relaxes the hash query, total timeout and cache eviction so even very large files transfer and open. When preview is disabled the explicit Open shows a message instead of doing nothing. Double-click preview behavior is unchanged. Localize the new menu item and dialogs in en_US/zh_TW/de_DE. Co-Authored-By: Qoder --- server/2015Remote/FileManagerDlg.cpp | 72 +++++++++++++++++++++++++--- server/2015Remote/FileManagerDlg.h | 5 +- server/2015Remote/FilePreview.cpp | 28 +++++++---- server/2015Remote/FilePreview.h | 7 ++- server/2015Remote/lang/de_DE.ini | 6 +++ server/2015Remote/lang/en_US.ini | 6 +++ server/2015Remote/lang/zh_TW.ini | 6 +++ server/2015Remote/resource.h | 1 + 8 files changed, 113 insertions(+), 18 deletions(-) diff --git a/server/2015Remote/FileManagerDlg.cpp b/server/2015Remote/FileManagerDlg.cpp index d862a60..8555584 100644 --- a/server/2015Remote/FileManagerDlg.cpp +++ b/server/2015Remote/FileManagerDlg.cpp @@ -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,65 @@ 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; + } + + // 显å¼�"打开"å�—预览开关约æ�Ÿï¼šç¦�用时给出å��馈而é�žé�™é»˜æ— åŠ¨ä½œï¼ˆå�Œå‡»é¢„览ä¿�æŒ�原é�™é»˜è¡Œä¸ºï¼‰ã€‚ + if (THIS_CFG.GetInt("settings", "PreviewEnabled", 1) == 0) { + ::MessageBox(m_hWnd, _TR("预览功能已ç¦�用,无法打开文件。å�¯åœ¨å�‚数中å�¯ç”¨é¢„览å�Žé‡�试。"), + _TR("æ��示"), MB_OK | MB_ICONINFORMATION); + 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; diff --git a/server/2015Remote/FileManagerDlg.h b/server/2015Remote/FileManagerDlg.h index b5113bb..22d6c33 100644 --- a/server/2015Remote/FileManagerDlg.h +++ b/server/2015Remote/FileManagerDlg.h @@ -143,9 +143,9 @@ public: // E2E 测试钩å­�:WM_APP+0x123,wParam=行å�·ï¼ŒlParam!=0 表示远程列表。 afx_msg LRESULT OnPreviewTest(WPARAM wParam, LPARAM lParam); #endif - void BeginRemotePreview(const CString& fullPath); + void BeginRemotePreview(const CString& fullPath, bool allowLarge = false); void ContinueRemotePreview(const CString& fullPath, uint64_t size, uint64_t mtimeMs, - const std::string& sha256); + const std::string& sha256, bool allowLarge = false); void OpenLocalPath(const CString& path); bool GetRemoteFileMeta(const CString& fullPath, RemoteMeta& meta); std::string GetPreviewClientKey(uint64_t clientID); @@ -270,6 +270,7 @@ protected: afx_msg void OnLocalOpen(); afx_msg void OnRemoteOpenShow(); afx_msg void OnRemoteOpenHide(); + afx_msg void OnRemoteOpenPreview(); afx_msg void OnRclickListLocal(NMHDR* pNMHDR, LRESULT* pResult); afx_msg void OnRclickListRemote(NMHDR* pNMHDR, LRESULT* pResult); afx_msg void OnLocalDesktop(); diff --git a/server/2015Remote/FilePreview.cpp b/server/2015Remote/FilePreview.cpp index 479d064..ac82e29 100644 --- a/server/2015Remote/FilePreview.cpp +++ b/server/2015Remote/FilePreview.cpp @@ -122,7 +122,7 @@ CFilePreviewMgr::PrepareResult CFilePreviewMgr::Prepare( const std::string& remotePath, const std::string& basename, uint64_t size, uint64_t mtimeMs, const std::string& sha256, HWND notifyHwnd, std::string& outPath, std::string& error, - std::string* outSha) + std::string* outSha, bool allowLarge) { outPath.clear(); error.clear(); @@ -238,6 +238,7 @@ CFilePreviewMgr::PrepareResult CFilePreviewMgr::Prepare( req.clientID = clientID; req.size = size; req.mtimeMs = mtimeMs; + req.allowLarge = allowLarge; req.clientKey = clientKey; req.clientDir = clientDir; req.remotePath = remotePath; @@ -346,8 +347,11 @@ bool CFilePreviewMgr::ObserveChunk(CONTEXT_OBJECT* ctx, const FileChunkPacketV2* FailLocked(*req, AsStd(_TR("预览文件å��越界"))); return false; } + // 显å¼�打开å°�顶到用户确认时的大å°�(req->size),普通预览ä»�用 8MiB 上é™�ï¼› + // é�¿å…� allowLarge 去掉闸门å�Žå®¢æˆ·ç«¯å£°æ˜Žä»»æ„�大å°�ç…§å�•è�½ç›˜ã€‚ + uint64_t sizeCap = req->allowLarge ? req->size : FILE_PREVIEW_MAX_BYTES; if (pkt->totalFiles != 1 || (pkt->flags & FFV2_DIRECTORY) || - pkt->fileSize > FILE_PREVIEW_MAX_BYTES) { + pkt->fileSize > sizeCap) { Mprintf("[Preview] observe gate reject total=%u flags=%u size=%llu\n", (unsigned)pkt->totalFiles, (unsigned)pkt->flags, (unsigned long long)pkt->fileSize); @@ -413,6 +417,7 @@ void CFilePreviewMgr::OnComplete(CONTEXT_OBJECT* ctx, const FileCompletePacketV2 job.recvName = req->recvName; job.size = req->size; job.mtimeMs = req->mtimeMs; + job.allowLarge = req->allowLarge; job.requestedSha = req->sha256; job.packetSha = packetSha; job.notifyHwnd = req->notifyHwnd; @@ -540,7 +545,7 @@ void CFilePreviewMgr::CheckTimeoutsLocked(std::chrono::steady_clock::time_point if (req.state != Request::WaitFirst && req.state != Request::Transferring) continue; bool stalled = now - req.lastDataAt > std::chrono::seconds(kStallSeconds); - bool tooLong = now - req.startAt > std::chrono::seconds(kTotalSeconds); + bool tooLong = !req.allowLarge && now - req.startAt > std::chrono::seconds(kTotalSeconds); if (stalled || tooLong) { FailLocked(req, AsStd(stalled ? _TR("预览传输å�œæ»žï¼Œå·²å�–消") : _TR("预览传输超时,已å�–消"))); @@ -621,7 +626,7 @@ void CFilePreviewMgr::FinalizeThread(FinalizeJob job) } if (!replaced) index.push_back(m); SaveIndex(job.clientDir, index); - EnforceCacheLimits(job.clientDir, index); + EnforceCacheLimits(job.clientDir, index, job.allowLarge ? localName : std::string()); RemoveTempDir(job.tempDir); Result* r = new Result(); @@ -844,7 +849,8 @@ bool CFilePreviewMgr::WriteEmptyFile(const std::string& path) return true; } -void CFilePreviewMgr::EnforceCacheLimits(const std::string& clientDir, std::vector& index) +void CFilePreviewMgr::EnforceCacheLimits(const std::string& clientDir, std::vector& index, + const std::string& protectName) { int maxFiles = 200; int maxMB = 512; @@ -882,9 +888,15 @@ void CFilePreviewMgr::EnforceCacheLimits(const std::string& clientDir, std::vect }); bool changed = false; while ((int)index.size() > maxFiles || uniqueBytes() > limitBytes) { - if (index.empty()) break; - std::string name = index.front().localName; - index.erase(index.begin()); + // 跳过å�—ä¿�护æ�¡ç›®ï¼ˆæœ¬æ¬¡æ˜¾å¼�打开的文件),淘汰最旧的å�¯æ·˜æ±°é¡¹ï¼› + // protectName 为空时等价于原逻辑(始终淘汰队首)。 + int victim = -1; + for (int i = 0; i < (int)index.size(); ++i) { + if (index[i].localName != protectName) { victim = i; break; } + } + if (victim < 0) break; + std::string name = index[victim].localName; + index.erase(index.begin() + victim); changed = true; bool referenced = false; for (const auto& m : index) diff --git a/server/2015Remote/FilePreview.h b/server/2015Remote/FilePreview.h index 87ffca4..889baea 100644 --- a/server/2015Remote/FilePreview.h +++ b/server/2015Remote/FilePreview.h @@ -82,7 +82,7 @@ public: const std::string& remotePath, const std::string& basename, uint64_t size, uint64_t mtimeMs, const std::string& sha256, HWND notifyHwnd, std::string& outPath, std::string& error, - std::string* outSha = nullptr); + std::string* outSha = nullptr, bool allowLarge = false); // UI 线程:对è¯�框关闭时放弃本窗å�£çš„æ‰€æœ‰é¢„览请求。 void CancelForHwnd(HWND hwnd); @@ -131,6 +131,7 @@ private: uint64_t transferID = 0; uint64_t size = 0; uint64_t mtimeMs = 0; + bool allowLarge = false; // 显å¼�"打开":放宽大å°�闸门/总超时,并ä¿�护本次缓存ä¸�被淘汰 std::string clientKey; std::string clientDir; std::string remotePath; @@ -156,6 +157,7 @@ private: std::string recvName; uint64_t size = 0; uint64_t mtimeMs = 0; + bool allowLarge = false; std::string requestedSha; std::string packetSha; HWND notifyHwnd = nullptr; @@ -192,7 +194,8 @@ private: const std::vector& index, const std::string& remotePath); static bool WriteEmptyFile(const std::string& path); - static void EnforceCacheLimits(const std::string& clientDir, std::vector& index); + static void EnforceCacheLimits(const std::string& clientDir, std::vector& index, + const std::string& protectName = std::string()); static bool MoveOrCopy(const std::string& from, const std::string& to); static void RemoveTempDir(const std::string& tempDir); diff --git a/server/2015Remote/lang/de_DE.ini b/server/2015Remote/lang/de_DE.ini index 46e91bd..a16d01b 100644 --- a/server/2015Remote/lang/de_DE.ini +++ b/server/2015Remote/lang/de_DE.ini @@ -2372,3 +2372,9 @@ MCP ÕýÔÚÔ¤ÀÀ %s ...=Vorschau von %s ... »ñȡԶ³ÌÎļþÐÅϢʧ°Ü£¨´íÎóÂë %u£©=Dateiinformationen konnten nicht abgerufen werden (Fehler %u) Ô¤ÀÀÏÂÔØÊ§°Ü£¨´íÎóÂë %u£©=Vorschau-Download fehlgeschlagen (Fehler %u) +; File manager remote Open (preview) menu + large-file confirmation +´ò¿ª(&O)=&Oeffnen +Îļþ½Ï´ó£º%s£¨%llu MB£¬³¬¹ý %u MB Ô¤ÀÀÉÏÏÞ£©¡£\nÈÔÒª´«Êäµ½±¾»ú²¢´ò¿ªÂ𣿴óÎļþ´«Êä¿ÉÄܺÄʱ½Ï³¤¡£=Grosse Datei: %s (%llu MB, ueberschreitet das %u MB-Vorschaulimit).\nTrotzdem auf diesen Rechner uebertragen und oeffnen? Grosse Uebertragungen koennen laenger dauern. + +; File manager remote Open: preview disabled feedback +Ô¤ÀÀ¹¦ÄÜÒѽûÓã¬ÎÞ·¨´ò¿ªÎļþ¡£¿ÉÔÚ²ÎÊýÖÐÆôÓÃÔ¤ÀÀºóÖØÊÔ¡£=Die Vorschau ist deaktiviert, die Datei kann nicht geoeffnet werden. Aktivieren Sie die Vorschau in den Einstellungen und versuchen Sie es erneut. diff --git a/server/2015Remote/lang/en_US.ini b/server/2015Remote/lang/en_US.ini index 82b46ff..3dde512 100644 --- a/server/2015Remote/lang/en_US.ini +++ b/server/2015Remote/lang/en_US.ini @@ -2383,3 +2383,9 @@ MCP ÕýÔÚÔ¤ÀÀ %s ...=Previewing %s ... »ñȡԶ³ÌÎļþÐÅϢʧ°Ü£¨´íÎóÂë %u£©=Failed to get remote file information (error %u) Ô¤ÀÀÏÂÔØÊ§°Ü£¨´íÎóÂë %u£©=Preview download failed (error %u) +; File manager remote Open (preview) menu + large-file confirmation +´ò¿ª(&O)=&Open +Îļþ½Ï´ó£º%s£¨%llu MB£¬³¬¹ý %u MB Ô¤ÀÀÉÏÏÞ£©¡£\nÈÔÒª´«Êäµ½±¾»ú²¢´ò¿ªÂ𣿴óÎļþ´«Êä¿ÉÄܺÄʱ½Ï³¤¡£=Large file: %s (%llu MB, exceeds the %u MB preview limit).\nTransfer it to this machine and open anyway? Large transfers may take a while. + +; File manager remote Open: preview disabled feedback +Ô¤ÀÀ¹¦ÄÜÒѽûÓã¬ÎÞ·¨´ò¿ªÎļþ¡£¿ÉÔÚ²ÎÊýÖÐÆôÓÃÔ¤ÀÀºóÖØÊÔ¡£=Preview is disabled, so the file cannot be opened. Enable preview in Settings and try again. diff --git a/server/2015Remote/lang/zh_TW.ini b/server/2015Remote/lang/zh_TW.ini index 8de99fa..d882d2b 100644 --- a/server/2015Remote/lang/zh_TW.ini +++ b/server/2015Remote/lang/zh_TW.ini @@ -2376,3 +2376,9 @@ MCP ÕýÔÚÔ¤ÀÀ %s ...=ÕýÔÚîAÓ[ %s ... »ñȡԶ³ÌÎļþÐÅϢʧ°Ü£¨´íÎóÂë %u£©=È¡µÃßh¶Ë™n°¸ÙYÓ�ʧ”¡£¨åeÕ`´a %u£© Ô¤ÀÀÏÂÔØÊ§°Ü£¨´íÎóÂë %u£©=îAÓ[ÏÂÝdʧ”¡£¨åeÕ`´a %u£© +; File manager remote Open (preview) menu + large-file confirmation +´ò¿ª(&O)=é_†¢(&O) +Îļþ½Ï´ó£º%s£¨%llu MB£¬³¬¹ý %u MB Ô¤ÀÀÉÏÏÞ£©¡£\nÈÔÒª´«Êäµ½±¾»ú²¢´ò¿ªÂ𣿴óÎļþ´«Êä¿ÉÄܺÄʱ½Ï³¤¡£=™n°¸Ý^´ó£º%s£¨%llu MB£¬³¬ß^ %u MB îAÓ[ÉÏÏÞ£©¡£\nÈÔÒª‚÷Ý”µ½±¾™C�Ké_†¢†á£¿´ó™n°¸‚÷Ý”¿ÉÄܺĕrÝ^éL¡£ + +; File manager remote Open: preview disabled feedback +Ô¤ÀÀ¹¦ÄÜÒѽûÓã¬ÎÞ·¨´ò¿ªÎļþ¡£¿ÉÔÚ²ÎÊýÖÐÆôÓÃÔ¤ÀÀºóÖØÊÔ¡£=îAÓ[¹¦ÄÜÒÑÍ£Ó㬟o·¨é_†¢™n°¸¡£¿ÉÔÚ…¢”µÖІ¢ÓÃîAÓ[ááÖØÔ‡¡£ diff --git a/server/2015Remote/resource.h b/server/2015Remote/resource.h index 601e6e9..f53fe85 100644 --- a/server/2015Remote/resource.h +++ b/server/2015Remote/resource.h @@ -452,6 +452,7 @@ #define IDM_LOCAL_OPEN 2134 #define IDM_REMOTE_OPEN_SHOW 2135 #define IDM_REMOTE_OPEN_HIDE 2136 +#define IDM_REMOTE_OPEN_PREVIEW 2137 #define ID_STAUTSTIP 2139 #define ID_STAUTSSPEED 2140 #define ID_STAUTSPORT 2141 -- 2.43.0