From be1a666066aa8762e45bd53b2322071e7a24b4df Mon Sep 17 00:00:00 2001 From: ztjohnst Date: Fri, 31 Jul 2020 22:27:18 -0400 Subject: [PATCH] [Base] Change behavior of has_console_attached(). [Base] Change has_console_attached() so that it no longer proves true if Xenia is launched from a Windows Terminal. --- src/xenia/base/main_win.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/xenia/base/main_win.cc b/src/xenia/base/main_win.cc index 6162d3846..6cf80b7ae 100644 --- a/src/xenia/base/main_win.cc +++ b/src/xenia/base/main_win.cc @@ -38,11 +38,29 @@ bool has_console_attached_ = true; bool has_console_attached() { return has_console_attached_; } +bool has_shell_environment_variable() { + size_t size = 0; + // Check if SHELL exists + // If it doesn't, then we are in a Windows Terminal + auto error = getenv_s(&size, nullptr, 0, "SHELL"); + if (error) { + return false; + } + return !!size; +} + void AttachConsole() { if (!cvars::enable_console) { return; } + bool has_console = ::AttachConsole(ATTACH_PARENT_PROCESS) == TRUE; + if (!has_console || !has_shell_environment_variable()) { + // We weren't launched from a console, so just return. + has_console_attached_ = false; + return; + } + AllocConsole(); has_console_attached_ = true;