From 77e97be151a2d3fd135f17ecf74b00b7e5fc8d1c Mon Sep 17 00:00:00 2001 From: Ingo Date: Wed, 19 Mar 2014 17:33:42 +0100 Subject: [PATCH] RT opens console window on Windows when a filename or a name of a folder is passed as argument, Issue 2300 --- rtgui/main.cc | 71 +++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/rtgui/main.cc b/rtgui/main.cc index 133d09245..f63672987 100644 --- a/rtgui/main.cc +++ b/rtgui/main.cc @@ -152,42 +152,45 @@ int main(int argc, char **argv) #ifdef WIN32 bool consoleOpened = false; + + if (argc>1 || options.rtSettings.verbose){ + if(options.rtSettings.verbose || ( !safe_file_test( safe_filename_to_utf8(argv[1]), Glib::FILE_TEST_EXISTS ) && !safe_file_test( safe_filename_to_utf8(argv[1]), Glib::FILE_TEST_IS_DIR ))) { + bool stdoutRedirectedtoFile = (GetFileType(GetStdHandle(STD_OUTPUT_HANDLE)) == 0x0001); + bool stderrRedirectedtoFile = (GetFileType(GetStdHandle(STD_ERROR_HANDLE)) == 0x0001); + // no console, if stdout and stderr both are redirected to file + if( !(stdoutRedirectedtoFile && stderrRedirectedtoFile)) { + AllocConsole(); + AttachConsole( GetCurrentProcessId() ) ; + // Don't allow CTRL-C in console to terminate RT + SetConsoleCtrlHandler( NULL, true ); + // Set title of console + char consoletitle[128]; + sprintf(consoletitle, "RawTherapee %s Console",VERSION); + SetConsoleTitle(consoletitle); + // increase size of screen buffer + COORD c; + c.X = 200; + c.Y = 1000; + SetConsoleScreenBufferSize( GetStdHandle( STD_OUTPUT_HANDLE ), c ); + // Disable console-Cursor + CONSOLE_CURSOR_INFO cursorInfo; + cursorInfo.dwSize = 100; + cursorInfo.bVisible = false; + SetConsoleCursorInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &cursorInfo ); + if(!stdoutRedirectedtoFile) + freopen( "CON", "w", stdout ) ; + if(!stderrRedirectedtoFile) + freopen( "CON", "w", stderr ) ; + freopen( "CON", "r", stdin ) ; - if (argc>1 || options.rtSettings.verbose){ - bool stdoutRedirectedtoFile = (GetFileType(GetStdHandle(STD_OUTPUT_HANDLE)) == 0x0001); - bool stderrRedirectedtoFile = (GetFileType(GetStdHandle(STD_ERROR_HANDLE)) == 0x0001); - // no console, if stdout and stderr both are redirected to file - if( !(stdoutRedirectedtoFile && stderrRedirectedtoFile)) { - AllocConsole(); - AttachConsole( GetCurrentProcessId() ) ; - // Don't allow CTRL-C in console to terminate RT - SetConsoleCtrlHandler( NULL, true ); - // Set title of console - char consoletitle[128]; - sprintf(consoletitle, "RawTherapee %s Console",VERSION); - SetConsoleTitle(consoletitle); - // increase size of screen buffer - COORD c; - c.X = 200; - c.Y = 1000; - SetConsoleScreenBufferSize( GetStdHandle( STD_OUTPUT_HANDLE ), c ); - // Disable console-Cursor - CONSOLE_CURSOR_INFO cursorInfo; - cursorInfo.dwSize = 100; - cursorInfo.bVisible = false; - SetConsoleCursorInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &cursorInfo ); - if(!stdoutRedirectedtoFile) - freopen( "CON", "w", stdout ) ; - if(!stderrRedirectedtoFile) - freopen( "CON", "w", stderr ) ; - freopen( "CON", "r", stdin ) ; + consoleOpened = true; - consoleOpened = true; - - // printing RT's version in all case, particularly useful for the 'verbose' mode, but also for the batch processing - std::cout << "RawTherapee, version " << VERSION << std::endl; - std::cout << "WARNING: closing this window will close RawTherapee!" << std::endl << std::endl; + // printing RT's version in all case, particularly useful for the 'verbose' mode, but also for the batch processing + std::cout << "RawTherapee, version " << VERSION << std::endl; + std::cout << "WARNING: closing this window will close RawTherapee!" << std::endl << std::endl; + } } + int ret = processLineParams( argc, argv); if( ret <= 0 ) { if(consoleOpened) { @@ -196,7 +199,7 @@ int main(int argc, char **argv) getch(); } return ret; - } + } } #else if (argc>1 || options.rtSettings.verbose){