From 32a49cb689d377e3bdb4d38b1d4ec8c43cfb852e Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Sat, 8 Oct 2011 11:28:28 +0200 Subject: [PATCH 1/2] fgpanel: improved path handling - Allow relative paths for panels. - Set FGROOT as resource manager base path, so absolute XML includes can be resolved --- utils/fgpanel/ApplicationProperties.hxx | 1 + utils/fgpanel/FGPanelApplication.cxx | 40 +++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/utils/fgpanel/ApplicationProperties.hxx b/utils/fgpanel/ApplicationProperties.hxx index f5578feb2..69de27226 100644 --- a/utils/fgpanel/ApplicationProperties.hxx +++ b/utils/fgpanel/ApplicationProperties.hxx @@ -24,6 +24,7 @@ class ApplicationProperties { public: static double getDouble( const char * name, double def = 0.0 ); static SGPath GetRootPath( const char * subDir = NULL ); + static SGPath GetCwd(); static SGPropertyNode_ptr Properties; static std::string root; static FGFontCache fontCache; diff --git a/utils/fgpanel/FGPanelApplication.cxx b/utils/fgpanel/FGPanelApplication.cxx index cf4bbcca3..74636c41c 100644 --- a/utils/fgpanel/FGPanelApplication.cxx +++ b/utils/fgpanel/FGPanelApplication.cxx @@ -38,6 +38,7 @@ #include #include #include +#include #include @@ -85,6 +86,8 @@ FGPanelApplication::FGPanelApplication( int argc, char ** argv ) : if( fgRoot.length() > 0 ) ApplicationProperties::root = fgRoot; + simgear::ResourceManager::instance()->addBasePath(ApplicationProperties::root); + if( panelFilename.length() == 0 ) { cerr << "Need a panel filename. Use --panel=path_to_filename" << endl; throw exception(); @@ -294,14 +297,45 @@ double ApplicationProperties::getDouble( const char * name, double def ) 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 subpath( sub ); - if ( subpath.isAbsolute() ) - return subpath; + if( sub != NULL ) + { + 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 ); if( sub != NULL ) path.append( sub ); + return path; } From c92bc96ff83fafc0038759db26c6bdc881f52fc6 Mon Sep 17 00:00:00 2001 From: Frederic Bouvier Date: Sat, 8 Oct 2011 13:41:32 +0200 Subject: [PATCH 2/2] Fix win32 fgpanel build --- utils/fgpanel/FGPanelApplication.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/fgpanel/FGPanelApplication.cxx b/utils/fgpanel/FGPanelApplication.cxx index 74636c41c..568d171b1 100644 --- a/utils/fgpanel/FGPanelApplication.cxx +++ b/utils/fgpanel/FGPanelApplication.cxx @@ -22,6 +22,7 @@ #ifdef HAVE_WINDOWS_H #include +#include #endif #include "FGGLApplication.hxx"