console.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #ifdef _WIN32
  5. #include <windows.h>
  6. #include <wincon.h>
  7. #endif
  8. #include "common/logging/backend.h"
  9. #include "yuzu/debugger/console.h"
  10. #include "yuzu/uisettings.h"
  11. namespace Debugger {
  12. void ToggleConsole() {
  13. static bool console_shown = false;
  14. if (console_shown == UISettings::values.show_console.GetValue()) {
  15. return;
  16. } else {
  17. console_shown = UISettings::values.show_console.GetValue();
  18. }
  19. using namespace Common::Log;
  20. #if defined(_WIN32) && !defined(_DEBUG)
  21. FILE* temp;
  22. if (UISettings::values.show_console) {
  23. if (AllocConsole()) {
  24. // The first parameter for freopen_s is a out parameter, so we can just ignore it
  25. freopen_s(&temp, "CONIN$", "r", stdin);
  26. freopen_s(&temp, "CONOUT$", "w", stdout);
  27. freopen_s(&temp, "CONOUT$", "w", stderr);
  28. SetColorConsoleBackendEnabled(true);
  29. }
  30. } else {
  31. if (FreeConsole()) {
  32. // In order to close the console, we have to also detach the streams on it.
  33. // Just redirect them to NUL if there is no console window
  34. SetColorConsoleBackendEnabled(false);
  35. freopen_s(&temp, "NUL", "r", stdin);
  36. freopen_s(&temp, "NUL", "w", stdout);
  37. freopen_s(&temp, "NUL", "w", stderr);
  38. }
  39. }
  40. #else
  41. SetColorConsoleBackendEnabled(UISettings::values.show_console.GetValue());
  42. #endif
  43. }
  44. } // namespace Debugger