]> git.mxchange.org Git - flightgear.git/commitdiff
fgpanel: improved path handling
authorThorstenB <brehmt@gmail.com>
Sat, 8 Oct 2011 09:28:28 +0000 (11:28 +0200)
committerThorstenB <brehmt@gmail.com>
Sat, 8 Oct 2011 09:28:28 +0000 (11:28 +0200)
- Allow relative paths for panels.
- Set FGROOT as resource manager base path, so absolute
  XML includes can be resolved

utils/fgpanel/ApplicationProperties.hxx
utils/fgpanel/FGPanelApplication.cxx

index f5578feb24d1510f8f98352c7518765f97bc9e02..69de27226952632983372065e19ab0112ad3905a 100644 (file)
@@ -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;
index cf4bbcca3c572738c6894e1395549916f03d0946..74636c41cf544b1f6c7b2d7cb2eca0b230db1002 100644 (file)
@@ -38,6 +38,7 @@
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/props/props_io.hxx>
 #include <simgear/structure/exception.hxx>
+#include <simgear/misc/ResourceManager.hxx>
 
 #include <iostream>
 
@@ -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;
 }