From 8ecd25cb9fdf3e7883613c377cafe8d7cd15f712 Mon Sep 17 00:00:00 2001 From: Lord-Grey Date: Thu, 14 Sep 2023 22:10:54 +0200 Subject: [PATCH] Support UTF-8 Output on console --- include/utils/global_defines.h | 2 +- libsrc/hyperion/SettingsManager.cpp | 10 +++++++++- src/hyperiond/console.h | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/utils/global_defines.h b/include/utils/global_defines.h index e5a6808e..e948fb97 100644 --- a/include/utils/global_defines.h +++ b/include/utils/global_defines.h @@ -1,6 +1,6 @@ #pragma once -#define QSTRING_CSTR(str) str.toLocal8Bit().constData() +#define QSTRING_CSTR(str) str.toUtf8().constData() typedef QList< int > QIntList; diff --git a/libsrc/hyperion/SettingsManager.cpp b/libsrc/hyperion/SettingsManager.cpp index b0b9675b..e9fa5805 100644 --- a/libsrc/hyperion/SettingsManager.cpp +++ b/libsrc/hyperion/SettingsManager.cpp @@ -269,7 +269,15 @@ bool SettingsManager::saveSettings(QJsonObject config, bool correct) } else { - emit settingsChanged(settings::stringToType(key), QJsonDocument::fromJson(data.toLocal8Bit())); + QJsonParseError error; + QJsonDocument jsonDocument = QJsonDocument::fromJson(data.toUtf8(), &error); + if (error.error != QJsonParseError::NoError) { + Error(_log, "Error parsing JSON: %s", QSTRING_CSTR(error.errorString())); + rc = false; + } + else { + emit settingsChanged(settings::stringToType(key), jsonDocument); + } } } } diff --git a/src/hyperiond/console.h b/src/hyperiond/console.h index 98469960..e61156ae 100644 --- a/src/hyperiond/console.h +++ b/src/hyperiond/console.h @@ -15,4 +15,5 @@ void CreateConsole() freopen_s(&fDummy, "CONOUT$", "w", stderr); freopen_s(&fDummy, "CONIN$", "r", stdin); SetConsoleTitle(TEXT("Hyperion")); + SetConsoleOutputCP(CP_UTF8); }