Fix: keep the preview hash timer for mismatched responses
Only consume a TOKEN_FILE_HASH response whose echoed path matches the pending request, and kill the 5 s timer only in that branch. A late, duplicate or malformed response previously killed the timer but left m_pendingHash set, so every later double-click in that window was rejected as "another preview is in progress" until the dialog closed. A mismatched response is now ignored and the timer still falls back to the size/mtime path, which clears the pending state. Co-Authored-By: deepseek-flash
This commit was merged in pull request #10.
This commit is contained in:
1 parent
bcd7ee692a
commit
ee20326bbf
1 file changed
+28
-28
@@ -1466,36 +1466,36 @@ LRESULT CFileManagerDlg::OnPreviewHashResult(WPARAM /*wParam*/, LPARAM lParam)
|
|||||||
{
|
{
|
||||||
FilePreviewHashResult* r = (FilePreviewHashResult*)lParam;
|
FilePreviewHashResult* r = (FilePreviewHashResult*)lParam;
|
||||||
if (!r) return 0;
|
if (!r) return 0;
|
||||||
KillTimer(kPreviewHashTimer);
|
|
||||||
|
|
||||||
if (!m_pendingHash.fullPath.IsEmpty()) {
|
// 只消费匹配当前 pending 路径的响应。迟到/重复/异常响应不能杀定时器,
|
||||||
std::string expected((LPCSTR)m_pendingHash.fullPath);
|
// 否则 m_pendingHash 会一直非空、而超时兜底已失效,窗口再也无法发起预览。
|
||||||
if (r->path == expected) {
|
if (!m_pendingHash.fullPath.IsEmpty() &&
|
||||||
CString full = m_pendingHash.fullPath;
|
r->path == std::string((LPCSTR)m_pendingHash.fullPath)) {
|
||||||
uint64_t size = m_pendingHash.size;
|
KillTimer(kPreviewHashTimer);
|
||||||
uint64_t mtime = m_pendingHash.mtimeMs;
|
CString full = m_pendingHash.fullPath;
|
||||||
m_pendingHash = PendingHashPreview();
|
uint64_t size = m_pendingHash.size;
|
||||||
|
uint64_t mtime = m_pendingHash.mtimeMs;
|
||||||
|
m_pendingHash = PendingHashPreview();
|
||||||
|
|
||||||
if (r->status == FILE_HASH_TOO_LARGE ||
|
if (r->status == FILE_HASH_TOO_LARGE ||
|
||||||
(r->status == FILE_HASH_OK && r->size > FILE_PREVIEW_MAX_BYTES)) {
|
(r->status == FILE_HASH_OK && r->size > FILE_PREVIEW_MAX_BYTES)) {
|
||||||
CString msg;
|
CString msg;
|
||||||
msg.FormatL("文件较大,不支持预览:%s(%llu MB,上限 %u MB)", full,
|
msg.FormatL("文件较大,不支持预览:%s(%llu MB,上限 %u MB)", full,
|
||||||
(unsigned long long)(r->size / 1024 / 1024),
|
(unsigned long long)(r->size / 1024 / 1024),
|
||||||
(unsigned)(FILE_PREVIEW_MAX_BYTES / 1024 / 1024));
|
(unsigned)(FILE_PREVIEW_MAX_BYTES / 1024 / 1024));
|
||||||
::MessageBox(m_hWnd, msg, _TR("提示"), MB_OK | MB_ICONINFORMATION);
|
::MessageBox(m_hWnd, msg, _TR("提示"), MB_OK | MB_ICONINFORMATION);
|
||||||
} else if (r->status == FILE_HASH_OK) {
|
} else if (r->status == FILE_HASH_OK) {
|
||||||
ContinueRemotePreview(full, r->size, r->mtimeMs, r->sha256);
|
ContinueRemotePreview(full, r->size, r->mtimeMs, r->sha256);
|
||||||
} else if (r->status == FILE_HASH_ERROR) {
|
} else if (r->status == FILE_HASH_ERROR) {
|
||||||
// 明确的错误(不存在/无权限/读失败):提示,不静默降级下载。
|
// 明确的错误(不存在/无权限/读失败):提示,不静默降级下载。
|
||||||
CString msg;
|
CString msg;
|
||||||
msg.FormatL("获取远程文件信息失败(错误码 %u)", r->err);
|
msg.FormatL("获取远程文件信息失败(错误码 %u)", r->err);
|
||||||
::MessageBox(m_hWnd, msg, _TR("提示"), MB_OK | MB_ICONWARNING);
|
::MessageBox(m_hWnd, msg, _TR("提示"), MB_OK | MB_ICONWARNING);
|
||||||
} else {
|
} else {
|
||||||
// 未知状态/哈希超时按 P1 降级:用列表里的 size+mtime 继续。
|
// 未知状态/哈希超时按 P1 降级:用列表里的 size+mtime 继续。
|
||||||
Mprintf("[Preview] hash error status=%u err=%u; fallback to metadata\n",
|
Mprintf("[Preview] hash error status=%u err=%u; fallback to metadata\n",
|
||||||
r->status, r->err);
|
r->status, r->err);
|
||||||
ContinueRemotePreview(full, size, mtime, std::string());
|
ContinueRemotePreview(full, size, mtime, std::string());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete r;
|
delete r;
|
||||||
|
|||||||
Reference in new issue
Block a user