]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_commands.cxx
apt.dat parser: clearer log and exception messages
[flightgear.git] / src / Main / fg_commands.cxx
index 8326aa77a2f2fcf787e67287ea6275a77c167ade..1e93a0b7b70e6cd32a12381c525c1646e5ab3f25 100644 (file)
@@ -23,7 +23,7 @@
 #include <simgear/structure/event_mgr.hxx>
 #include <simgear/sound/soundmgr_openal.hxx>
 #include <simgear/timing/sg_time.hxx>
-#include <simgear/io/HTTPRequest.hxx>
+#include <Network/RemoteXMLRequest.hxx>
 
 #include <FDM/flight.hxx>
 #include <GUI/gui.h>
 #include <GUI/dialog.hxx>
 #include <Aircraft/replay.hxx>
 #include <Scenery/scenery.hxx>
+#include <Scenery/tilemgr.hxx>
 #include <Scripting/NasalSys.hxx>
 #include <Sound/sample_queue.hxx>
 #include <Airports/xmlloader.hxx>
 #include <Network/HTTPClient.hxx>
 #include <Viewer/viewmgr.hxx>
-#include <Viewer/viewer.hxx>
+#include <Viewer/view.hxx>
 #include <Environment/presets.hxx>
+#include <Navaids/NavDataCache.hxx>
 
 #include "fg_init.hxx"
 #include "fg_io.hxx"
 
 #include <boost/scoped_array.hpp>
 
-#ifdef FG_HAVE_GPERFTOOLS
+#if FG_HAVE_GPERFTOOLS
 # include <google/profiler.h>
 #endif
 
+#if defined(HAVE_QT)
+#include <GUI/QtLauncher.hxx>
+#endif
+
 using std::string;
 using std::ifstream;
 using std::ofstream;
@@ -158,7 +164,7 @@ compare_values (SGPropertyNode * value1, SGPropertyNode * value2)
 }
 
 
-\f
+
 ////////////////////////////////////////////////////////////////////////
 // Command implementations.
 ////////////////////////////////////////////////////////////////////////
@@ -204,10 +210,32 @@ do_exit (const SGPropertyNode * arg)
 static bool
 do_reset (const SGPropertyNode * arg)
 {
-    fgReInitSubsystems();
+    fgResetIdleState();
+    return true;
+}
+
+
+/**
+ * Change aircraft
+ */
+static bool
+do_switch_aircraft (const SGPropertyNode * arg)
+{
+    fgSetString("/sim/aircraft", arg->getStringValue("aircraft"));
+    // start a reset
+    fgResetIdleState();
     return true;
 }
 
+/**
+ */
+static bool
+do_reposition (const SGPropertyNode * arg)
+{
+  fgStartReposition();
+  return true;
+}
+
 /**
  * Built-in command: replay the FDR buffer
  */
@@ -224,7 +252,14 @@ do_replay (const SGPropertyNode * arg)
 static bool
 do_pause (const SGPropertyNode * arg)
 {
+    bool forcePause = arg->getBoolValue("force-pause", false );
+    bool forcePlay = arg->getBoolValue("force-play", false );
+
     bool paused = fgGetBool("/sim/freeze/master",true) || fgGetBool("/sim/freeze/clock",true);
+
+    if(forcePause) paused = false;
+    if(forcePlay) paused = true;
+
     if (paused && (fgGetInt("/sim/freeze/replay-state",0)>0))
     {
         do_replay(NULL);
@@ -235,15 +270,7 @@ do_pause (const SGPropertyNode * arg)
         fgSetBool("/sim/freeze/clock",!paused);
     }
   
-    SGPropertyNode_ptr args(new SGPropertyNode);
-    args->setStringValue("id", "sim-pause");
-    if (!paused) {
-      args->setStringValue("label", "Simulation is paused");
-      globals->get_commands()->execute("show-message", args);
-    } else {
-      globals->get_commands()->execute("clear-message", args);
-    }
-  
+    syncPausePopupState();
     return true;
 }
 
