Load --help output and translated strings from $FG_INSTALL_PREFIX/share/flightgear
$FG_INSTALL_PREFIX represents the FlightGear installation prefix, such as /usr, /usr/local or /opt/FlightGear on Unix systems. Copying the --help output and translated strings there avoids having to write to $FG_ROOT when 'make install' (or some OS-dependent equivalent) is run from the FlightGear build directory---that would be ugly when $FG_ROOT points to the FGData Git repository. In FGLocale::FGLocale(), Translations/locale.xml is loaded using readProperties() and fatalMessageBox() (in case an error is encountered). Note that it couldn't be loaded via fgLoadProps() in the current state, because this function relies on guiErrorMessage() when an error is encountered, which calls mkDialog(), which itself does globals->get_subsystem("gui"). This last call can't be done from FGGlobals' constructor---where the 'globals' pointer is still NULL---hence the need for a different mechanism not relying on FGGlobals. For consistency, and also because it provides a better user experience[1], load options.xml using the same method instead of with fgLoadProps(). [1] I.e., in case of an error, the user gets to see a graphical popup window with an explanatory message before FG exits, assuming he is either on Windows, or on Mac, or has Qt support built in FG, as opposed to only an SG_LOG() call [because when options.xml is loaded, guiErrorMessage() used by fgLoadProps() can't use the 'gui' subsystem].
This commit is contained in:
parent
a6afda53bb
commit
7288628919
2 changed files with 35 additions and 9 deletions
|
@ -27,6 +27,7 @@
|
|||
#endif
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include <simgear/props/props_io.hxx>
|
||||
|
@ -34,6 +35,7 @@
|
|||
|
||||
#include "fg_props.hxx"
|
||||
#include "locale.hxx"
|
||||
#include <GUI/MessageBox.hxx>
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
|
@ -42,6 +44,25 @@ FGLocale::FGLocale(SGPropertyNode* root) :
|
|||
_intl(root->getNode("/sim/intl",0, true)),
|
||||
_defaultLocale(_intl->getChild("locale",0, true))
|
||||
{
|
||||
// Load locale.xml under _intl (which corresponds to /sim/intl). I don't
|
||||
// pretend it is very useful to have this in the Global Property Tree; I
|
||||
// am just making it visible under /sim/intl to preserve the previous
|
||||
// behavior (when locale.xml was in FGData and automatically loaded under
|
||||
// /sim/intl via an <intl include=... /> in $FG_ROOT/preferences.xml).
|
||||
SGPath localeXML =
|
||||
SGPath(FG_INSTALL_PREFIX) / "share/flightgear/Translations/locale.xml";
|
||||
|
||||
try {
|
||||
readProperties(localeXML, _intl);
|
||||
} catch (const sg_exception &e) {
|
||||
string msg = "Unable to load '" + localeXML.utf8Str() + "'. "
|
||||
"Please check that this file exists and is readable.\n\n" +
|
||||
"Exception information: " + e.getFormattedMessage();
|
||||
SG_LOG( SG_GENERAL, SG_ALERT, msg );
|
||||
flightgear::fatalMessageBox(
|
||||
"FlightGear", "Unable to load translation data.", msg);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
FGLocale::~FGLocale()
|
||||
|
@ -202,7 +223,7 @@ FGLocale::selectLanguage(const char *language)
|
|||
bool
|
||||
FGLocale::loadResource(SGPropertyNode* localeNode, const char* resource)
|
||||
{
|
||||
SGPath path( globals->get_fg_root() );
|
||||
SGPath path = SGPath(FG_INSTALL_PREFIX) / "share/flightgear";
|
||||
|
||||
SGPropertyNode* stringNode = localeNode->getNode("strings", 0, true);
|
||||
|
||||
|
|
|
@ -2452,14 +2452,18 @@ void Options::showUsage() const
|
|||
simgear::requestConsole(); // ensure console is shown on Windows
|
||||
cout << endl;
|
||||
|
||||
try {
|
||||
fgLoadProps("options.xml", &options_root);
|
||||
} catch (const sg_exception &) {
|
||||
cout << "Unable to read the help file." << endl;
|
||||
cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
|
||||
cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
|
||||
cout << "by adding --fg-root=path as a program argument." << endl;
|
||||
SGPath optionsXML =
|
||||
SGPath(FG_INSTALL_PREFIX) / "share/flightgear/options.xml";
|
||||
|
||||
try {
|
||||
readProperties(optionsXML, &options_root);
|
||||
} catch (const sg_exception &e) {
|
||||
string msg = "Unable to load '" + optionsXML.utf8Str() + "'. "
|
||||
"Please check that this file exists and is readable.\n\n" +
|
||||
"Exception information: " + e.getFormattedMessage();
|
||||
SG_LOG( SG_GENERAL, SG_ALERT, msg );
|
||||
flightgear::fatalMessageBox(
|
||||
"FlightGear", "Unable to load the command-line help file.", msg);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
@ -2472,7 +2476,8 @@ void Options::showUsage() const
|
|||
|
||||
if (!locale->loadResource("options"))
|
||||
{
|
||||
cout << "Unable to read the language resource." << endl;
|
||||
SG_LOG( SG_GENERAL, SG_ALERT,
|
||||
"Unable to read the 'options' language resource." );
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue