1 ///////////////////////////////////////////////////////////////////////////////
2 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
20 //////////////////////////////////////////////////////////////////////////////////
23 #include <MUtils/Startup.h>
24 #include <MUtils/OSSupport.h>
25 #include <MUtils/Terminal.h>
26 #include <MUtils/ErrorHandler.h>
27 #include <MUtils/Exception.h>
32 ///////////////////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////////
36 static void qt_message_handler(QtMsgType type, const char *msg)
38 if((!msg) || (!(msg[0])))
43 MUtils::Terminal::write(type, msg);
45 if((type == QtCriticalMsg) || (type == QtFatalMsg))
47 MUtils::OS::fatal_exit(MUTILS_WCHR(QString::fromUtf8(msg)));
51 ///////////////////////////////////////////////////////////////////////////////
53 ///////////////////////////////////////////////////////////////////////////////
55 static int startup_main(int &argc, char **argv, MUtils::Startup::main_function_t *const entry_point)
57 qInstallMsgHandler(qt_message_handler);
58 MUtils::Terminal::setup(argc, argv, MUTILS_DEBUG);
59 return entry_point(argc, argv);
62 static int startup_helper(int &argc, char **argv, MUtils::Startup::main_function_t *const entry_point)
67 iResult = startup_main(argc, argv, entry_point);
69 catch(const std::exception &error)
71 MUTILS_PRINT_ERROR("\nGURU MEDITATION !!!\n\nException error:\n%s\n", error.what());
72 MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!");
76 MUTILS_PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnknown exception error!\n");
77 MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!");
82 int MUtils::Startup::startup(int &argc, char **argv, main_function_t *const entry_point)
86 iResult = startup_main(argc, argv, entry_point);
91 MUtils::ErrorHandler::initialize();
92 iResult = startup_helper(argc, argv, entry_point);
96 MUTILS_PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnhandeled structured exception error!\n");
97 MUtils::OS::fatal_exit(L"Unhandeled structured exception error, application will exit!");
100 MUtils::ErrorHandler::initialize();
101 iResult = startup_helper(argc, argv, entry_point);
103 #endif //MUTILS_DEBUG
107 ///////////////////////////////////////////////////////////////////////////////