1
0
Fork 0

Use Paths instead of strings.

This commit is contained in:
James Turner 2016-06-21 12:29:04 +01:00
parent 03ecac9dbc
commit 16814800ce
26 changed files with 223 additions and 227 deletions

View file

@ -75,15 +75,15 @@ bool XMLLoader::findAirportData(const std::string& aICAO,
fileName.append(".xml"); fileName.append(".xml");
} }
string_list sc = globals->get_fg_scenery(); PathList sc = globals->get_fg_scenery();
char buffer[128]; char buffer[128];
::snprintf(buffer, 128, "%c/%c/%c/%s.%s", ::snprintf(buffer, 128, "%c/%c/%c/%s.%s",
aICAO[0], aICAO[1], aICAO[2], aICAO[0], aICAO[1], aICAO[2],
aICAO.c_str(), fileName.c_str()); 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) // fg_senery contains empty strings as "markers" (see FGGlobals::set_fg_scenery)
if (!it->empty()) { if (!it->isNull()) {
SGPath path(*it); SGPath path(*it);
path.append("Airports"); path.append("Airports");
path.append(string(buffer)); path.append(string(buffer));

View file

@ -516,8 +516,8 @@ void AircraftItemModel::scanDirs()
QStringList dirs = m_paths; QStringList dirs = m_paths;
Q_FOREACH(std::string ap, globals->get_aircraft_paths()) { Q_FOREACH(SGPath ap, globals->get_aircraft_paths()) {
dirs << QString::fromStdString(ap); dirs << QString::fromStdString(ap.utf8Str());
} }
SGPath rootAircraft(globals->get_fg_root()); SGPath rootAircraft(globals->get_fg_root());

View file

@ -133,14 +133,14 @@ SGPath platformDefaultDataPath()
namespace flightgear namespace flightgear
{ {
std::string Options::platformDefaultRoot() const SGPath Options::platformDefaultRoot() const
{ {
CocoaAutoreleasePool ap; CocoaAutoreleasePool ap;
NSURL* url = [[NSBundle mainBundle] resourceURL]; NSURL* url = [[NSBundle mainBundle] resourceURL];
SGPath dataDir(URLToPath(url)); SGPath dataDir(URLToPath(url));
dataDir.append("data"); dataDir.append("data");
return dataDir.str(); return dataDir;
} }
} // of namespace flightgear } // of namespace flightgear

View file

@ -177,9 +177,9 @@ void FGFontCache::init()
if (!_initialized) { if (!_initialized) {
char *envp = ::getenv("FG_FONTS"); char *envp = ::getenv("FG_FONTS");
if (envp != NULL) { if (envp != NULL) {
_path.set(envp); _path = SGPath::fromEnv("FG_FONTS");
} else { } else {
_path.set(globals->get_fg_root()); _path = globals->get_fg_root();
_path.append("Fonts"); _path.append("Fonts");
} }
_initialized = true; _initialized = true;

View file

@ -386,7 +386,7 @@ void initApp(int& argc, char** argv)
QSettings::setDefaultFormat(QSettings::IniFormat); QSettings::setDefaultFormat(QSettings::IniFormat);
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, 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: // reset numeric / collation locales as described at:
// http://doc.qt.io/qt-5/qcoreapplication.html#details // http://doc.qt.io/qt-5/qcoreapplication.html#details
@ -655,7 +655,7 @@ void QtLauncher::setSceneryPaths()
SGPath terraSyncDir(downloadDir.toStdString()); SGPath terraSyncDir(downloadDir.toStdString());
terraSyncDir.append("TerraSync"); terraSyncDir.append("TerraSync");
if (terraSyncDir.exists()) { if (terraSyncDir.exists()) {
globals->append_fg_scenery(terraSyncDir.utf8Str()); globals->append_fg_scenery(terraSyncDir);
} }
} }

View file

@ -90,7 +90,7 @@ bool SetupRootDialog::runDialog(PromptState prompt)
return true; return true;
} }
std::string SetupRootDialog::restoreUserSelectedRoot() SGPath SetupRootDialog::restoreUserSelectedRoot()
{ {
QSettings settings; QSettings settings;
QString path = settings.value("fg-root").toString(); QString path = settings.value("fg-root").toString();
@ -153,8 +153,8 @@ bool SetupRootDialog::validateVersion(QString path)
bool SetupRootDialog::defaultRootAcceptable() bool SetupRootDialog::defaultRootAcceptable()
{ {
std::string r = flightgear::Options::sharedInstance()->platformDefaultRoot(); SGPath r = flightgear::Options::sharedInstance()->platformDefaultRoot();
QString defaultRoot = QString::fromStdString(r); QString defaultRoot = QString::fromStdString(r.utf8Str());
return validatePath(defaultRoot) && validateVersion(defaultRoot); return validatePath(defaultRoot) && validateVersion(defaultRoot);
} }
@ -200,8 +200,8 @@ void SetupRootDialog::onDownload()
void SetupRootDialog::onUseDefaults() void SetupRootDialog::onUseDefaults()
{ {
std::string r = flightgear::Options::sharedInstance()->platformDefaultRoot(); SGPath r = flightgear::Options::sharedInstance()->platformDefaultRoot();
m_browsedPath = QString::fromStdString(r); m_browsedPath = QString::fromStdString(r.utf8Str());
globals->set_fg_root(r); globals->set_fg_root(r);
QSettings settings; QSettings settings;
settings.remove("fg-root"); // remove any setting settings.remove("fg-root"); // remove any setting
@ -211,7 +211,7 @@ void SetupRootDialog::onUseDefaults()
void SetupRootDialog::updatePromptText() void SetupRootDialog::updatePromptText()
{ {
QString t; QString t;
QString curRoot = QString::fromStdString(globals->get_fg_root()); QString curRoot = QString::fromStdString(globals->get_fg_root().utf8Str());
switch (m_promptState) { switch (m_promptState) {
case DefaultPathCheckFailed: case DefaultPathCheckFailed:
t = tr("This copy of FlightGear does not include the base data files. " \ t = tr("This copy of FlightGear does not include the base data files. " \

View file

@ -24,6 +24,8 @@
#include <string> #include <string>
#include <simgear/misc/sg_path.hxx>
namespace Ui namespace Ui
{ {
class SetupRootDialog; class SetupRootDialog;
@ -38,7 +40,7 @@ public:
static bool runDialog(bool usingDefaultRoot); static bool runDialog(bool usingDefaultRoot);
static std::string restoreUserSelectedRoot(); static SGPath restoreUserSelectedRoot();
private slots: private slots:
void onBrowse(); void onBrowse();

View file

@ -439,7 +439,7 @@ namespace
{ {
using namespace flightgear; using namespace flightgear;
SGPath nextScreenshotPath(const std::string& screenshotDir) SGPath nextScreenshotPath(const SGPath& screenshotDir)
{ {
char filename[32]; char filename[32];
static int count = 1; static int count = 1;
@ -497,12 +497,11 @@ namespace
fgSetMouseCursor(MOUSE_CURSOR_NONE); fgSetMouseCursor(MOUSE_CURSOR_NONE);
string dir = fgGetString("/sim/paths/screenshot-dir"); SGPath dir = SGPath::fromUtf8(fgGetString("/sim/paths/screenshot-dir"));
if (dir.empty()) if (dir.isNull())
dir = SGPath::desktop().str(); dir = SGPath::desktop();
_path.set(dir + '/'); if (!dir.exists() && dir.create_dir( 0755 )) {
if (_path.create_dir( 0755 )) {
SG_LOG(SG_GENERAL, SG_ALERT, "Cannot create screenshot directory '" SG_LOG(SG_GENERAL, SG_ALERT, "Cannot create screenshot directory '"
<< dir << "'. Trying home directory."); << dir << "'. Trying home directory.");
dir = globals->get_fg_home(); dir = globals->get_fg_home();

View file

@ -43,11 +43,10 @@ protected:
VisitResult visitAircraftPaths() VisitResult visitAircraftPaths()
{ {
const string_list& paths(globals->get_aircraft_paths()); const PathList& paths(globals->get_aircraft_paths());
string_list::const_iterator it = paths.begin(); PathList::const_iterator it = paths.begin();
for (; it != paths.end(); ++it) { for (; it != paths.end(); ++it) {
SGPath p(*it); VisitResult vr = visitDir(*it, 0);
VisitResult vr = visitDir(p, 0);
if (vr != VISIT_CONTINUE) { if (vr != VISIT_CONTINUE) {
return vr; return vr;
} }

View file

@ -538,7 +538,7 @@ do_materials_reload (const SGPropertyNode * arg)
SGMaterialLib* new_matlib = new SGMaterialLib; SGMaterialLib* new_matlib = new SGMaterialLib;
SGPath mpath( globals->get_fg_root() ); SGPath mpath( globals->get_fg_root() );
mpath.append( fgGetString("/sim/rendering/materials-file") ); 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(), mpath.str(),
globals->get_props()); globals->get_props());

View file

@ -172,7 +172,7 @@ string fgBasePackageVersion(const SGPath& base_path) {
return string(); return string();
} }
sg_gzifstream in( p.str() ); sg_gzifstream in( p );
if (!in.is_open()) { if (!in.is_open()) {
return string(); return string();
} }
@ -277,27 +277,18 @@ public:
} }
private: private:
SGPath getAircraftPaths() { std::string getAircraftPaths()
string_list pathList = globals->get_aircraft_paths(); {
SGPath aircraftPaths; return SGPath::join(globals->get_aircraft_paths(), ";");
string_list::const_iterator it = pathList.begin();
if (it != pathList.end()) {
aircraftPaths.set(*it);
it++;
}
for (; it != pathList.end(); ++it) {
aircraftPaths.add(*it);
}
return aircraftPaths;
} }
bool checkCache() 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 return false; // cache mismatch
} }
if (getAircraftPaths().str() != _cache->getStringValue("fg-aircraft", "")) { if (getAircraftPaths() != _cache->getStringValue("fg-aircraft", "")) {
return false; // cache mismatch return false; // cache mismatch
} }
@ -377,7 +368,7 @@ static SGPath platformDefaultDataPath()
bool fgInitHome() bool fgInitHome()
{ {
SGPath dataPath = SGPath::fromEnv("FG_HOME", platformDefaultDataPath()); SGPath dataPath = SGPath::fromEnv("FG_HOME", platformDefaultDataPath());
globals->set_fg_home(dataPath.c_str()); globals->set_fg_home(dataPath);
simgear::Dir fgHome(dataPath); simgear::Dir fgHome(dataPath);
if (!fgHome.exists()) { if (!fgHome.exists()) {
@ -387,7 +378,7 @@ bool fgInitHome()
if (!fgHome.exists()) { if (!fgHome.exists()) {
flightgear::fatalMessageBox("Problem setting up user data", flightgear::fatalMessageBox("Problem setting up user data",
"Unable to create the user-data storage folder at: '" "Unable to create the user-data storage folder at: '"
+ dataPath.str() + "'"); + dataPath.utf8Str() + "'");
return false; return false;
} }
@ -503,13 +494,12 @@ static void initAircraftDirsNasalSecurity()
sim->removeChildren("fg-aircraft"); sim->removeChildren("fg-aircraft");
int index = 0; int index = 0;
string_list const aircraft_paths = globals->get_aircraft_paths(); const PathList& aircraft_paths = globals->get_aircraft_paths();
for( string_list::const_iterator it = aircraft_paths.begin(); for (PathList::const_iterator it = aircraft_paths.begin();
it != aircraft_paths.end(); it != aircraft_paths.end(); ++it, ++index )
++it, ++index )
{ {
SGPropertyNode* n = sim->getChild("fg-aircraft", index, true); SGPropertyNode* n = sim->getChild("fg-aircraft", index, true);
n->setStringValue(*it); n->setStringValue(it->utf8Str());
n->setAttribute(SGPropertyNode::WRITE, false); n->setAttribute(SGPropertyNode::WRITE, false);
} }
} }
@ -638,20 +628,18 @@ fgInitNav ()
// General house keeping initializations // General house keeping initializations
bool fgInitGeneral() { bool fgInitGeneral() {
string root;
SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" ); SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" );
SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" ); SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" );
root = globals->get_fg_root(); if ( globals->get_fg_root().isNull() ) {
if ( ! root.length() ) {
// No root path set? Then bail ... // No root path set? Then bail ...
SG_LOG( SG_GENERAL, SG_ALERT, SG_LOG( SG_GENERAL, SG_ALERT,
"Cannot continue without a path to the base package " "Cannot continue without a path to the base package "
<< "being defined." ); << "being defined." );
return false; 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 // 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)); globals->set_browser(fgGetString("/sim/startup/browser-app", WEB_BROWSER));
@ -683,8 +671,8 @@ void fgOutputSettings()
SG_LOG( SG_GENERAL, SG_INFO, "download-dir = " << '"' << fgGetString("/sim/paths/download-dir") << '"' ); 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, "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, "aircraft-search-paths = \n\t" << SGPath::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, "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 // This is the top level init routine which calls all the other
@ -743,7 +731,7 @@ void fgCreateSubsystems(bool duringReset) {
SGPath mpath( globals->get_fg_root() ); SGPath mpath( globals->get_fg_root() );
mpath.append( fgGetString("/sim/rendering/materials-file") ); 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()) ) { globals->get_props()) ) {
throw sg_io_exception("Error loading materials file", mpath); throw sg_io_exception("Error loading materials file", mpath);
} }

View file

@ -108,10 +108,11 @@ public:
// try each aircraft dir in turn // try each aircraft dir in turn
std::string res(aResource, 9); // resource path with 'Aircraft/' removed std::string res(aResource, 9); // resource path with 'Aircraft/' removed
const string_list& dirs(globals->get_aircraft_paths()); const PathList& dirs(globals->get_aircraft_paths());
string_list::const_iterator it = dirs.begin(); PathList::const_iterator it = dirs.begin();
for (; it != dirs.end(); ++it) { for (; it != dirs.end(); ++it) {
SGPath p(*it, res); SGPath p(*it);
p.append(res);
if (p.exists()) { if (p.exists()) {
return p; return p;
} }
@ -131,8 +132,7 @@ public:
virtual SGPath resolve(const std::string& aResource, SGPath&) const virtual SGPath resolve(const std::string& aResource, SGPath&) const
{ {
const char* aircraftDir = fgGetString("/sim/aircraft-dir"); SGPath p = SGPath::fromUtf8(fgGetString("/sim/aircraft-dir"));
SGPath p(aircraftDir);
p.append(aResource); p.append(aResource);
return p.exists() ? p : SGPath(); return p.exists() ? p : SGPath();
} }
@ -248,7 +248,7 @@ FGGlobals::~FGGlobals()
} }
// set the fg_root path // 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); SGPath tmp(root);
fg_root = tmp.realpath(); fg_root = tmp.realpath();
@ -256,9 +256,9 @@ void FGGlobals::set_fg_root (const std::string &root) {
tmp.append( "data" ); tmp.append( "data" );
tmp.append( "version" ); tmp.append( "version" );
if ( tmp.exists() ) { if ( tmp.exists() ) {
fgGetNode("BAD_FG_ROOT", true)->setStringValue(fg_root); fgGetNode("BAD_FG_ROOT", true)->setStringValue(fg_root.utf8Str());
fg_root += "/data"; fg_root.append("data");
fgGetNode("GOOD_FG_ROOT", true)->setStringValue(fg_root); 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 '" SG_LOG(SG_GENERAL, SG_ALERT, "***\n***\n*** Warning: changing bad FG_ROOT/--fg-root to '"
<< fg_root << "'\n***\n***"); << fg_root << "'\n***\n***");
} }
@ -268,7 +268,7 @@ void FGGlobals::set_fg_root (const std::string &root) {
SGPropertyNode *n = fgGetNode("/sim", true); SGPropertyNode *n = fgGetNode("/sim", true);
n->removeChild("fg-root", 0); n->removeChild("fg-root", 0);
n = n->getChild("fg-root", 0, true); n = n->getChild("fg-root", 0, true);
n->setStringValue(fg_root.c_str()); n->setStringValue(fg_root.utf8Str());
n->setAttribute(SGPropertyNode::WRITE, false); n->setAttribute(SGPropertyNode::WRITE, false);
simgear::ResourceManager::instance()->addBasePath(fg_root, simgear::ResourceManager::instance()->addBasePath(fg_root,
@ -276,15 +276,15 @@ void FGGlobals::set_fg_root (const std::string &root) {
} }
// set the fg_home path // set the fg_home path
void FGGlobals::set_fg_home (const std::string &home) { void FGGlobals::set_fg_home (const SGPath &home)
SGPath tmp(home); {
fg_home = tmp.realpath(); fg_home = home.realpath();
} }
PathList FGGlobals::get_data_paths() const PathList FGGlobals::get_data_paths() const
{ {
PathList r(additional_data_paths); PathList r(additional_data_paths);
r.push_back(SGPath(fg_root)); r.push_back(fg_root);
return r; return r;
} }
@ -329,7 +329,14 @@ SGPath FGGlobals::find_data_dir(const std::string& pathSuffix) const
return SGPath(); 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); SGPropertyNode* sim = fgGetNode("/sim", true);
@ -339,18 +346,17 @@ void FGGlobals::append_fg_scenery (const std::string &paths, bool secure)
++propIndex; ++propIndex;
} }
BOOST_FOREACH(const SGPath& path, sgPathSplit( paths )) {
SGPath abspath(path.realpath()); SGPath abspath(path.realpath());
if (!abspath.exists()) { if (!abspath.exists()) {
SG_LOG(SG_GENERAL, SG_WARN, "scenery path not found:" << abspath.str()); SG_LOG(SG_GENERAL, SG_WARN, "scenery path not found:" << abspath);
continue; return;
} }
// check for duplicates // check for duplicates
string_list::const_iterator ex = std::find(fg_scenery.begin(), fg_scenery.end(), abspath.str()); PathList::const_iterator ex = std::find(fg_scenery.begin(), fg_scenery.end(), abspath);
if (ex != fg_scenery.end()) { if (ex != fg_scenery.end()) {
SG_LOG(SG_GENERAL, SG_INFO, "skipping duplicate add of scenery path:" << abspath.str()); SG_LOG(SG_GENERAL, SG_INFO, "skipping duplicate add of scenery path:" << abspath);
continue; return;
} }
// tell the ResouceManager about the scenery path // tell the ResouceManager about the scenery path
@ -366,32 +372,31 @@ void FGGlobals::append_fg_scenery (const std::string &paths, bool secure)
// Terrain and Objects subdirs, but the conditional logic was commented // Terrain and Objects subdirs, but the conditional logic was commented
// out, such that all three dirs are added. Unfortunately there's // out, such that all three dirs are added. Unfortunately there's
// no information as to why the change was made. // no information as to why the change was made.
fg_scenery.push_back(abspath.str()); fg_scenery.push_back(abspath);
if (secure) { if (secure) {
secure_fg_scenery.push_back(abspath.str()); secure_fg_scenery.push_back(abspath);
} }
if (terrainDir.exists()) { if (terrainDir.exists()) {
fg_scenery.push_back(terrainDir.str()); fg_scenery.push_back(terrainDir);
} }
if (objectsDir.exists()) { if (objectsDir.exists()) {
fg_scenery.push_back(objectsDir.str()); fg_scenery.push_back(objectsDir);
} }
// insert a marker for FGTileEntry::load(), so that // insert a marker for FGTileEntry::load(), so that
// FG_SCENERY=A:B becomes list ["A/Terrain", "A/Objects", "", // FG_SCENERY=A:B becomes list ["A/Terrain", "A/Objects", "",
// "B/Terrain", "B/Objects", ""] // "B/Terrain", "B/Objects", ""]
fg_scenery.push_back(""); fg_scenery.push_back(SGPath());
// make scenery dirs available to Nasal // make scenery dirs available to Nasal
SGPropertyNode* n = sim->getChild("fg-scenery", propIndex++, true); SGPropertyNode* n = sim->getChild("fg-scenery", propIndex++, true);
n->setStringValue(abspath.str()); n->setStringValue(abspath.utf8Str());
n->setAttribute(SGPropertyNode::WRITE, false); n->setAttribute(SGPropertyNode::WRITE, false);
// temporary fix so these values survive reset // temporary fix so these values survive reset
n->setAttribute(SGPropertyNode::PRESERVE, true); n->setAttribute(SGPropertyNode::PRESERVE, true);
} // of path list iteration
} }
void FGGlobals::clear_fg_scenery() void FGGlobals::clear_fg_scenery()
@ -407,18 +412,18 @@ void FGGlobals::set_catalog_aircraft_path(const SGPath& path)
catalog_aircraft_dir = path; 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()) { 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()); r.insert(r.end(), fg_aircraft_dirs.begin(), fg_aircraft_dirs.end());
return r; return r;
} }
void FGGlobals::append_aircraft_path(const std::string& path) void FGGlobals::append_aircraft_path(const SGPath& path)
{ {
SGPath dirPath(path); SGPath dirPath(path);
if (!dirPath.exists()) { if (!dirPath.exists()) {
@ -438,13 +443,11 @@ void FGGlobals::append_aircraft_path(const std::string& path)
dirPath = acSubdir; dirPath = acSubdir;
} }
std::string abspath = dirPath.realpath(); fg_aircraft_dirs.push_back(dirPath.realpath());
fg_aircraft_dirs.push_back(abspath);
} }
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) { for (unsigned int p = 0; p<paths.size(); ++p) {
append_aircraft_path(paths[p]); append_aircraft_path(paths[p]);
} }

View file

@ -95,7 +95,7 @@ private:
double sim_time_sec; double sim_time_sec;
// Root of FlightGear data tree // Root of FlightGear data tree
std::string fg_root; SGPath fg_root;
/** /**
* locations to search for (non-scenery) data. * locations to search for (non-scenery) data.
@ -103,11 +103,11 @@ private:
PathList additional_data_paths; PathList additional_data_paths;
// Users home directory for data // Users home directory for data
std::string fg_home; SGPath fg_home;
// Roots of FlightGear scenery tree // Roots of FlightGear scenery tree
string_list fg_scenery; PathList fg_scenery;
string_list secure_fg_scenery; PathList secure_fg_scenery;
std::string browser; std::string browser;
@ -130,7 +130,7 @@ private:
FGTACANList *channellist; FGTACANList *channellist;
/// roots of Aircraft trees /// roots of Aircraft trees
string_list fg_aircraft_dirs; PathList fg_aircraft_dirs;
SGPath catalog_aircraft_dir; SGPath catalog_aircraft_dir;
bool haveUserSettings; bool haveUserSettings;
@ -191,8 +191,8 @@ public:
inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; } 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 void set_sim_time_sec (double t) { sim_time_sec = t; }
inline const std::string &get_fg_root () const { return fg_root; } const SGPath &get_fg_root () const { return fg_root; }
void set_fg_root (const std::string &root); void set_fg_root (const SGPath&root);
/** /**
* Get list of data locations. fg_root is always the final item in the * Get list of data locations. fg_root is always the final item in the
@ -214,11 +214,11 @@ public:
*/ */
SGPath find_data_dir(const std::string& pathSuffix) const; SGPath find_data_dir(const std::string& pathSuffix) const;
inline const std::string &get_fg_home () const { return fg_home; } const SGPath &get_fg_home () const { return fg_home; }
void set_fg_home (const std::string &home); void set_fg_home (const SGPath &home);
inline const string_list &get_fg_scenery () const { return fg_scenery; } const PathList &get_fg_scenery () const { return fg_scenery; }
inline const string_list &get_secure_fg_scenery () const { return secure_fg_scenery; } const PathList &get_secure_fg_scenery () const { return secure_fg_scenery; }
/** /**
* Add a scenery directory * Add a scenery directory
* *
@ -227,7 +227,9 @@ public:
* obtained from the property tree (e.g. /sim/terrasync/scenery-dir) * obtained from the property tree (e.g. /sim/terrasync/scenery-dir)
* or other Nasal-writable places * 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 clear_fg_scenery();
@ -238,10 +240,10 @@ public:
*/ */
void set_catalog_aircraft_path(const SGPath& path); 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_path(const SGPath& path);
void append_aircraft_paths(const std::string& path); void append_aircraft_paths(const PathList& path);
/** /**
* Given a path to an aircraft-related resource file, resolve it * Given a path to an aircraft-related resource file, resolve it

View file

@ -293,7 +293,7 @@ static void fgIdleFunction ( void ) {
flightgear::initPosition(); flightgear::initPosition();
flightgear::initTowerLocationListener(); 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* timeManager = (TimeManager*) globals->get_subsystem("time");
timeManager->init(); timeManager->init();

View file

@ -852,15 +852,16 @@ fgOptRoc( const char *arg )
static int static int
fgOptFgScenery( const char *arg ) fgOptFgScenery( const char *arg )
{ {
globals->append_fg_scenery(arg, true); globals->append_fg_scenery(SGPath::pathsFromLocal8Bit(arg), true);
return FG_OPTIONS_OK; return FG_OPTIONS_OK;
} }
static int static int
fgOptTerrasyncDir( const char *arg ) fgOptTerrasyncDir( const char *arg )
{ {
globals->append_fg_scenery(arg, true); SGPath p = SGPath::fromLocal8Bit(arg);
fgSetString("/sim/terrasync/scenery-dir", arg); globals->append_fg_scenery(p, true);
fgSetString("/sim/terrasync/scenery-dir", p.utf8Str());
return FG_OPTIONS_OK; return FG_OPTIONS_OK;
} }
@ -1340,8 +1341,8 @@ fgOptVersion( const char *arg )
cerr << "FG_SCENERY="; cerr << "FG_SCENERY=";
int didsome = 0; int didsome = 0;
string_list scn = globals->get_fg_scenery(); PathList scn = globals->get_fg_scenery();
for (string_list::const_iterator it = scn.begin(); it != scn.end(); it++) for (PathList::const_iterator it = scn.begin(); it != scn.end(); it++)
{ {
if (didsome) cerr << ":"; if (didsome) cerr << ":";
didsome++; didsome++;
@ -2007,7 +2008,7 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath)
// fg-root/fg-home/fg-aircraft and hence control what files Nasal can access // 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(); std::string name_for_error = homedir.empty() ? appDataConfig.str() : config.str();
if( ! hostname.empty() ) { if( ! hostname.empty() ) {
config.set(globals->get_fg_root()); config = globals->get_fg_root();
config.append( "system.fgfsrc" ); config.append( "system.fgfsrc" );
config.concat( "." ); config.concat( "." );
config.concat( hostname ); config.concat( hostname );
@ -2018,7 +2019,7 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath)
} }
} }
config.set(globals->get_fg_root()); config = globals->get_fg_root();
config.append( "system.fgfsrc" ); config.append( "system.fgfsrc" );
if (config.exists()) { if (config.exists()) {
flightgear::fatalMessageBox("Unsupported configuration", flightgear::fatalMessageBox("Unsupported configuration",
@ -2029,13 +2030,14 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath)
void Options::initPaths() 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); globals->append_aircraft_paths(paths);
} }
const char* envp = ::getenv("FG_AIRCRAFT"); const char* envp = ::getenv("FG_AIRCRAFT");
if (envp) { if (envp) {
globals->append_aircraft_paths(envp); globals->append_aircraft_paths(SGPath::pathsFromEnv("FG_AIRCRAFT"));
} }
} }
@ -2057,22 +2059,22 @@ void Options::initAircraft()
} }
if (p->showAircraft) { if (p->showAircraft) {
vector<SGPath> path_list; PathList path_list;
fgOptLogLevel( "alert" ); fgOptLogLevel( "alert" );
// First place to check is the 'Aircraft' sub-directory in $FG_ROOT // First place to check is the 'Aircraft' sub-directory in $FG_ROOT
path_list.push_back( SGPath( globals->get_fg_root() ) ); SGPath rootAircraft = globals->get_fg_root();
path_list.back().append("Aircraft"); rootAircraft.append("Aircraft");
path_list.push_back(rootAircraft);
// Additionally, aircraft may also be found in user-defined places // Additionally, aircraft may also be found in user-defined places
// (via $FG_AIRCRAFT or with the '--fg-aircraft' option) // (via $FG_AIRCRAFT or with the '--fg-aircraft' option)
PathList aircraft_paths = globals->get_aircraft_paths();
string_list aircraft_paths = globals->get_aircraft_paths(); path_list.insert(path_list.end(), aircraft_paths.begin(),
for (string_list::iterator it = aircraft_paths.begin(); aircraft_paths.end());
it != aircraft_paths.end(); ++it)
path_list.push_back( SGPath(*it));
fgShowAircraft(path_list); fgShowAircraft(path_list);
exit(0); exit(0);
@ -2354,7 +2356,7 @@ OptionResult Options::processOptions()
// now options are process, do supplemental fixup // now options are process, do supplemental fixup
const char *envp = ::getenv( "FG_SCENERY" ); const char *envp = ::getenv( "FG_SCENERY" );
if (envp) { if (envp) {
globals->append_fg_scenery(envp, true); globals->append_fg_scenery(SGPath::pathsFromEnv("FG_SCENERY"), true);
} }
// download dir fix-up // download dir fix-up
@ -2394,10 +2396,10 @@ OptionResult Options::processOptions()
// always add the terrasync location, regardless of whether terrasync // always add the terrasync location, regardless of whether terrasync
// is enabled or not. This allows us to toggle terrasync on/off at // is enabled or not. This allows us to toggle terrasync on/off at
// runtime and have things work as expected // runtime and have things work as expected
const string_list& scenery_paths(globals->get_fg_scenery()); const PathList& scenery_paths(globals->get_fg_scenery());
if (std::find(scenery_paths.begin(), scenery_paths.end(), terrasyncDir) == scenery_paths.end()) { if (std::find(scenery_paths.begin(), scenery_paths.end(), SGPath(terrasyncDir)) == scenery_paths.end()) {
// terrasync dir is not in the scenery paths, add it // terrasync dir is not in the scenery paths, add it
globals->append_fg_scenery(terrasyncDir); globals->append_fg_scenery(SGPath(terrasyncDir));
} }
if (addFGDataScenery) { if (addFGDataScenery) {
@ -2405,7 +2407,7 @@ OptionResult Options::processOptions()
// ensure this path is added last // ensure this path is added last
SGPath root(globals->get_fg_root()); SGPath root(globals->get_fg_root());
root.append("Scenery"); root.append("Scenery");
globals->append_fg_scenery(root.str()); globals->append_fg_scenery(root);
} }
return FG_OPTIONS_OK; return FG_OPTIONS_OK;
@ -2544,20 +2546,20 @@ void Options::showUsage() const
} }
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
string Options::platformDefaultRoot() const SGPath Options::platformDefaultRoot() const
{ {
return "../data"; return "../data";
} }
#elif defined(SG_WINDOWS) #elif defined(SG_WINDOWS)
string Options::platformDefaultRoot() const SGPath Options::platformDefaultRoot() const
{ {
return "..\\data"; return "..\\data";
} }
#elif defined(SG_MAC) #elif defined(SG_MAC)
// platformDefaultRoot defined in CocoaHelpers.mm // platformDefaultRoot defined in CocoaHelpers.mm
#else #else
string Options::platformDefaultRoot() const SGPath Options::platformDefaultRoot() const
{ {
return PKGLIBDIR; return PKGLIBDIR;
} }
@ -2565,24 +2567,24 @@ string Options::platformDefaultRoot() const
void Options::setupRoot(int argc, char **argv) void Options::setupRoot(int argc, char **argv)
{ {
string root; SGPath root;
bool usingDefaultRoot = false; bool usingDefaultRoot = false;
if (isOptionSet("fg-root")) { if (isOptionSet("fg-root")) {
root = valueForOption("fg-root"); // easy! root = SGPath::fromLocal8Bit(valueForOption("fg-root").c_str()); // easy!
SG_LOG(SG_GENERAL, SG_INFO, "set from command-line argument: fg_root = " << root ); SG_LOG(SG_GENERAL, SG_INFO, "set from command-line argument: fg_root = " << root );
} else { } else {
// Next check if fg-root is set as an env variable // Next check if fg-root is set as an env variable
char *envp = ::getenv( "FG_ROOT" ); char *envp = ::getenv( "FG_ROOT" );
if ( envp != NULL ) { if ( envp != NULL ) {
root = envp; root = SGPath::fromLocal8Bit(envp);
SG_LOG(SG_GENERAL, SG_INFO, "set from FG_ROOT env var: fg_root = " << root ); SG_LOG(SG_GENERAL, SG_INFO, "set from FG_ROOT env var: fg_root = " << root );
} else { } else {
#if defined(HAVE_QT) #if defined(HAVE_QT)
flightgear::initApp(argc, argv); flightgear::initApp(argc, argv);
root = SetupRootDialog::restoreUserSelectedRoot(); root = SetupRootDialog::restoreUserSelectedRoot();
#endif #endif
if (root.empty()) { if (root.isNull()) {
usingDefaultRoot = true; usingDefaultRoot = true;
root = platformDefaultRoot(); root = platformDefaultRoot();
SG_LOG(SG_GENERAL, SG_INFO, "platform default fg_root = " << root ); SG_LOG(SG_GENERAL, SG_INFO, "platform default fg_root = " << root );

View file

@ -142,7 +142,7 @@ public:
*/ */
static bool checkForArg(int argc, char* argv[], const char* arg); static bool checkForArg(int argc, char* argv[], const char* arg);
std::string platformDefaultRoot() const; SGPath platformDefaultRoot() const;
private: private:
void showUsage() const; void showUsage() const;

View file

@ -92,8 +92,8 @@ void fgInitAllowedPaths()
} }
read_allowed_paths.clear(); read_allowed_paths.clear();
write_allowed_paths.clear(); write_allowed_paths.clear();
std::string fg_root = SGPath(globals->get_fg_root()).realpath(); std::string fg_root = globals->get_fg_root().realpath();
std::string fg_home = SGPath(globals->get_fg_home()).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*/ #if defined(_MSC_VER) /*for MS compilers */ || defined(_WIN32) /*needed for non MS windows compilers like MingW*/
std::string sep = "\\"; std::string sep = "\\";
#else #else
@ -103,31 +103,27 @@ void fgInitAllowedPaths()
read_allowed_paths.push_back(fg_home + sep + "*"); read_allowed_paths.push_back(fg_home + sep + "*");
read_allowed_paths.push_back(fg_root); read_allowed_paths.push_back(fg_root);
read_allowed_paths.push_back(fg_home); 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 // not plain fg_scenery, to avoid making
// /sim/terrasync/scenery-dir a security hole // /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( PathList::const_iterator it = read_paths.begin(); it != read_paths.end(); ++it )
{
for( string_list::const_iterator it = path_lists_to_add[i]->begin(); it != path_lists_to_add[i]->end();++it )
{ {
// if we get the initialization order wrong, better to have an // if we get the initialization order wrong, better to have an
// obvious error than a can-read-everything security hole... // 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", flightgear::fatalMessageBox("Nasal initialization error",
"Empty string in FG_ROOT, FG_HOME, FG_AIRCRAFT or FG_SCENERY", "Empty string in FG_ROOT, FG_HOME, FG_AIRCRAFT or FG_SCENERY",
"or fgInitAllowedPaths() called too early"); "or fgInitAllowedPaths() called too early");
exit(-1); exit(-1);
} }
read_allowed_paths.push_back(SGPath(*it).realpath() + sep + "*"); read_allowed_paths.push_back(it->realpath() + sep + "*");
read_allowed_paths.push_back(SGPath(*it).realpath()); read_allowed_paths.push_back(it->realpath());
}
} }
write_allowed_paths.push_back(fg_home + sep + "*.sav"); write_allowed_paths.push_back(fg_home + sep + "*.sav");
@ -141,13 +137,14 @@ void fgInitAllowedPaths()
write_allowed_paths.push_back(fg_home + sep + "Input" + sep + "Joysticks" + sep + "*.xml"); write_allowed_paths.push_back(fg_home + sep + "Input" + sep + "Joysticks" + sep + "*.xml");
// Check that it works // Check that it works
if(!fgValidatePath(globals->get_fg_home() + "/../no.log",true).empty() || std::string homePath = globals->get_fg_home().utf8Str();
!fgValidatePath(globals->get_fg_home() + "/no.logt",true).empty() || if(!fgValidatePath(homePath + "/../no.log",true).empty() ||
!fgValidatePath(globals->get_fg_home() + "/nolog",true).empty() || !fgValidatePath(homePath + "/no.logt",true).empty() ||
!fgValidatePath(globals->get_fg_home() + "no.log",true).empty() || !fgValidatePath(homePath + "/nolog",true).empty() ||
!fgValidatePath(globals->get_fg_home() + "\\..\\no.log",false).empty() || !fgValidatePath(homePath + "no.log",true).empty() ||
fgValidatePath(globals->get_fg_home() + "/aircraft-data/yes..xml",true).empty() || !fgValidatePath(homePath + "\\..\\no.log",false).empty() ||
fgValidatePath(globals->get_fg_root() + "/.\\yes.bmp",false).empty()) { fgValidatePath(homePath + "/aircraft-data/yes..xml",true).empty() ||
fgValidatePath(homePath + "/.\\yes.bmp",false).empty()) {
flightgear::fatalMessageBox("Nasal initialization error", flightgear::fatalMessageBox("Nasal initialization error",
"The FG_HOME directory must not be inside any of the FG_ROOT, FG_AIRCRAFT or FG_SCENERY directories", "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)"); "(check that you have not accidentally included an extra :, as an empty part means the current directory)");

View file

@ -1223,7 +1223,7 @@ void NavDataCache::doRebuild()
d->flushDeferredOctreeUpdates(); d->flushDeferredOctreeUpdates();
string sceneryPaths = simgear::strutils::join(globals->get_fg_scenery(), ";"); string sceneryPaths = SGPath::join(globals->get_fg_scenery(), ";");
writeStringProperty("scenery_paths", sceneryPaths); writeStringProperty("scenery_paths", sceneryPaths);
st.stamp(); st.stamp();

View file

@ -165,10 +165,13 @@ void FGTileMgr::reinit()
_options->setPropertyNode(globals->get_props()); _options->setPropertyNode(globals->get_props());
osgDB::FilePathList &fp = _options->getDatabasePathList(); osgDB::FilePathList &fp = _options->getDatabasePathList();
const string_list &sc = globals->get_fg_scenery(); const PathList &sc = globals->get_fg_scenery();
fp.clear(); fp.clear();
std::copy(sc.begin(), sc.end(), back_inserter(fp)); PathList::const_iterator it;
_options->setPluginStringData("SimGear::FG_ROOT", globals->get_fg_root()); 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) { if (_terra_sync) {
_options->setPluginStringData("SimGear::TERRASYNC_ROOT", fgGetString("/sim/terrasync/scenery-dir")); _options->setPluginStringData("SimGear::TERRASYNC_ROOT", fgGetString("/sim/terrasync/scenery-dir"));

View file

@ -58,8 +58,8 @@ void FLITEVoiceSynthesizer::WorkerThread::run()
string FLITEVoiceSynthesizer::getVoicePath( voice_t voice ) string FLITEVoiceSynthesizer::getVoicePath( voice_t voice )
{ {
if( voice < 0 || voice >= VOICE_UNKNOWN ) return string(""); if( voice < 0 || voice >= VOICE_UNKNOWN ) return string("");
string voicePath = globals->get_fg_root() + "/ATC/" + VOICE_FILES[voice]; SGPath voicePath = globals->get_fg_root() / "ATC" / VOICE_FILES[voice];
return voicePath; return voicePath.local8BitStr();
} }
string FLITEVoiceSynthesizer::getVoicePath( const string & voice ) string FLITEVoiceSynthesizer::getVoicePath( const string & voice )

View file

@ -38,10 +38,10 @@ FGFLITEVoice::FGFLITEVoice(FGVoiceMgr * mgr, const SGPropertyNode_ptr node, cons
_sampleName = node->getStringValue("desc", node->getPath().c_str()); _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"); 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>(); SGSoundMgr *smgr = globals->get_subsystem<SGSoundMgr>();
_sgr = smgr->find(sampleGroupRefName, true); _sgr = smgr->find(sampleGroupRefName, true);

View file

@ -343,9 +343,8 @@ SGPath FGAISchedule::resolveModelPath(const std::string& modelPath)
} }
// check aircraft dirs // check aircraft dirs
BOOST_FOREACH(std::string aircraftPath, globals->get_aircraft_paths()) { BOOST_FOREACH(SGPath aircraftPath, globals->get_aircraft_paths()) {
SGPath mp(aircraftPath); SGPath mp = aircraftPath / modelPath;
mp.append(modelPath);
if (mp.exists()) { if (mp.exists()) {
return mp; return mp;
} }

View file

@ -534,12 +534,14 @@ void FGTrafficManager::init()
simgear::PathList dirs = globals->get_data_paths("AI/Traffic"); simgear::PathList dirs = globals->get_data_paths("AI/Traffic");
// temporary flag to restrict loading while traffic data is found // 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. // overlay sources.
if (dirs.size() > 1) { if (dirs.size() > 1) {
SGPath p = dirs.back(); 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(); dirs.pop_back();
} }
} }

View file

@ -180,21 +180,21 @@ fgviewerMain(int argc, char** argv)
osgDB::FilePathList filePathList osgDB::FilePathList filePathList
= osgDB::Registry::instance()->getDataFilePathList(); = 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) { 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 ); 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. // Initialize the material property subsystem.
SGPath mpath( globals->get_fg_root() ); SGPath mpath( globals->get_fg_root() );
mpath.append( fgGetString("/sim/rendering/materials-file") ); 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()) ) { globals->get_props()) ) {
throw sg_io_exception("Error loading materials file", mpath); throw sg_io_exception("Error loading materials file", mpath);
} }

