Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/forks/sandbox_qt/src/orxonox/Main.cc @ 7816

Last change on this file since 7816 was 7816, checked in by rgrieder, 13 years ago

Improved exception handling in sandbox Qt.

  • Property svn:eol-style set to native
File size: 3.7 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
24 *      Reto Grieder
25 *   Co-authors:
26 *      ...
27 *
28 */
29
30/**
31@file
32@brief
33    The main function of Orxonox (but not the entry point of the program!)
34*/
35
36#include "Main.h"
37
38#include <memory>
39#include <QApplication>
40#include <QCoreApplication>
41
42#ifdef ORXONOX_PLATFORM_WINDOWS
43#  include <windows.h>
44#endif
45
46#include "util/Debug.h"
47#include "util/Exception.h"
48#include "core/CommandLineParser.h"
49#include "core/Core.h"
50#include "MainWindow.h"
51
52namespace orxonox
53{
54    SetCommandLineArgument(generateDoc, "")
55        .information("Generates a Doxygen file from things like SetConsoleCommand");
56
57    /**
58    @brief
59        Starting point of orxonox (however not the entry point of the program!)
60    */
61    int main(int argc, char** argv)
62    {
63        QApplication app(argc, argv);
64
65        std::auto_ptr<Core> core;
66        try
67        {
68            QStringList arguments = QCoreApplication::arguments();
69            if (!arguments.value(0).isEmpty() && arguments.value(0)[0] != '-')
70                arguments.pop_front(); // Remove application path
71            core.reset(new Core(arguments.join(" ").toStdString()));
72        }
73        catch (const Exception& ex)
74        {
75            COUT(0) << "Exception: " << ex.getDescription() << endl;
76#ifdef ORXONOX_PLATFORM_WINDOWS
77            MessageBox(NULL, ex.getDescription().c_str(), "Exception", MB_ICONERROR);
78#endif
79            return 1;
80        }
81
82        QCoreApplication::setOrganizationName("Orxonox");
83        QCoreApplication::setOrganizationDomain("www.orxonox.net");
84        QCoreApplication::setApplicationName("Orxonox Sandbox");
85        QString versionString;
86        versionString += QString::number(ORXONOX_VERSION_MAJOR);
87        versionString += QString::number(ORXONOX_VERSION_MINOR);
88        versionString += QString::number(ORXONOX_VERSION_PATCH);
89        QCoreApplication::setApplicationVersion(versionString);
90
91        // Define library path
92        // Note: May not work (untested) because QApplication was already created.
93        // However doing the beforehand is difficult because the Core is required.
94        QStringList libraryPaths = QCoreApplication::libraryPaths();
95        libraryPaths.prepend(PathConfig::getExecutablePath().path() + "/plugins");
96        QCoreApplication::setLibraryPaths(libraryPaths);
97
98        try
99        {
100            if (CommandLineParser::getValue("generateDoc").toString().isEmpty())
101            {
102                MainWindow window;
103                window.show();
104                return app.exec();
105            }
106            else
107                return 0;
108        }
109        catch (const Exception& ex)
110        {
111            COUT(0) << "Exception: " << ex.getDescription() << endl;
112#ifdef ORXONOX_PLATFORM_WINDOWS
113            MessageBox(NULL, ex.getDescription().c_str(), "Exception", MB_ICONERROR);
114#endif
115            return 1;
116        }
117    }
118}
Note: See TracBrowser for help on using the repository browser.