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
@@ -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;
|
||||
@@ -347,7 +348,7 @@ bool CFilePreviewMgr::ObserveChunk(CONTEXT_OBJECT* ctx, const FileChunkPacketV2*
|
||||
return false;
|
||||
}
|
||||
if (pkt->totalFiles != 1 || (pkt->flags & FFV2_DIRECTORY) ||
|
||||
pkt->fileSize > FILE_PREVIEW_MAX_BYTES) {
|
||||
(!req->allowLarge && pkt->fileSize > FILE_PREVIEW_MAX_BYTES)) {
|
||||
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 +414,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 +542,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 +623,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 +846,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 +885,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)
|
||||
|
||||
Reference in new issue
Block a user