| 1 | // SPDX-FileCopyrightText: 2016 Torsten Dreyer |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #include <string> |
| 5 | |
| 6 | #include <simgear/misc/sg_dir.hxx> |
| 7 | |
| 8 | #include "ApplicationProperties.hxx" |
| 9 | |
| 10 | using std::string; |
| 11 | using namespace std::string_literals; |
| 12 | |
| 13 | double |
| 14 | ApplicationProperties::getDouble (const char *name, const double def) { |
| 15 | const SGPropertyNode_ptr n (ApplicationProperties::Properties->getNode (name, false)); |
| 16 | if (n == nullptr) { |
| 17 | return def; |
| 18 | } |
| 19 | return n->getDoubleValue (); |
| 20 | } |
| 21 | |
| 22 | SGPath |
| 23 | ApplicationProperties::GetRootPath (const char *sub) { |
| 24 | if (sub != nullptr) { |
| 25 | const SGPath subpath{std::string(sub)}; |
| 26 | |
| 27 | // relative path to current working dir? |
| 28 | if (subpath.isRelative()) { |
| 29 | const SGPath path = simgear::Dir::current().path() / sub; |
| 30 | if (path.exists()) { |
| 31 | return path; |
| 32 | } |
| 33 | } else if (subpath.exists()) { |
| 34 | // absolute path |
| 35 | return subpath; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | // default: relative path to FGROOT |
| 40 | SGPath path (ApplicationProperties::root); |
| 41 | if (sub != nullptr) { |
| 42 | path.append(sub); |
| 43 | } |
| 44 | return path; |
| 45 | } |
| 46 | |
| 47 | string ApplicationProperties::root = "."; |
| 48 | SGPropertyNode_ptr ApplicationProperties::Properties = new SGPropertyNode; |