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
This commit was merged in pull request #11.
This commit is contained in:
yuanyuanxiangandQoder committed 2026-12-05 19:55:51 +01:00
1 parent ee20326bbf
commit 4bc51d2498
8 files changed
+113 -18

No files matched your search

+20 -8
View File
@@ -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<Meta>& index)
void CFilePreviewMgr::EnforceCacheLimits(const std::string& clientDir, std::vector<Meta>& 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)