diff options
author | James Rowe <jroweboy@gmail.com> | 2018-07-02 11:10:41 -0600 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2018-07-02 21:45:47 -0400 |
commit | 6269a01b4e9963ffdaf98ddf5d5f2a90d49e58ff (patch) | |
tree | c69305f1bca02461e4af8dc20f0b47601f276fc0 /src/yuzu/debugger | |
parent | 0d46f0df122dbc9b9a9d9f97e2da6b1953ef939b (diff) |
Add configurable logging backends
Diffstat (limited to 'src/yuzu/debugger')
-rw-r--r-- | src/yuzu/debugger/console.cpp | 45 | ||||
-rw-r--r-- | src/yuzu/debugger/console.h | 14 |
2 files changed, 59 insertions, 0 deletions
diff --git a/src/yuzu/debugger/console.cpp b/src/yuzu/debugger/console.cpp new file mode 100644 index 000000000..e3d2d975f --- /dev/null +++ b/src/yuzu/debugger/console.cpp @@ -0,0 +1,45 @@ +// 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/ui_settings.h" + +namespace Debugger { +void ToggleConsole() { +#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); + 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); + } + } +#else + if (UISettings::values.show_console) { + Log::AddBackend(std::make_unique<Log::ColorConsoleBackend>()); + } else { + Log::RemoveBackend(Log::ColorConsoleBackend::Name()); + } +#endif +} +} // namespace Debugger diff --git a/src/yuzu/debugger/console.h b/src/yuzu/debugger/console.h new file mode 100644 index 000000000..d1990c496 --- /dev/null +++ b/src/yuzu/debugger/console.h @@ -0,0 +1,14 @@ +// Copyright 2018 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +namespace Debugger { + +/** + * Uses the WINAPI to hide or show the stderr console. This function is a placeholder until we can + * get a real qt logging window which would work for all platforms. + */ +void ToggleConsole(); +} // namespace Debugger
\ No newline at end of file |