Skip to content

Commit

Permalink
Windows: Fix console using OEMCP instead of the resource string table…
Browse files Browse the repository at this point in the history
…'s codepage
  • Loading branch information
Fulgen301 committed Aug 28, 2024
1 parent c03c177 commit 358c184
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/C4Language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ bool C4Language::LoadStringTable(C4Group &hGroup, const char *strCode)
// Set the internal charset
SCopy(LoadResStr(C4ResStrTableKey::IDS_LANG_CHARSET), Config.General.LanguageCharset);

#ifdef _WIN32
Application.LogSystem.SetConsoleCharset(C4Config::GetCharsetCodePage(Config.General.LanguageCharset));
#endif

#ifdef HAVE_ICONV_AND_LANGINFO_H
const char *const to_set = nl_langinfo(CODESET);
if (local_to_host == iconv_t(-1))
Expand Down
11 changes: 11 additions & 0 deletions src/C4Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,17 @@ void C4LogSystem::ClearRingbuffer()
ringbufferSink->Clear();
}

#ifdef _WIN32

void C4LogSystem::SetConsoleCharset(const std::int32_t charset)
{
SetConsoleCP(charset);
SetConsoleOutputCP(charset);
}

#endif


void LogNTr(const spdlog::level::level_enum level, const std::string_view message)
{
Application.LogSystem.GetLogger()->log(level, message);
Expand Down
4 changes: 4 additions & 0 deletions src/C4Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ class C4LogSystem
void EnableDebugLog(bool enable);
void SetVerbose(bool verbose);

#ifdef _WIN32
void SetConsoleCharset(std::int32_t charset);
#endif

private:
std::shared_ptr<spdlog::logger> logger;
std::shared_ptr<spdlog::logger> loggerSilent;
Expand Down

0 comments on commit 358c184

Please sign in to comment.