summaryrefslogtreecommitdiffstats
path: root/client/windows
diff options
context:
space:
mode:
Diffstat (limited to 'client/windows')
-rw-r--r--client/windows/main.cpp28
-rw-r--r--client/windows/platform.cpp64
2 files changed, 66 insertions, 26 deletions
diff --git a/client/windows/main.cpp b/client/windows/main.cpp
index a1575e90..afc98c97 100644
--- a/client/windows/main.cpp
+++ b/client/windows/main.cpp
@@ -22,12 +22,6 @@ extern "C" {
#include "pthread.h"
}
-//#define OPEN_CONSOLE
-#ifdef OPEN_CONSOLE
-#include <io.h>
-#include <conio.h>
-#endif
-
#include "application.h"
#include "debug.h"
#include "utils.h"
@@ -83,23 +77,6 @@ int WINAPI WinMain(HINSTANCE hInstance,
try {
init_version_string();
-#ifdef OPEN_CONSOLE
- AllocConsole();
- HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
- int hConHandle = _open_osfhandle((intptr_t)h, _O_TEXT);
- FILE * fp = _fdopen(hConHandle, "w");
- *stdout = *fp;
-
- h = GetStdHandle(STD_INPUT_HANDLE);
- hConHandle = _open_osfhandle((intptr_t)h, _O_TEXT);
- fp = _fdopen(hConHandle, "r");
- *stdin = *fp;
-
- h = GetStdHandle(STD_ERROR_HANDLE);
- hConHandle = _open_osfhandle((intptr_t)h, _O_TEXT);
- fp = _fdopen(hConHandle, "w");
- *stderr = *fp;
-#endif
pthread_win32_process_attach_np();
init_winsock();
exit_val = Application::main(__argc, __argv, version_string);
@@ -114,11 +91,10 @@ int WINAPI WinMain(HINSTANCE hInstance,
LOG_ERROR("unhandled exception");
exit_val = SPICEC_ERROR_CODE_ERROR;
}
+
log4cpp::Category::shutdown();
-#ifdef OPEN_CONSOLE
- _getch();
-#endif
pthread_win32_process_detach_np();
+
return exit_val;
}
diff --git a/client/windows/platform.cpp b/client/windows/platform.cpp
index dcdb84e3..d5ff0f09 100644
--- a/client/windows/platform.cpp
+++ b/client/windows/platform.cpp
@@ -18,6 +18,8 @@
#include "common.h"
#include <shlobj.h>
+#include <io.h>
+#include <conio.h>
#include "platform.h"
#include "win_platform.h"
@@ -740,3 +742,65 @@ void WinPlatform::exit_modal_loop()
KillTimer(paltform_win, MODAL_LOOP_TIMER_ID);
modal_loop_active = false;
}
+
+static bool has_console = false;
+
+static void create_console()
+{
+ static Mutex console_mutex;
+
+ Lock lock(console_mutex);
+
+ if (has_console) {
+ return;
+ }
+
+ AllocConsole();
+ HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
+ int hConHandle = _open_osfhandle((intptr_t)h, _O_TEXT);
+ FILE * fp = _fdopen(hConHandle, "w");
+ *stdout = *fp;
+
+ h = GetStdHandle(STD_INPUT_HANDLE);
+ hConHandle = _open_osfhandle((intptr_t)h, _O_TEXT);
+ fp = _fdopen(hConHandle, "r");
+ *stdin = *fp;
+
+ h = GetStdHandle(STD_ERROR_HANDLE);
+ hConHandle = _open_osfhandle((intptr_t)h, _O_TEXT);
+ fp = _fdopen(hConHandle, "w");
+ *stderr = *fp;
+
+ has_console = true;
+
+ HWND consol_window = GetConsoleWindow();
+
+ if (consol_window) {
+ SetForegroundWindow(consol_window);
+ }
+}
+
+class ConsoleWait {
+public:
+ ~ConsoleWait()
+ {
+ if (has_console) {
+ Platform::term_printf("\n\nPress any key to exit...");
+ _getch();
+ }
+ }
+
+} console_wait;
+
+
+void Platform::term_printf(const char* format, ...)
+{
+ if (!has_console) {
+ create_console();
+ }
+
+ va_list ap;
+ va_start(ap, format);
+ vprintf(format, ap);
+ va_end(ap);
+}