- if(_environ)
- {
- wchar_t *logfile = NULL;
- size_t logfile_len = 0;
- if(!_wdupenv_s(&logfile, &logfile_len, L"X264_LAUNCHER_LOGFILE"))
- {
- if(logfile && (logfile_len > 0))
- {
- FILE *temp = NULL;
- if(!_wfopen_s(&temp, logfile, L"wb"))
- {
- fprintf(temp, "%c%c%c", 0xEF, 0xBB, 0xBF);
- g_x264_log_file = temp;
- }
- free(logfile);
- }
- }
- }
-
- if(!X264_DEBUG)
- {
- for(int i = 0; i < argc; i++)
- {
- if(!_stricmp(argv[i], "--console"))
- {
- enableConsole = true;
- }
- else if(!_stricmp(argv[i], "--no-console"))
- {
- enableConsole = false;
- }
- }
- }
-
- if(enableConsole)
- {
- if(!g_x264_console_attached)
- {
- if(AllocConsole() != FALSE)
- {
- SetConsoleCtrlHandler(NULL, TRUE);
- SetConsoleTitle(L"Simple x264 Launcher | Debug Console");
- SetConsoleOutputCP(CP_UTF8);
- g_x264_console_attached = true;
- }
- }
-
- if(g_x264_console_attached)
- {
- //-------------------------------------------------------------------
- //See: http://support.microsoft.com/default.aspx?scid=kb;en-us;105305
- //-------------------------------------------------------------------
- const int flags = _O_WRONLY | _O_U8TEXT;
- int hCrtStdOut = _open_osfhandle((intptr_t) GetStdHandle(STD_OUTPUT_HANDLE), flags);
- int hCrtStdErr = _open_osfhandle((intptr_t) GetStdHandle(STD_ERROR_HANDLE), flags);
- FILE *hfStdOut = (hCrtStdOut >= 0) ? _fdopen(hCrtStdOut, "wb") : NULL;
- FILE *hfStdErr = (hCrtStdErr >= 0) ? _fdopen(hCrtStdErr, "wb") : NULL;
- if(hfStdOut) { *stdout = *hfStdOut; std::cout.rdbuf(new std::filebuf(hfStdOut)); }
- if(hfStdErr) { *stderr = *hfStdErr; std::cerr.rdbuf(new std::filebuf(hfStdErr)); }
- }
-
- HWND hwndConsole = GetConsoleWindow();
-
- if((hwndConsole != NULL) && (hwndConsole != INVALID_HANDLE_VALUE))
- {
- HMENU hMenu = GetSystemMenu(hwndConsole, 0);
- EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
- RemoveMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);
-
- SetWindowPos(hwndConsole, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED);
- SetWindowLong(hwndConsole, GWL_STYLE, GetWindowLong(hwndConsole, GWL_STYLE) & (~WS_MAXIMIZEBOX) & (~WS_MINIMIZEBOX));
- SetWindowPos(hwndConsole, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED);
- }
- }
-}