mirror of
https://github.com/reactos/reactos.git
synced 2024-12-29 10:35:28 +00:00
[CHCP] Reset the current thread UI language and streams codepage after changing the console codepage.
CORE-17601
This commit is contained in:
parent
7c3aabc088
commit
a8ef85ad71
1 changed files with 19 additions and 11 deletions
|
@ -1,10 +1,9 @@
|
||||||
/*
|
/*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* PROJECT: ReactOS Change CodePage Command
|
||||||
* PROJECT: ReactOS Change CodePage Command
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
||||||
* FILE: base/applications/cmdutils/chcp/chcp.c
|
* PURPOSE: Displays or changes the active console input and output code pages.
|
||||||
* PURPOSE: Displays or changes the active console input and output codepages.
|
* COPYRIGHT: Copyright 1999 Eric Kohl
|
||||||
* PROGRAMMERS: Eric Kohl
|
* Copyright 2017-2021 Hermes Belusca-Maito
|
||||||
* Hermes Belusca-Maito (hermes.belusca@sfr.fr)
|
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
* CHCP.C - chcp internal command.
|
* CHCP.C - chcp internal command.
|
||||||
|
@ -64,27 +63,36 @@ int wmain(int argc, WCHAR* argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
** IMPORTANT NOTE: This code must be kept synchronized with MODE.COM!SetConsoleCPState()
|
||||||
|
**/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Save the original console codepage to be restored in case
|
* Save the original console code page to be restored
|
||||||
* SetConsoleCP() or SetConsoleOutputCP() fails.
|
* in case SetConsoleCP() or SetConsoleOutputCP() fails.
|
||||||
*/
|
*/
|
||||||
uOldCodePage = GetConsoleCP();
|
uOldCodePage = GetConsoleCP();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Try changing the console input codepage. If it works then also change
|
* Try changing the console input and output code pages.
|
||||||
* the console output codepage, and refresh our local codepage cache.
|
* If it succeeds, refresh the local code page information.
|
||||||
*/
|
*/
|
||||||
if (SetConsoleCP(uNewCodePage))
|
if (SetConsoleCP(uNewCodePage))
|
||||||
{
|
{
|
||||||
if (SetConsoleOutputCP(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 */
|
/* Display the active code page number */
|
||||||
ConResPrintf(StdOut, STRING_CHCP_ERROR1, GetConsoleOutputCP());
|
ConResPrintf(StdOut, STRING_CHCP_ERROR1, GetConsoleOutputCP());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Failure, restore the original console codepage */
|
/* Failure, restore the original console code page */
|
||||||
SetConsoleCP(uOldCodePage);
|
SetConsoleCP(uOldCodePage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue