From b1b057a628f6ea03212ea3e3f84cdb48b5ac0445 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Mon, 9 Aug 2021 15:07:21 +0100 Subject: [PATCH 1/3] Add a console if Olive is started via cmd --- app/main.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/app/main.cpp b/app/main.cpp index 14dd9bbf1..b3287d85f 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -42,12 +42,41 @@ extern "C" { #include "common/debug.h" #include "version.h" +#ifdef _WIN32 +#include +#endif + #ifdef USE_CRASHPAD #include "common/crashpadinterface.h" #endif // USE_CRASHPAD int main(int argc, char *argv[]) { + +#ifdef _WIN32 + bool console = false; + FILE *stream_stdout; + FILE *stream_stderr; + + AttachConsole(ATTACH_PARENT_PROCESS); + DWORD procIDs[2]; + DWORD maxIds = 2; + DWORD count = GetConsoleProcessList((LPDWORD)procIDs, maxIds); + + if (count == 2) { + /* this is a terminal */ + FreeConsole(); + + // Create own console + if (AllocConsole()) { + freopen_s(&stream_stdout, "CONOUT$", "w", stdout); + freopen_s(&stream_stderr, "CONOUT$", "w", stderr); + console = true; + } + + } +#endif + // Set up debug handler qInstallMessageHandler(olive::DebugHandler); @@ -208,5 +237,11 @@ int main(int argc, char *argv[]) // Clear core memory c.Stop(); + #ifdef _WIN32 + if (console) { + system("pause"); + } + #endif + return ret; } From 42dd029f9eb050287f01fb885250640a5b6dd671 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Mon, 9 Aug 2021 23:14:12 +0100 Subject: [PATCH 2/3] Revert back to a console application Revert Olive back to a console application and then hide the console on startup. Also add an option to run a console if required. Windows only. --- app/CMakeLists.txt | 3 --- app/main.cpp | 42 +++++++++++------------------------------- 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index f2e95c1aa..83f58967a 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -101,9 +101,6 @@ if (WIN32) # Set Windows application icon target_sources(olive-editor PRIVATE packaging/windows/resources.rc) - set_target_properties(olive-editor PROPERTIES - WIN32_EXECUTABLE TRUE - ) elseif(APPLE) # Set Mac application icon set(OLIVE_ICON packaging/macos/olive.icns) diff --git a/app/main.cpp b/app/main.cpp index b3287d85f..a0a583b16 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -52,31 +52,6 @@ extern "C" { int main(int argc, char *argv[]) { - -#ifdef _WIN32 - bool console = false; - FILE *stream_stdout; - FILE *stream_stderr; - - AttachConsole(ATTACH_PARENT_PROCESS); - DWORD procIDs[2]; - DWORD maxIds = 2; - DWORD count = GetConsoleProcessList((LPDWORD)procIDs, maxIds); - - if (count == 2) { - /* this is a terminal */ - FreeConsole(); - - // Create own console - if (AllocConsole()) { - freopen_s(&stream_stdout, "CONOUT$", "w", stdout); - freopen_s(&stream_stderr, "CONOUT$", "w", stderr); - console = true; - } - - } -#endif - // Set up debug handler qInstallMessageHandler(olive::DebugHandler); @@ -129,10 +104,15 @@ int main(int argc, char *argv[]) true, QCoreApplication::translate("main", "qm-file")); + auto console_option = + parser.AddOption({QStringLiteral("c"), QStringLiteral("-console")}, + QCoreApplication::translate("main", "Launch console (Windows only)")); + auto project_argument = parser.AddPositionalArgument(QStringLiteral("project"), QCoreApplication::translate("main", "Project to open on startup")); + // Qt options re-implemented (add to this as necessary) // // Because we don't use QCommandLineParser, we must filter out Qt's arguments ourselves. Here, @@ -153,6 +133,12 @@ int main(int argc, char *argv[]) parser.Process(argc, argv); + if (!console_option->IsSet()) { +#ifdef _WIN32 + FreeConsole(); +#endif // _WIN32 + } + if (help_option->IsSet()) { // Show help parser.PrintHelp(argv[0]); @@ -237,11 +223,5 @@ int main(int argc, char *argv[]) // Clear core memory c.Stop(); - #ifdef _WIN32 - if (console) { - system("pause"); - } - #endif - return ret; } From d1d23e540069eacca0f59fb086f9a2b507496758 Mon Sep 17 00:00:00 2001 From: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Sat, 14 Aug 2021 11:36:30 -0700 Subject: [PATCH 3/3] only free console if program launches in gui mode --- app/main.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/main.cpp b/app/main.cpp index a0a583b16..f177be0de 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -104,9 +104,11 @@ int main(int argc, char *argv[]) true, QCoreApplication::translate("main", "qm-file")); +#ifdef _WIN32 auto console_option = parser.AddOption({QStringLiteral("c"), QStringLiteral("-console")}, - QCoreApplication::translate("main", "Launch console (Windows only)")); + QCoreApplication::translate("main", "Launch with debug console")); +#endif // _WIN32 auto project_argument = parser.AddPositionalArgument(QStringLiteral("project"), @@ -133,12 +135,6 @@ int main(int argc, char *argv[]) parser.Process(argc, argv); - if (!console_option->IsSet()) { -#ifdef _WIN32 - FreeConsole(); -#endif // _WIN32 - } - if (help_option->IsSet()) { // Show help parser.PrintHelp(argv[0]); @@ -193,6 +189,14 @@ int main(int argc, char *argv[]) std::unique_ptr a; if (startup_params.run_mode() == olive::Core::CoreParams::kRunNormal) { +#ifdef _WIN32 + // Since Olive is linked with the console subsystem (for better POSIX compatibility), a console + // is created by default. If the user didn't request one, we free it here. + if (!console_option->IsSet()) { + FreeConsole(); + } +#endif // _WIN32 + a.reset(new QApplication(argc, argv)); } else { a.reset(new QCoreApplication(argc, argv));