2018-02-20 01:51:27 +01:00
|
|
|
// Copyright 2018 Citra 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 "citra_qt/debugger/console.h"
|
2019-08-15 06:38:54 +02:00
|
|
|
#include "citra_qt/uisettings.h"
|
2018-02-20 01:51:27 +01:00
|
|
|
#include "common/logging/backend.h"
|
|
|
|
|
|
|
|
namespace Debugger {
|
|
|
|
void ToggleConsole() {
|
2018-07-02 18:39:13 +02:00
|
|
|
static bool console_shown = false;
|
|
|
|
if (console_shown == UISettings::values.show_console) {
|
|
|
|
return;
|
2018-06-30 12:07:30 +02:00
|
|
|
} else {
|
2018-07-02 18:39:13 +02:00
|
|
|
console_shown = UISettings::values.show_console;
|
2018-06-30 12:07:30 +02:00
|
|
|
}
|
2018-07-02 18:47:41 +02:00
|
|
|
|
2018-02-20 01:51:27 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
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);
|
|
|
|
Log::AddBackend(std::make_unique<Log::ColorConsoleBackend>());
|
|
|
|
}
|
|
|
|
} 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
|
|
|
|
Log::RemoveBackend(Log::ColorConsoleBackend::Name());
|
|
|
|
freopen_s(&temp, "NUL", "r", stdin);
|
|
|
|
freopen_s(&temp, "NUL", "w", stdout);
|
|
|
|
freopen_s(&temp, "NUL", "w", stderr);
|
|
|
|
}
|
|
|
|
}
|
2018-04-27 17:58:48 +02:00
|
|
|
#else
|
|
|
|
if (UISettings::values.show_console) {
|
|
|
|
Log::AddBackend(std::make_unique<Log::ColorConsoleBackend>());
|
|
|
|
} else {
|
|
|
|
Log::RemoveBackend(Log::ColorConsoleBackend::Name());
|
|
|
|
}
|
2018-02-20 01:51:27 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
} // namespace Debugger
|