- catch exception from readProperties and show dialog
This commit is contained in:
parent
004055a3be
commit
7004475732
4 changed files with 83 additions and 27 deletions
|
@ -21,6 +21,7 @@
|
|||
// $Id$
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
#include <simgear/misc/exception.hxx>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
|
@ -644,10 +645,16 @@ int readHud( istream &input )
|
|||
|
||||
SGPropertyNode root;
|
||||
|
||||
|
||||
if (!readProperties(input, &root)) {
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "Malformed property list for hud.");
|
||||
return 0;
|
||||
try {
|
||||
readProperties(input, &root);
|
||||
} catch (const sg_io_exception &e) {
|
||||
string message = "Error reading HUD: ";
|
||||
message += e.getMessage();
|
||||
message += "\n at ";
|
||||
message += e.getLocation().asString();
|
||||
SG_LOG(SG_INPUT, SG_ALERT, message);
|
||||
mkDialog(message.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -677,11 +684,18 @@ int readHud( istream &input )
|
|||
|
||||
|
||||
SGPropertyNode root2;
|
||||
if (readProperties(path.str(), &root2)) {
|
||||
|
||||
readInstrument(&root2);
|
||||
|
||||
}//if
|
||||
try {
|
||||
readProperties(path.str(), &root2);
|
||||
} catch (const sg_io_exception &e) {
|
||||
string message = "Error reading HUD instrument: ";
|
||||
message += e.getMessage();
|
||||
message += "\n at ";
|
||||
message += e.getLocation().asString();
|
||||
SG_LOG(SG_INPUT, SG_ALERT, message);
|
||||
mkDialog(message.c_str());
|
||||
continue;
|
||||
}
|
||||
readInstrument(&root2);
|
||||
}//for loop(i)
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
#include <simgear/misc/exception.hxx>
|
||||
|
||||
#include <simgear/misc/sg_path.hxx>
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
|
@ -39,6 +40,8 @@
|
|||
#include <Main/globals.hxx>
|
||||
#include <Main/fg_props.hxx>
|
||||
|
||||
#include <GUI/gui.h>
|
||||
|
||||
#include "panel.hxx"
|
||||
#include "steam.hxx"
|
||||
#include "panel_io.hxx"
|
||||
|
@ -760,8 +763,14 @@ fgReadPanel (istream &input)
|
|||
{
|
||||
SGPropertyNode root;
|
||||
|
||||
if (!readProperties(input, &root)) {
|
||||
SG_LOG( SG_COCKPIT, SG_ALERT, "Malformed property list for panel." );
|
||||
try {
|
||||
readProperties(input, &root);
|
||||
} catch (const sg_io_exception &e) {
|
||||
string message = e.getMessage();
|
||||
message += "\n at ";
|
||||
message += e.getLocation().asString();
|
||||
SG_LOG(SG_INPUT, SG_ALERT, message);
|
||||
mkDialog(message.c_str());
|
||||
return 0;
|
||||
}
|
||||
return readPanel(&root);
|
||||
|
@ -781,8 +790,14 @@ fgReadPanel (const string &relative_path)
|
|||
path.append(relative_path);
|
||||
SGPropertyNode root;
|
||||
|
||||
if (!readProperties(path.str(), &root)) {
|
||||
SG_LOG( SG_COCKPIT, SG_ALERT, "Malformed property list for panel." );
|
||||
try {
|
||||
readProperties(path.str(), &root);
|
||||
} catch (const sg_io_exception &e) {
|
||||
string message = e.getMessage();
|
||||
message += "\n at ";
|
||||
message += e.getLocation().asString();
|
||||
SG_LOG(SG_INPUT, SG_ALERT, message);
|
||||
mkDialog(message.c_str());
|
||||
return 0;
|
||||
}
|
||||
return readPanel(&root);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// fg_commands.cxx - internal FGFS commands.
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
#include <simgear/misc/exception.hxx>
|
||||
|
||||
#include STL_STRING
|
||||
#include STL_FSTREAM
|
||||
|
@ -208,13 +209,19 @@ do_preferences_load (const SGPropertyNode * arg, SGCommandState ** state)
|
|||
props_path.append(path);
|
||||
SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences from "
|
||||
<< props_path.str());
|
||||
if (!readProperties(props_path.str(), globals->get_props())) {
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "Failed to reread global preferences");
|
||||
try {
|
||||
readProperties(props_path.str(), globals->get_props());
|
||||
} catch (const sg_io_exception &e) {
|
||||
string message = "Error reading global preferences: ";
|
||||
message += e.getMessage();
|
||||
message += "\n at ";
|
||||
message += e.getLocation().asString();
|
||||
SG_LOG(SG_INPUT, SG_ALERT, message);
|
||||
mkDialog(message.c_str());
|
||||
return false;
|
||||
} else {
|
||||
SG_LOG(SG_INPUT, SG_INFO, "Successfully read global preferences.");
|
||||
return true;
|
||||
}
|
||||
SG_LOG(SG_INPUT, SG_INFO, "Successfully read global preferences.");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
# include <simgear/compiler.h>
|
||||
#endif
|
||||
|
||||
#include <simgear/misc/exception.hxx>
|
||||
|
||||
#include STL_IOSTREAM
|
||||
|
||||
#include <Autopilot/newauto.hxx>
|
||||
|
@ -37,6 +39,8 @@
|
|||
#endif
|
||||
#include <Objects/matlib.hxx>
|
||||
|
||||
#include <GUI/gui.h>
|
||||
|
||||
#include "fgfs.hxx"
|
||||
#include "fg_props.hxx"
|
||||
|
||||
|
@ -1037,7 +1041,18 @@ fgUpdateProps ()
|
|||
bool
|
||||
fgSaveFlight (ostream &output)
|
||||
{
|
||||
return writeProperties(output, globals->get_props());
|
||||
try {
|
||||
writeProperties(output, globals->get_props());
|
||||
} catch (const sg_io_exception &e) {
|
||||
string message = "Error saving flight: ";
|
||||
message += e.getMessage();
|
||||
message += "\n at ";
|
||||
message += e.getLocation().asString();
|
||||
SG_LOG(SG_INPUT, SG_ALERT, message);
|
||||
mkDialog(message.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1048,16 +1063,21 @@ bool
|
|||
fgLoadFlight (istream &input)
|
||||
{
|
||||
SGPropertyNode props;
|
||||
if (readProperties(input, &props)) {
|
||||
copyProperties(&props, globals->get_props());
|
||||
// When loading a flight, make it the
|
||||
// new initial state.
|
||||
globals->saveInitialState();
|
||||
} else {
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "Error restoring flight; aborted");
|
||||
try {
|
||||
readProperties(input, &props);
|
||||
} catch (const sg_io_exception &e) {
|
||||
string message = "Error reading saved flight: ";
|
||||
message += e.getMessage();
|
||||
message += "\n at ";
|
||||
message += e.getLocation().asString();
|
||||
SG_LOG(SG_INPUT, SG_ALERT, message);
|
||||
mkDialog(message.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
copyProperties(&props, globals->get_props());
|
||||
// When loading a flight, make it the
|
||||
// new initial state.
|
||||
globals->saveInitialState();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue