-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.cpp
118 lines (105 loc) · 4.69 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*****************************************************************************
* Copyright 2015-2022 Alexander Barthel alex@littlenavmap.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include "exception.h"
#include "geo/calculations.h"
#include "gui/consoleapplication.h"
#include "io/fileroller.h"
#include "logging/logginghandler.h"
#include "navdatareader.h"
#include <QFileInfo>
#include <QDir>
/*
* .Options:
* . -h, --help Displays this help.
* . -v, --version Displays version information.
* . -f, --flight-simulator <simulator> Required option. Flight simulator
* . type <simulator> or other data
* . source. Either FSX, FSXSE, P3DV2,
* . P3DV3, P3DV4, P3DV5, P3DV6, XP11,
* . XP12, MSFS or DFD.
* . -s, --scenery <scenery> Scenery.cfg file <scenery> for FSX
* . and P3D. Determined by registry
* . entries if not given.
* . -d, --source-database <source-database> Required option for DFD compilation.
* . Source database <source-database> for
* . DFD based compilation.
* . -b, --basepath <basepath> Flight simulator basepath for BGL
* . files <basepath>. Determined by
* . registry entries if not given.
* . -o, --output <output> Output Sqlite database filename
* . <output> Default is "navdata.sqlite".
* . -c, --config <config> Configuration file <config> for
* . Navdatareader. Default is to use
* . integrated "navdatareader.cfg".
*/
int main(int argc, char *argv[])
{
// Initialize the resources from atools static library
Q_INIT_RESOURCE(atools);
atools::fs::FsPaths::intitialize();
atools::geo::registerMetaTypes();
int retval = 0; // Success is default
atools::gui::ConsoleApplication app(argc, argv);
QCoreApplication::setApplicationName("Navdatareader");
QCoreApplication::setOrganizationName("ABarthel");
QCoreApplication::setOrganizationDomain("littlenavmap.org");
QCoreApplication::setApplicationVersion(VERSION_NUMBER_NAVDATAREADER);
NavdataReader reader;
try
{
// Read the scenery.cfg, read all scenery areas and BGL files and store them in the Sqlite database
reader.run();
if(reader.getResultFlags().testFlag(atools::fs::COMPILE_BASIC_VALIDATION_ERROR))
retval = 1;
}
catch(const atools::Exception& e)
{
qCritical() << "*** Compilation failed";
qCritical() << "Caught atools::Exception " << e.what();
retval = 1;
}
catch(const std::exception& e)
{
qCritical() << "*** Compilation failed";
qCritical() << "Caught std::exception " << e.what();
retval = 1;
}
catch(...)
{
qCritical() << "*** Compilation failed";
qCritical() << "Caught unknown exception";
retval = 1;
}
if(retval == 1)
{
// Failed - rename output file and add "BROKEN" suffix to avoid accidental use
QFileInfo filename = reader.getDatabaseName();
QString newName = filename.absolutePath() + QDir::separator() + filename.baseName() + "_BROKEN." + filename.completeSuffix();
// Create backup copies of broken files
// little_navmap_navigraph_BROKEN.sqlite
// little_navmap_navigraph_BROKEN.sqlite.1
atools::io::FileRoller roller(2);
roller.rollFile(newName);
// Rename output file
qWarning() << "Renaming output file from" << filename << "to" << newName;
if(!QFile::rename(reader.getDatabaseName(), newName))
qWarning() << "*** Renaming failed";
}
qInfo() << "done.";
atools::logging::LoggingHandler::shutdown();
return retval;
}