[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.
This commit is contained in:
ztjohnst 2020-07-31 22:27:18 -04:00 committed by Rick Gibbed
parent 44bfba4b0e
commit be1a666066
1 changed files with 18 additions and 0 deletions

View File

@ -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;