1
0
Fork 0

Lots of UTF8 path correctness fixes

This commit is contained in:
James Turner 2020-03-12 14:23:44 +00:00
parent 5b41f374c6
commit 27410761f3
12 changed files with 34 additions and 40 deletions

View file

@ -544,7 +544,7 @@ std::vector<std::string> FGAIBase::resolveModelPath(ModelSearchOrder searchOrder
for (SGPath p : globals->get_data_paths("AI")) {
p.append(model_path);
if (p.exists()) {
SG_LOG(SG_AI, SG_DEBUG, "Found AI model: " << p.local8BitStr());
SG_LOG(SG_AI, SG_DEBUG, "Found AI model: " << p);
path_list.push_back(p.local8BitStr());
break;
}

View file

@ -52,7 +52,7 @@ namespace canvas
"canvas::Text: using font file " << path
);
simgear::canvas::FontPtr font = osgText::readFontFile(path.local8BitStr());
simgear::canvas::FontPtr font = osgText::readFontFile(path.utf8Str());
if( !font )
SG_LOG
(
@ -86,9 +86,9 @@ namespace canvas
SGPath valid_path = fgValidatePath(p, false);
if( !valid_path.isNull() )
#if OSG_VERSION_LESS_THAN(3,4,0)
return osgDB::readRefImageFile(valid_path.local8BitStr());
return osgDB::readRefImageFile(valid_path.utf8Str());
#else
return osgDB::readRefImageFile(valid_path.local8BitStr());
return osgDB::readRefImageFile(valid_path.utf8Str());
#endif
SG_LOG(SG_IO, SG_ALERT, "canvas::Image: reading '" << path << "' denied");
@ -98,9 +98,9 @@ namespace canvas
SGPath tpath = globals->resolve_resource_path(path);
if( !tpath.isNull() )
#if OSG_VERSION_LESS_THAN(3,4,0)
return osgDB::readImageFile(tpath.local8BitStr());
return osgDB::readImageFile(tpath.utf8Str());
#else
return osgDB::readRefImageFile(tpath.local8BitStr());
return osgDB::readRefImageFile(tpath.utf8Str());
#endif
SG_LOG(SG_IO, SG_ALERT, "canvas::Image: No such image: '" << path << "'");

View file

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

View file

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

View file

@ -37,7 +37,7 @@ AddonsModel::AddonsModel(QObject* pr) :
int roleValue = IdRole;
for (auto it = m_roles.begin(); it != m_roles.end(); ++it) {
QByteArray name = (*it).toLocal8Bit();
QByteArray name = it->toUtf8();
m_roleToName[roleValue] = name;
m_nameToRole[*it] = roleValue++;
}

View file

@ -27,6 +27,7 @@
#include <plib/pu.h>
#include <simgear/props/props.hxx>
#include <simgear/misc/sg_dir.hxx>
#include <Main/globals.hxx>
@ -211,26 +212,19 @@ FGFontCache::getfntpath(const std::string& name)
bool FGFontCache::initializeFonts()
{
static std::string fontext("txf");
static std::string fontext(",txf");
init();
std::string fontPath = _path.local8BitStr();
ulDir* fontdir = ulOpenDir(fontPath.c_str());
if (!fontdir)
return false;
const ulDirEnt *dirEntry;
while ((dirEntry = ulReadDir(fontdir)) != 0) {
SGPath path(_path);
path.append(dirEntry->d_name);
if (path.extension() == fontext) {
fntTexFont* f = new fntTexFont;
std::string ps = path.local8BitStr();
if (f->load(ps.c_str()))
_texFonts[std::string(dirEntry->d_name)] = f;
else
delete f;
}
auto dir = simgear::Dir(_path);
for (auto p : dir.children(simgear::Dir::TYPE_FILE, fontext)) {
fntTexFont* f = new fntTexFont;
// FIXME : this will fail when fonts are on UTF8 paths
if (f->load(p.local8BitStr()))
_texFonts[p.file()] = f;
else
delete f;
}
ulCloseDir(fontdir);
return true;
}

View file

@ -483,7 +483,7 @@ bool fgInitHome()
}
char buf[16];
std::string ps = pidPath.local8BitStr();
std::string ps = pidPath.utf8Str();
// do open+unlink trick to the file is deleted on exit, even if we
// crash or exit(-1)
@ -873,8 +873,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.local8BitStr(),
globals->get_props()) ) {
if ( ! globals->get_matlib()->load(globals->get_fg_root(), mpath, globals->get_props()) ) {
throw sg_io_exception("Error loading materials file", mpath);
}

View file

@ -364,9 +364,7 @@ void FGGlobals::append_fg_scenery (const SGPath &path)
// tell the ResouceManager about the scenery path
// needed to load Models from this scenery path
simgear::ResourceManager::instance()->addBasePath(abspath.local8BitStr(),
simgear::ResourceManager::PRIORITY_DEFAULT);
simgear::Dir dir(abspath);
simgear::ResourceManager::instance()->addBasePath(abspath, simgear::ResourceManager::PRIORITY_DEFAULT);
fg_scenery.push_back(abspath);
extra_read_allowed_paths.push_back(abspath);

View file

@ -91,8 +91,13 @@ namespace flightgear
void SHPParser::parsePolyLines(const SGPath& aPath, PolyLine::Type aTy,
PolyLineList& aResult, bool aClosed)
{
std::string s = aPath.local8BitStr();
#if defined(SG_WINDOWS)
const auto ws = aPath.wstr();
gzFile file = gzopen_w(ws.c_str(), "rb");
#else
const auto s = aPath.utf8Str();
gzFile file = gzopen(s.c_str(), "rb");
#endif
if (!file) {
throw sg_io_exception("couldn't open file:", aPath);
}

View file

@ -172,10 +172,10 @@ void FGTileMgr::reinit()
for (it = sc.begin(); it != sc.end(); ++it) {
fp.push_back(it->local8BitStr());
}
_options->setPluginStringData("SimGear::FG_ROOT", globals->get_fg_root().local8BitStr());
_options->setPluginStringData("SimGear::FG_ROOT", globals->get_fg_root().utf8Str());
if (_terra_sync) {
_options->setPluginStringData("SimGear::TERRASYNC_ROOT", globals->get_terrasync_dir().local8BitStr());
_options->setPluginStringData("SimGear::TERRASYNC_ROOT", globals->get_terrasync_dir().utf8Str());
}
if (!_disableNasalHooks->getBoolValue())

View file

@ -386,9 +386,7 @@ void TimeManager::throttleUpdateRate()
// periodic time updater wrapper
void TimeManager::updateLocalTime()
{
SGPath zone(globals->get_fg_root());
zone.append("Timezone");
_impl->updateLocal(globals->get_aircraft_position(), zone.local8BitStr());
_impl->updateLocal(globals->get_aircraft_position(), globals->get_fg_root() / "Timezone");
}
void TimeManager::initTimeOffset()