1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2015 Jussi Lind <jussi.lind@iki.fi>
3 //
4 // Dust Racing 2D is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 // Dust Racing 2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>.
15 
16 #include <QDebug>
17 #include <QDir>
18 #include <QLocale>
19 #include <QMessageBox>
20 #include <QSettings>
21 
22 #include "../common/config.hpp"
23 #include "../common/userexception.hpp"
24 
25 #include "application.hpp"
26 #include "game.hpp"
27 
28 #include "simple_logger.hpp"
29 
30 #include <iostream>
31 #include <string>
32 #include <vector>
33 
34 using juzzlin::L;
35 
initLogger()36 static void initLogger()
37 {
38     QString logPath = QDir::tempPath() + QDir::separator() + "dr2d.log";
39     L::init(logPath.toStdString().c_str());
40     L::setTimestampMode(L::TimestampMode::DateTime);
41     L::setLevelSymbol(L::Level::Trace, "<T>");
42     L::setLevelSymbol(L::Level::Debug, "<D>");
43     L::setLevelSymbol(L::Level::Info, "<I>");
44     L::setLevelSymbol(L::Level::Warning, "<W>");
45     L::setLevelSymbol(L::Level::Fatal, "<F>");
46     L::enableEchoMode(true);
47     L().info() << "Dust Racing 2D version " << VERSION;
48     L().info() << "Compiled against Qt version " << QT_VERSION_STR;
49 }
50 
main(int argc,char ** argv)51 int main(int argc, char ** argv)
52 {
53     QApplication::setOrganizationName(Config::General::QT_ORGANIZATION_NAME);
54     QApplication::setApplicationName(Config::Game::QT_APPLICATION_NAME);
55 #ifdef Q_OS_WIN32
56     QSettings::setDefaultFormat(QSettings::IniFormat);
57 #endif
58 
59     try
60     {
61         initLogger();
62         return Game(argc, argv).run();
63     } //
64     catch (std::exception & e)
65     {
66         if (!dynamic_cast<UserException *>(&e))
67         {
68             L().fatal() << e.what();
69             L().fatal() << "Initializing the game failed!";
70         }
71         return EXIT_FAILURE;
72     }
73 }
74