[Base] Attach console on cvar help/failure.

[Base] Attempt attaching to console on cvar help/failure.
This commit is contained in:
gibbed 2021-06-28 11:27:36 -05:00 committed by Rick Gibbed
parent 80cafd9358
commit 92242f3f7d
4 changed files with 9 additions and 5 deletions

View File

@ -65,6 +65,7 @@ void ParseLaunchArguments(int& argc, char**& argv,
auto result = options.parse(argc, argv);
if (result.count("help")) {
xe::AttachConsole();
if (xe::has_console_attached()) {
PrintHelpAndExit();
} else {
@ -88,6 +89,7 @@ void ParseLaunchArguments(int& argc, char**& argv,
}
}
} catch (const cxxopts::OptionException& e) {
xe::AttachConsole();
if (xe::has_console_attached()) {
std::cout << e.what() << std::endl;
PrintHelpAndExit();

View File

@ -22,6 +22,8 @@ namespace xe {
// Returns true if there is a user-visible console attached to receive stdout.
bool has_console_attached();
void AttachConsole();
// Extern defined by user code. This must be present for the application to
// launch.
struct EntryInfo {

View File

@ -18,6 +18,8 @@ namespace xe {
bool has_console_attached() { return true; }
void AttachConsole() {}
} // namespace xe
extern "C" int main(int argc, char** argv) {

View File

@ -50,10 +50,6 @@ bool has_shell_environment_variable() {
}
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.
@ -145,7 +141,9 @@ int Main() {
// Attach a console so we can write output to stdout. If the user hasn't
// redirected output themselves it'll pop up a window.
xe::AttachConsole();
if (cvars::enable_console) {
xe::AttachConsole();
}
// Setup COM on the main thread.
// NOTE: this may fail if COM has already been initialized - that's OK.