@@ -256,17 +283,19 @@ do_pause (const SGPropertyNode * arg)
 static bool
 do_load (const SGPropertyNode * arg)
 {
-    string file = arg->getStringValue("file", "fgfs.sav");
-    if (file.size() < 4 || file.substr(file.size() - 4) != ".sav")
-        file += ".sav";
+    SGPath file(arg->getStringValue("file", "fgfs.sav"));
+
+    if (file.extension() != "sav")
+        file.concat(".sav");
 
-    if (!fgValidatePath(file.c_str(), false)) {
+    std::string validated_path = fgValidatePath(file, false);
+    if (validated_path.empty()) {
         SG_LOG(SG_IO, SG_ALERT, "load: reading '" << file << "' denied "
                 "(unauthorized access)");
         return false;
     }
 
-    ifstream input(file.c_str());
+    ifstream input(validated_path.c_str());
     if (input.good() && fgLoadFlight(input)) {
         input.close();
         SG_LOG(SG_INPUT, SG_INFO, "Restored flight from " << file);
@@ -287,11 +316,13 @@ do_load (const SGPropertyNode * arg)
 static bool
 do_save (const SGPropertyNode * arg)
 {
-    string file = arg->getStringValue("file", "fgfs.sav");
-    if (file.size() < 4 || file.substr(file.size() - 4) != ".sav")
-        file += ".sav";
+    SGPath file(arg->getStringValue("file", "fgfs.sav"));
 
-    if (!fgValidatePath(file.c_str(), false)) {
+    if (file.extension() != "sav")
+        file.concat(".sav");
+
+    std::string validated_path = fgValidatePath(file, true);
+    if (validated_path.empty()) {
         SG_LOG(SG_IO, SG_ALERT, "save: writing '" << file << "' denied "
                 "(unauthorized access)");
         return false;
@@ -299,7 +330,7 @@ do_save (const SGPropertyNode * arg)
 
     bool write_all = arg->getBoolValue("write-all", false);
     SG_LOG(SG_INPUT, SG_INFO, "Saving flight");
-    ofstream output(file.c_str());
+    ofstream output(validated_path.c_str());
     if (output.good() && fgSaveFlight(output, write_all)) {
         output.close();
         SG_LOG(SG_INPUT, SG_INFO, "Saved flight to " << file);
@@ -375,17 +406,25 @@ do_preferences_load (const SGPropertyNode * arg)
 }
 
 static void
-do_view_next( bool )
+do_view_next(bool do_it)
 {
+  // Only switch view if really requested to do so (and not for example while
+  // reset/reposition where /command/view/next is set to false)
+  if( do_it )
+  {
     globals->get_current_view()->setHeadingOffset_deg(0.0);
     globals->get_viewmgr()->next_view();
+  }
 }
 
 static void
-do_view_prev( bool )
+do_view_prev(bool do_it)
 {
+  if( do_it )
+  {
     globals->get_current_view()->setHeadingOffset_deg(0.0);
     globals->get_viewmgr()->prev_view();
+  }
 }
 
 /**
@@ -492,159 +531,30 @@ do_tile_cache_reload (const SGPropertyNode * arg)
 /**
  * Reload the materials definition
  */
- static bool
- do_materials_reload (const SGPropertyNode * arg)
- {
-   SG_LOG(SG_INPUT, SG_INFO, "Reloading Materials");
-   SGMaterialLib* new_matlib =  new SGMaterialLib;
-   SGPath mpath( globals->get_fg_root() );
-   mpath.append( fgGetString("/sim/rendering/materials-file") );
-   bool loaded = new_matlib->load(globals->get_fg_root(), 
+static bool
+do_materials_reload (const SGPropertyNode * arg)
+{
+    SG_LOG(SG_INPUT, SG_INFO, "Reloading Materials");
+    SGMaterialLib* new_matlib =  new SGMaterialLib;
+    SGPath mpath( globals->get_fg_root() );
+    mpath.append( fgGetString("/sim/rendering/materials-file") );
+    bool loaded = new_matlib->load(globals->get_fg_root(), 
                                   mpath.str(), 
                                   globals->get_props());
-   
-   if ( ! loaded ) {
+
+    if ( ! loaded ) {
        SG_LOG( SG_GENERAL, SG_ALERT,
                "Error loading materials file " << mpath.str() );
        return false;
-   }  
-   
-   globals->set_matlib(new_matlib);    
-   return true;   
- }
-
-
-#if 0
-These do_set_(some-environment-parameters) are deprecated and no longer 
-useful/functional - Torsten Dreyer, January 2011
-/**
- * Set the sea level outside air temperature and assigning that to all
- * boundary and aloft environment layers.
- */
-static bool
-do_set_sea_level_degc ( double temp_sea_level_degc)
-{
-    SGPropertyNode *node, *child;
-
-    // boundary layers
-    node = fgGetNode( "/environment/config/boundary" );
-    if ( node != NULL ) {
-      int i = 0;
-      while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
-       child->setDoubleValue( "temperature-sea-level-degc",
-                              temp_sea_level_degc );
-       ++i;
-      }
-    }
-
-    // aloft layers
-    node = fgGetNode( "/environment/config/aloft" );
-    if ( node != NULL ) {
-      int i = 0;
-      while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
-       child->setDoubleValue( "temperature-sea-level-degc",
-                              temp_sea_level_degc );
-       ++i;
-      }
-    }
-
-    return true;
-}
-
-static bool
-do_set_sea_level_degc (const SGPropertyNode * arg)
-{
-    return do_set_sea_level_degc( arg->getDoubleValue("temp-degc", 15.0) );
-}
-
-
-/**
- * Set the outside air temperature at the "current" altitude by first
- * calculating the corresponding sea level temp, and assigning that to
- * all boundary and aloft environment layers.
- */
-static bool
-do_set_oat_degc (const SGPropertyNode * arg)
-{
-    double oat_degc = arg->getDoubleValue("temp-degc", 15.0);
-    // check for an altitude specified in the arguments, otherwise use
-    // current aircraft altitude.
-    const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
-    if ( altitude_ft == NULL ) {
-        altitude_ft = fgGetNode("/position/altitude-ft");
-    }
-
-    FGEnvironment dummy;       // instantiate a dummy so we can leech a method
-    dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
-    dummy.set_temperature_degc( oat_degc );
-    return do_set_sea_level_degc( dummy.get_temperature_sea_level_degc());
-}
-
-/**
- * Set the sea level outside air dewpoint and assigning that to all
- * boundary and aloft environment layers.
- */
-static bool
-do_set_dewpoint_sea_level_degc (double dewpoint_sea_level_degc)
-{
-
-    SGPropertyNode *node, *child;
-
-    // boundary layers
-    node = fgGetNode( "/environment/config/boundary" );
-    if ( node != NULL ) {
-      int i = 0;
-      while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
-       child->setDoubleValue( "dewpoint-sea-level-degc",
-                              dewpoint_sea_level_degc );
-       ++i;
-      }
-    }
-
-    // aloft layers
-    node = fgGetNode( "/environment/config/aloft" );
-    if ( node != NULL ) {
-      int i = 0;
-      while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
-       child->setDoubleValue( "dewpoint-sea-level-degc",
-                              dewpoint_sea_level_degc );
-       ++i;
-      }
-    }
+    }  
 
+    globals->set_matlib(new_matlib);    
+    FGTileMgr* tileManager = static_cast<FGTileMgr*>(globals->get_subsystem("tile-manager"));
+    tileManager->materialLibChanged();
+    
     return true;
 }
 
-static bool
-do_set_dewpoint_sea_level_degc (const SGPropertyNode * arg)
-{
-    return do_set_dewpoint_sea_level_degc(arg->getDoubleValue("dewpoint-degc", 5.0));
-}
-
-/**
- * Set the outside air dewpoint at the "current" altitude by first
- * calculating the corresponding sea level dewpoint, and assigning
- * that to all boundary and aloft environment layers.
- */
-static bool
-do_set_dewpoint_degc (const SGPropertyNode * arg)
-{
-    double dewpoint_degc = arg->getDoubleValue("dewpoint-degc", 5.0);
-
-    // check for an altitude specified in the arguments, otherwise use
-    // current aircraft altitude.
-    const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
-    if ( altitude_ft == NULL ) {
-        altitude_ft = fgGetNode("/position/altitude-ft");
-    }
-
-    FGEnvironment dummy;       // instantiate a dummy so we can leech a method
-    dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
-    dummy.set_dewpoint_degc( dewpoint_degc );
-    return do_set_dewpoint_sea_level_degc(dummy.get_dewpoint_sea_level_degc());
-}
-#endif
-
 /**
  * Built-in command: toggle a bool property value.
  *
@@ -835,7 +745,7 @@ static bool
 do_property_cycle (const SGPropertyNode * arg)
 {
     SGPropertyNode * prop = get_prop(arg);
-    vector<SGPropertyNode_ptr> values = arg->getChildren("value");
+    std::vector<SGPropertyNode_ptr> values = arg->getChildren("value");
     
     bool wrap = arg->getBoolValue("wrap", true);
     // compatible with knob/pick animations
@@ -1078,6 +988,21 @@ do_open_browser (const SGPropertyNode * arg)
     return openBrowser(path);
 }
 
+static bool
+do_open_launcher(const SGPropertyNode *)
+{
+#if defined(HAVE_QT)
+    bool ok = flightgear::runInAppLauncherDialog();
+    if (ok) {
+        // start a full reset
+        fgResetIdleState();
+    }
+    return ok;
+#else
+    return false;
+#endif
+}
+
 /**
  * Apply a value in the active XML-configured dialog.
  *
@@ -1136,45 +1061,6 @@ do_add_model (const SGPropertyNode * arg)
     return true;
 }
 
-/**
- * Built-in command: play an audio message (i.e. a wav file) This is
- * fire and forget.  Call this once per message and it will get dumped
- * into a queue.  Messages are played sequentially so they do not
- * overlap.
- */
-static bool
-do_play_audio_sample (const SGPropertyNode * arg)
-{
-    SGSoundMgr *smgr = globals->get_soundmgr();
-    if (!smgr) {
-        SG_LOG(SG_GENERAL, SG_WARN, "play-audio-sample: sound-manager not running");
-        return false;
-    }
-  
-    string path = arg->getStringValue("path");
-    string file = arg->getStringValue("file");
-    float volume = arg->getFloatValue("volume");
-    // cout << "playing " << path << " / " << file << endl;
-    try {
-        static FGSampleQueue *queue = 0;
-        if ( !queue ) {
-           queue = new FGSampleQueue(smgr, "chatter");
-           queue->tie_to_listener();
-        }
-
-        SGSoundSample *msg = new SGSoundSample(file.c_str(), path);
-        msg->set_volume( volume );
-        queue->add( msg );
-
-        return true;
-
-    } catch (const sg_io_exception&) {
-        SG_LOG(SG_GENERAL, SG_ALERT, "play-audio-sample: "
-                "failed to load" << path << '/' << file);
-        return false;
-    }
-}
-
 /**
  * Built-in command: commit presets (read from in /sim/presets/)
  */
@@ -1182,7 +1068,7 @@ static bool
 do_presets_commit (const SGPropertyNode * arg)
 {
     if (fgGetBool("/sim/initialized", false)) {
-      fgReInitSubsystems();
+      fgResetIdleState();
     } else {
       // Nasal can trigger this during initial init, which confuses
       // the logic in ReInitSubsystems, since initial state has not been
@@ -1262,9 +1148,10 @@ do_load_xml_to_proptree(const SGPropertyNode * arg)
         }
     }
     
-    if (!fgValidatePath(file.c_str(), false)) {
+    std::string validated_path = fgValidatePath(file, false);
+    if (validated_path.empty()) {
         SG_LOG(SG_IO, SG_ALERT, "loadxml: reading '" << file.str() << "' denied "
-                "(unauthorized access)");
+                "(unauthorized directory - authorization no longer follows symlinks; to authorize reading additional directories, add them to --fg-aircraft)");
         return false;
     }
 
@@ -1275,7 +1162,7 @@ do_load_xml_to_proptree(const SGPropertyNode * arg)
         targetnode = const_cast<SGPropertyNode *>(arg)->getNode("data", true);
 
     try {
-        readProperties(file.c_str(), targetnode, true);
+        readProperties(validated_path.c_str(), targetnode, true);
     } catch (const sg_exception &e) {
         SG_LOG(SG_IO, SG_WARN, "loadxml: " << e.getFormattedMessage());
         return false;
@@ -1284,112 +1171,6 @@ do_load_xml_to_proptree(const SGPropertyNode * arg)
     return true;
 }
 
-class RemoteXMLRequest : public simgear::HTTP::Request
-{
-public:
-    SGPropertyNode_ptr _complete;
-    SGPropertyNode_ptr _status;
-    SGPropertyNode_ptr _failed;
-    SGPropertyNode_ptr _target;
-    string propsData;
-    mutable string _requestBody;
-    int _requestBodyLength;
-    string _method;
-    
-    RemoteXMLRequest(const std::string& url, SGPropertyNode* targetNode) :
-        simgear::HTTP::Request(url),
-        _target(targetNode),
-        _requestBodyLength(-1),
-        _method("GET")
-    {
-    }
-    
-    void setCompletionProp(SGPropertyNode_ptr p)
-    {
-        _complete = p;
-    }
-    
-    void setStatusProp(SGPropertyNode_ptr p)
-    {
-        _status = p;
-    }
-    
-    void setFailedProp(SGPropertyNode_ptr p)
-    {
-        _failed = p;
-    }
-  
-    void setRequestData(const SGPropertyNode* body)
-    {
-        _method = "POST";
-        std::stringstream buf;
-        writeProperties(buf, body, true);
-        _requestBody = buf.str();
-        _requestBodyLength = _requestBody.size();
-    }
-    
-    virtual std::string method() const
-    {
-        return _method;
-    }
-protected:
-    virtual int requestBodyLength() const
-    {
-        return _requestBodyLength;
-    }
-    
-    virtual void getBodyData(char* s, int& count) const
-    {
-        int toRead = std::min(count, (int) _requestBody.size());
-        memcpy(s, _requestBody.c_str(), toRead);
-        count = toRead;
-        _requestBody = _requestBody.substr(count);
-    }
-    
-    virtual std::string requestBodyType() const
-    {
-        return "application/xml";
-    }
-    
-    virtual void gotBodyData(const char* s, int n)
-    {
-        propsData += string(s, n);
-    }
-    
-    virtual void failed()
-    {
-        SG_LOG(SG_IO, SG_INFO, "network level failure in RemoteXMLRequest");
-        if (_failed) {
-            _failed->setBoolValue(true);
-        }
-    }
-    
-    virtual void responseComplete()
-    {
-        simgear::HTTP::Request::responseComplete();
-        
-        int response = responseCode();
-        bool failed = false;
-        if (response == 200) {
-            try {
-                const char* buffer = propsData.c_str();
-                readProperties(buffer, propsData.size(), _target, true);
-            } catch (const sg_exception &e) {
-                SG_LOG(SG_IO, SG_WARN, "parsing XML from remote, failed: " << e.getFormattedMessage());
-                failed = true;
-                response = 406; // 'not acceptable', anything better?
-            }
-        } else {
-            failed = true;
-        }
-    // now the response data is output, signal Nasal / listeners
-        if (_complete) _complete->setBoolValue(true);
-        if (_status) _status->setIntValue(response);
-        if (_failed && failed) _failed->setBoolValue(true);
-    }
-};
-
-
 static bool
 do_load_xml_from_url(const SGPropertyNode * arg)
 {
@@ -1412,7 +1193,7 @@ do_load_xml_from_url(const SGPropertyNode * arg)
     RemoteXMLRequest* req = new RemoteXMLRequest(url, targetnode);
     
     if (arg->hasChild("body"))
-        req->setRequestData(arg->getChild("body"));
+        req->setBodyData(arg->getChild("body"));
     
 // connect up optional reporting properties
     if (arg->hasValue("complete")) 
@@ -1450,9 +1231,10 @@ do_save_xml_from_proptree(const SGPropertyNode * arg)
     if (file.extension() != "xml")
         file.concat(".xml");
 
-    if (!fgValidatePath(file.c_str(), true)) {
+    std::string validated_path = fgValidatePath(file, true);
+    if (validated_path.empty()) {
         SG_LOG(SG_IO, SG_ALERT, "savexml: writing to '" << file.str() << "' denied "
-                "(unauthorized access)");
+                "(unauthorized directory - authorization no longer follows symlinks)");
         return false;
     }
 
@@ -1465,7 +1247,7 @@ do_save_xml_from_proptree(const SGPropertyNode * arg)
         return false;
 
     try {
-        writeProperties (file.c_str(), sourcenode, true);
+        writeProperties (validated_path.c_str(), sourcenode, true);
     } catch (const sg_exception &e) {
         SG_LOG(SG_IO, SG_WARN, "savexml: " << e.getFormattedMessage());
         return false;
@@ -1520,7 +1302,7 @@ do_release_cockpit_button (const SGPropertyNode *arg)
 // Optional profiling commands using gperftools:
 // http://code.google.com/p/gperftools/
 
-#ifndef FG_HAVE_GPERFTOOLS
+#if !FG_HAVE_GPERFTOOLS
 static void
 no_profiling_support()
 {
@@ -1536,7 +1318,7 @@ no_profiling_support()
 static bool
 do_profiler_start(const SGPropertyNode *arg)
 {
-#ifdef FG_HAVE_GPERFTOOLS
+#if FG_HAVE_GPERFTOOLS
   const char *filename = arg->getStringValue("filename", "fgfs.profile");
   ProfilerStart(filename);
   return true;
@@ -1549,7 +1331,7 @@ do_profiler_start(const SGPropertyNode *arg)
 static bool
 do_profiler_stop(const SGPropertyNode *arg)
 {
-#ifdef FG_HAVE_GPERFTOOLS
+#if FG_HAVE_GPERFTOOLS
   ProfilerStop();
   return true;
 #else
@@ -1559,6 +1341,38 @@ do_profiler_stop(const SGPropertyNode *arg)
 }
 
 
+static bool
+do_set_scenery_paths(const SGPropertyNode* arg)
+{
+  globals->clear_fg_scenery();
+  
+  std::string terrasyncPath(fgGetString("/sim/terrasync/scenery-dir"));
+  bool seenTerrasyncPath = false;
+  
+  simgear::PropertyList paths = arg->getChildren("path");
+  for (size_t i = 0; i < paths.size(); ++i) {
+    std::string s = paths[i]->getStringValue();
+    if (s == terrasyncPath) {
+      seenTerrasyncPath = true;
+    }
+    
+    globals->append_fg_scenery(s);
+  }
+  
+  if (fgGetBool("/sim/terrasync/enabled") && !seenTerrasyncPath) {
+    globals->append_fg_scenery(terrasyncPath);
+  }
+  
+  if (paths.empty()) {
+    // 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());
+  }
+
+  return true;
+}
+
 ////////////////////////////////////////////////////////////////////////
 // Command setup.
 ////////////////////////////////////////////////////////////////////////
@@ -1578,6 +1392,8 @@ static struct {
     { "nasal", do_nasal },
     { "exit", do_exit },
     { "reset", do_reset },
+    { "reposition", do_reposition },
+    { "switch-aircraft", do_switch_aircraft },
     { "pause", do_pause },
     { "load", do_load },
     { "save", do_save },
@@ -1614,10 +1430,10 @@ static struct {
     { "open-browser", do_open_browser },
     { "gui-redraw", do_gui_redraw },
     { "add-model", do_add_model },
-    { "play-audio-sample", do_play_audio_sample },
     { "presets-commit", do_presets_commit },
     { "log-level", do_log_level },
     { "replay", do_replay },
+    { "open-launcher", do_open_launcher },
     /*
     { "decrease-visibility", do_decrease_visibility },
     { "increase-visibility", do_increase_visibility },
@@ -1632,7 +1448,8 @@ static struct {
     { "print-visible-scene", do_print_visible_scene_info },
     { "reload-shaders", do_reload_shaders },
     { "reload-materials", do_materials_reload },
-
+    { "set-scenery-paths", do_set_scenery_paths },
+  
     { "profiler-start", do_profiler_start },
     { "profiler-stop",  do_profiler_stop },
 
@@ -1659,14 +1476,8 @@ fgInitCommands ()
   fgTie( "/command/view/next", dummy(0), do_view_next );
   fgTie( "/command/view/prev", dummy(0), do_view_prev );
 
-  SGPropertyNode* profiler_available =
-    globals->get_props()->getNode("/sim/debug/profiler-available", true);
-#ifdef FG_HAVE_GPERFTOOLS
-  profiler_available->setBoolValue(true);
-#else
-  profiler_available->setBoolValue(false);
-#endif
-  profiler_available->setAttributes(SGPropertyNode::READ);
+  globals->get_props()->setValueReadOnly( "/sim/debug/profiler-available",
+                                          bool(FG_HAVE_GPERFTOOLS) );
 }
 
 // end of fg_commands.cxx