1
0
Fork 0

Use future-proof SGPath APIs.

Remove uses of .str(), .c_str() and some other methods of SGPath.
Pass SGPath directly where possible, or explicitly convert to the
appropriate 8-bit encoding.
This commit is contained in:
James Turner 2016-06-23 14:26:34 +01:00
parent d9129cfe80
commit 6d0c2070fd
65 changed files with 646 additions and 621 deletions

View file

@ -397,7 +397,7 @@ bool FGAIBase::init(bool search_in_AI_path)
BOOST_FOREACH(SGPath p, globals->get_data_paths("AI")) {
p.append(model_path);
if (p.exists()) {
f = p.str();
f = p.local8BitStr();
break;
}
} // of AI data paths iteration

View file

@ -817,12 +817,12 @@ loadRawReplayData(gzContainerReader& input, FGFlightRecorder* pRecorder, replay_
/** Write flight recorder tape with given filename and meta properties to disk */
bool
FGReplay::saveTape(const char* Filename, SGPropertyNode* MetaDataProps)
FGReplay::saveTape(const SGPath& Filename, SGPropertyNode* MetaDataProps)
{
bool ok = true;
/* open output stream *******************************************/
gzContainerWriter output(Filename, FlightRecorderFileMagic);
gzContainerWriter output(Filename.local8BitStr(), FlightRecorderFileMagic);
if (!output.good())
{
SG_LOG(SG_SYSTEMS, SG_ALERT, "Cannot open file" << Filename);
@ -921,7 +921,7 @@ FGReplay::saveTape(const SGPropertyNode* ConfigData)
}
if (ok)
ok &= saveTape(p.c_str(), myMetaData.get());
ok &= saveTape(p, myMetaData.get());
if (ok)
guiMessage("Flight recorder tape saved successfully!");
@ -935,12 +935,12 @@ FGReplay::saveTape(const SGPropertyNode* ConfigData)
* Actual data and signal configuration is not read when in "Preview" mode.
*/
bool
FGReplay::loadTape(const char* Filename, bool Preview, SGPropertyNode* UserData)
FGReplay::loadTape(const SGPath& Filename, bool Preview, SGPropertyNode* UserData)
{
bool ok = true;
/* open input stream ********************************************/
gzContainerReader input(Filename, FlightRecorderFileMagic);
gzContainerReader input(Filename.local8BitStr(), FlightRecorderFileMagic);
if (input.eof() || !input.good())
{
SG_LOG(SG_SYSTEMS, SG_ALERT, "Cannot open file " << Filename);
@ -1142,6 +1142,6 @@ FGReplay::loadTape(const SGPropertyNode* ConfigData)
tapeDirectory.append(tape);
tapeDirectory.concat(".fgtape");
SG_LOG(SG_SYSTEMS, MY_SG_DEBUG, "Checking flight recorder file " << tapeDirectory << ", preview: " << Preview);
return loadTape(tapeDirectory.c_str(), Preview, UserData);
return loadTape(tapeDirectory, Preview, UserData);
}
}

View file

@ -91,8 +91,8 @@ private:
double get_end_time();
bool listTapes(bool SameAircraftFilter, const SGPath& tapeDirectory);
bool saveTape(const char* Filename, SGPropertyNode* MetaData);
bool loadTape(const char* Filename, bool Preview, SGPropertyNode* UserData);
bool saveTape(const SGPath& Filename, SGPropertyNode* MetaData);
bool loadTape(const SGPath& Filename, bool Preview, SGPropertyNode* UserData);
double sim_time;
double last_mt_time;

View file

@ -91,7 +91,7 @@ namespace canvas
{
SGPath tpath = globals->resolve_resource_path(path);
if( !tpath.isNull() )
return osgDB::readRefImageFile(tpath.c_str());
return osgDB::readRefImageFile(tpath.local8BitStr());
SG_LOG(SG_IO, SG_ALERT, "canvas::Image: No such image: '" << path << "'");
}

View file

@ -780,7 +780,7 @@ NavDisplay::updateFont()
}
osg::ref_ptr<osgDB::ReaderWriter::Options> fontOptions = new osgDB::ReaderWriter::Options("monochrome");
osg::ref_ptr<osgText::Font> font = osgText::readFontFile(tpath.c_str(), fontOptions.get());
osg::ref_ptr<osgText::Font> font = osgText::readFontFile(tpath.local8BitStr(), fontOptions.get());
if (font != 0) {
_font = font;

View file

@ -1084,7 +1084,7 @@ wxRadarBg::updateFont()
}
osg::ref_ptr<osgDB::ReaderWriter::Options> fontOptions = new osgDB::ReaderWriter::Options("monochrome");
osg::ref_ptr<osgText::Font> font = osgText::readFontFile(tpath.c_str(), fontOptions.get());
osg::ref_ptr<osgText::Font> font = osgText::readFontFile(tpath.local8BitStr(), fontOptions.get());
if (font != 0) {
_font = font;

View file

@ -52,7 +52,7 @@ void Ephemeris::init()
{
SGPath ephem_data_path(globals->get_fg_root());
ephem_data_path.append("Astro");
_impl = new SGEphemeris(ephem_data_path.c_str());
_impl = new SGEphemeris(ephem_data_path.local8BitStr());
tieStar("/ephemeris/sun/xs", _impl->get_sun(), &Star::getxs);
tieStar("/ephemeris/sun/ys", _impl->get_sun(), &Star::getys);

View file

@ -134,7 +134,7 @@ void CocoaFileDialog::exec()
if (result == NSFileHandlingPanelOKButton) {
completion_path = [[d->panel URL] path];
//NSLog(@"the URL is: %@", d->panel URL]);
completion_sgpath = ([completion_path UTF8String]);
completion_sgpath = SGPath::fromUtf8([completion_path UTF8String]);
_callback->onFileDialogDone(this, completion_sgpath);
}
}];

View file

@ -41,8 +41,8 @@ NSCursor* cocoaCursorForKey(FGMouseCursor::Cursor aKey)
{
NSImage* img = nil;
NSString* path = [NSString stringWithCString:globals->get_fg_root().c_str()
encoding:NSUTF8StringEncoding];
std::string p = globals->get_fg_root().utf8Str();
NSString* path = [NSString stringWithCString:p.c_str() encoding:NSUTF8StringEncoding];
path = [path stringByAppendingPathComponent:@"gui"];
switch (aKey) {

View file

@ -207,7 +207,8 @@ bool FGFontCache::initializeFonts()
{
static std::string fontext("txf");
init();
ulDir* fontdir = ulOpenDir(_path.c_str());
std::string fontPath = _path.local8BitStr();
ulDir* fontdir = ulOpenDir(fontPath.c_str());
if (!fontdir)
return false;
const ulDirEnt *dirEntry;
@ -216,7 +217,8 @@ bool FGFontCache::initializeFonts()
path.append(dirEntry->d_name);
if (path.extension() == fontext) {
fntTexFont* f = new fntTexFont;
if (f->load((char *)path.c_str()))
std::string ps = path.local8BitStr();
if (f->load(ps.c_str()))
_texFonts[std::string(dirEntry->d_name)] = f;
else
delete f;

View file

@ -141,7 +141,7 @@ InstallSceneryDialog::InstallSceneryDialog(QWidget *parent, QString downloadDir)
{
ui->setupUi(this);
if (m_downloadDir.isEmpty()) {
m_downloadDir = QString::fromStdString(flightgear::defaultDownloadDir());
m_downloadDir = QString::fromStdString(flightgear::defaultDownloadDir().utf8Str());
}
QString baseIntroString = ui->introText->text();

View file

@ -51,14 +51,14 @@ void PUIFileDialog::exec()
SGPropertyNode_ptr dlg = _dialogRoot->getChild("dialog", 0, true);
SGPath dlgXML = globals->resolve_resource_path("gui/dialogs/file-select.xml");
readProperties(dlgXML.str(), dlg);
readProperties(dlgXML, dlg);
dlg->setStringValue("name", name);
gui->newDialog(dlg);
_dialogRoot->setStringValue("title", _title);
_dialogRoot->setStringValue("button", _buttonText);
_dialogRoot->setStringValue("directory", _initialPath.str());
_dialogRoot->setStringValue("directory", _initialPath.utf8Str());
_dialogRoot->setStringValue("selection", _placeholder);
// convert patterns vector into pattern nodes

View file

@ -339,7 +339,7 @@ void AddOnsPage::updateUi()
{
QString s = m_downloadDir;
if (s.isEmpty()) {
s = QString::fromStdString(flightgear::defaultDownloadDir());
s = QString::fromStdString(flightgear::defaultDownloadDir().utf8Str());
s.append(tr(" (default)"));
m_ui->clearDownloadDir->setEnabled(false);
} else {

View file

@ -649,7 +649,7 @@ void QtLauncher::setSceneryPaths()
// append the TerraSync path
QString downloadDir = settings.value("download-dir").toString();
if (downloadDir.isEmpty()) {
downloadDir = QString::fromStdString(flightgear::defaultDownloadDir());
downloadDir = QString::fromStdString(flightgear::defaultDownloadDir().utf8Str());
}
SGPath terraSyncDir(downloadDir.toStdString());
@ -947,7 +947,7 @@ void QtLauncher::onToggleTerrasync(bool enabled)
QSettings settings;
QString downloadDir = settings.value("download-dir").toString();
if (downloadDir.isEmpty()) {
downloadDir = QString::fromStdString(flightgear::defaultDownloadDir());
downloadDir = QString::fromStdString(flightgear::defaultDownloadDir().utf8Str());
}
QFileInfo info(downloadDir);

View file

@ -181,7 +181,7 @@ bool openBrowser(const std::string& aAddress)
SGPath path(address);
path = globals->resolve_maybe_aircraft_path(address);
if (!path.isNull())
address = path.str();
address = path.local8BitStr();
else
{
mkDialog ("Sorry, file not found!");
@ -521,7 +521,8 @@ namespace
// to be executed in graphics context (maybe separate thread)
void run(osg::GraphicsContext* gc)
{
_result = sg_glDumpWindow(_path.c_str(),
std::string ps = _path.local8BitStr();
_result = sg_glDumpWindow(ps.c_str(),
_xsize,
_ysize);
}
@ -533,7 +534,7 @@ namespace
{
globals->get_event_mgr()->removeTask("SnapShotTimer");
fgSetString("/sim/paths/screenshot-last", _path.c_str());
fgSetString("/sim/paths/screenshot-last", _path.utf8Str());
fgSetBool("/sim/signals/screenshot", _result);
fgSetMouseCursor(_mouse);

View file

@ -250,7 +250,7 @@ NewGUI::getDialogProperties (const string &name)
SGPath path = _dialog_names[name];
SGPropertyNode_ptr props = new SGPropertyNode;
try {
readProperties(path.str(), props);
readProperties(path, props);
} catch (const sg_exception &) {
SG_LOG(SG_INPUT, SG_ALERT, "Error parsing dialog " << path);
return NULL;
@ -328,7 +328,7 @@ NewGUI::readDir (const SGPath& path)
simgear::Dir dir(path);
if( !dir.exists() )
{
SG_LOG(SG_INPUT, SG_INFO, "directory does not exist: " << path.str());
SG_LOG(SG_INPUT, SG_INFO, "directory does not exist: " << path);
return;
}
@ -339,7 +339,7 @@ NewGUI::readDir (const SGPath& path)
BOOST_FOREACH(SGPath xmlPath, xmls) {
if (!cache->isCachedFileModified(xmlPath)) {
// cached, easy
string name = cache->readStringProperty(xmlPath.str());
string name = cache->readStringProperty(xmlPath.utf8Str());
_dialog_names[name] = xmlPath;
continue;
}
@ -347,7 +347,7 @@ NewGUI::readDir (const SGPath& path)
// we need to parse the actual XML
SGPropertyNode_ptr props = new SGPropertyNode;
try {
readProperties(xmlPath.str(), props);
readProperties(xmlPath, props);
} catch (const sg_exception &) {
SG_LOG(SG_INPUT, SG_ALERT, "Error parsing dialog " << xmlPath);
continue;
@ -364,7 +364,7 @@ NewGUI::readDir (const SGPath& path)
// update cached values
if (!cache->isReadOnly()) {
cache->stampCacheFile(xmlPath);
cache->writeStringProperty(xmlPath.str(), name);
cache->writeStringProperty(xmlPath.utf8Str(), name);
}
} // of directory children iteration

View file

@ -75,8 +75,8 @@ FGDeviceConfigurationMap::configurationForDeviceName(const std::string& name)
SGPropertyNode_ptr result(new SGPropertyNode);
try {
readProperties(it->second.str(), result);
result->setStringValue("source", it->second.c_str());
readProperties(it->second, result);
result->setStringValue("source", it->second.utf8Str());
} catch (sg_exception&) {
SG_LOG(SG_INPUT, SG_WARN, "parse failure reading:" << it->second);
return NULL;
@ -126,7 +126,7 @@ void FGDeviceConfigurationMap::readCachedData(const SGPath& path)
{
flightgear::NavDataCache* cache = flightgear::NavDataCache::instance();
NamePathMap::iterator it;
BOOST_FOREACH(string s, cache->readStringListProperty(path.str())) {
BOOST_FOREACH(string s, cache->readStringListProperty(path.utf8Str())) {
// important - only insert if not already present. This ensures
// user configs can override those in the base package, since they are
// searched first.
@ -139,10 +139,10 @@ void FGDeviceConfigurationMap::readCachedData(const SGPath& path)
void FGDeviceConfigurationMap::refreshCacheForFile(const SGPath& path)
{
SG_LOG(SG_INPUT, SG_DEBUG, "Reading device file " << path.str());
SG_LOG(SG_INPUT, SG_DEBUG, "Reading device file " << path);
SGPropertyNode_ptr n(new SGPropertyNode);
try {
readProperties(path.str(), n);
readProperties(path, n);
} catch (sg_exception&) {
SG_LOG(SG_INPUT, SG_ALERT, "parse failure reading:" << path);
return;
@ -161,5 +161,5 @@ void FGDeviceConfigurationMap::refreshCacheForFile(const SGPath& path)
flightgear::NavDataCache* cache = flightgear::NavDataCache::instance();
cache->stampCacheFile(path);
cache->writeStringListProperty(path.str(), names);
cache->writeStringListProperty(path.utf8Str(), names);
}

View file

@ -258,7 +258,7 @@ static string fgScanForOption( const string& option, int argc, char **argv ) {
// Scan the user config files for the specified option and return
// the value.
static string fgScanForOption( const string& option, const string& path ) {
static string fgScanForOption( const string& option, const SGPath& path ) {
sg_gzifstream in( path );
if ( !in.is_open() ) {
return "";
@ -311,7 +311,7 @@ static string fgScanForOption( const string& option ) {
if ( homedir != NULL ) {
SGPath config( homedir );
config.append( ".fgfsrc" );
arg = fgScanForOption( option, config.str() );
arg = fgScanForOption( option, config );
}
}

View file

@ -31,6 +31,7 @@
#include <simgear/constants.h>
#include <simgear/misc/sg_path.hxx>
#include <simgear/misc/sgstream.hxx>
#include <simgear/props/props_io.hxx>
#include <osg/GLU>
@ -374,9 +375,9 @@ int HUD::load(const char *file, float x, float y, int level, const string& inden
}
int ret = 0;
ifstream input(path.c_str());
sg_ifstream input(path);
if (!input.good()) {
SG_LOG(SG_INPUT, SG_ALERT, "HUD: Cannot read configuration from '" << path.c_str() << "'");
SG_LOG(SG_INPUT, SG_ALERT, "HUD: Cannot read configuration from '" << path << "'");
return 0x4;
}

View file

@ -27,6 +27,7 @@
#include <simgear/sg_inlines.h>
#include <simgear/misc/sg_path.hxx>
#include <simgear/misc/sgstream.hxx>
#include <simgear/timing/sg_time.hxx>
#include <simgear/magvar/magvar.hxx>
#include <simgear/structure/exception.hxx>
@ -652,10 +653,10 @@ void DCLGPS::LoadApproachData() {
GPSFlightPlan* fp;
const GPSWaypoint* cwp;
std::ifstream fin;
sg_ifstream fin;
SGPath path = globals->get_fg_root();
path.append("Navaids/rnav.dat");
fin.open(path.c_str(), ios::in);
fin.open(path, ios::in);
if(!fin) {
//cout << "Unable to open input file " << path.c_str() << '\n';
return;
@ -1614,4 +1615,3 @@ SGGeod AlignedProjection::ConvertFromLocal(const SGVec3d& pt) {
return SGGeod::fromRadM(_origin.getLongitudeRad()+delta_lon, _origin.getLatitudeRad()+delta_lat, pt.z());
}

View file

@ -73,10 +73,10 @@ void FGInstrumentMgr::init()
}
SGPath config = globals->resolve_aircraft_path(path_n->getStringValue());
SG_LOG( SG_COCKPIT, SG_INFO, "Reading instruments from " << config.str() );
SG_LOG( SG_COCKPIT, SG_INFO, "Reading instruments from " << config );
try {
readProperties( config.str(), config_props );
readProperties( config, config_props );
if (!build(config_props)) {
throw sg_exception(
"Detected an internal inconsistency in the instrumentation\n"
@ -84,7 +84,7 @@ void FGInstrumentMgr::init()
}
} catch (const sg_exception& e) {
SG_LOG(SG_COCKPIT, SG_ALERT, "Failed to load instrumentation system model: "
<< config.str() << ":" << e.getFormattedMessage() );
<< config << ":" << e.getFormattedMessage() );
}

View file

@ -140,9 +140,9 @@ FGNavRadio::FGNavRadio(SGPropertyNode *node) :
SGPath high = path;
high.append( "Navaids/range.high" );
static_terminalRangeInterp.reset(new SGInterpTable(term.str()));
static_lowRangeInterp.reset(new SGInterpTable(low.str()));
static_highRangeInterp.reset(new SGInterpTable(high.str()));
static_terminalRangeInterp.reset(new SGInterpTable(term));
static_lowRangeInterp.reset(new SGInterpTable(low));
static_highRangeInterp.reset(new SGInterpTable(high));
}
string branch("/instrumentation/" + _name);

View file

@ -307,12 +307,12 @@ void NavRadioComponent::update( double dt, const SGGeod & aircraftPosition )
/* ---------------------------------------------------------------- */
static std::string VORTablePath( const char * name )
static SGPath VORTablePath( const char * name )
{
SGPath path( globals->get_fg_root() );
path.append( "Navaids" );
path.append(name);
return path.str();
return path;
}
class VOR : public NavRadioComponentWithIdent {

View file

@ -539,12 +539,12 @@ do_materials_reload (const SGPropertyNode * arg)
SGPath mpath( globals->get_fg_root() );
mpath.append( fgGetString("/sim/rendering/materials-file") );
bool loaded = new_matlib->load(globals->get_fg_root().local8BitStr(),
mpath.str(),
mpath.local8BitStr(),
globals->get_props());
if ( ! loaded ) {
SG_LOG( SG_GENERAL, SG_ALERT,
"Error loading materials file " << mpath.str() );
"Error loading materials file " << mpath );
return false;
}
@ -1121,7 +1121,7 @@ static bool
do_load_xml_to_proptree(const SGPropertyNode * arg)
{
SGPath file(arg->getStringValue("filename"));
if (file.str().empty())
if (file.isNull())
return false;
if (file.extension() != "xml")
@ -1130,27 +1130,27 @@ do_load_xml_to_proptree(const SGPropertyNode * arg)
std::string icao = arg->getStringValue("icao");
if (icao.empty()) {
if (file.isRelative()) {
SGPath absPath = globals->resolve_maybe_aircraft_path(file.str());
SGPath absPath = globals->resolve_maybe_aircraft_path(file.utf8Str());
if (!absPath.isNull())
file = absPath;
else
{
SG_LOG(SG_IO, SG_ALERT, "loadxml: Cannot find XML property file '"
<< file.str() << "'.");
<< file << "'.");
return false;
}
}
} else {
if (!XMLLoader::findAirportData(icao, file.str(), file)) {
if (!XMLLoader::findAirportData(icao, file.utf8Str(), file)) {
SG_LOG(SG_IO, SG_INFO, "loadxml: failed to find airport data for "
<< file.str() << " at ICAO:" << icao);
<< file << " at ICAO:" << icao);
return false;
}
}
std::string validated_path = fgValidatePath(file, false);
if (validated_path.empty()) {
SG_LOG(SG_IO, SG_ALERT, "loadxml: reading '" << file.str() << "' denied "
SG_LOG(SG_IO, SG_ALERT, "loadxml: reading '" << file << "' denied "
"(unauthorized directory - authorization no longer follows symlinks; to authorize reading additional directories, add them to --fg-aircraft)");
return false;
}
@ -1225,7 +1225,7 @@ static bool
do_save_xml_from_proptree(const SGPropertyNode * arg)
{
SGPath file(arg->getStringValue("filename"));
if (file.str().empty())
if (file.isNull())
return false;
if (file.extension() != "xml")
@ -1233,7 +1233,7 @@ do_save_xml_from_proptree(const SGPropertyNode * arg)
std::string validated_path = fgValidatePath(file, true);
if (validated_path.empty()) {
SG_LOG(SG_IO, SG_ALERT, "savexml: writing to '" << file.str() << "' denied "
SG_LOG(SG_IO, SG_ALERT, "savexml: writing to '" << file << "' denied "
"(unauthorized directory - authorization no longer follows symlinks)");
return false;
}
@ -1367,7 +1367,7 @@ do_set_scenery_paths(const SGPropertyNode* arg)
// no scenery paths set *at all*, use the data in FG_ROOT
SGPath root(globals->get_fg_root());
root.append("Scenery");
globals->append_fg_scenery(root.str());
globals->append_fg_scenery(root);
}
return true;

View file

@ -210,7 +210,7 @@ public:
SG_LOG(SG_GENERAL, SG_INFO, "found aircraft in dir: " << aircraftDir );
try {
readProperties(setFile.str(), globals->get_props());
readProperties(setFile, globals->get_props());
} catch ( const sg_exception &e ) {
SG_LOG(SG_INPUT, SG_ALERT, "Error reading aircraft: " << e.getFormattedMessage());
flightgear::fatalMessageBox("Error reading aircraft",
@ -234,7 +234,7 @@ public:
if (!checkCache()) {
// prepare cache for re-scan
SGPropertyNode *n = _cache->getNode("fg-root", true);
n->setStringValue(globals->get_fg_root().c_str());
n->setStringValue(globals->get_fg_root().utf8Str());
n->setAttribute(SGPropertyNode::USERARCHIVE, true);
n = _cache->getNode("fg-aircraft", true);
n->setStringValue(getAircraftPaths().c_str());
@ -244,7 +244,7 @@ public:
visitAircraftPaths();
}
if (_foundPath.str().empty()) {
if (_foundPath.isNull()) {
SG_LOG(SG_GENERAL, SG_ALERT, "Cannot find specified aircraft: " << aircraft );
flightgear::fatalMessageBox("Aircraft not found",
"The requested aircraft '" + aircraft + "' could not be found in any of the search paths");
@ -252,15 +252,15 @@ public:
return false;
}
SG_LOG(SG_GENERAL, SG_INFO, "Loading aircraft -set file from:" << _foundPath.str());
SG_LOG(SG_GENERAL, SG_INFO, "Loading aircraft -set file from:" << _foundPath);
fgSetString( "/sim/aircraft-dir", _foundPath.dir().c_str());
if (!_foundPath.exists()) {
SG_LOG(SG_GENERAL, SG_ALERT, "Unable to find -set file:" << _foundPath.str());
SG_LOG(SG_GENERAL, SG_ALERT, "Unable to find -set file:" << _foundPath);
return false;
}
try {
readProperties(_foundPath.str(), globals->get_props());
readProperties(_foundPath, globals->get_props());
} catch ( const sg_exception &e ) {
SG_LOG(SG_INPUT, SG_ALERT, "Error reading aircraft: " << e.getFormattedMessage());
flightgear::fatalMessageBox("Error reading aircraft",
@ -400,10 +400,11 @@ bool fgInitHome()
char buf[16];
bool result = false;
std::string ps = pidPath.local8BitStr();
#if defined(SG_WINDOWS)
size_t len = snprintf(buf, 16, "%d", _getpid());
HANDLE f = CreateFileA(pidPath.c_str(), GENERIC_READ | GENERIC_WRITE,
HANDLE f = CreateFileA(ps.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ, /* sharing */
NULL, /* security attributes */
CREATE_NEW, /* error if already exists */
@ -419,10 +420,10 @@ bool fgInitHome()
// POSIX, do open+unlink trick to the file is deleted on exit, even if we
// crash or exit(-1)
ssize_t len = snprintf(buf, 16, "%d", getpid());
int fd = ::open(pidPath.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0644);
int fd = ::open(ps.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0644);
if (fd >= 0) {
result = ::write(fd, buf, len) == len;
if( ::unlink(pidPath.c_str()) != 0 ) // delete file when app quits
if( ::unlink(ps.c_str()) != 0 ) // delete file when app quits
result = false;
}
#endif
@ -432,7 +433,7 @@ bool fgInitHome()
if (!result) {
flightgear::fatalMessageBox("File permissions problem",
"Can't write to user-data storage folder, check file permissions and FG_HOME.",
"User-data at:" + dataPath.str());
"User-data at:" + dataPath.utf8Str());
}
return result;
}
@ -453,7 +454,7 @@ int fgInitConfig ( int argc, char **argv, bool reinit )
SGPropertyNode *home = fgGetNode("/sim", true);
home->removeChild("fg-home", 0);
home = home->getChild("fg-home", 0, true);
home->setStringValue(dataPath.c_str());
home->setStringValue(dataPath.utf8Str());
home->setAttribute(SGPropertyNode::WRITE, false);
fgSetDefaults();
@ -540,7 +541,7 @@ int fgInitAircraft(bool reinit)
// set aircraft-dir to short circuit the search process
InstallRef acftInstall = acftPackage->install();
fgSetString("/sim/aircraft-dir", acftInstall->path().c_str());
fgSetString("/sim/aircraft-dir", acftInstall->path().utf8Str());
// overwrite the fully qualified ID with the aircraft one, so the
// code in FindAndCacheAircraft works as normal
@ -649,7 +650,7 @@ bool fgInitGeneral() {
SGPropertyNode *curr = fgGetNode("/sim", true);
curr->removeChild("fg-current", 0);
curr = curr->getChild("fg-current", 0, true);
curr->setStringValue(cwd.path().str());
curr->setStringValue(cwd.path().utf8Str());
curr->setAttribute(SGPropertyNode::WRITE, false);
fgSetBool("/sim/startup/stdout-to-terminal", isatty(1) != 0 );
@ -731,7 +732,7 @@ void fgCreateSubsystems(bool duringReset) {
SGPath mpath( globals->get_fg_root() );
mpath.append( fgGetString("/sim/rendering/materials-file") );
if ( ! globals->get_matlib()->load(globals->get_fg_root().local8BitStr(), mpath.str(),
if ( ! globals->get_matlib()->load(globals->get_fg_root().local8BitStr(), mpath.local8BitStr(),
globals->get_props()) ) {
throw sg_io_exception("Error loading materials file", mpath);
}
@ -1137,7 +1138,7 @@ void fgInitPackageRoot()
packageAircraftDir.append("Aircraft");
SG_LOG(SG_GENERAL, SG_INFO, "init package root at:" << packageAircraftDir.str());
SG_LOG(SG_GENERAL, SG_INFO, "init package root at:" << packageAircraftDir);
SGSharedPtr<Root> pkgRoot(new Root(packageAircraftDir, FLIGHTGEAR_VERSION));

View file

@ -684,15 +684,15 @@ fgLoadFlight (std::istream &input)
bool
fgLoadProps (const char * path, SGPropertyNode * props, bool in_fg_root, int default_mode)
fgLoadProps (const std::string& path, SGPropertyNode * props, bool in_fg_root, int default_mode)
{
string fullpath;
SGPath fullpath;
if (in_fg_root) {
SGPath loadpath(globals->get_fg_root());
loadpath.append(path);
fullpath = loadpath.str();
fullpath = loadpath;
} else {
fullpath = path;
fullpath = SGPath::fromUtf8(path);
}
try {

View file

@ -79,7 +79,7 @@ extern bool fgLoadFlight (std::istream &input);
* @return true if the properties loaded successfully, false
* otherwise.
*/
extern bool fgLoadProps (const char * path, SGPropertyNode * props,
extern bool fgLoadProps (const std::string& path, SGPropertyNode * props,
bool in_fg_root = true, int default_mode = 0);
void setLoggingClasses (const char * c);

View file

@ -361,7 +361,7 @@ void FGGlobals::append_fg_scenery (const SGPath &path, bool secure)
// tell the ResouceManager about the scenery path
// needed to load Models from this scenery path
simgear::ResourceManager::instance()->addBasePath(abspath.str(),
simgear::ResourceManager::instance()->addBasePath(abspath.local8BitStr(),
simgear::ResourceManager::PRIORITY_DEFAULT);
simgear::Dir dir(abspath);
@ -611,7 +611,7 @@ FGGlobals::resetPropertyRoot()
SGPropertyNode *n = props->getNode("/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);
}
@ -637,9 +637,9 @@ FGGlobals::loadUserSettings(const SGPath& dataPath)
SGPath autosaveFile = simgear::Dir(dataPath).file(autosaveName());
SGPropertyNode autosave;
if (autosaveFile.exists()) {
SG_LOG(SG_INPUT, SG_INFO, "Reading user settings from " << autosaveFile.str());
SG_LOG(SG_INPUT, SG_INFO, "Reading user settings from " << autosaveFile);
try {
readProperties(autosaveFile.str(), &autosave, SGPropertyNode::USERARCHIVE);
readProperties(autosaveFile, &autosave, SGPropertyNode::USERARCHIVE);
} catch (sg_exception& e) {
SG_LOG(SG_INPUT, SG_WARN, "failed to read user settings:" << e.getMessage()
<< "(from " << e.getOrigin() << ")");
@ -664,9 +664,9 @@ FGGlobals::saveUserSettings()
SGPath autosaveFile(globals->get_fg_home());
autosaveFile.append(autosaveName());
autosaveFile.create_dir( 0700 );
SG_LOG(SG_IO, SG_INFO, "Saving user settings to " << autosaveFile.str());
SG_LOG(SG_IO, SG_INFO, "Saving user settings to " << autosaveFile);
try {
writeProperties(autosaveFile.str(), globals->get_props(), false, SGPropertyNode::USERARCHIVE);
writeProperties(autosaveFile, globals->get_props(), false, SGPropertyNode::USERARCHIVE);
} catch (const sg_exception &e) {
guiErrorMessage("Error writing autosave:", e);
}

View file

@ -216,15 +216,15 @@ FGLocale::loadResource(SGPropertyNode* localeNode, const char* resource)
path.append(path_str);
SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings for '" <<
localeNode->getStringValue("lang", "<none>")
<<"' from " << path.str());
<<"' from " << path);
// load the actual file
try
{
readProperties(path.str(), stringNode->getNode(resource, 0, true));
readProperties(path, stringNode->getNode(resource, 0, true));
} catch (const sg_exception &e)
{
SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings from " << path.str() <<
SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings from " << path <<
". Error: " << e.getFormattedMessage());
return false;
}

View file

@ -140,7 +140,7 @@ static void initTerrasync()
}
}
fgSetString("/sim/terrasync/cache-path", tsyncCache.c_str());
fgSetString("/sim/terrasync/cache-path", tsyncCache.utf8Str());
simgear::SGTerraSync* terra_sync = new simgear::SGTerraSync();
terra_sync->setRoot(globals->get_props());
@ -171,10 +171,10 @@ static void fgSetVideoOptions()
}
path.append(renderer+".xml");
if (path.exists()) {
SG_LOG(SG_INPUT, SG_INFO, "Reading video settings from " << path.str());
SG_LOG(SG_INPUT, SG_INFO, "Reading video settings from " << path);
try {
SGPropertyNode *r_prop = fgGetNode("/sim/rendering");
readProperties(path.str(), r_prop);
readProperties(path, r_prop);
} catch (sg_exception& e) {
SG_LOG(SG_INPUT, SG_WARN, "failed to read video settings:" << e.getMessage()
<< "(from " << e.getOrigin() << ")");

View file

@ -277,7 +277,7 @@ private:
{
SGPropertyNode root;
try {
readProperties(path.str(), &root);
readProperties(path, &root);
} catch (sg_exception& ) {
return VISIT_CONTINUE;
}
@ -1455,7 +1455,7 @@ fgOptLoadTape(const char* arg)
class DelayedTapeLoader : SGPropertyChangeListener {
public:
DelayedTapeLoader( const char * tape ) :
_tape(tape)
_tape(SGPath::fromLocal8Bit(tape))
{
SGPropertyNode_ptr n = fgGetNode("/sim/signals/fdm-initialized", true);
n->addChangeListener( this );
@ -1470,14 +1470,14 @@ fgOptLoadTape(const char* arg)
// tell the replay subsystem to load the tape
FGReplay* replay = (FGReplay*) globals->get_subsystem("replay");
SGPropertyNode_ptr arg = new SGPropertyNode();
arg->setStringValue("tape", _tape );
arg->setStringValue("tape", _tape.utf8Str() );
arg->setBoolValue( "same-aircraft", 0 );
replay->loadTape(arg);
delete this; // commence suicide
}
private:
std::string _tape;
SGPath _tape;
};
@ -1952,9 +1952,9 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath)
processArgResult(result);
} else {
// XML properties file
SGPath f(argv[i]);
SGPath f = SGPath::fromLocal8Bit(argv[i]);
if (!f.exists()) {
SG_LOG(SG_GENERAL, SG_ALERT, "config file not found:" << f.str());
SG_LOG(SG_GENERAL, SG_ALERT, "config file not found:" << f);
} else {
p->propertyFiles.push_back(f);
}
@ -1973,14 +1973,11 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath)
// then config files
SGPath config;
std::string homedir;
if (getenv("HOME")) {
homedir = getenv("HOME");
}
if( !homedir.empty() && !hostname.empty() ) {
if( !hostname.empty() ) {
// Check for ~/.fgfsrc.hostname
config.set(homedir);
config = SGPath::home();
config.append(".fgfsrc");
config.concat( "." );
config.concat( hostname );
@ -1988,11 +1985,9 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath)
}
// Check for ~/.fgfsrc
if( !homedir.empty() ) {
config.set(homedir);
config = SGPath::home();
config.append(".fgfsrc");
readConfig(config);
}
// check for a config file in app data
SGPath appDataConfig(appDataPath);
@ -2006,7 +2001,7 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath)
// system.fgfsrc is disabled, as we no longer allow anything in fgdata to set
// 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 = config.utf8Str();
if( ! hostname.empty() ) {
config = globals->get_fg_root();
config.append( "system.fgfsrc" );
@ -2014,7 +2009,7 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath)
config.concat( hostname );
if (config.exists()) {
flightgear::fatalMessageBox("Unsupported configuration",
"You have a " + config.str() + " file, which is no longer processed for security reasons",
"You have a " + config.utf8Str() + " file, which is no longer processed for security reasons",
"If you created this file intentionally, please move it to " + name_for_error);
}
}
@ -2023,7 +2018,7 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath)
config.append( "system.fgfsrc" );
if (config.exists()) {
flightgear::fatalMessageBox("Unsupported configuration",
"You have a " + config.str() + " file, which is no longer processed for security reasons",
"You have a " + config.utf8Str() + " file, which is no longer processed for security reasons",
"If you created this file intentionally, please move it to " + name_for_error);
}
}
@ -2132,12 +2127,12 @@ void Options::processArgResult(int result)
void Options::readConfig(const SGPath& path)
{
sg_gzifstream in( path.str() );
sg_gzifstream in( path );
if ( !in.is_open() ) {
return;
}
SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path.str() );
SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
in >> skipcomment;
while ( ! in.eof() ) {
@ -2152,7 +2147,7 @@ void Options::readConfig(const SGPath& path)
line = line.substr( 0, i );
if ( parseOption( line ) == FG_OPTIONS_ERROR ) {
cerr << endl << "Config file parse error: " << path.str() << " '"
cerr << endl << "Config file parse error: " << path << " '"
<< line << "'" << endl;
p->showHelp = true;
}
@ -2290,7 +2285,7 @@ string_list Options::valuesForOption(const std::string& key) const
return result;
}
string defaultDownloadDir()
SGPath defaultDownloadDir()
{
#if defined(SG_WINDOWS)
SGPath p(SGPath::documents());
@ -2298,7 +2293,7 @@ string defaultDownloadDir()
#else
SGPath p(globals->get_fg_home());
#endif
return p.str();
return p;
}
OptionResult Options::processOptions()
@ -2349,8 +2344,8 @@ OptionResult Options::processOptions()
BOOST_FOREACH(const SGPath& file, p->propertyFiles) {
SG_LOG(SG_GENERAL, SG_INFO,
"Reading command-line property file " << file.str());
readProperties(file.str(), globals->get_props());
"Reading command-line property file " << file);
readProperties(file, globals->get_props());
}
// now options are process, do supplemental fixup
@ -2360,8 +2355,8 @@ OptionResult Options::processOptions()
}
// download dir fix-up
string downloadDir = simgear::strutils::strip(fgGetString("/sim/paths/download-dir"));
if (downloadDir.empty()) {
SGPath downloadDir = SGPath::fromUtf8(fgGetString("/sim/paths/download-dir"));
if (downloadDir.isNull()) {
downloadDir = defaultDownloadDir();
SG_LOG(SG_GENERAL, SG_INFO, "Using default download dir: " << downloadDir);
} else {
@ -2373,11 +2368,11 @@ OptionResult Options::processOptions()
}
// terrasync directory fixup
string terrasyncDir = simgear::strutils::strip(fgGetString("/sim/terrasync/scenery-dir"));
if (terrasyncDir.empty()) {
SGPath terrasyncDir = SGPath::fromUtf8(fgGetString("/sim/terrasync/scenery-dir"));
if (terrasyncDir.isNull()) {
SGPath p(downloadDir);
p.append("TerraSync");
terrasyncDir = p.str();
terrasyncDir = p;
simgear::Dir d(terrasyncDir);
if (!d.exists()) {
@ -2385,7 +2380,7 @@ OptionResult Options::processOptions()
}
SG_LOG(SG_GENERAL, SG_INFO, "Using default TerraSync: " << terrasyncDir);
fgSetString("/sim/terrasync/scenery-dir", p.str());
fgSetString("/sim/terrasync/scenery-dir", p.utf8Str());
} else {
SG_LOG(SG_GENERAL, SG_INFO, "Using explicit TerraSync dir: " << terrasyncDir);
}
@ -2397,9 +2392,9 @@ OptionResult Options::processOptions()
// is enabled or not. This allows us to toggle terrasync on/off at
// runtime and have things work as expected
const PathList& scenery_paths(globals->get_fg_scenery());
if (std::find(scenery_paths.begin(), scenery_paths.end(), SGPath(terrasyncDir)) == scenery_paths.end()) {
if (std::find(scenery_paths.begin(), scenery_paths.end(), terrasyncDir) == scenery_paths.end()) {
// terrasync dir is not in the scenery paths, add it
globals->append_fg_scenery(SGPath(terrasyncDir));
globals->append_fg_scenery(terrasyncDir);
}
if (addFGDataScenery) {
@ -2548,20 +2543,20 @@ void Options::showUsage() const
#if defined(__CYGWIN__)
SGPath Options::platformDefaultRoot() const
{
return "../data";
return SGPath::fromUtf8("../data");
}
#elif defined(SG_WINDOWS)
SGPath Options::platformDefaultRoot() const
{
return "..\\data";
return SGPath::fromUtf8("..\\data");
}
#elif defined(SG_MAC)
// platformDefaultRoot defined in CocoaHelpers.mm
#else
SGPath Options::platformDefaultRoot() const
{
return SGPath(PKGLIBDIR);
return SGPath::fromUtf8(PKGLIBDIR);
}
#endif
@ -2660,4 +2655,3 @@ bool Options::checkForArg(int argc, char* argv[], const char* checkArg)
}
} // of namespace flightgear

View file

@ -42,7 +42,7 @@ namespace flightgear
* Documents (FlightGear), on Unixes we default to FG_HOME, which is
* typically invisible.
*/
std::string defaultDownloadDir();
SGPath defaultDownloadDir();
/// option processing can have various result values
/// depending on what the user requested. Note processOptions only

View file

@ -213,24 +213,24 @@ static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& par
string acfile = fgGetString("/sim/aircraft") + string(".xml");
acData.append(acfile);
SGPropertyNode root;
readProperties(acData.str(), &root);
readProperties(acData, &root);
SGPropertyNode * node = root.getNode("sim");
fltType = node->getStringValue("aircraft-class", "NONE" );
acOperator = node->getStringValue("aircraft-operator", "NONE" );
} catch (const sg_exception &) {
SG_LOG(SG_GENERAL, SG_INFO,
"Could not load aircraft aircrat type and operator information from: " << acData.str() << ". Using defaults");
"Could not load aircraft aircrat type and operator information from: " << acData << ". Using defaults");
// cout << path.str() << endl;
}
if (fltType.empty() || fltType == "NONE") {
SG_LOG(SG_GENERAL, SG_INFO,
"Aircraft type information not found in: " << acData.str() << ". Using default value");
"Aircraft type information not found in: " << acData << ". Using default value");
fltType = fgGetString("/sim/aircraft-class" );
}
if (acOperator.empty() || fltType == "NONE") {
SG_LOG(SG_GENERAL, SG_INFO,
"Aircraft operator information not found in: " << acData.str() << ". Using default value");
"Aircraft operator information not found in: " << acData << ". Using default value");
acOperator = fgGetString("/sim/aircraft-operator" );
}

View file

@ -191,6 +191,6 @@ std::string fgValidatePath (const std::string& path, bool write)
// no match found
return "";
}
std::string fgValidatePath(const SGPath& path, bool write) { return fgValidatePath(path.str(),write); }
std::string fgValidatePath(const SGPath& path, bool write) { return fgValidatePath(path.utf8Str(),write); }
// end of util.cxx

View file

@ -30,10 +30,10 @@
static osg::Node *
fgLoad3DModelPanel(const std::string &path, SGPropertyNode *prop_root)
fgLoad3DModelPanel(const SGPath &path, SGPropertyNode *prop_root)
{
bool loadPanels = true;
osg::Node* node = simgear::SGModelLib::loadModel(path, prop_root, NULL, loadPanels);
osg::Node* node = simgear::SGModelLib::loadModel(path.local8BitStr(), prop_root, NULL, loadPanels);
if (node)
node->setNodeMask(~SG_NODEMASK_TERRAIN_BIT);
return node;
@ -82,7 +82,7 @@ FGAircraftModel::init ()
osg::Node* node = NULL;
try {
node = fgLoad3DModelPanel( resolvedPath.str(), globals->get_props());
node = fgLoad3DModelPanel( resolvedPath, globals->get_props());
} catch (const sg_exception &ex) {
SG_LOG(SG_AIRCRAFT, SG_ALERT, "Failed to load aircraft from " << path << ':');
SG_LOG(SG_AIRCRAFT, SG_ALERT, " " << ex.getFormattedMessage());
@ -110,7 +110,7 @@ FGAircraftModel::init ()
// no models loaded, load the glider instead
if (!_aircraft.get()) {
SG_LOG(SG_AIRCRAFT, SG_ALERT, "(Falling back to glider.ac.)");
osg::Node* model = fgLoad3DModelPanel( "Models/Geometry/glider.ac",
osg::Node* model = fgLoad3DModelPanel( SGPath::fromLocal8Bit("Models/Geometry/glider.ac"),
globals->get_props());
_aircraft.reset(new SGModelPlacement);
_aircraft->init(model);

View file

@ -576,7 +576,7 @@ void FlightPlan::setApproach(flightgear::Approach *app)
bool FlightPlan::save(const SGPath& path)
{
SG_LOG(SG_NAVAID, SG_INFO, "Saving route to " << path.str());
SG_LOG(SG_NAVAID, SG_INFO, "Saving route to " << path);
try {
SGPropertyNode_ptr d(new SGPropertyNode);
d->setIntValue("version", 2);
@ -615,10 +615,10 @@ bool FlightPlan::save(const SGPath& path)
Waypt* wpt = _legs[i]->waypoint();
wpt->saveAsNode(routeNode->getChild("wp", i, true));
} // of waypoint iteration
writeProperties(path.str(), d, true /* write-all */);
writeProperties(path, d, true /* write-all */);
return true;
} catch (sg_exception& e) {
SG_LOG(SG_NAVAID, SG_ALERT, "Failed to save flight-plan '" << path.str() << "'. " << e.getMessage());
SG_LOG(SG_NAVAID, SG_ALERT, "Failed to save flight-plan '" << path << "'. " << e.getMessage());
return false;
}
}
@ -627,12 +627,12 @@ bool FlightPlan::load(const SGPath& path)
{
if (!path.exists())
{
SG_LOG(SG_NAVAID, SG_ALERT, "Failed to load flight-plan '" << path.str()
SG_LOG(SG_NAVAID, SG_ALERT, "Failed to load flight-plan '" << path
<< "'. The file does not exist.");
return false;
}
SG_LOG(SG_NAVAID, SG_INFO, "going to read flight-plan from:" << path.str());
SG_LOG(SG_NAVAID, SG_INFO, "going to read flight-plan from:" << path);
bool Status = false;
lockDelegate();
@ -727,7 +727,7 @@ bool FlightPlan::loadGpxFormat(const SGPath& path)
GpxXmlVisitor gpxVistor(this);
try
{
readXML(path.str(), gpxVistor);
readXML(path.local8BitStr(), gpxVistor);
} catch (sg_exception& e)
{
// XML parsing fails => not a GPX XML file
@ -750,7 +750,7 @@ bool FlightPlan::loadXmlFormat(const SGPath& path)
{
SGPropertyNode_ptr routeData(new SGPropertyNode);
try {
readProperties(path.str(), routeData);
readProperties(path, routeData);
} catch (sg_exception& e) {
SG_LOG(SG_NAVAID, SG_ALERT, "Failed to load flight-plan '" << e.getOrigin()
<< "'. " << e.getMessage());
@ -949,7 +949,7 @@ bool FlightPlan::loadPlainTextFormat(const SGPath& path)
_legs.push_back(new Leg(this, w));
} // of line iteration
} catch (sg_exception& e) {
SG_LOG(SG_NAVAID, SG_ALERT, "Failed to load route from: '" << path.str() << "'. " << e.getMessage());
SG_LOG(SG_NAVAID, SG_ALERT, "Failed to load route from: '" << path << "'. " << e.getMessage());
_legs.clear();
return false;
}

View file

@ -44,7 +44,7 @@ void NavdataVisitor::startElement(const char* name, const XMLAttributes &atts)
if (tag == "Airport") {
string icao(atts.getValue("ICAOcode"));
if (_airport->ident() != icao) {
throw sg_format_exception("Airport and ICAO mismatch", icao, _path.str());
throw sg_format_exception("Airport and ICAO mismatch", icao, _path.utf8Str());
}
} else if (tag == "Sid") {
string ident(atts.getValue("Name"));

View file

@ -91,9 +91,10 @@ namespace flightgear
void SHPParser::parsePolyLines(const SGPath& aPath, PolyLine::Type aTy,
PolyLineList& aResult, bool aClosed)
{
gzFile file = gzopen(aPath.c_str(), "rb");
std::string s = aPath.local8BitStr();
gzFile file = gzopen(s.c_str(), "rb");
if (!file) {
throw sg_io_exception("couldn't open file:" + aPath.str());
throw sg_io_exception("couldn't open file:", aPath);
}
try {

View file

@ -129,10 +129,10 @@ void Airway::load(const SGPath& path)
//int airwayIndex = 0;
//FGNode *n;
sg_gzifstream in( path.str() );
sg_gzifstream in( path );
if ( !in.is_open() ) {
SG_LOG( SG_NAVAID, SG_ALERT, "Cannot open file: " << path.str() );
throw sg_io_exception("Could not open airways data", sg_location(path.str()));
SG_LOG( SG_NAVAID, SG_ALERT, "Cannot open file: " << path );
throw sg_io_exception("Could not open airways data", path);
}
// toss the first two lines of the file
in >> skipeol;

View file

@ -50,7 +50,7 @@ const unsigned int LINES_IN_FIX_DAT = 119724;
void loadFixes(const SGPath& path)
{
sg_gzifstream in( path.str() );
sg_gzifstream in( path );
if ( !in.is_open() ) {
throw sg_io_exception("Cannot open file:", path);
}

View file

@ -265,9 +265,9 @@ const unsigned int LINES_IN_NAV_DAT = 26775;
// load and initialize the navigational databases
bool navDBInit(const SGPath& path)
{
sg_gzifstream in( path.str() );
sg_gzifstream in( path );
if ( !in.is_open() ) {
SG_LOG( SG_NAVAID, SG_ALERT, "Cannot open file: " << path.str() );
SG_LOG( SG_NAVAID, SG_ALERT, "Cannot open file: " << path );
return false;
}
@ -299,11 +299,11 @@ bool navDBInit(const SGPath& path)
bool loadCarrierNav(const SGPath& path)
{
SG_LOG( SG_NAVAID, SG_DEBUG, "opening file: " << path.str() );
sg_gzifstream incarrier( path.str() );
SG_LOG( SG_NAVAID, SG_DEBUG, "opening file: " << path );
sg_gzifstream incarrier( path );
if ( !incarrier.is_open() ) {
SG_LOG( SG_NAVAID, SG_ALERT, "Cannot open file: " << path.str() );
SG_LOG( SG_NAVAID, SG_ALERT, "Cannot open file: " << path );
return false;
}
@ -318,11 +318,11 @@ bool loadCarrierNav(const SGPath& path)
bool loadTacan(const SGPath& path, FGTACANList *channellist)
{
SG_LOG( SG_NAVAID, SG_DEBUG, "opening file: " << path.str() );
sg_gzifstream inchannel( path.str() );
SG_LOG( SG_NAVAID, SG_DEBUG, "opening file: " << path );
sg_gzifstream inchannel( path );
if ( !inchannel.is_open() ) {
SG_LOG( SG_NAVAID, SG_ALERT, "Cannot open file: " << path.str() );
SG_LOG( SG_NAVAID, SG_ALERT, "Cannot open file: " << path );
return false;
}

View file

@ -92,9 +92,9 @@ static PositionedID readPOIFromStream(std::istream& aStream, NavDataCache* cache
// load and initialize the POI database
bool poiDBInit(const SGPath& path)
{
sg_gzifstream in( path.str() );
sg_gzifstream in( path );
if ( !in.is_open() ) {
SG_LOG( SG_NAVAID, SG_ALERT, "Cannot open file: " << path.str() );
SG_LOG( SG_NAVAID, SG_ALERT, "Cannot open file: " << path );
return false;
}

View file

@ -333,10 +333,9 @@ void Waypt::writeToProperties(SGPropertyNode_ptr aProp) const
void RouteBase::dumpRouteToKML(const WayptVec& aRoute, const std::string& aName)
{
SGPath p = "/Users/jmt/Desktop/" + aName + ".kml";
std::fstream f;
f.open(p.str().c_str(), fstream::out | fstream::app);
sg_ofstream f(p);
if (!f.is_open()) {
SG_LOG(SG_NAVAID, SG_WARN, "unable to open:" << p.str());
SG_LOG(SG_NAVAID, SG_WARN, "unable to open:" << p);
return;
}
@ -380,12 +379,12 @@ void RouteBase::loadAirportProcedures(const SGPath& aPath, FGAirport* aApt)
assert(aApt);
try {
NavdataVisitor visitor(aApt, aPath);
readXML(aPath.str(), visitor);
readXML(aPath.local8BitStr(), visitor);
} catch (sg_io_exception& ex) {
SG_LOG(SG_NAVAID, SG_WARN, "failure parsing procedures: " << aPath.str() <<
SG_LOG(SG_NAVAID, SG_WARN, "failure parsing procedures: " << aPath <<
"\n\t" << ex.getMessage() << "\n\tat:" << ex.getLocation().asString());
} catch (sg_exception& ex) {
SG_LOG(SG_NAVAID, SG_WARN, "failure parsing procedures: " << aPath.str() <<
SG_LOG(SG_NAVAID, SG_WARN, "failure parsing procedures: " << aPath <<
"\n\t" << ex.getMessage());
}
}

View file

@ -151,19 +151,19 @@ bool FGATCMain::open() {
exit( -1 );
}
if ( input0_path.str().length() ) {
if ( !input0_path.isNull() ) {
input0 = new FGATCInput( 0, input0_path );
input0->open();
}
if ( input1_path.str().length() ) {
if ( !input1_path.isNull() ) {
input1 = new FGATCInput( 1, input1_path );
input1->open();
}
if ( output0_path.str().length() ) {
if ( !output0_path.isNull() ) {
output0 = new FGATCOutput( 0, output0_path );
output0->open( lock0_fd );
}
if ( output1_path.str().length() ) {
if ( !output1_path.isNull() ) {
output1 = new FGATCOutput( 1, output1_path );
output1->open( lock1_fd );
}

View file

@ -758,11 +758,11 @@ FGGeneric::reinit()
path.append(file_name.c_str());
SG_LOG(SG_NETWORK, SG_INFO, "Reading communication protocol from "
<< path.str());
<< path);
SGPropertyNode root;
try {
readProperties(path.str(), &root);
readProperties(path, &root);
} catch (const sg_exception & ex) {
SG_LOG(SG_NETWORK, SG_ALERT,
"Unable to load the protocol configuration file: " << ex.getFormattedMessage() );

View file

@ -96,7 +96,8 @@ static cJSON * CatalogToJson( simgear::pkg::Catalog * c )
cJSON * json = cJSON_CreateObject();
if( c ) {
cJSON_AddItemToObject(json, "id", cJSON_CreateString( c->id().c_str() ));
cJSON_AddItemToObject(json, "installRoot", cJSON_CreateString( c->installRoot().str().c_str() ));
std::string s = c->installRoot().utf8Str();
cJSON_AddItemToObject(json, "installRoot", cJSON_CreateString( s.c_str() ));
cJSON_AddItemToObject(json, "url", cJSON_CreateString( c->url().c_str() ));
cJSON_AddItemToObject(json, "description", cJSON_CreateString( c->description().c_str() ));
cJSON_AddItemToObject(json, "packages", PackageListToJson(c->packages()) );
@ -112,8 +113,8 @@ static string PackageRootCommand( simgear::pkg::Root* packageRoot, const string
cJSON * json = cJSON_CreateObject();
if( command == "path" ) {
cJSON_AddItemToObject(json, "path", cJSON_CreateString( packageRoot->path().str().c_str() ));
std::string p = packageRoot->path().utf8Str();
cJSON_AddItemToObject(json, "path", cJSON_CreateString( p.c_str() ));
} else if( command == "version" ) {

View file

@ -26,6 +26,8 @@
#include <stdlib.h>
#include <fstream>
#include <Scenery/scenery.hxx>
#include <simgear/misc/sgstream.hxx>
#include "antenna.hxx"
using namespace std;
@ -80,7 +82,7 @@ void FGRadioAntenna::load_NEC_antenna_pattern(string type) {
if (!pattern_file.exists()) {
return;
}
ifstream file_in(pattern_file.c_str());
sg_ifstream file_in(pattern_file);
int heading, elevation;
double gain;
while(!file_in.eof()) {

View file

@ -1736,7 +1736,8 @@ static naRef f_route(naContext c, naRef me, int argc, naRef* args)
flightgear::FlightPlan* fp = new flightgear::FlightPlan;
SGPath path(naStr_data(args[0]));
if (!path.exists()) {
naRuntimeError(c, "flightplan, no file at path %s", path.c_str());
std::string pdata = path.utf8Str();
naRuntimeError(c, "flightplan, no file at path %s", pdata.c_str());
}
if (!fp->load(path)) {

View file

@ -42,12 +42,12 @@ SGPath::Permissions checkIORules(const SGPath& path)
// SGPath caches permissions, which breaks for relative paths
// if the current directory changes
SG_LOG(SG_NASAL, SG_ALERT, "os.path: file operation on '" <<
path.str() << "' access denied (relative paths not accepted; use "
path<< "' access denied (relative paths not accepted; use "
"realpath() to make a path absolute)");
}
perm.read = path.isAbsolute() && !fgValidatePath(path.str(), false).empty();
perm.write = path.isAbsolute() && !fgValidatePath(path.str(), true ).empty();
perm.read = path.isAbsolute() && !fgValidatePath(path, false).empty();
perm.write = path.isAbsolute() && !fgValidatePath(path, true ).empty();
return perm;
}
@ -56,7 +56,7 @@ SGPath::Permissions checkIORules(const SGPath& path)
static naRef validatedPathToNasal( const nasal::CallContext& ctx,
const SGPath& p )
{
return ctx.to_nasal( SGPathRef(new SGPath(p.str(), &checkIORules)) );
return ctx.to_nasal( SGPathRef(new SGPath(p.utf8Str(), &checkIORules)) );
}
/**
@ -73,6 +73,11 @@ static int f_path_create_dir(SGPath& p, const nasal::CallContext& ctx)
return p.create_dir(ctx.getArg<mode_t>(0, 0755) & 0775);
}
static void f_path_set(SGPath& p, const nasal::CallContext& ctx)
{
p = SGPath::fromUtf8(ctx.getArg<std::string>(0), p.getPermissionChecker());
}
/**
* os.path.desktop()
*/
@ -113,9 +118,8 @@ naRef initNasalSGPath(naRef globals, naContext c)
// See: http://docs.freeflightsim.org/simgear/classSGPath.html
NasalSGPath::init("os.path")
.method("set", &SGPath::set)
.method("set", &f_path_set)
.method("append", &SGPath::append)
.method("add", &SGPath::add)
.method("concat", &SGPath::concat)
.member("realpath", &SGPath::realpath)
@ -126,8 +130,7 @@ naRef initNasalSGPath(naRef globals, naContext c)
.member("extension", &SGPath::extension)
.member("lower_extension", &SGPath::lower_extension)
.member("complete_lower_extension", &SGPath::complete_lower_extension)
.member("str", &SGPath::str)
.member("str_native", &SGPath::str_native)
.member("str", &SGPath::utf8Str)
.member("mtime", &SGPath::modTime)
.method("exists", &SGPath::exists)

View file

@ -608,8 +608,8 @@ static naRef f_resolveDataPath(naContext c, naRef me, int argc, naRef* args)
naRuntimeError(c, "bad arguments to resolveDataPath()");
SGPath p = globals->resolve_maybe_aircraft_path(naStr_data(args[0]));
const char* pdata = p.c_str();
return naStr_fromdata(naNewString(c), const_cast<char*>(pdata), strlen(pdata));
std::string pdata = p.utf8Str();
return naStr_fromdata(naNewString(c), const_cast<char*>(pdata.c_str()), pdata.length());
}
static naRef f_findDataDir(naContext c, naRef me, int argc, naRef* args)
@ -618,8 +618,8 @@ static naRef f_findDataDir(naContext c, naRef me, int argc, naRef* args)
naRuntimeError(c, "bad arguments to findDataDir()");
SGPath p = globals->find_data_dir(naStr_data(args[0]));
const char* pdata = p.c_str();
return naStr_fromdata(naNewString(c), const_cast<char*>(pdata), strlen(pdata));
std::string pdata = p.utf8Str();
return naStr_fromdata(naNewString(c), const_cast<char*>(pdata.c_str()), pdata.length());
}
class NasalCommand : public SGCommandMgr::Command
@ -1032,7 +1032,7 @@ void FGNasalSys::addModule(string moduleName, simgear::PathList scripts)
SGPropertyNode* module_node = nasal->getChild(moduleName,0,true);
for (unsigned int i=0; i<scripts.size(); ++i) {
SGPropertyNode* pFileNode = module_node->getChild("file",i,true);
pFileNode->setStringValue(scripts[i].c_str());
pFileNode->setStringValue(scripts[i].utf8Str());
}
if (!module_node->hasChild("enabled",0))
{
@ -1146,15 +1146,16 @@ void FGNasalSys::logError(naContext context)
bool FGNasalSys::loadModule(SGPath file, const char* module)
{
int len = 0;
char* buf = readfile(file.c_str(), &len);
std::string pdata = file.local8BitStr();
char* buf = readfile(pdata.c_str(), &len);
if(!buf) {
SG_LOG(SG_NASAL, SG_ALERT,
"Nasal error: could not read script file " << file.c_str()
"Nasal error: could not read script file " << file
<< " into module " << module);
return false;
}
bool ok = createModule(module, file.c_str(), buf, len);
bool ok = createModule(module, pdata.c_str(), buf, len);
delete[] buf;
return ok;
}

View file

@ -116,14 +116,14 @@ FGFX::init()
return;
}
SG_LOG(SG_SOUND, SG_INFO, "Reading sound " << node->getName()
<< " from " << path.str());
<< " from " << path);
SGPropertyNode root;
try {
readProperties(path.str(), &root);
readProperties(path, &root);
} catch (const sg_exception &) {
SG_LOG(SG_SOUND, SG_ALERT,
"Error reading file '" << path.str() << '\'');
"Error reading file '" << path << '\'');
return;
}

View file

@ -382,7 +382,7 @@ void FGElectricalSystem::init () {
<< config.str() );
#endif
try {
readProperties( config.str(), config_props );
readProperties( config, config_props );
if ( build(config_props) ) {
enabled = true;
@ -392,7 +392,7 @@ void FGElectricalSystem::init () {
} catch (const sg_exception&) {
SG_LOG( SG_SYSTEMS, SG_ALERT,
"Failed to load electrical system model: "
<< config.str() );
<< config );
}
} else {
SG_LOG( SG_SYSTEMS, SG_INFO,

View file

@ -38,16 +38,16 @@ FGSystemMgr::FGSystemMgr ()
SGPath config = globals->resolve_aircraft_path(path_n->getStringValue());
SG_LOG( SG_SYSTEMS, SG_INFO, "Reading systems from "
<< config.str() );
<< config );
try
{
readProperties( config.str(), config_props );
readProperties( config, config_props );
build(config_props);
}
catch( const sg_exception& )
{
SG_LOG( SG_SYSTEMS, SG_ALERT, "Failed to load systems system model: "
<< config.str() );
<< config );
}
} else {

View file

@ -335,7 +335,7 @@ void TimeManager::updateLocalTime()
{
SGPath zone(globals->get_fg_root());
zone.append("Timezone");
_impl->updateLocal(globals->get_aircraft_position(), zone.str());
_impl->updateLocal(globals->get_aircraft_position(), zone.local8BitStr());
}
void TimeManager::initTimeOffset()

View file

@ -105,20 +105,20 @@ void FGLight::init () {
// initialize ambient, diffuse and specular tables
SGPath ambient_path = path;
ambient_path.append( "Lighting/ambient" );
_ambient_tbl = new SGInterpTable( ambient_path.str() );
_ambient_tbl = new SGInterpTable( ambient_path );
SGPath diffuse_path = path;
diffuse_path.append( "Lighting/diffuse" );
_diffuse_tbl = new SGInterpTable( diffuse_path.str() );
_diffuse_tbl = new SGInterpTable( diffuse_path );
SGPath specular_path = path;
specular_path.append( "Lighting/specular" );
_specular_tbl = new SGInterpTable( specular_path.str() );
_specular_tbl = new SGInterpTable( specular_path );
// initialize sky table
SGPath sky_path = path;
sky_path.append( "Lighting/sky" );
_sky_tbl = new SGInterpTable( sky_path.str() );
_sky_tbl = new SGInterpTable( sky_path );
globals->get_event_mgr()->addTask("updateSunPos", this,
&FGLight::updateSunPos, 0.5 );

View file

@ -54,6 +54,7 @@
#include <simgear/compiler.h>
#include <simgear/misc/sg_path.hxx>
#include <simgear/misc/sgstream.hxx>
#include <simgear/misc/sg_dir.hxx>
#include <simgear/props/props.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
@ -166,7 +167,7 @@ public:
SGPath path = globals->get_fg_root();
path.append("/Traffic/");
path.append(attval);
readXML(path.str(), *this);
readXML(path.local8BitStr(), *this);
}
elementValueStack.push_back("");
// cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl;
@ -384,7 +385,7 @@ private:
SG_LOG(SG_AI, SG_INFO, "parsing traffic in:" << p);
simgear::PathList trafficFiles = d2.children(simgear::Dir::TYPE_FILE, ".xml");
BOOST_FOREACH(SGPath xml, trafficFiles) {
readXML(xml.str(), *this);
readXML(xml.local8BitStr(), *this);
if (_cancelThread) {
return;
}
@ -450,7 +451,7 @@ void FGTrafficManager::shutdown()
// Save the heuristics data
bool saveData = false;
std::ofstream cachefile;
sg_ofstream cachefile;
if (fgGetBool("/sim/traffic-manager/heuristics")) {
SGPath cacheData(globals->get_fg_home());
cacheData.append("ai");
@ -468,12 +469,12 @@ void FGTrafficManager::shutdown()
// the trailing dir separator and then determines the directory part of the file path by searching
// for the last dir separator. Effecively, this causes a full element of the directory tree to be
// skipped.
SG_LOG(SG_GENERAL, SG_DEBUG, "Trying to create dir for : " << cacheData.c_str());
SG_LOG(SG_GENERAL, SG_DEBUG, "Trying to create dir for : " << cacheData);
if (!cacheData.exists()) {
cacheData.create_dir(0755);
}
saveData = true;
cachefile.open(cacheData.str().c_str());
cachefile.open(cacheData);
cachefile << "[TrafficManagerCachedata:ref:2011:09:04]" << endl;
}
@ -563,7 +564,7 @@ void FGTrafficManager::init()
// use a SchedulerParser to parse, but run it in this thread,
// i.e don't start it
ScheduleParseThread parser(this);
readXML(path.str(), parser);
readXML(path.local8BitStr(), parser);
}
} else if (path.extension() == "conf") {
if (path.exists()) {
@ -571,7 +572,7 @@ void FGTrafficManager::init()
}
} else {
SG_LOG(SG_AI, SG_ALERT,
"Unknown data format " << path.str()
"Unknown data format " << path
<< " for traffic");
}
//exit(1);
@ -627,11 +628,11 @@ void FGTrafficManager::loadHeuristics()
cacheData.append(airport + "-cache.txt");
string revisionStr;
if (cacheData.exists()) {
std::ifstream data(cacheData.c_str());
sg_ifstream data(cacheData);
data >> revisionStr;
if (revisionStr != "[TrafficManagerCachedata:ref:2011:09:04]") {
SG_LOG(SG_AI, SG_ALERT,"Traffic Manager Warning: discarding outdated cachefile " <<
cacheData.c_str() << " for Airport " << airport);
cacheData << " for Airport " << airport);
} else {
while (1) {
Heuristic h; // = new Heuristic;
@ -761,7 +762,8 @@ void FGTrafficManager::readTimeTableFromFile(SGPath infileName)
string buffString;
vector <string> tokens, depTime,arrTime;
vector <string>::iterator it;
std::ifstream infile(infileName.str().c_str());
sg_ifstream infile(infileName);
while (1) {
infile.getline(buffer, 256);
if (infile.eof()) {
@ -778,7 +780,7 @@ void FGTrafficManager::readTimeTableFromFile(SGPath infileName)
if (!tokens.empty()) {
if (tokens[0] == string("AC")) {
if (tokens.size() != 13) {
throw sg_io_exception("Error parsing traffic file @ " + buffString, sg_location(infileName.str()));
throw sg_io_exception("Error parsing traffic file @ " + buffString, infileName);
}
@ -801,7 +803,7 @@ void FGTrafficManager::readTimeTableFromFile(SGPath infileName)
if (!FGAISchedule::validModelPath(model)) {
SG_LOG(SG_AI, SG_WARN, "TrafficMgr: Missing model path:" <<
model << " from " << infileName.str());
model << " from " << infileName);
} else {
SG_LOG(SG_AI, SG_INFO, "Adding Aircraft" << model << " " << livery << " " << homePort << " "
@ -825,7 +827,7 @@ void FGTrafficManager::readTimeTableFromFile(SGPath infileName)
if (tokens[0] == string("FLIGHT")) {
//cerr << "Found flight " << buffString << " size is : " << tokens.size() << endl;
if (tokens.size() != 10) {
SG_LOG(SG_AI, SG_ALERT, "Error parsing traffic file " << infileName.str() << " at " << buffString);
SG_LOG(SG_AI, SG_ALERT, "Error parsing traffic file " << infileName << " at " << buffString);
exit(1);
}
string callsign = tokens[1];
@ -920,5 +922,3 @@ void FGTrafficManager::Tokenize(const string& str,
pos = str.find_first_of(delimiters, lastPos);
}
}

View file

@ -194,7 +194,8 @@ fgviewerMain(int argc, char** argv)
SGPath mpath( globals->get_fg_root() );
mpath.append( fgGetString("/sim/rendering/materials-file") );
if ( ! globals->get_matlib()->load(globals->get_fg_root().local8BitStr(), mpath.str(),
if ( ! globals->get_matlib()->load(globals->get_fg_root().local8BitStr(),
mpath.local8BitStr(),
globals->get_props()) ) {
throw sg_io_exception("Error loading materials file", mpath);
}

View file

@ -596,11 +596,11 @@ FGRenderer::init( void )
texture_path.append("Textures");
texture_path.append("Sky");
for (int i = 0; i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
SGCloudLayer * layer = new SGCloudLayer(texture_path.str());
SGCloudLayer * layer = new SGCloudLayer(texture_path.local8BitStr());
_sky->add_cloud_layer(layer);
}
_sky->texture_path( texture_path.str() );
_sky->texture_path( texture_path.local8BitStr() );
if (!_classicalRenderer) {
eventHandler->setChangeStatsCameraRenderOrder( true );

View file

@ -231,7 +231,7 @@ static osg::Node* fgCreateSplashCamera()
SGSharedPtr<SGPropertyNode> style = fgGetNode("/sim/gui/style[0]", true);
osg::Texture2D* splashTexture = new osg::Texture2D;
splashTexture->setImage(osgDB::readImageFile(tpath.c_str()));
splashTexture->setImage(osgDB::readImageFile(tpath.local8BitStr()));
osg::Camera* camera = new osg::Camera;
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
@ -318,7 +318,7 @@ static osg::Node* fgCreateSplashCamera()
FGFontCache* fontCache = FGFontCache::instance();
osgText::Text* text = new osgText::Text;
std::string fn = style->getStringValue("fonts/splash", "");
text->setFont(fontCache->getfntpath(fn).str());
text->setFont(fontCache->getfntpath(fn).local8BitStr());
text->setCharacterSize(0.06);
text->setColor(osg::Vec4(1, 1, 1, 1));
text->setPosition(osg::Vec3(0, -0.92, 0));
@ -329,7 +329,7 @@ static osg::Node* fgCreateSplashCamera()
geode->addDrawable(text);
osgText::Text* spinnertext = new osgText::Text;
spinnertext->setFont(fontCache->getfntpath(fn).str());
spinnertext->setFont(fontCache->getfntpath(fn).local8BitStr());
spinnertext->setCharacterSize(0.06);
spinnertext->setColor(osg::Vec4(1, 1, 1, 1));
spinnertext->setPosition(osg::Vec3(0, -0.97, 0));
@ -340,7 +340,7 @@ static osg::Node* fgCreateSplashCamera()
geode->addDrawable(spinnertext);
text = new osgText::Text;
text->setFont(fontCache->getfntpath(fn).str());
text->setFont(fontCache->getfntpath(fn).local8BitStr());
text->setCharacterSize(0.08);
text->setColor(osg::Vec4(1, 1, 1, 1));
text->setPosition(osg::Vec3(0, 0.92, 0));
@ -351,7 +351,7 @@ static osg::Node* fgCreateSplashCamera()
text = new osgText::Text;
text->setFont(fontCache->getfntpath(fn).str());
text->setFont(fontCache->getfntpath(fn).local8BitStr());
text->setCharacterSize(0.06);
text->setColor(osg::Vec4(1, 1, 1, 1));
text->setPosition(osg::Vec3(0, 0.82, 0));

View file

@ -261,8 +261,10 @@ bool UGTrack::load_flight( const string &path ) {
// open the gps file
file = path; file.append( "gps.dat.gz" );
if ( (fgps = gzopen( file.c_str(), "r" )) == NULL ) {
printf("Cannot open %s\n", file.c_str());
std::string fdata = file.local8BitStr();
if ( (fgps = gzopen( fdata.c_str(), "r" )) == NULL ) {
printf("Cannot open %s\n", fdata.c_str());
return false;
}
@ -274,8 +276,9 @@ bool UGTrack::load_flight( const string &path ) {
// open the imu file
file = path; file.append( "imu.dat.gz" );
if ( (fimu = gzopen( file.c_str(), "r" )) == NULL ) {
printf("Cannot open %s\n", file.c_str());
fdata = file.local8BitStr();
if ( (fimu = gzopen( fdata.c_str(), "r" )) == NULL ) {
printf("Cannot open %s\n", fdata.c_str());
return false;
}
@ -287,8 +290,10 @@ bool UGTrack::load_flight( const string &path ) {
// open the nav file
file = path; file.append( "nav.dat.gz" );
if ( (fnav = gzopen( file.c_str(), "r" )) == NULL ) {
printf("Cannot open %s\n", file.c_str());
fdata = file.local8BitStr();
if ( (fnav = gzopen( fdata.c_str(), "r" )) == NULL ) {
printf("Cannot open %s\n", fdata.c_str());
return false;
}
@ -301,8 +306,10 @@ bool UGTrack::load_flight( const string &path ) {
// open the servo file
file = path; file.append( "servo.dat.gz" );
if ( (fservo = gzopen( file.c_str(), "r" )) == NULL ) {
printf("Cannot open %s\n", file.c_str());
fdata = file.local8BitStr();
if ( (fservo = gzopen( fdata.c_str(), "r" )) == NULL ) {
printf("Cannot open %s\n", fdata.c_str());
return false;
}
@ -314,8 +321,10 @@ bool UGTrack::load_flight( const string &path ) {
// open the health file
file = path; file.append( "health.dat.gz" );
if ( (fhealth = gzopen( file.c_str(), "r" )) == NULL ) {
printf("Cannot open %s\n", file.c_str());
fdata = file.local8BitStr();
if ( (fhealth = gzopen( fdata.c_str(), "r" )) == NULL ) {
printf("Cannot open %s\n", fdata.c_str());
return false;
}

View file

@ -105,21 +105,23 @@ main(int argc, char** argv)
fg_root = PKGLIBDIR;
}
std::string fg_scenery;
if (arguments.read("--fg-scenery", fg_scenery)) {
} else if (const char *fg_scenery_env = std::getenv("FG_SCENERY")) {
fg_scenery = fg_scenery_env;
SGPath fg_scenery;
std::string s;
if (arguments.read("--fg-scenery", s)) {
fg_scenery = SGPath::fromLocal8Bit(s.c_str());
} else if (std::getenv("FG_SCENERY")) {
fg_scenery = SGPath::fromEnv("FG_SCENERY");
} else {
SGPath path(fg_root);
path.append("Scenery");
fg_scenery = path.str();
fg_scenery = path;
}
SGSharedPtr<SGPropertyNode> props = new SGPropertyNode;
try {
SGPath preferencesFile = fg_root;
preferencesFile.append("preferences.xml");
readProperties(preferencesFile.str(), props);
readProperties(preferencesFile, props);
} catch (...) {
// In case of an error, at least make summer :)
props->getNode("sim/startup/season", true)->setStringValue("summer");
@ -140,7 +142,7 @@ main(int argc, char** argv)
SGPath mpath(fg_root);
mpath.append("Materials/default/materials.xml");
try {
ml->load(fg_root, mpath.str(), props);
ml->load(fg_root, mpath.local8BitStr(), props);
} catch (...) {
SG_LOG(SG_GENERAL, SG_ALERT, "Problems loading FlightGear materials.\n"
<< "Probably FG_ROOT is not properly set.");
@ -153,7 +155,7 @@ main(int argc, char** argv)
options = new simgear::SGReaderWriterOptions(*ropt);
else
options = new simgear::SGReaderWriterOptions;
osgDB::convertStringPathIntoFilePathList(fg_scenery,
osgDB::convertStringPathIntoFilePathList(fg_scenery.local8BitStr(),
options->getDatabasePathList());
options->setMaterialLib(ml);
options->setPropertyNode(props);

View file

@ -175,9 +175,9 @@ void FGFontCache::init()
if (!_initialized) {
char *envp = ::getenv("FG_FONTS");
if (envp != NULL) {
_path.set(envp);
_path = SGPath::fromEnv("FG_FONTS");
} else {
_path.set(ApplicationProperties::GetRootPath("Fonts").str());
_path = ApplicationProperties::GetRootPath("Fonts");
}
_initialized = true;
}
@ -204,7 +204,8 @@ bool FGFontCache::initializeFonts()
{
static std::string fontext("txf");
init();
ulDir* fontdir = ulOpenDir(_path.c_str());
std::string pdata = _path.local8BitStr();
ulDir* fontdir = ulOpenDir(pdata.c_str());
if (!fontdir)
return false;
const ulDirEnt *dirEntry;
@ -212,8 +213,9 @@ bool FGFontCache::initializeFonts()
SGPath path(_path);
path.append(dirEntry->d_name);
if (path.extension() == fontext) {
std::string fdata = path.local8BitStr();
fntTexFont* f = new fntTexFont;
if (f->load((char *)path.c_str()))
if (f->load((char *)fdata.c_str()))
_texFonts[std::string(dirEntry->d_name)] = f;
else
delete f;

View file

@ -153,7 +153,7 @@ FGPanelApplication::FGPanelApplication( int argc, char ** argv ) :
try {
SGPath tpath = ApplicationProperties::GetRootPath( panelFilename.c_str() );
readProperties( tpath.str(), ApplicationProperties::Properties );
readProperties( tpath, ApplicationProperties::Properties );
}
catch( sg_io_exception & e ) {
cerr << e.getFormattedMessage() << endl;
@ -353,7 +353,7 @@ SGPath ApplicationProperties::GetCwd()
buf[511] = '\0';
if (cwd)
{
path = cwd;
path = SGPath::fromLocal8Bit(cwd);
}
return path;
}

View file

@ -117,8 +117,8 @@ void FGCroppedTexture::bind( bool doGLBind )
loader = textureLoader[extension];
}
_texture = loader->loadTexture( tpath.c_str() );
SG_LOG( SG_COCKPIT, SG_DEBUG, "Texture " << tpath.c_str() << " loaded from file as #" << _texture );
_texture = loader->loadTexture( tpath.local8BitStr() );
SG_LOG( SG_COCKPIT, SG_DEBUG, "Texture " << tpath << " loaded from file as #" << _texture );
cache[_path] = _texture;
}

View file

@ -60,29 +60,33 @@ main(int argc, char** argv)
sglog().set_log_classes(SG_ALL);
sglog().set_log_priority(SG_ALERT);
std::string fg_root;
if (arguments.read("--fg-root", fg_root)) {
} else if (const char *fg_root_env = std::getenv("FG_ROOT")) {
fg_root = fg_root_env;
SGPath fg_root;
std::string r;
if (arguments.read("--fg-root", r)) {
fg_root = SGPath::fromLocal8Bit(r.c_str());
} else if (std::getenv("FG_ROOT")) {
fg_root = SGPath::fromEnv("FG_ROOT");
} else {
fg_root = PKGLIBDIR;
fg_root = SGPath(PKGLIBDIR);
}
std::string fg_scenery;
if (arguments.read("--fg-scenery", fg_scenery)) {
} else if (const char *fg_scenery_env = std::getenv("FG_SCENERY")) {
fg_scenery = fg_scenery_env;
SGPath fg_scenery;
std::string s;
if (arguments.read("--fg-scenery", s)) {
fg_scenery = SGPath::fromLocal8Bit(s.c_str());
} else if (std::getenv("FG_SCENERY")) {
fg_scenery = SGPath::fromEnv("FG_SCENERY");
} else {
SGPath path(fg_root);
path.append("Scenery");
fg_scenery = path.str();
fg_scenery = path;
}
SGSharedPtr<SGPropertyNode> props = new SGPropertyNode;
try {
SGPath preferencesFile = fg_root;
preferencesFile.append("preferences.xml");
readProperties(preferencesFile.str(), props);
readProperties(preferencesFile, props);
} catch (...) {
// In case of an error, at least make summer :)
props->getNode("sim/startup/season", true)->setStringValue("summer");
@ -183,12 +187,12 @@ main(int argc, char** argv)
SGPath mpath(fg_root);
mpath.append("Materials/default/materials.xml");
try {
ml->load(fg_root, mpath.str(), props);
ml->load(fg_root.local8BitStr(), mpath.local8BitStr(), props);
} catch (...) {
SG_LOG(SG_GENERAL, SG_ALERT, "Problems loading FlightGear materials.\n"
<< "Probably FG_ROOT is not properly set.");
}
simgear::SGModelLib::init(fg_root, props);
simgear::SGModelLib::init(fg_root.local8BitStr(), props);
// Set up the reader/writer options
osg::ref_ptr<simgear::SGReaderWriterOptions> options;
@ -196,11 +200,11 @@ main(int argc, char** argv)
options = new simgear::SGReaderWriterOptions(*ropt);
else
options = new simgear::SGReaderWriterOptions;
osgDB::convertStringPathIntoFilePathList(fg_scenery,
osgDB::convertStringPathIntoFilePathList(fg_scenery.local8BitStr(),
options->getDatabasePathList());
options->setMaterialLib(ml);
options->setPropertyNode(props);
options->setPluginStringData("SimGear::FG_ROOT", fg_root);
options->setPluginStringData("SimGear::FG_ROOT", fg_root.local8BitStr());
// Omit building bounding volume trees, as the viewer will not run a simulation
options->setPluginStringData("SimGear::BOUNDINGVOLUMES", "OFF");
viewer.setReaderWriterOptions(options.get());