diff --git a/src/main.cpp b/src/main.cpp index 4658b6b5..91fea668 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,45 +31,16 @@ #include "serverdlg.h" #include "settings.h" #include "testbench.h" +#include "util.h" - -/******************************************************************************\ -* Console logging * -\******************************************************************************/ -// Try for a portable console -------------------------------------------------- - -QTextStream* ConsoleWriterFactory::get() -{ - if ( ptsConsole == nullptr ) - { -#if _WIN32 - if ( !AttachConsole ( ATTACH_PARENT_PROCESS ) ) - { - // Not run from console, dump logging to nowhere - static QString conout; - ptsConsole = new QTextStream ( &conout ); - } - else - { - freopen ( "CONOUT$", "w", stdout ); - ptsConsole = new QTextStream ( stdout ); - } -#else - ptsConsole = new QTextStream ( stdout ); -#endif - } - return ptsConsole; -} - // Implementation ************************************************************** int main ( int argc, char** argv ) { - QTextStream& tsConsole = *((new ConsoleWriterFactory())->get()); - - QString strArgument; - double rDbleArgument; + QTextStream& tsConsole = *( ( new ConsoleWriterFactory() )->get() ); + QString strArgument; + double rDbleArgument; // initialize all flags and string which might be changed by command line // arguments diff --git a/src/util.cpp b/src/util.cpp index 50160cde..c5aa7801 100755 --- a/src/util.cpp +++ b/src/util.cpp @@ -1209,6 +1209,31 @@ QString CCountyFlagIcons::GetResourceReference ( const QLocale::Country eCountry } +// Console writer factory ------------------------------------------------------ +QTextStream* ConsoleWriterFactory::get() +{ + if ( ptsConsole == nullptr ) + { +#if _WIN32 + if ( !AttachConsole ( ATTACH_PARENT_PROCESS ) ) + { + // Not run from console, dump logging to nowhere + static QString conout; + ptsConsole = new QTextStream ( &conout ); + } + else + { + freopen ( "CONOUT$", "w", stdout ); + ptsConsole = new QTextStream ( stdout ); + } +#else + ptsConsole = new QTextStream ( stdout ); +#endif + } + return ptsConsole; +} + + /******************************************************************************\ * Global Functions Implementation * \******************************************************************************/ diff --git a/src/util.h b/src/util.h index 20a8f09e..5eb2c1fa 100755 --- a/src/util.h +++ b/src/util.h @@ -482,6 +482,19 @@ public slots: }; +// Console writer factory ------------------------------------------------------ +// this class was written by pljones +class ConsoleWriterFactory +{ +public: + ConsoleWriterFactory() : ptsConsole ( nullptr ) { } + QTextStream* get(); + +private: + QTextStream* ptsConsole; +}; + + /******************************************************************************\ * Other Classes/Enums * \******************************************************************************/ @@ -1275,13 +1288,4 @@ protected: bool bPreviousState; }; -class ConsoleWriterFactory -{ -public: - ConsoleWriterFactory() : ptsConsole ( nullptr ) { } - QTextStream* get(); -private: - QTextStream* ptsConsole; -}; - #endif /* !defined ( UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) */