1
0
Fork 0

Merge branch 'next' of gitorious.org:fg/flightgear into next

This commit is contained in:
Durk Talsma 2011-10-09 00:31:47 +02:00
commit ed30b0c9a3
2 changed files with 39 additions and 3 deletions

View file

@ -24,6 +24,7 @@ class ApplicationProperties {
public: public:
static double getDouble( const char * name, double def = 0.0 ); static double getDouble( const char * name, double def = 0.0 );
static SGPath GetRootPath( const char * subDir = NULL ); static SGPath GetRootPath( const char * subDir = NULL );
static SGPath GetCwd();
static SGPropertyNode_ptr Properties; static SGPropertyNode_ptr Properties;
static std::string root; static std::string root;
static FGFontCache fontCache; static FGFontCache fontCache;

View file

@ -22,6 +22,7 @@
#ifdef HAVE_WINDOWS_H #ifdef HAVE_WINDOWS_H
#include <windows.h> #include <windows.h>
#include <direct.h>
#endif #endif
#include "FGGLApplication.hxx" #include "FGGLApplication.hxx"
@ -38,6 +39,7 @@
#include <simgear/misc/sg_path.hxx> #include <simgear/misc/sg_path.hxx>
#include <simgear/props/props_io.hxx> #include <simgear/props/props_io.hxx>
#include <simgear/structure/exception.hxx> #include <simgear/structure/exception.hxx>
#include <simgear/misc/ResourceManager.hxx>
#include <iostream> #include <iostream>
@ -85,6 +87,8 @@ FGPanelApplication::FGPanelApplication( int argc, char ** argv ) :
if( fgRoot.length() > 0 ) if( fgRoot.length() > 0 )
ApplicationProperties::root = fgRoot; ApplicationProperties::root = fgRoot;
simgear::ResourceManager::instance()->addBasePath(ApplicationProperties::root);
if( panelFilename.length() == 0 ) { if( panelFilename.length() == 0 ) {
cerr << "Need a panel filename. Use --panel=path_to_filename" << endl; cerr << "Need a panel filename. Use --panel=path_to_filename" << endl;
throw exception(); throw exception();
@ -294,14 +298,45 @@ double ApplicationProperties::getDouble( const char * name, double def )
return n->getDoubleValue(); return n->getDoubleValue();
} }
SGPath ApplicationProperties::GetCwd()
{
SGPath path(".");
char buf[512], *cwd = getcwd(buf, 511);
buf[511] = '\0';
if (cwd)
{
path = cwd;
}
return path;
}
SGPath ApplicationProperties::GetRootPath( const char * sub ) SGPath ApplicationProperties::GetRootPath( const char * sub )
{ {
SGPath subpath( sub ); if( sub != NULL )
if ( subpath.isAbsolute() ) {
return subpath; SGPath subpath( sub );
// relative path to current working dir?
if (subpath.isRelative())
{
SGPath path = GetCwd();
path.append( sub );
if (path.exists())
return path;
}
else
if ( subpath.exists() )
{
// absolute path
return subpath;
}
}
// default: relative path to FGROOT
SGPath path( ApplicationProperties::root ); SGPath path( ApplicationProperties::root );
if( sub != NULL ) if( sub != NULL )
path.append( sub ); path.append( sub );
return path; return path;
} }