fileName.append(".xml");
}
- string_list sc = globals->get_fg_scenery();
+ PathList sc = globals->get_fg_scenery();
char buffer[128];
::snprintf(buffer, 128, "%c/%c/%c/%s.%s",
aICAO[0], aICAO[1], aICAO[2],
aICAO.c_str(), fileName.c_str());
- for (string_list_iterator it = sc.begin(); it != sc.end(); ++it) {
+ for (PathList::const_iterator it = sc.begin(); it != sc.end(); ++it) {
// fg_senery contains empty strings as "markers" (see FGGlobals::set_fg_scenery)
- if (!it->empty()) {
+ if (!it->isNull()) {
SGPath path(*it);
path.append("Airports");
path.append(string(buffer));
QStringList dirs = m_paths;
- Q_FOREACH(std::string ap, globals->get_aircraft_paths()) {
- dirs << QString::fromStdString(ap);
+ Q_FOREACH(SGPath ap, globals->get_aircraft_paths()) {
+ dirs << QString::fromStdString(ap.utf8Str());
}
SGPath rootAircraft(globals->get_fg_root());
namespace flightgear
{
-std::string Options::platformDefaultRoot() const
+SGPath Options::platformDefaultRoot() const
{
CocoaAutoreleasePool ap;
NSURL* url = [[NSBundle mainBundle] resourceURL];
SGPath dataDir(URLToPath(url));
dataDir.append("data");
- return dataDir.str();
+ return dataDir;
}
} // of namespace flightgear
if (!_initialized) {
char *envp = ::getenv("FG_FONTS");
if (envp != NULL) {
- _path.set(envp);
+ _path = SGPath::fromEnv("FG_FONTS");
} else {
- _path.set(globals->get_fg_root());
+ _path = globals->get_fg_root();
_path.append("Fonts");
}
_initialized = true;
QSettings::setDefaultFormat(QSettings::IniFormat);
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope,
- QString::fromStdString(globals->get_fg_home()));
+ QString::fromStdString(globals->get_fg_home().utf8Str()));
// reset numeric / collation locales as described at:
// http://doc.qt.io/qt-5/qcoreapplication.html#details
SGPath terraSyncDir(downloadDir.toStdString());
terraSyncDir.append("TerraSync");
if (terraSyncDir.exists()) {
- globals->append_fg_scenery(terraSyncDir.utf8Str());
+ globals->append_fg_scenery(terraSyncDir);
}
}
return true;
}
-std::string SetupRootDialog::restoreUserSelectedRoot()
+SGPath SetupRootDialog::restoreUserSelectedRoot()
{
QSettings settings;
QString path = settings.value("fg-root").toString();
bool SetupRootDialog::defaultRootAcceptable()
{
- std::string r = flightgear::Options::sharedInstance()->platformDefaultRoot();
- QString defaultRoot = QString::fromStdString(r);
+ SGPath r = flightgear::Options::sharedInstance()->platformDefaultRoot();
+ QString defaultRoot = QString::fromStdString(r.utf8Str());
return validatePath(defaultRoot) && validateVersion(defaultRoot);
}
void SetupRootDialog::onUseDefaults()
{
- std::string r = flightgear::Options::sharedInstance()->platformDefaultRoot();
- m_browsedPath = QString::fromStdString(r);
+ SGPath r = flightgear::Options::sharedInstance()->platformDefaultRoot();
+ m_browsedPath = QString::fromStdString(r.utf8Str());
globals->set_fg_root(r);
QSettings settings;
settings.remove("fg-root"); // remove any setting
void SetupRootDialog::updatePromptText()
{
QString t;
- QString curRoot = QString::fromStdString(globals->get_fg_root());
+ QString curRoot = QString::fromStdString(globals->get_fg_root().utf8Str());
switch (m_promptState) {
case DefaultPathCheckFailed:
t = tr("This copy of FlightGear does not include the base data files. " \
#include <string>
+#include <simgear/misc/sg_path.hxx>
+
namespace Ui
{
class SetupRootDialog;
static bool runDialog(bool usingDefaultRoot);
- static std::string restoreUserSelectedRoot();
+ static SGPath restoreUserSelectedRoot();
private slots:
void onBrowse();
{
using namespace flightgear;
- SGPath nextScreenshotPath(const std::string& screenshotDir)
+ SGPath nextScreenshotPath(const SGPath& screenshotDir)
{
char filename[32];
static int count = 1;
fgSetMouseCursor(MOUSE_CURSOR_NONE);
- string dir = fgGetString("/sim/paths/screenshot-dir");
- if (dir.empty())
- dir = SGPath::desktop().str();
+ SGPath dir = SGPath::fromUtf8(fgGetString("/sim/paths/screenshot-dir"));
+ if (dir.isNull())
+ dir = SGPath::desktop();
- _path.set(dir + '/');
- if (_path.create_dir( 0755 )) {
+ if (!dir.exists() && dir.create_dir( 0755 )) {
SG_LOG(SG_GENERAL, SG_ALERT, "Cannot create screenshot directory '"
<< dir << "'. Trying home directory.");
dir = globals->get_fg_home();
VisitResult visitAircraftPaths()
{
- const string_list& paths(globals->get_aircraft_paths());
- string_list::const_iterator it = paths.begin();
+ const PathList& paths(globals->get_aircraft_paths());
+ PathList::const_iterator it = paths.begin();
for (; it != paths.end(); ++it) {
- SGPath p(*it);
- VisitResult vr = visitDir(p, 0);
+ VisitResult vr = visitDir(*it, 0);
if (vr != VISIT_CONTINUE) {
return vr;
}
SGMaterialLib* new_matlib = new SGMaterialLib;
SGPath mpath( globals->get_fg_root() );
mpath.append( fgGetString("/sim/rendering/materials-file") );
- bool loaded = new_matlib->load(globals->get_fg_root(),
+ bool loaded = new_matlib->load(globals->get_fg_root().local8BitStr(),
mpath.str(),
globals->get_props());
return string();
}
- sg_gzifstream in( p.str() );
+ sg_gzifstream in( p );
if (!in.is_open()) {
return string();
}
}
private:
- SGPath getAircraftPaths() {
- string_list pathList = globals->get_aircraft_paths();
- SGPath aircraftPaths;
- string_list::const_iterator it = pathList.begin();
- if (it != pathList.end()) {
- aircraftPaths.set(*it);
- it++;
- }
- for (; it != pathList.end(); ++it) {
- aircraftPaths.add(*it);
+ std::string getAircraftPaths()
+ {
+ return SGPath::join(globals->get_aircraft_paths(), ";");
}
- return aircraftPaths;
- }
bool checkCache()
{
- if (globals->get_fg_root() != _cache->getStringValue("fg-root", "")) {
+ if (globals->get_fg_root().utf8Str() != _cache->getStringValue("fg-root", "")) {
return false; // cache mismatch
}
- if (getAircraftPaths().str() != _cache->getStringValue("fg-aircraft", "")) {
+ if (getAircraftPaths() != _cache->getStringValue("fg-aircraft", "")) {
return false; // cache mismatch
}
bool fgInitHome()
{
SGPath dataPath = SGPath::fromEnv("FG_HOME", platformDefaultDataPath());
- globals->set_fg_home(dataPath.c_str());
+ globals->set_fg_home(dataPath);
simgear::Dir fgHome(dataPath);
if (!fgHome.exists()) {
if (!fgHome.exists()) {
flightgear::fatalMessageBox("Problem setting up user data",
"Unable to create the user-data storage folder at: '"
- + dataPath.str() + "'");
+ + dataPath.utf8Str() + "'");
return false;
}
sim->removeChildren("fg-aircraft");
int index = 0;
- string_list const aircraft_paths = globals->get_aircraft_paths();
- for( string_list::const_iterator it = aircraft_paths.begin();
- it != aircraft_paths.end();
- ++it, ++index )
+ const PathList& aircraft_paths = globals->get_aircraft_paths();
+ for (PathList::const_iterator it = aircraft_paths.begin();
+ it != aircraft_paths.end(); ++it, ++index )
{
SGPropertyNode* n = sim->getChild("fg-aircraft", index, true);
- n->setStringValue(*it);
+ n->setStringValue(it->utf8Str());
n->setAttribute(SGPropertyNode::WRITE, false);
}
}
// General house keeping initializations
bool fgInitGeneral() {
- string root;
SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" );
SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" );
- root = globals->get_fg_root();
- if ( ! root.length() ) {
+ if ( globals->get_fg_root().isNull() ) {
// No root path set? Then bail ...
SG_LOG( SG_GENERAL, SG_ALERT,
"Cannot continue without a path to the base package "
<< "being defined." );
return false;
}
- SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
+ SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << globals->get_fg_root() << '"' << endl );
// Note: browser command is hard-coded for Mac/Windows, so this only affects other platforms
globals->set_browser(fgGetString("/sim/startup/browser-app", WEB_BROWSER));
SG_LOG( SG_GENERAL, SG_INFO, "download-dir = " << '"' << fgGetString("/sim/paths/download-dir") << '"' );
SG_LOG( SG_GENERAL, SG_INFO, "terrasync-dir = " << '"' << fgGetString("/sim/terrasync/scenery-dir") << '"' );
- SG_LOG( SG_GENERAL, SG_INFO, "aircraft-search-paths = \n\t" << simgear::strutils::join(globals->get_aircraft_paths(), "\n\t") );
- SG_LOG( SG_GENERAL, SG_INFO, "scenery-search-paths = \n\t" << simgear::strutils::join(globals->get_fg_scenery(), "\n\t") );
+ SG_LOG( SG_GENERAL, SG_INFO, "aircraft-search-paths = \n\t" << SGPath::join(globals->get_aircraft_paths(), "\n\t") );
+ SG_LOG( SG_GENERAL, SG_INFO, "scenery-search-paths = \n\t" << SGPath::join(globals->get_fg_scenery(), "\n\t") );
}
// This is the top level init routine which calls all the other
SGPath mpath( globals->get_fg_root() );
mpath.append( fgGetString("/sim/rendering/materials-file") );
- if ( ! globals->get_matlib()->load(globals->get_fg_root(), mpath.str(),
+ if ( ! globals->get_matlib()->load(globals->get_fg_root().local8BitStr(), mpath.str(),
globals->get_props()) ) {
throw sg_io_exception("Error loading materials file", mpath);
}
// try each aircraft dir in turn
std::string res(aResource, 9); // resource path with 'Aircraft/' removed
- const string_list& dirs(globals->get_aircraft_paths());
- string_list::const_iterator it = dirs.begin();
+ const PathList& dirs(globals->get_aircraft_paths());
+ PathList::const_iterator it = dirs.begin();
for (; it != dirs.end(); ++it) {
- SGPath p(*it, res);
+ SGPath p(*it);
+ p.append(res);
if (p.exists()) {
return p;
}
virtual SGPath resolve(const std::string& aResource, SGPath&) const
{
- const char* aircraftDir = fgGetString("/sim/aircraft-dir");
- SGPath p(aircraftDir);
+ SGPath p = SGPath::fromUtf8(fgGetString("/sim/aircraft-dir"));
p.append(aResource);
return p.exists() ? p : SGPath();
}
}
// set the fg_root path
-void FGGlobals::set_fg_root (const std::string &root) {
+void FGGlobals::set_fg_root (const SGPath &root) {
SGPath tmp(root);
fg_root = tmp.realpath();
tmp.append( "data" );
tmp.append( "version" );
if ( tmp.exists() ) {
- fgGetNode("BAD_FG_ROOT", true)->setStringValue(fg_root);
- fg_root += "/data";
- fgGetNode("GOOD_FG_ROOT", true)->setStringValue(fg_root);
+ fgGetNode("BAD_FG_ROOT", true)->setStringValue(fg_root.utf8Str());
+ fg_root.append("data");
+ fgGetNode("GOOD_FG_ROOT", true)->setStringValue(fg_root.utf8Str());
SG_LOG(SG_GENERAL, SG_ALERT, "***\n***\n*** Warning: changing bad FG_ROOT/--fg-root to '"
<< fg_root << "'\n***\n***");
}
SGPropertyNode *n = fgGetNode("/sim", true);
n->removeChild("fg-root", 0);
n = n->getChild("fg-root", 0, true);
- n->setStringValue(fg_root.c_str());
+ n->setStringValue(fg_root.utf8Str());
n->setAttribute(SGPropertyNode::WRITE, false);
simgear::ResourceManager::instance()->addBasePath(fg_root,
}
// set the fg_home path
-void FGGlobals::set_fg_home (const std::string &home) {
- SGPath tmp(home);
- fg_home = tmp.realpath();
+void FGGlobals::set_fg_home (const SGPath &home)
+{
+ fg_home = home.realpath();
}
PathList FGGlobals::get_data_paths() const
{
PathList r(additional_data_paths);
- r.push_back(SGPath(fg_root));
+ r.push_back(fg_root);
return r;
}
return SGPath();
}
-void FGGlobals::append_fg_scenery (const std::string &paths, bool secure)
+void FGGlobals::append_fg_scenery (const PathList &paths, bool secure)
+{
+ BOOST_FOREACH(const SGPath& path, paths) {
+ append_fg_scenery(path);
+ }
+}
+
+void FGGlobals::append_fg_scenery (const SGPath &path, bool secure)
{
SGPropertyNode* sim = fgGetNode("/sim", true);
- // find first unused fg-scenery property in /sim
+ // find first unused fg-scenery property in /sim
int propIndex = 0;
while (sim->getChild("fg-scenery", propIndex) != NULL) {
- ++propIndex;
+ ++propIndex;
}
- BOOST_FOREACH(const SGPath& path, sgPathSplit( paths )) {
- SGPath abspath(path.realpath());
- if (!abspath.exists()) {
- SG_LOG(SG_GENERAL, SG_WARN, "scenery path not found:" << abspath.str());
- continue;
- }
-
- // check for duplicates
- string_list::const_iterator ex = std::find(fg_scenery.begin(), fg_scenery.end(), abspath.str());
- if (ex != fg_scenery.end()) {
- SG_LOG(SG_GENERAL, SG_INFO, "skipping duplicate add of scenery path:" << abspath.str());
- continue;
- }
+ SGPath abspath(path.realpath());
+ if (!abspath.exists()) {
+ SG_LOG(SG_GENERAL, SG_WARN, "scenery path not found:" << abspath);
+ return;
+ }
- // tell the ResouceManager about the scenery path
- // needed to load Models from this scenery path
- simgear::ResourceManager::instance()->addBasePath(abspath.str(),
- simgear::ResourceManager::PRIORITY_DEFAULT);
-
- simgear::Dir dir(abspath);
- SGPath terrainDir(dir.file("Terrain"));
- SGPath objectsDir(dir.file("Objects"));
-
- // this code used to add *either* the base dir, OR add the
- // Terrain and Objects subdirs, but the conditional logic was commented
- // out, such that all three dirs are added. Unfortunately there's
- // no information as to why the change was made.
- fg_scenery.push_back(abspath.str());
- if (secure) {
- secure_fg_scenery.push_back(abspath.str());
- }
+ // check for duplicates
+ PathList::const_iterator ex = std::find(fg_scenery.begin(), fg_scenery.end(), abspath);
+ if (ex != fg_scenery.end()) {
+ SG_LOG(SG_GENERAL, SG_INFO, "skipping duplicate add of scenery path:" << abspath);
+ return;
+ }
- if (terrainDir.exists()) {
- fg_scenery.push_back(terrainDir.str());
- }
+ // tell the ResouceManager about the scenery path
+ // needed to load Models from this scenery path
+ simgear::ResourceManager::instance()->addBasePath(abspath.str(),
+ simgear::ResourceManager::PRIORITY_DEFAULT);
+
+ simgear::Dir dir(abspath);
+ SGPath terrainDir(dir.file("Terrain"));
+ SGPath objectsDir(dir.file("Objects"));
+
+ // this code used to add *either* the base dir, OR add the
+ // Terrain and Objects subdirs, but the conditional logic was commented
+ // out, such that all three dirs are added. Unfortunately there's
+ // no information as to why the change was made.
+ fg_scenery.push_back(abspath);
+ if (secure) {
+ secure_fg_scenery.push_back(abspath);
+ }
- if (objectsDir.exists()) {
- fg_scenery.push_back(objectsDir.str());
- }
+ if (terrainDir.exists()) {
+ fg_scenery.push_back(terrainDir);
+ }
- // insert a marker for FGTileEntry::load(), so that
- // FG_SCENERY=A:B becomes list ["A/Terrain", "A/Objects", "",
- // "B/Terrain", "B/Objects", ""]
- fg_scenery.push_back("");
+ if (objectsDir.exists()) {
+ fg_scenery.push_back(objectsDir);
+ }
- // make scenery dirs available to Nasal
- SGPropertyNode* n = sim->getChild("fg-scenery", propIndex++, true);
- n->setStringValue(abspath.str());
- n->setAttribute(SGPropertyNode::WRITE, false);
+ // insert a marker for FGTileEntry::load(), so that
+ // FG_SCENERY=A:B becomes list ["A/Terrain", "A/Objects", "",
+ // "B/Terrain", "B/Objects", ""]
+ fg_scenery.push_back(SGPath());
- // temporary fix so these values survive reset
- n->setAttribute(SGPropertyNode::PRESERVE, true);
- } // of path list iteration
+ // make scenery dirs available to Nasal
+ SGPropertyNode* n = sim->getChild("fg-scenery", propIndex++, true);
+ n->setStringValue(abspath.utf8Str());
+ n->setAttribute(SGPropertyNode::WRITE, false);
+
+ // temporary fix so these values survive reset
+ n->setAttribute(SGPropertyNode::PRESERVE, true);
}
void FGGlobals::clear_fg_scenery()
catalog_aircraft_dir = path;
}
-string_list FGGlobals::get_aircraft_paths() const
+PathList FGGlobals::get_aircraft_paths() const
{
- string_list r;
+ PathList r;
if (!catalog_aircraft_dir.isNull()) {
- r.push_back(catalog_aircraft_dir.str());
+ r.push_back(catalog_aircraft_dir);
}
r.insert(r.end(), fg_aircraft_dirs.begin(), fg_aircraft_dirs.end());
return r;
}
-void FGGlobals::append_aircraft_path(const std::string& path)
+void FGGlobals::append_aircraft_path(const SGPath& path)
{
SGPath dirPath(path);
if (!dirPath.exists()) {
dirPath = acSubdir;
}
- std::string abspath = dirPath.realpath();
- fg_aircraft_dirs.push_back(abspath);
+ fg_aircraft_dirs.push_back(dirPath.realpath());
}
-void FGGlobals::append_aircraft_paths(const std::string& path)
+void FGGlobals::append_aircraft_paths(const PathList& paths)
{
- string_list paths = sgPathSplit(path);
for (unsigned int p = 0; p<paths.size(); ++p) {
append_aircraft_path(paths[p]);
}
double sim_time_sec;
// Root of FlightGear data tree
- std::string fg_root;
+ SGPath fg_root;
/**
* locations to search for (non-scenery) data.
PathList additional_data_paths;
// Users home directory for data
- std::string fg_home;
+ SGPath fg_home;
// Roots of FlightGear scenery tree
- string_list fg_scenery;
- string_list secure_fg_scenery;
+ PathList fg_scenery;
+ PathList secure_fg_scenery;
std::string browser;
FGTACANList *channellist;
/// roots of Aircraft trees
- string_list fg_aircraft_dirs;
+ PathList fg_aircraft_dirs;
SGPath catalog_aircraft_dir;
bool haveUserSettings;
inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
inline void set_sim_time_sec (double t) { sim_time_sec = t; }
- inline const std::string &get_fg_root () const { return fg_root; }
- void set_fg_root (const std::string &root);
+ const SGPath &get_fg_root () const { return fg_root; }
+ void set_fg_root (const SGPath&root);
/**
* Get list of data locations. fg_root is always the final item in the
*/
SGPath find_data_dir(const std::string& pathSuffix) const;
- inline const std::string &get_fg_home () const { return fg_home; }
- void set_fg_home (const std::string &home);
+ const SGPath &get_fg_home () const { return fg_home; }
+ void set_fg_home (const SGPath &home);
- inline const string_list &get_fg_scenery () const { return fg_scenery; }
- inline const string_list &get_secure_fg_scenery () const { return secure_fg_scenery; }
+ const PathList &get_fg_scenery () const { return fg_scenery; }
+ const PathList &get_secure_fg_scenery () const { return secure_fg_scenery; }
/**
* Add a scenery directory
*
* obtained from the property tree (e.g. /sim/terrasync/scenery-dir)
* or other Nasal-writable places
*/
- void append_fg_scenery (const std::string &scenery, bool secure = false);
+ void append_fg_scenery (const SGPath &scenery, bool secure = false);
+ void append_fg_scenery (const PathList &scenery, bool secure = false);
+
void clear_fg_scenery();
/**
*/
void set_catalog_aircraft_path(const SGPath& path);
- string_list get_aircraft_paths() const;
+ PathList get_aircraft_paths() const;
- void append_aircraft_path(const std::string& path);
- void append_aircraft_paths(const std::string& path);
+ void append_aircraft_path(const SGPath& path);
+ void append_aircraft_paths(const PathList& path);
/**
* Given a path to an aircraft-related resource file, resolve it
flightgear::initPosition();
flightgear::initTowerLocationListener();
- simgear::SGModelLib::init(globals->get_fg_root(), globals->get_props());
+ simgear::SGModelLib::init(globals->get_fg_root().local8BitStr(), globals->get_props());
TimeManager* timeManager = (TimeManager*) globals->get_subsystem("time");
timeManager->init();
static int
fgOptFgScenery( const char *arg )
{
- globals->append_fg_scenery(arg, true);
+ globals->append_fg_scenery(SGPath::pathsFromLocal8Bit(arg), true);
return FG_OPTIONS_OK;
}
static int
fgOptTerrasyncDir( const char *arg )
{
- globals->append_fg_scenery(arg, true);
- fgSetString("/sim/terrasync/scenery-dir", arg);
+ SGPath p = SGPath::fromLocal8Bit(arg);
+ globals->append_fg_scenery(p, true);
+ fgSetString("/sim/terrasync/scenery-dir", p.utf8Str());
return FG_OPTIONS_OK;
}
cerr << "FG_SCENERY=";
int didsome = 0;
- string_list scn = globals->get_fg_scenery();
- for (string_list::const_iterator it = scn.begin(); it != scn.end(); it++)
+ PathList scn = globals->get_fg_scenery();
+ for (PathList::const_iterator it = scn.begin(); it != scn.end(); it++)
{
if (didsome) cerr << ":";
didsome++;
// fg-root/fg-home/fg-aircraft and hence control what files Nasal can access
std::string name_for_error = homedir.empty() ? appDataConfig.str() : config.str();
if( ! hostname.empty() ) {
- config.set(globals->get_fg_root());
+ config = globals->get_fg_root();
config.append( "system.fgfsrc" );
config.concat( "." );
config.concat( hostname );
}
}
- config.set(globals->get_fg_root());
+ config = globals->get_fg_root();
config.append( "system.fgfsrc" );
if (config.exists()) {
flightgear::fatalMessageBox("Unsupported configuration",
void Options::initPaths()
{
- BOOST_FOREACH(const string& paths, valuesForOption("fg-aircraft")) {
+ BOOST_FOREACH(const string& pathOpt, valuesForOption("fg-aircraft")) {
+ PathList paths = SGPath::pathsFromLocal8Bit(pathOpt);
globals->append_aircraft_paths(paths);
}
const char* envp = ::getenv("FG_AIRCRAFT");
if (envp) {
- globals->append_aircraft_paths(envp);
+ globals->append_aircraft_paths(SGPath::pathsFromEnv("FG_AIRCRAFT"));
}
}
}
if (p->showAircraft) {
- vector<SGPath> path_list;
+ PathList path_list;
fgOptLogLevel( "alert" );
// First place to check is the 'Aircraft' sub-directory in $FG_ROOT
- path_list.push_back( SGPath( globals->get_fg_root() ) );
- path_list.back().append("Aircraft");
+ SGPath rootAircraft = globals->get_fg_root();
+ rootAircraft.append("Aircraft");
+ path_list.push_back(rootAircraft);
// Additionally, aircraft may also be found in user-defined places
// (via $FG_AIRCRAFT or with the '--fg-aircraft' option)
+ PathList aircraft_paths = globals->get_aircraft_paths();
- string_list aircraft_paths = globals->get_aircraft_paths();
- for (string_list::iterator it = aircraft_paths.begin();
- it != aircraft_paths.end(); ++it)
- path_list.push_back( SGPath(*it));
+ path_list.insert(path_list.end(), aircraft_paths.begin(),
+ aircraft_paths.end());
fgShowAircraft(path_list);
exit(0);
// now options are process, do supplemental fixup
const char *envp = ::getenv( "FG_SCENERY" );
if (envp) {
- globals->append_fg_scenery(envp, true);
+ globals->append_fg_scenery(SGPath::pathsFromEnv("FG_SCENERY"), true);
}
// download dir fix-up
// always add the terrasync location, regardless of whether terrasync
// is enabled or not. This allows us to toggle terrasync on/off at
// runtime and have things work as expected
- const string_list& scenery_paths(globals->get_fg_scenery());
- if (std::find(scenery_paths.begin(), scenery_paths.end(), terrasyncDir) == scenery_paths.end()) {
+ const PathList& scenery_paths(globals->get_fg_scenery());
+ if (std::find(scenery_paths.begin(), scenery_paths.end(), SGPath(terrasyncDir)) == scenery_paths.end()) {
// terrasync dir is not in the scenery paths, add it
- globals->append_fg_scenery(terrasyncDir);
+ globals->append_fg_scenery(SGPath(terrasyncDir));
}
if (addFGDataScenery) {
// ensure this path is added last
SGPath root(globals->get_fg_root());
root.append("Scenery");
- globals->append_fg_scenery(root.str());
+ globals->append_fg_scenery(root);
}
return FG_OPTIONS_OK;
}
#if defined(__CYGWIN__)
-string Options::platformDefaultRoot() const
+SGPath Options::platformDefaultRoot() const
{
return "../data";
}
#elif defined(SG_WINDOWS)
-string Options::platformDefaultRoot() const
+SGPath Options::platformDefaultRoot() const
{
return "..\\data";
}
#elif defined(SG_MAC)
// platformDefaultRoot defined in CocoaHelpers.mm
#else
-string Options::platformDefaultRoot() const
+SGPath Options::platformDefaultRoot() const
{
return PKGLIBDIR;
}
void Options::setupRoot(int argc, char **argv)
{
- string root;
+ SGPath root;
bool usingDefaultRoot = false;
if (isOptionSet("fg-root")) {
- root = valueForOption("fg-root"); // easy!
- SG_LOG(SG_GENERAL, SG_INFO, "set from command-line argument: fg_root = " << root );
+ root = SGPath::fromLocal8Bit(valueForOption("fg-root").c_str()); // easy!
+ SG_LOG(SG_GENERAL, SG_INFO, "set from command-line argument: fg_root = " << root );
} else {
// Next check if fg-root is set as an env variable
char *envp = ::getenv( "FG_ROOT" );
if ( envp != NULL ) {
- root = envp;
- SG_LOG(SG_GENERAL, SG_INFO, "set from FG_ROOT env var: fg_root = " << root );
+ root = SGPath::fromLocal8Bit(envp);
+ SG_LOG(SG_GENERAL, SG_INFO, "set from FG_ROOT env var: fg_root = " << root );
} else {
#if defined(HAVE_QT)
flightgear::initApp(argc, argv);
root = SetupRootDialog::restoreUserSelectedRoot();
#endif
- if (root.empty()) {
+ if (root.isNull()) {
usingDefaultRoot = true;
root = platformDefaultRoot();
SG_LOG(SG_GENERAL, SG_INFO, "platform default fg_root = " << root );
*/
static bool checkForArg(int argc, char* argv[], const char* arg);
- std::string platformDefaultRoot() const;
+ SGPath platformDefaultRoot() const;
private:
void showUsage() const;
}
read_allowed_paths.clear();
write_allowed_paths.clear();
- std::string fg_root = SGPath(globals->get_fg_root()).realpath();
- std::string fg_home = SGPath(globals->get_fg_home()).realpath();
+ std::string fg_root = globals->get_fg_root().realpath();
+ std::string fg_home = globals->get_fg_home().realpath();
#if defined(_MSC_VER) /*for MS compilers */ || defined(_WIN32) /*needed for non MS windows compilers like MingW*/
std::string sep = "\\";
#else
read_allowed_paths.push_back(fg_home + sep + "*");
read_allowed_paths.push_back(fg_root);
read_allowed_paths.push_back(fg_home);
- string_list const aircraft_paths = globals->get_aircraft_paths();
- string_list const scenery_paths = globals->get_secure_fg_scenery();
+
+ const PathList& aircraft_paths = globals->get_aircraft_paths();
+ const PathList& scenery_paths = globals->get_secure_fg_scenery();
// not plain fg_scenery, to avoid making
// /sim/terrasync/scenery-dir a security hole
+ PathList read_paths = aircraft_paths;
+ read_paths.insert(read_paths.end(), scenery_paths.begin(), scenery_paths.end());
- const string_list * path_lists_to_add[] = {
- &aircraft_paths,
- &scenery_paths
- };
- for( size_t i = 0; i < sizeof(path_lists_to_add)/sizeof(path_lists_to_add[0]); i++ )
- {
- for( string_list::const_iterator it = path_lists_to_add[i]->begin(); it != path_lists_to_add[i]->end();++it )
+ for( PathList::const_iterator it = read_paths.begin(); it != read_paths.end(); ++it )
{
// if we get the initialization order wrong, better to have an
// obvious error than a can-read-everything security hole...
- if (it->empty() || fg_root.empty() || fg_home.empty()){
+ if (it->isNull() || fg_root.empty() || fg_home.empty()) {
flightgear::fatalMessageBox("Nasal initialization error",
"Empty string in FG_ROOT, FG_HOME, FG_AIRCRAFT or FG_SCENERY",
"or fgInitAllowedPaths() called too early");
exit(-1);
}
- read_allowed_paths.push_back(SGPath(*it).realpath() + sep + "*");
- read_allowed_paths.push_back(SGPath(*it).realpath());
+ read_allowed_paths.push_back(it->realpath() + sep + "*");
+ read_allowed_paths.push_back(it->realpath());
}
- }
write_allowed_paths.push_back(fg_home + sep + "*.sav");
write_allowed_paths.push_back(fg_home + sep + "*.log");
write_allowed_paths.push_back(fg_home + sep + "Input" + sep + "Joysticks" + sep + "*.xml");
// Check that it works
- if(!fgValidatePath(globals->get_fg_home() + "/../no.log",true).empty() ||
- !fgValidatePath(globals->get_fg_home() + "/no.logt",true).empty() ||
- !fgValidatePath(globals->get_fg_home() + "/nolog",true).empty() ||
- !fgValidatePath(globals->get_fg_home() + "no.log",true).empty() ||
- !fgValidatePath(globals->get_fg_home() + "\\..\\no.log",false).empty() ||
- fgValidatePath(globals->get_fg_home() + "/aircraft-data/yes..xml",true).empty() ||
- fgValidatePath(globals->get_fg_root() + "/.\\yes.bmp",false).empty()) {
+ std::string homePath = globals->get_fg_home().utf8Str();
+ if(!fgValidatePath(homePath + "/../no.log",true).empty() ||
+ !fgValidatePath(homePath + "/no.logt",true).empty() ||
+ !fgValidatePath(homePath + "/nolog",true).empty() ||
+ !fgValidatePath(homePath + "no.log",true).empty() ||
+ !fgValidatePath(homePath + "\\..\\no.log",false).empty() ||
+ fgValidatePath(homePath + "/aircraft-data/yes..xml",true).empty() ||
+ fgValidatePath(homePath + "/.\\yes.bmp",false).empty()) {
flightgear::fatalMessageBox("Nasal initialization error",
"The FG_HOME directory must not be inside any of the FG_ROOT, FG_AIRCRAFT or FG_SCENERY directories",
"(check that you have not accidentally included an extra :, as an empty part means the current directory)");
d->flushDeferredOctreeUpdates();
- string sceneryPaths = simgear::strutils::join(globals->get_fg_scenery(), ";");
+ string sceneryPaths = SGPath::join(globals->get_fg_scenery(), ";");
writeStringProperty("scenery_paths", sceneryPaths);
st.stamp();
_options->setPropertyNode(globals->get_props());
osgDB::FilePathList &fp = _options->getDatabasePathList();
- const string_list &sc = globals->get_fg_scenery();
+ const PathList &sc = globals->get_fg_scenery();
fp.clear();
- std::copy(sc.begin(), sc.end(), back_inserter(fp));
- _options->setPluginStringData("SimGear::FG_ROOT", globals->get_fg_root());
+ PathList::const_iterator it;
+ for (it = sc.begin(); it != sc.end(); ++it) {
+ fp.push_back(it->local8BitStr());
+ }
+ _options->setPluginStringData("SimGear::FG_ROOT", globals->get_fg_root().local8BitStr());
if (_terra_sync) {
_options->setPluginStringData("SimGear::TERRASYNC_ROOT", fgGetString("/sim/terrasync/scenery-dir"));
string FLITEVoiceSynthesizer::getVoicePath( voice_t voice )
{
if( voice < 0 || voice >= VOICE_UNKNOWN ) return string("");
- string voicePath = globals->get_fg_root() + "/ATC/" + VOICE_FILES[voice];
- return voicePath;
+ SGPath voicePath = globals->get_fg_root() / "ATC" / VOICE_FILES[voice];
+ return voicePath.local8BitStr();
}
string FLITEVoiceSynthesizer::getVoicePath( const string & voice )
_sampleName = node->getStringValue("desc", node->getPath().c_str());
- string voice = globals->get_fg_root() + "/ATC/" +
+ SGPath voice = globals->get_fg_root() / "ATC" /
node->getStringValue("htsvoice", "cmu_us_arctic_slt.htsvoice");
- _synthesizer = new FLITEVoiceSynthesizer(voice.c_str());
+ _synthesizer = new FLITEVoiceSynthesizer(voice.local8BitStr());
SGSoundMgr *smgr = globals->get_subsystem<SGSoundMgr>();
_sgr = smgr->find(sampleGroupRefName, true);
}
// check aircraft dirs
- BOOST_FOREACH(std::string aircraftPath, globals->get_aircraft_paths()) {
- SGPath mp(aircraftPath);
- mp.append(modelPath);
+ BOOST_FOREACH(SGPath aircraftPath, globals->get_aircraft_paths()) {
+ SGPath mp = aircraftPath / modelPath;
if (mp.exists()) {
return mp;
}
simgear::PathList dirs = globals->get_data_paths("AI/Traffic");
// temporary flag to restrict loading while traffic data is found
- // through terrasync /and/ fgdata. Ultimatley we *do* want to be able to
+ // through terrasync /and/ fgdata. Ultimately we *do* want to be able to
// overlay sources.
if (dirs.size() > 1) {
SGPath p = dirs.back();
- if (simgear::strutils::starts_with(p.str(), globals->get_fg_root())) {
+ if (simgear::strutils::starts_with(p.utf8Str(),
+ globals->get_fg_root().utf8Str()))
+ {
dirs.pop_back();
}
}
osgDB::FilePathList filePathList
= osgDB::Registry::instance()->getDataFilePathList();
- filePathList.push_back(globals->get_fg_root());
+ filePathList.push_back(globals->get_fg_root().local8BitStr());
- string_list path_list = globals->get_fg_scenery();
+ const PathList& path_list = globals->get_fg_scenery();
for (unsigned i = 0; i < path_list.size(); ++i) {
- filePathList.push_back(path_list[i]);
+ filePathList.push_back(path_list[i].local8BitStr());
}
globals->set_matlib( new SGMaterialLib );
- simgear::SGModelLib::init(globals->get_fg_root(), globals->get_props());
+ simgear::SGModelLib::init(globals->get_fg_root().local8BitStr(), globals->get_props());
// Initialize the material property subsystem.
SGPath mpath( globals->get_fg_root() );
mpath.append( fgGetString("/sim/rendering/materials-file") );
- if ( ! globals->get_matlib()->load(globals->get_fg_root(), mpath.str(),
+ if ( ! globals->get_matlib()->load(globals->get_fg_root().local8BitStr(), mpath.str(),
globals->get_props()) ) {
throw sg_io_exception("Error loading materials file", mpath);
}
g->setUseDisplayList(false);
simgear::EffectGeode* eg = new simgear::EffectGeode;
osg::ref_ptr<SGReaderWriterOptions> opt;
- opt = SGReaderWriterOptions::fromPath(globals->get_fg_root());
+ opt = SGReaderWriterOptions::fromPath(globals->get_fg_root().local8BitStr());
opt->setPropertyNode(globals->get_props());
simgear::Effect* effect = simgear::makeEffect(pass->effect, true, opt.get());
if (effect) {
g->setUseDisplayList(false); //DEBUG
simgear::EffectGeode* eg = new simgear::EffectGeode;
osg::ref_ptr<SGReaderWriterOptions> opt;
- opt = SGReaderWriterOptions::fromPath(globals->get_fg_root());
+ opt = SGReaderWriterOptions::fromPath(globals->get_fg_root().local8BitStr());
opt->setPropertyNode(globals->get_props());
simgear::Effect* effect = simgear::makeEffect(stage->effect, true, opt.get());
if (!effect) {
// Moon diameter: 3,476 kilometers
// Sun diameter: 1,390,000 kilometers
osg::ref_ptr<SGReaderWriterOptions> opt;
- opt = SGReaderWriterOptions::fromPath(globals->get_fg_root());
+ opt = SGReaderWriterOptions::fromPath(globals->get_fg_root().local8BitStr());
opt->setPropertyNode(globals->get_props());
_sky->build( 80000.0, 80000.0,
463.3, 361.8,
// define default location of fgdata (use the same as for fgfs)
#if defined(__CYGWIN__)
-inline static string platformDefaultRoot()
+inline static SGPath platformDefaultRoot()
{
- return "../data";
+ return SGPath("../data");
}
#elif defined(_WIN32)
-inline static string platformDefaultRoot()
+inline static SGPath platformDefaultRoot()
{
- return "..\\data";
+ return SGPath("..\\data");
}
#elif defined(__APPLE__)
-inline static string platformDefaultRoot()
+inline static SGPath platformDefaultRoot()
{
/*
The following code looks for the base package inside the application
CFRelease(dataDir);
CFRelease(path);
- return root;
+ return SGPath(root);
}
#else
-inline static string platformDefaultRoot()
+inline static SGPath platformDefaultRoot()
{
- return PKGLIBDIR;
+ return SGPath(PKGLIBDIR);
}
#endif
FGCroppedTexture::registerTextureLoader( "png", &pngTextureLoader );
FGCroppedTexture::registerTextureLoader( "rgb", &rgbTextureLoader );
- ApplicationProperties::root = platformDefaultRoot();
+ ApplicationProperties::root = platformDefaultRoot().local8BitStr();
string panelFilename;
string fgRoot;