Feature: Show live transfer speed in file-transfer dialog title
Add a smoothed bytes-per-second readout to the CDlgFileSend title, refreshed about every 200 ms during transfer (e.g. "发送文件 - 5.3M/s"). The base title is captured on the first progress frame and the speed suffix applied through Unicode APIs (GetWindowTextW / SetWindowTextW), so the whole title stays correct on non-Chinese systems where the ANSI message path would misdecode GBK as the system ACP. Also add the missing "接收文件 (V2)" translation (en_US "Receive File (V2)", zh_TW "接收檔案 (V2)"), so the V2 receive title no longer falls back to raw Chinese on non-Chinese systems. Co-Authored-By: deepseek-v4-pro
This commit is contained in:
1 parent
6220335f63
commit
da0ec983ba
4 files changed
+61
No files matched your search
@@ -151,6 +151,54 @@ void CDlgFileSend::UpdateProgress(CString file, const FileProgressInfo& info)
|
||||
PostMessageA(WM_UPDATEFILEPROGRESS, (WPARAM)new CString(file), (LPARAM)new FileProgressInfo(info));
|
||||
}
|
||||
|
||||
// 将字节/秒格式化为人类可读的速度串(如 "5.3M/s"、"320K/s"、"800B/s")
|
||||
static CStringW FormatSpeed(double bps)
|
||||
{
|
||||
CStringW s;
|
||||
if (bps >= 1024.0 * 1024.0)
|
||||
s.Format(L"%.1fM/s", bps / (1024.0 * 1024.0));
|
||||
else if (bps >= 1024.0)
|
||||
s.Format(L"%.0fK/s", bps / 1024.0);
|
||||
else
|
||||
s.Format(L"%.0fB/s", bps);
|
||||
return s;
|
||||
}
|
||||
|
||||
// 累计字节并周期性刷新标题中的速度(如 "发送文件 - 5.3M/s")
|
||||
void CDlgFileSend::UpdateTitleWithSpeed(uint64_t dataLength)
|
||||
{
|
||||
m_ullTotalBytes += dataLength;
|
||||
ULONGLONG now = GetTickCount64();
|
||||
|
||||
// 首帧:用 Unicode API 捕获当前标题作为基础部分(可能已被 V2/C2C 覆盖为 "接收文件 (V2)" 等),
|
||||
// 并建立采样基准;此时尚无速度可显示。
|
||||
if (!m_bBaseTitleCaptured) {
|
||||
WCHAR wBase[128] = { 0 };
|
||||
::GetWindowTextW(m_hWnd, wBase, 128);
|
||||
m_strBaseTitle = wBase;
|
||||
m_bBaseTitleCaptured = true;
|
||||
m_ullLastTick = now;
|
||||
m_ullLastBytes = m_ullTotalBytes;
|
||||
return;
|
||||
}
|
||||
|
||||
ULONGLONG dt = now - m_ullLastTick;
|
||||
if (dt < 200) return; // 采样间隔未到,仅累积字节
|
||||
|
||||
uint64_t delta = m_ullTotalBytes - m_ullLastBytes;
|
||||
double speed = dt ? (double)delta * 1000.0 / (double)dt : 0.0;
|
||||
m_dSpeedBps = (m_dSpeedBps == 0.0) ? speed : m_dSpeedBps * 0.6 + speed * 0.4; // 轻度平滑
|
||||
|
||||
m_ullLastTick = now;
|
||||
m_ullLastBytes = m_ullTotalBytes;
|
||||
|
||||
// 基础标题(Unicode)+ ASCII 速度后缀,全程 Unicode API,避免非中文系统上 ANSI 消息按系统 ACP 解码乱码
|
||||
CStringW title = m_strBaseTitle;
|
||||
title += L" - ";
|
||||
title += FormatSpeed(m_dSpeedBps);
|
||||
::SetWindowTextW(m_hWnd, title);
|
||||
}
|
||||
|
||||
void CDlgFileSend::FinishFileSend(BOOL succeed)
|
||||
{
|
||||
if (!GetSafeHwnd()) return;
|
||||
@@ -170,6 +218,7 @@ LRESULT CDlgFileSend::OnUpdateFileProgress(WPARAM wParam, LPARAM lParam)
|
||||
SetDlgItemText(IDC_STATIC_CURRENTINDEX, status);
|
||||
SetDlgItemText(IDC_STATIC_CURRENT_FILE, *pFile);
|
||||
m_Progress.SetPos((int)percent);
|
||||
UpdateTitleWithSpeed(pInfo->dataLength);
|
||||
|
||||
// 只在第一次显示时置顶,后续更新不抢焦点
|
||||
if (!IsWindowVisible()) {
|
||||
|
||||
Reference in new issue
Block a user