[Base] Attach console on cvar help/failure.
[Base] Attempt attaching to console on cvar help/failure.
This commit is contained in:
parent
80cafd9358
commit
92242f3f7d
|
@ -65,6 +65,7 @@ void ParseLaunchArguments(int& argc, char**& argv,
|
||||||
|
|
||||||
auto result = options.parse(argc, argv);
|
auto result = options.parse(argc, argv);
|
||||||
if (result.count("help")) {
|
if (result.count("help")) {
|
||||||
|
xe::AttachConsole();
|
||||||
if (xe::has_console_attached()) {
|
if (xe::has_console_attached()) {
|
||||||
PrintHelpAndExit();
|
PrintHelpAndExit();
|
||||||
} else {
|
} else {
|
||||||
|
@ -88,6 +89,7 @@ void ParseLaunchArguments(int& argc, char**& argv,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (const cxxopts::OptionException& e) {
|
} catch (const cxxopts::OptionException& e) {
|
||||||
|
xe::AttachConsole();
|
||||||
if (xe::has_console_attached()) {
|
if (xe::has_console_attached()) {
|
||||||
std::cout << e.what() << std::endl;
|
std::cout << e.what() << std::endl;
|
||||||
PrintHelpAndExit();
|
PrintHelpAndExit();
|
||||||
|
|
|
@ -22,6 +22,8 @@ namespace xe {
|
||||||
// Returns true if there is a user-visible console attached to receive stdout.
|
// Returns true if there is a user-visible console attached to receive stdout.
|
||||||
bool has_console_attached();
|
bool has_console_attached();
|
||||||
|
|
||||||
|
void AttachConsole();
|
||||||
|
|
||||||
// Extern defined by user code. This must be present for the application to
|
// Extern defined by user code. This must be present for the application to
|
||||||
// launch.
|
// launch.
|
||||||
struct EntryInfo {
|
struct EntryInfo {
|
||||||
|
|
|
@ -18,6 +18,8 @@ namespace xe {
|
||||||
|
|
||||||
bool has_console_attached() { return true; }
|
bool has_console_attached() { return true; }
|
||||||
|
|
||||||
|
void AttachConsole() {}
|
||||||
|
|
||||||
} // namespace xe
|
} // namespace xe
|
||||||
|
|
||||||
extern "C" int main(int argc, char** argv) {
|
extern "C" int main(int argc, char** argv) {
|
||||||
|
|
|
@ -50,10 +50,6 @@ bool has_shell_environment_variable() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AttachConsole() {
|
void AttachConsole() {
|
||||||
if (!cvars::enable_console) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool has_console = ::AttachConsole(ATTACH_PARENT_PROCESS) == TRUE;
|
bool has_console = ::AttachConsole(ATTACH_PARENT_PROCESS) == TRUE;
|
||||||
if (!has_console || !has_shell_environment_variable()) {
|
if (!has_console || !has_shell_environment_variable()) {
|
||||||
// We weren't launched from a console, so just return.
|
// 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
|
// Attach a console so we can write output to stdout. If the user hasn't
|
||||||
// redirected output themselves it'll pop up a window.
|
// redirected output themselves it'll pop up a window.
|
||||||
xe::AttachConsole();
|
if (cvars::enable_console) {
|
||||||
|
xe::AttachConsole();
|
||||||
|
}
|
||||||
|
|
||||||
// Setup COM on the main thread.
|
// Setup COM on the main thread.
|
||||||
// NOTE: this may fail if COM has already been initialized - that's OK.
|
// NOTE: this may fail if COM has already been initialized - that's OK.
|
||||||
|
|
Loading…
Reference in New Issue