2018-07-02 10:10:41 -07:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include <wincon.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "common/logging/backend.h"
|
|
|
|
#include "yuzu/debugger/console.h"
|
2019-07-29 13:06:33 -07:00
|
|
|
#include "yuzu/uisettings.h"
|
2018-07-02 10:10:41 -07:00
|
|
|
|
|
|
|
namespace Debugger {
|
|
|
|
void ToggleConsole() {
|
2018-07-12 00:11:43 -07:00
|
|
|
static bool console_shown = false;
|
2021-06-28 14:32:24 -07:00
|
|
|
if (console_shown == UISettings::values.show_console.GetValue()) {
|
2018-07-12 00:11:43 -07:00
|
|
|
return;
|
|
|
|
} else {
|
2021-06-28 14:32:24 -07:00
|
|
|
console_shown = UISettings::values.show_console.GetValue();
|
2018-07-12 00:11:43 -07:00
|
|
|
}
|
|
|
|
|
2021-08-13 11:39:45 -07:00
|
|
|
using namespace Common::Log;
|
2018-07-02 10:10:41 -07:00
|
|
|
#if defined(_WIN32) && !defined(_DEBUG)
|
|
|
|
FILE* temp;
|
|
|
|
if (UISettings::values.show_console) {
|
|
|
|
if (AllocConsole()) {
|
|
|
|
// The first parameter for freopen_s is a out parameter, so we can just ignore it
|
|
|
|
freopen_s(&temp, "CONIN$", "r", stdin);
|
|
|
|
freopen_s(&temp, "CONOUT$", "w", stdout);
|
|
|
|
freopen_s(&temp, "CONOUT$", "w", stderr);
|
2022-02-13 15:18:05 -08:00
|
|
|
SetConsoleOutputCP(65001);
|
2021-08-13 11:39:45 -07:00
|
|
|
SetColorConsoleBackendEnabled(true);
|
2018-07-02 10:10:41 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (FreeConsole()) {
|
|
|
|
// In order to close the console, we have to also detach the streams on it.
|
|
|
|
// Just redirect them to NUL if there is no console window
|
2021-08-13 11:39:45 -07:00
|
|
|
SetColorConsoleBackendEnabled(false);
|
2018-07-02 10:10:41 -07:00
|
|
|
freopen_s(&temp, "NUL", "r", stdin);
|
|
|
|
freopen_s(&temp, "NUL", "w", stdout);
|
|
|
|
freopen_s(&temp, "NUL", "w", stderr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2021-08-13 11:39:45 -07:00
|
|
|
SetColorConsoleBackendEnabled(UISettings::values.show_console.GetValue());
|
2018-07-02 10:10:41 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
} // namespace Debugger
|