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:
yuanyuanxianganddeepseek-flash committed 2026-12-05 16:50:06 +01:00
1 parent bcd7ee692a
commit ee20326bbf
1 file changed
+28 -28
+28 -28
View File
@@ -1466,36 +1466,36 @@ LRESULT CFileManagerDlg::OnPreviewHashResult(WPARAM /*wParam*/, LPARAM lParam)
{
FilePreviewHashResult* r = (FilePreviewHashResult*)lParam;
if (!r) return 0;
KillTimer(kPreviewHashTimer);
if (!m_pendingHash.fullPath.IsEmpty()) {
std::string expected((LPCSTR)m_pendingHash.fullPath);
if (r->path == expected) {
CString full = m_pendingHash.fullPath;
uint64_t size = m_pendingHash.size;
uint64_t mtime = m_pendingHash.mtimeMs;
m_pendingHash = PendingHashPreview();
// 只消费匹配当前 pending 路径的响应。迟到/重复/异常响应不能杀定时器,
// 否则 m_pendingHash 会一直非空、而超时兜底已失效,窗口再也无法发起预览。
if (!m_pendingHash.fullPath.IsEmpty() &&
r->path == std::string((LPCSTR)m_pendingHash.fullPath)) {
KillTimer(kPreviewHashTimer);
CString full = m_pendingHash.fullPath;
uint64_t size = m_pendingHash.size;
uint64_t mtime = m_pendingHash.mtimeMs;
m_pendingHash = PendingHashPreview();
if (r->status == FILE_HASH_TOO_LARGE ||
(r->status == FILE_HASH_OK && r->size > FILE_PREVIEW_MAX_BYTES)) {
CString msg;
msg.FormatL("文件较大,不支持预览:%s(%llu MB,上限 %u MB)", full,
(unsigned long long)(r->size / 1024 / 1024),
(unsigned)(FILE_PREVIEW_MAX_BYTES / 1024 / 1024));
::MessageBox(m_hWnd, msg, _TR("提示"), MB_OK | MB_ICONINFORMATION);
} else if (r->status == FILE_HASH_OK) {
ContinueRemotePreview(full, r->size, r->mtimeMs, r->sha256);
} else if (r->status == FILE_HASH_ERROR) {
// 明确的错误(不存在/无权限/读失败):提示,不静默降级下载。
CString msg;
msg.FormatL("获取远程文件信息失败(错误码 %u)", r->err);
::MessageBox(m_hWnd, msg, _TR("提示"), MB_OK | MB_ICONWARNING);
} else {
// 未知状态/哈希超时按 P1 降级:用列表里的 size+mtime 继续。
Mprintf("[Preview] hash error status=%u err=%u; fallback to metadata\n",
r->status, r->err);
ContinueRemotePreview(full, size, mtime, std::string());
}
if (r->status == FILE_HASH_TOO_LARGE ||
(r->status == FILE_HASH_OK && r->size > FILE_PREVIEW_MAX_BYTES)) {
CString msg;
msg.FormatL("文件较大,不支持预览:%s(%llu MB,上限 %u MB)", full,
(unsigned long long)(r->size / 1024 / 1024),
(unsigned)(FILE_PREVIEW_MAX_BYTES / 1024 / 1024));
::MessageBox(m_hWnd, msg, _TR("提示"), MB_OK | MB_ICONINFORMATION);
} else if (r->status == FILE_HASH_OK) {
ContinueRemotePreview(full, r->size, r->mtimeMs, r->sha256);
} else if (r->status == FILE_HASH_ERROR) {
// 明确的错误(不存在/无权限/读失败):提示,不静默降级下载。
CString msg;
msg.FormatL("获取远程文件信息失败(错误码 %u)", r->err);
::MessageBox(m_hWnd, msg, _TR("提示"), MB_OK | MB_ICONWARNING);
} else {
// 未知状态/哈希超时按 P1 降级:用列表里的 size+mtime 继续。
Mprintf("[Preview] hash error status=%u err=%u; fallback to metadata\n",
r->status, r->err);
ContinueRemotePreview(full, size, mtime, std::string());
}
}
delete r;