Add a console if Olive is started via cmd

This commit is contained in:
Thomas Wilshaw
2021-08-09 15:07:21 +01:00
parent 132e637f3f
commit b1b057a628
+35
View File
@@ -42,12 +42,41 @@ extern "C" {
#include "common/debug.h"
#include "version.h"
#ifdef _WIN32
#include <Windows.h>
#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;
}