View file

@ -1173,7 +1173,7 @@ FGRenderer::buildDeferredFullscreenCamera( flightgear::CameraInfo* info, const F
g->setUseDisplayList(false); g->setUseDisplayList(false);
simgear::EffectGeode* eg = new simgear::EffectGeode; simgear::EffectGeode* eg = new simgear::EffectGeode;
osg::ref_ptr<SGReaderWriterOptions> opt; 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()); opt->setPropertyNode(globals->get_props());
simgear::Effect* effect = simgear::makeEffect(pass->effect, true, opt.get()); simgear::Effect* effect = simgear::makeEffect(pass->effect, true, opt.get());
if (effect) { if (effect) {
@ -1226,7 +1226,7 @@ FGRenderer::buildDeferredDisplayCamera( osg::Camera* camera, flightgear::CameraI
g->setUseDisplayList(false); //DEBUG g->setUseDisplayList(false); //DEBUG
simgear::EffectGeode* eg = new simgear::EffectGeode; simgear::EffectGeode* eg = new simgear::EffectGeode;
osg::ref_ptr<SGReaderWriterOptions> opt; 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()); opt->setPropertyNode(globals->get_props());
simgear::Effect* effect = simgear::makeEffect(stage->effect, true, opt.get()); simgear::Effect* effect = simgear::makeEffect(stage->effect, true, opt.get());
if (!effect) { if (!effect) {
@ -1459,7 +1459,7 @@ FGRenderer::setupView( void )
// Moon diameter: 3,476 kilometers // Moon diameter: 3,476 kilometers
// Sun diameter: 1,390,000 kilometers // Sun diameter: 1,390,000 kilometers
osg::ref_ptr<SGReaderWriterOptions> opt; 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()); opt->setPropertyNode(globals->get_props());
_sky->build( 80000.0, 80000.0, _sky->build( 80000.0, 80000.0,
463.3, 361.8, 463.3, 361.8,

View file

@ -71,18 +71,18 @@ inline static string ParseArgs( int argc, char ** argv, const char * token )
// define default location of fgdata (use the same as for fgfs) // define default location of fgdata (use the same as for fgfs)
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
inline static string platformDefaultRoot() inline static SGPath platformDefaultRoot()
{ {
return "../data"; return SGPath("../data");
} }
#elif defined(_WIN32) #elif defined(_WIN32)
inline static string platformDefaultRoot() inline static SGPath platformDefaultRoot()
{ {
return "..\\data"; return SGPath("..\\data");
} }
#elif defined(__APPLE__) #elif defined(__APPLE__)
inline static string platformDefaultRoot() inline static SGPath platformDefaultRoot()
{ {
/* /*
The following code looks for the base package inside the application The following code looks for the base package inside the application
@ -101,12 +101,12 @@ inline static string platformDefaultRoot()
CFRelease(dataDir); CFRelease(dataDir);
CFRelease(path); CFRelease(path);
return root; return SGPath(root);
} }
#else #else
inline static string platformDefaultRoot() inline static SGPath platformDefaultRoot()
{ {
return PKGLIBDIR; return SGPath(PKGLIBDIR);
} }
#endif #endif
@ -122,7 +122,7 @@ FGPanelApplication::FGPanelApplication( int argc, char ** argv ) :
FGCroppedTexture::registerTextureLoader( "png", &pngTextureLoader ); FGCroppedTexture::registerTextureLoader( "png", &pngTextureLoader );
FGCroppedTexture::registerTextureLoader( "rgb", &rgbTextureLoader ); FGCroppedTexture::registerTextureLoader( "rgb", &rgbTextureLoader );
ApplicationProperties::root = platformDefaultRoot(); ApplicationProperties::root = platformDefaultRoot().local8BitStr();
string panelFilename; string panelFilename;
string fgRoot; string fgRoot;