diff --git a/Nasal/IOrules b/Nasal/IOrules index 138513059..07117c0f1 100644 --- a/Nasal/IOrules +++ b/Nasal/IOrules @@ -28,6 +28,7 @@ READ ALLOW $FG_ROOT/* READ ALLOW $FG_HOME/* READ ALLOW $FG_AIRCRAFT/* +READ ALLOW $FG_SCENERY/* WRITE ALLOW /tmp/*.xml WRITE ALLOW $FG_HOME/*.sav diff --git a/Nasal/io.nas b/Nasal/io.nas index 41d5d7fc9..fbf1e358f 100644 --- a/Nasal/io.nas +++ b/Nasal/io.nas @@ -81,6 +81,33 @@ var read_properties = func(path, target = nil) { return fgcommand("loadxml", args) ? ret : nil; } +# Load XML file in FlightGear's native format. +# file will be located in the airport-scenery directories according to +# ICAO and filename, i,e in Airports/I/C/A/ICAO.filename.xml +# If the second, optional target parameter is set, then the properties +# are loaded to this node in the global property tree. Otherwise they +# are returned as a separate props.Node tree. Returns the data as a +# props.Node on success or nil on error. +# +# Usage: io.read_airport_properties(, [, ]); +# +# Examples: +# +# var data = io.read_properties("KSFO", "rwyuse"); +# +var read_airport_properties = func(icao, fname, target = nil) { + var args = props.Node.new({ filename: fname, icao:icao }); + if (target == nil) { + var ret = args.getNode("data", 1); + } elsif (isa(target, props.Node)) { + args.getNode("targetnode", 1).setValue(target.getPath()); + var ret = target; + } else { + args.getNode("targetnode", 1).setValue(target); + var ret = props.globals.getNode(target, 1); + } + return fgcommand("loadxml", args) ? ret : nil; +} # Write XML file in FlightGear's native format. # Returns the filename on success or nil on error. If the source @@ -245,6 +272,14 @@ _setlistener("/sim/signals/nasal-dir-initialized", func { pattern = c.getValue() ~ "/" ~ p; append(rules, [pattern, allow]); printlog("info", "IORules: appending ", pattern); + } + } elsif (substr(pattern, 0, 12) == "$FG_SCENERY/") { + var p = substr(pattern, 12); + var sim = props.globals.getNode("/sim"); + foreach (var c; sim.getChildren("fg-scenery")) { + pattern = c.getValue() ~ "/" ~ p; + append(rules, [pattern, allow]); + printlog("info", "IORules: appending ", pattern); } } else { if (substr(pattern, 0, 9) == "$FG_ROOT/")