From 499c0010b1b24e37c95783405ad2d9fc9afe5a35 Mon Sep 17 00:00:00 2001 From: Larry Li Date: Tue, 9 Apr 2024 17:33:29 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=88=87=E6=8D=A2=E8=87=B3=20utf8=20?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmake/platforms/windows.cmake | 2 +- version.h | 6 +++--- windows/controls.c | 33 +++++++++++++++++++++++++++++++-- windows/pageant.mft | 2 +- windows/plink.c | 3 +++ windows/putty.mft | 2 +- windows/puttygen.mft | 2 +- windows/puttytel.mft | 2 +- windows/sftp.c | 3 +++ 9 files changed, 45 insertions(+), 10 deletions(-) diff --git a/cmake/platforms/windows.cmake b/cmake/platforms/windows.cmake index e3847876..767e9561 100644 --- a/cmake/platforms/windows.cmake +++ b/cmake/platforms/windows.cmake @@ -84,7 +84,7 @@ dwmapi_test_wrapper() set(NO_SECURITY ${PUTTY_NO_SECURITY}) add_compile_options("$<$:/source-charset:utf-8>") -add_compile_options("$<$:/execution-charset:gbk>") +add_compile_options("$<$:/execution-charset:utf-8>") add_compile_definitions( _WINDOWS diff --git a/version.h b/version.h index ab1b92f4..5428d3ed 100644 --- a/version.h +++ b/version.h @@ -8,6 +8,6 @@ * default stuff used for local development runs of 'make'. */ -#define TEXTVER "发布版 0.80-cn1" -#define SSHVER "-Release-0-80-CN1" -#define BINARY_VERSION 0,80,0,1 +#define TEXTVER "发布版 0.80-cn2" +#define SSHVER "-Release-0-80-CN2" +#define BINARY_VERSION 0,80,0,2 diff --git a/windows/controls.c b/windows/controls.c index 27f22be3..6f51fbed 100644 --- a/windows/controls.c +++ b/windows/controls.c @@ -381,6 +381,35 @@ void checkbox(struct ctlpos *cp, const char *text, int id) text, id); } +static BOOL _GetTextExtentExPoint(HDC hdc, LPCSTR lpszString, int cchString, int nMaxExtent, LPINT lpnFit, LPINT lpnDx, LPSIZE lpSize) +{ + BOOL ret = GetTextExtentExPoint(hdc, lpszString, cchString, nMaxExtent, lpnFit, lpnDx, lpSize); + if (ret && GetACP() == CP_UTF8) { + // fix lpnFit to bytes from characters on utf-8 codepage + int n = 0; + for (int i = 0; i < *lpnFit; i++) { + unsigned char c = lpszString[n]; + if (c >= 0 && c <= 127 ) { + n += 1; + } else if (c >= 192 && c <= 223) { + n += 2; + } else if (c >= 224 && c <= 239) { + n += 3; + } else if (c >= 240 && c <= 247) { + n += 4; + } else if (c >= 248 && c <= 255) { + n += 1; + } + if (n >= cchString) { + n = cchString; + break; + } + } + *lpnFit = n; + } + return ret; +} + /* * Wrap a piece of text for a static text control. Returns the * wrapped text (a malloc'ed string containing \ns), and also @@ -423,8 +452,8 @@ char *staticwrap(struct ctlpos *cp, HWND hwnd, const char *text, int *lines) oldfont = SelectObject(hdc, newfont); while (*p) { - if (!GetTextExtentExPoint(hdc, p, strlen(p), width, - &nfit, pwidths, &size) || + if (!_GetTextExtentExPoint(hdc, p, strlen(p), width, + &nfit, pwidths, &size) || (size_t)nfit >= strlen(p)) { /* * Either GetTextExtentExPoint returned failure, or the diff --git a/windows/pageant.mft b/windows/pageant.mft index 75a8b8ac..8b95f2d0 100644 --- a/windows/pageant.mft +++ b/windows/pageant.mft @@ -27,7 +27,7 @@ true PerMonitorV2 - zh-CN + UTF-8 diff --git a/windows/plink.c b/windows/plink.c index 2d45c51e..7890542b 100644 --- a/windows/plink.c +++ b/windows/plink.c @@ -293,6 +293,9 @@ int main(int argc, char **argv) enum TriState sanitise_stdout = AUTO, sanitise_stderr = AUTO; const struct BackendVtable *vt; + SetConsoleCP(CP_UTF8); + SetConsoleOutputCP(CP_UTF8); + dll_hijacking_protection(); /* diff --git a/windows/putty.mft b/windows/putty.mft index fe2962bd..9ef53f49 100644 --- a/windows/putty.mft +++ b/windows/putty.mft @@ -27,7 +27,7 @@ true PerMonitorV2 - zh-CN + UTF-8 diff --git a/windows/puttygen.mft b/windows/puttygen.mft index 829cae2a..cd13b661 100644 --- a/windows/puttygen.mft +++ b/windows/puttygen.mft @@ -27,7 +27,7 @@ true PerMonitorV2 - zh-CN + UTF-8 diff --git a/windows/puttytel.mft b/windows/puttytel.mft index a1b0c194..4c2912e8 100644 --- a/windows/puttytel.mft +++ b/windows/puttytel.mft @@ -27,7 +27,7 @@ true PerMonitorV2 - zh-CN + UTF-8 diff --git a/windows/sftp.c b/windows/sftp.c index a6546269..e4e8827b 100644 --- a/windows/sftp.c +++ b/windows/sftp.c @@ -648,6 +648,9 @@ int main(int argc, char *argv[]) { int ret; + SetConsoleCP(CP_UTF8); + SetConsoleOutputCP(CP_UTF8); + dll_hijacking_protection(); ret = psftp_main(argc, argv); From 6f40f4afd157e259ea184228834404892c076fd1 Mon Sep 17 00:00:00 2001 From: Larry Li Date: Wed, 10 Apr 2024 17:01:56 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20pageant=20=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E5=B7=B2=E6=9C=89=E4=B8=AD=E6=96=87=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E4=BC=9A=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmake/platforms/windows.cmake | 3 +-- windows/pageant.c | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/cmake/platforms/windows.cmake b/cmake/platforms/windows.cmake index 767e9561..337a09c5 100644 --- a/cmake/platforms/windows.cmake +++ b/cmake/platforms/windows.cmake @@ -83,8 +83,7 @@ dwmapi_test_wrapper() set(NO_SECURITY ${PUTTY_NO_SECURITY}) -add_compile_options("$<$:/source-charset:utf-8>") -add_compile_options("$<$:/execution-charset:utf-8>") +add_compile_options("$<$:/utf-8>") add_compile_definitions( _WINDOWS diff --git a/windows/pageant.c b/windows/pageant.c index dc1c3493..ca7c30ba 100644 --- a/windows/pageant.c +++ b/windows/pageant.c @@ -1255,6 +1255,25 @@ static void create_keylist_window(void) ShowWindow(keylist, SW_SHOWNORMAL); } +static BOOL _GetMenuItemInfo(HMENU hmenu, UINT item, BOOL fByPositon, LPMENUITEMINFO lpmii) +{ + if (GetACP() == CP_UTF8) { + // fix the incomplete return of dwTypeData + // IMPORTANT: This is NOT a complete implementation!! + int cch = lpmii->cch; // Must keep + LPTSTR mbs = lpmii->dwTypeData; + wchar_t ws[MAX_PATH + 1]; // @fixme + lpmii->dwTypeData = (LPSTR)ws; + BOOL ret = GetMenuItemInfoW(hmenu, item, fByPositon, (LPCMENUITEMINFOW)lpmii); + if (ret) { + WideCharToMultiByte(CP_UTF8, 0, ws, -1, mbs, cch, NULL, NULL); + } + lpmii->dwTypeData = mbs; + return ret; + } + return SetMenuItemInfo(hmenu, item, fByPositon, lpmii); +} + static LRESULT CALLBACK TrayWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { @@ -1378,7 +1397,7 @@ static LRESULT CALLBACK TrayWndProc(HWND hwnd, UINT message, mii.fMask = MIIM_TYPE; mii.cch = MAX_PATH; mii.dwTypeData = buf; - GetMenuItemInfo(session_menu, wParam, false, &mii); + _GetMenuItemInfo(session_menu, wParam, false, &mii); param[0] = '\0'; if (restrict_putty_acl) strcat(param, "&R"); From 90c0a2bb925138d2775f5e32c2baf74a18743d63 Mon Sep 17 00:00:00 2001 From: Larry Li Date: Wed, 10 Apr 2024 17:26:04 +0800 Subject: [PATCH 3/4] opt --- windows/pageant.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/windows/pageant.c b/windows/pageant.c index ca7c30ba..6ae2de24 100644 --- a/windows/pageant.c +++ b/windows/pageant.c @@ -1258,7 +1258,7 @@ static void create_keylist_window(void) static BOOL _GetMenuItemInfo(HMENU hmenu, UINT item, BOOL fByPositon, LPMENUITEMINFO lpmii) { if (GetACP() == CP_UTF8) { - // fix the incomplete return of dwTypeData + // fix the incomplete return of dwTypeData on utf-8 codepage // IMPORTANT: This is NOT a complete implementation!! int cch = lpmii->cch; // Must keep LPTSTR mbs = lpmii->dwTypeData; @@ -1266,7 +1266,7 @@ static BOOL _GetMenuItemInfo(HMENU hmenu, UINT item, BOOL fByPositon, LPMENUITEM lpmii->dwTypeData = (LPSTR)ws; BOOL ret = GetMenuItemInfoW(hmenu, item, fByPositon, (LPCMENUITEMINFOW)lpmii); if (ret) { - WideCharToMultiByte(CP_UTF8, 0, ws, -1, mbs, cch, NULL, NULL); + WideCharToMultiByte(CP_UTF8, 0, ws, lpmii->cch, mbs, cch, NULL, NULL); } lpmii->dwTypeData = mbs; return ret; From 6b9bcfd56f408a0bb73d99a0b7e78e1a74114541 Mon Sep 17 00:00:00 2001 From: Larry Li Date: Mon, 29 Apr 2024 16:52:33 +0800 Subject: [PATCH 4/4] fix --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 513da55d..fc060ad2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,7 +31,7 @@ jobs: if: ${{ github.ref_type == 'tag' }} uses: actions/upload-artifact@v4 with: - name: putty${{matrix.config.archive}}-${{github.ref_name}}.zip + name: putty${{matrix.config.archive}}-${{github.ref_name}} path: | build/Release/putty.exe build/Release/pscp.exe