RT opens console window on Windows when a filename or a name of a folder is passed as argument, Issue 2300

This commit is contained in:
Ingo 2014-03-19 17:33:42 +01:00
parent f63cf64bcf
commit 77e97be151

View File

@ -154,40 +154,43 @@ int main(int argc, char **argv)
bool consoleOpened = false; bool consoleOpened = false;
if (argc>1 || options.rtSettings.verbose){ if (argc>1 || options.rtSettings.verbose){
bool stdoutRedirectedtoFile = (GetFileType(GetStdHandle(STD_OUTPUT_HANDLE)) == 0x0001); 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 stderrRedirectedtoFile = (GetFileType(GetStdHandle(STD_ERROR_HANDLE)) == 0x0001); bool stdoutRedirectedtoFile = (GetFileType(GetStdHandle(STD_OUTPUT_HANDLE)) == 0x0001);
// no console, if stdout and stderr both are redirected to file bool stderrRedirectedtoFile = (GetFileType(GetStdHandle(STD_ERROR_HANDLE)) == 0x0001);
if( !(stdoutRedirectedtoFile && stderrRedirectedtoFile)) { // no console, if stdout and stderr both are redirected to file
AllocConsole(); if( !(stdoutRedirectedtoFile && stderrRedirectedtoFile)) {
AttachConsole( GetCurrentProcessId() ) ; AllocConsole();
// Don't allow CTRL-C in console to terminate RT AttachConsole( GetCurrentProcessId() ) ;
SetConsoleCtrlHandler( NULL, true ); // Don't allow CTRL-C in console to terminate RT
// Set title of console SetConsoleCtrlHandler( NULL, true );
char consoletitle[128]; // Set title of console
sprintf(consoletitle, "RawTherapee %s Console",VERSION); char consoletitle[128];
SetConsoleTitle(consoletitle); sprintf(consoletitle, "RawTherapee %s Console",VERSION);
// increase size of screen buffer SetConsoleTitle(consoletitle);
COORD c; // increase size of screen buffer
c.X = 200; COORD c;
c.Y = 1000; c.X = 200;
SetConsoleScreenBufferSize( GetStdHandle( STD_OUTPUT_HANDLE ), c ); c.Y = 1000;
// Disable console-Cursor SetConsoleScreenBufferSize( GetStdHandle( STD_OUTPUT_HANDLE ), c );
CONSOLE_CURSOR_INFO cursorInfo; // Disable console-Cursor
cursorInfo.dwSize = 100; CONSOLE_CURSOR_INFO cursorInfo;
cursorInfo.bVisible = false; cursorInfo.dwSize = 100;
SetConsoleCursorInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &cursorInfo ); cursorInfo.bVisible = false;
if(!stdoutRedirectedtoFile) SetConsoleCursorInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &cursorInfo );
freopen( "CON", "w", stdout ) ; if(!stdoutRedirectedtoFile)
if(!stderrRedirectedtoFile) freopen( "CON", "w", stdout ) ;
freopen( "CON", "w", stderr ) ; if(!stderrRedirectedtoFile)
freopen( "CON", "r", stdin ) ; 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 // 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 << "RawTherapee, version " << VERSION << std::endl;
std::cout << "WARNING: closing this window will close RawTherapee!" << std::endl << std::endl; std::cout << "WARNING: closing this window will close RawTherapee!" << std::endl << std::endl;
}
} }
int ret = processLineParams( argc, argv); int ret = processLineParams( argc, argv);
if( ret <= 0 ) { if( ret <= 0 ) {
if(consoleOpened) { if(consoleOpened) {