Launcher: guard against missing data files
More robust checking that FGData is setup correctly, when we try to parse defaults.xml from the launcher. Relates to Sentry exception: https://sentry.io/organizations/flightgear/issues/1901193353
This commit is contained in:
parent
db4e71955e
commit
d07360b37d
1 changed files with 14 additions and 3 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <simgear/props/props_io.hxx>
|
#include <simgear/props/props_io.hxx>
|
||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
|
#include <simgear/structure/exception.hxx>
|
||||||
|
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
#include <Main/locale.hxx>
|
#include <Main/locale.hxx>
|
||||||
|
@ -10,11 +11,21 @@ static SGPropertyNode_ptr loadXMLDefaults()
|
||||||
{
|
{
|
||||||
SGPropertyNode_ptr root(new SGPropertyNode);
|
SGPropertyNode_ptr root(new SGPropertyNode);
|
||||||
const SGPath defaultsXML = globals->get_fg_root() / "defaults.xml";
|
const SGPath defaultsXML = globals->get_fg_root() / "defaults.xml";
|
||||||
readProperties(defaultsXML, root);
|
if (!defaultsXML.exists()) {
|
||||||
|
SG_LOG(SG_GUI, SG_POPUP, "Failed to find required data file (defaults.xml)");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
readProperties(defaultsXML, root);
|
||||||
|
} catch (sg_exception& e) {
|
||||||
|
SG_LOG(SG_GUI, SG_POPUP, "Failed to read required data file (defaults.xml)");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
if (!root->hasChild("sim")) {
|
if (!root->hasChild("sim")) {
|
||||||
SG_LOG(SG_GUI, SG_POPUP, "Failed to find /sim node in defaults.xml, broken");
|
SG_LOG(SG_GUI, SG_POPUP, "Failed to find /sim node in defaults.xml, broken");
|
||||||
return SGPropertyNode_ptr();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
|
@ -28,7 +39,7 @@ std::string defaultAirportICAO()
|
||||||
{
|
{
|
||||||
SGPropertyNode_ptr root = loadXMLDefaults();
|
SGPropertyNode_ptr root = loadXMLDefaults();
|
||||||
if (!root) {
|
if (!root) {
|
||||||
return std::string();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string airportCode = root->getStringValue("/sim/presets/airport-id");
|
std::string airportCode = root->getStringValue("/sim/presets/airport-id");
|
||||||
|
|
Loading…
Add table
Reference in a new issue