Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmake/platforms/windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ dwmapi_test_wrapper()

set(NO_SECURITY ${PUTTY_NO_SECURITY})

add_compile_options("$<$<C_COMPILER_ID:MSVC>:/source-charset:utf-8>")
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/execution-charset:gbk>")
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")

add_compile_definitions(
_WINDOWS
Expand Down
6 changes: 3 additions & 3 deletions version.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
* default stuff used for local development runs of 'make'.
*/

#define TEXTVER "发布版 0.82-cn1"
#define SSHVER "-Release-0-82-CN1"
#define BINARY_VERSION 0,82,0,1
#define TEXTVER "发布版 0.82-cn2"
#define SSHVER "-Release-0-82-CN2"
#define BINARY_VERSION 0,82,0,2
33 changes: 31 additions & 2 deletions windows/controls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -421,8 +450,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
Expand Down
21 changes: 20 additions & 1 deletion windows/pageant.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 on utf-8 codepage
// 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, lpmii->cch, 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)
{
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion windows/pageant.mft
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<dpiAware>true</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
<!-- CP936 -->
<activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">zh-CN</activeCodePage>
<activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
3 changes: 3 additions & 0 deletions windows/plink.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,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();

/*
Expand Down
2 changes: 1 addition & 1 deletion windows/putty.mft
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<dpiAware>true</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
<!-- CP936 -->
<activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">zh-CN</activeCodePage>
<activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
2 changes: 1 addition & 1 deletion windows/puttygen.mft
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<dpiAware>true</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
<!-- CP936 -->
<activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">zh-CN</activeCodePage>
<activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
2 changes: 1 addition & 1 deletion windows/puttytel.mft
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<dpiAware>true</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
<!-- CP936 -->
<activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">zh-CN</activeCodePage>
<activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
3 changes: 3 additions & 0 deletions windows/sftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,9 @@ int main(int argc, char *argv[])
{
int ret;

SetConsoleCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8);

dll_hijacking_protection();

CmdlineArgList *arglist = cmdline_arg_list_from_GetCommandLineW();
Expand Down