https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a8ef85ad710a8a48256165...
commit a8ef85ad710a8a48256165a08dfb6b725433ab2f Author: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org AuthorDate: Tue May 25 20:04:01 2021 +0200 Commit: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org CommitDate: Wed May 26 01:42:11 2021 +0200
[CHCP] Reset the current thread UI language and streams codepage after changing the console codepage. CORE-17601 --- base/applications/cmdutils/chcp/chcp.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
diff --git a/base/applications/cmdutils/chcp/chcp.c b/base/applications/cmdutils/chcp/chcp.c index 56c13089edf..36f5291f42c 100644 --- a/base/applications/cmdutils/chcp/chcp.c +++ b/base/applications/cmdutils/chcp/chcp.c @@ -1,10 +1,9 @@ /* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS Change CodePage Command - * FILE: base/applications/cmdutils/chcp/chcp.c - * PURPOSE: Displays or changes the active console input and output codepages. - * PROGRAMMERS: Eric Kohl - * Hermes Belusca-Maito (hermes.belusca@sfr.fr) + * PROJECT: ReactOS Change CodePage Command + * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) + * PURPOSE: Displays or changes the active console input and output code pages. + * COPYRIGHT: Copyright 1999 Eric Kohl + * Copyright 2017-2021 Hermes Belusca-Maito */ /* * CHCP.C - chcp internal command. @@ -64,27 +63,36 @@ int wmain(int argc, WCHAR* argv[]) return 1; }
+/** + ** IMPORTANT NOTE: This code must be kept synchronized with MODE.COM!SetConsoleCPState() + **/ + /* - * Save the original console codepage to be restored in case - * SetConsoleCP() or SetConsoleOutputCP() fails. + * Save the original console code page to be restored + * in case SetConsoleCP() or SetConsoleOutputCP() fails. */ uOldCodePage = GetConsoleCP();
/* - * Try changing the console input codepage. If it works then also change - * the console output codepage, and refresh our local codepage cache. + * Try changing the console input and output code pages. + * If it succeeds, refresh the local code page information. */ if (SetConsoleCP(uNewCodePage)) { if (SetConsoleOutputCP(uNewCodePage)) { + /* Success, reset the current thread UI language + * and update the streams cached code page. */ + ConSetThreadUILanguage(0); + ConStdStreamsSetCacheCodePage(uNewCodePage, uNewCodePage); + /* Display the active code page number */ ConResPrintf(StdOut, STRING_CHCP_ERROR1, GetConsoleOutputCP()); return 0; } else { - /* Failure, restore the original console codepage */ + /* Failure, restore the original console code page */ SetConsoleCP(uOldCodePage); } }