MBCS dialog templates are decoded with the system ANSI code page, so on
non-Chinese systems the GBK template strings turn into "?" before
TranslateDialog can read them. Set those strings explicitly in OnInitDialog
(PluginSettings save/close, the three Advanced dialogs, the file-manager
search buttons/checkboxes, and Trigger Settings) so they are re-decoded
with the thread locale. Also fix the language-selection dialog and the
toolbar "Lang/语言" button: the language dialog's template is built as
WCHAR strings but created through the ANSI path, so its title, label, and
buttons are set explicitly in OnInitDialog (AppendString stays on CP_ACP),
with the title looked up via _TR("切换语言") and set through SetWindowTextW
after an explicit GBK conversion; new en_US ("Switch Language") and zh_TW
("切換語言") translations accompany it. The toolbar button is set through
the Unicode TB_SETBUTTONINFOW message after an explicit GBK conversion. Add
en_US/zh_TW translations for the experimental-features context menu items.
Co-Authored-By: deepseek-v4-pro
134 lines
4.8 KiB
C++
134 lines
4.8 KiB
C++
// CFileSpeedDlg.h
|
||
// 文件传输速度调节对话框:拖动滑块选档位,实时显示预估速度。
|
||
// 纯主控端 UI 偏好,持久化由 CMy2015RemoteDlg::OnFileTransferSpeed() 负责。
|
||
// 仅在 2015RemoteDlg.cpp 中 include 一次(头文件内联实现 + 消息映射,勿多处包含)。
|
||
#pragma once
|
||
|
||
#include "LangManager.h"
|
||
#include <afxcmn.h>
|
||
|
||
// 档位表(权威来源:docs/FileTransferSpeed_Design.md §3)。
|
||
// chunkKb * 1024 / durationMs 即理论字节/秒;durationMs==0 表示不人为限速。
|
||
struct FileSpeedTier { int chunkKb; int durMs; const TCHAR* name; };
|
||
|
||
static const FileSpeedTier kFileSpeedTiers[] = {
|
||
{ 64, 200, _T("最慢") }, // ≈0.31 MB/s
|
||
{ 64, 100, _T("慢") }, // ≈0.63 MB/s
|
||
{ 64, 50, _T("默认") }, // ≈1.25 MB/s
|
||
{ 128, 50, _T("快") }, // ≈2.5 MB/s
|
||
{ 256, 50, _T("更快") }, // ≈5 MB/s
|
||
{ 512, 50, _T("很快") }, // ≈10 MB/s
|
||
{ 1024, 0, _T("不限速") }, // 网络上限
|
||
};
|
||
#define FILE_SPEED_TIER_COUNT 7
|
||
#define FILE_SPEED_DEFAULT_TIER 2 // 默认档位
|
||
|
||
class CFileSpeedDlg : public CDialog
|
||
{
|
||
public:
|
||
enum { IDD = IDD_FILE_SPEED };
|
||
|
||
CFileSpeedDlg(int chunkKb, int durMs, CWnd* pParent = NULL)
|
||
: CDialog(CFileSpeedDlg::IDD, pParent), m_chunkKb(chunkKb), m_durMs(durMs)
|
||
{
|
||
}
|
||
|
||
int GetChunkKb() const { return m_chunkKb; }
|
||
int GetDurMs() const { return m_durMs; }
|
||
|
||
protected:
|
||
int m_chunkKb;
|
||
int m_durMs;
|
||
|
||
static int TierIndexFor(int chunkKb, int durMs)
|
||
{
|
||
for (int i = 0; i < FILE_SPEED_TIER_COUNT; i++)
|
||
if (kFileSpeedTiers[i].chunkKb == chunkKb && kFileSpeedTiers[i].durMs == durMs)
|
||
return i;
|
||
return FILE_SPEED_DEFAULT_TIER; // 未知值回落默认
|
||
}
|
||
|
||
static void FormatSpeed(int idx, CString& out)
|
||
{
|
||
const FileSpeedTier& t = kFileSpeedTiers[idx];
|
||
// 档位名与格式串经 _TR/_LF 走多语言表(LangManager),语言文件以中文原文为 key。
|
||
if (t.durMs <= 0) {
|
||
out.FormatL(_T("%s · 不受限速(受网络带宽约束)"), _LF(t.name));
|
||
return;
|
||
}
|
||
double mbps = (double)t.chunkKb * 1024.0 / (t.durMs / 1000.0) / (1024.0 * 1024.0);
|
||
out.FormatL(_T("%s · 约 %.2f MB/s"), _LF(t.name), mbps);
|
||
}
|
||
|
||
int GetSliderPos()
|
||
{
|
||
int pos = (int)SendDlgItemMessage(IDC_FSPEED_SLIDER, TBM_GETPOS, 0, 0);
|
||
if (pos < 0) pos = 0;
|
||
if (pos >= FILE_SPEED_TIER_COUNT) pos = FILE_SPEED_TIER_COUNT - 1;
|
||
return pos;
|
||
}
|
||
|
||
void UpdateLabel()
|
||
{
|
||
CString s;
|
||
FormatSpeed(GetSliderPos(), s);
|
||
SetDlgItemText(IDC_FSPEED_LABEL, s);
|
||
}
|
||
|
||
virtual BOOL OnInitDialog() override
|
||
{
|
||
CDialog::OnInitDialog();
|
||
|
||
// 非中文系统上 MBCS 对话框模板的中文会被系统 ACP 转成 "?",TranslateDialog
|
||
// 拿到的是已乱码文本无法还原,故在此显式设置(参照 NotifySettingsDlg)。
|
||
// 均经 _TR 支持多语言翻译。
|
||
SetWindowText(_TR("文件传输速度"));
|
||
SetDlgItemText(IDC_FSPEED_HINT, _TR("拖动滑块设置文件传输速度:"));
|
||
SetDlgItemText(IDC_FSPEED_LABEL_SLOWEST, _TR("最慢"));
|
||
SetDlgItemText(IDC_FSPEED_LABEL_DEFAULT, _TR("默认"));
|
||
SetDlgItemText(IDC_FSPEED_LABEL_UNLIMITED, _TR("不限速"));
|
||
SetDlgItemText(IDC_FSPEED_RESET, _TR("恢复默认"));
|
||
SetDlgItemText(IDOK, _TR("确定"));
|
||
SetDlgItemText(IDCANCEL, _TR("取消"));
|
||
|
||
SendDlgItemMessage(IDC_FSPEED_SLIDER, TBM_SETRANGE, TRUE,
|
||
MAKELONG(0, FILE_SPEED_TIER_COUNT - 1));
|
||
SendDlgItemMessage(IDC_FSPEED_SLIDER, TBM_SETPAGESIZE, 0, 1);
|
||
SendDlgItemMessage(IDC_FSPEED_SLIDER, TBM_SETTICFREQ, 0, 1);
|
||
SendDlgItemMessage(IDC_FSPEED_SLIDER, TBM_SETPOS, TRUE, TierIndexFor(m_chunkKb, m_durMs));
|
||
|
||
UpdateLabel();
|
||
return TRUE;
|
||
}
|
||
|
||
virtual void OnOK() override
|
||
{
|
||
int idx = GetSliderPos();
|
||
m_chunkKb = kFileSpeedTiers[idx].chunkKb;
|
||
m_durMs = kFileSpeedTiers[idx].durMs;
|
||
CDialog::OnOK();
|
||
}
|
||
|
||
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
|
||
{
|
||
(void)nSBCode; (void)nPos; (void)pScrollBar;
|
||
UpdateLabel(); // 拖动过程中实时刷新预估速度
|
||
}
|
||
|
||
virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam) override
|
||
{
|
||
if (LOWORD(wParam) == IDC_FSPEED_RESET && HIWORD(wParam) == BN_CLICKED) {
|
||
SendDlgItemMessage(IDC_FSPEED_SLIDER, TBM_SETPOS, TRUE, FILE_SPEED_DEFAULT_TIER);
|
||
UpdateLabel();
|
||
return TRUE;
|
||
}
|
||
return CDialog::OnCommand(wParam, lParam);
|
||
}
|
||
|
||
DECLARE_MESSAGE_MAP()
|
||
};
|
||
|
||
BEGIN_MESSAGE_MAP(CFileSpeedDlg, CDialog)
|
||
ON_WM_HSCROLL()
|
||
END_MESSAGE_MAP()
|