2020-12-28 16:15:37 +01: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"
|
|
|
|
#include "yuzu/uisettings.h"
|
|
|
|
|
|
|
|
namespace Debugger {
|
|
|
|
void ToggleConsole() {
|
|
|
|
static bool console_shown = false;
|
2021-07-01 14:23:06 +02:00
|
|
|
if (console_shown == UISettings::values.show_console) {
|
2020-12-28 16:15:37 +01:00
|
|
|
return;
|
|
|
|
} else {
|
2021-07-01 14:23:06 +02:00
|
|
|
console_shown = UISettings::values.show_console;
|
2020-12-28 16:15:37 +01: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);
|
2021-04-15 07:16:22 +02:00
|
|
|
Common::Log::AddBackend(std::make_unique<Common::Log::ColorConsoleBackend>());
|
2020-12-28 16:15:37 +01: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-04-15 07:16:22 +02:00
|
|
|
Common::Log::RemoveBackend(Common::Log::ColorConsoleBackend::Name());
|
2020-12-28 16:15:37 +01:00
|
|
|
freopen_s(&temp, "NUL", "r", stdin);
|
|
|
|
freopen_s(&temp, "NUL", "w", stdout);
|
|
|
|
freopen_s(&temp, "NUL", "w", stderr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (UISettings::values.show_console) {
|
2021-04-15 07:16:22 +02:00
|
|
|
Common::Log::AddBackend(std::make_unique<Common::Log::ColorConsoleBackend>());
|
2020-12-28 16:15:37 +01:00
|
|
|
} else {
|
2021-04-15 07:16:22 +02:00
|
|
|
Common::Log::RemoveBackend(Common::Log::ColorConsoleBackend::Name());
|
2020-12-28 16:15:37 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
} // namespace Debugger
|