///////////////////////////////////////////////////////////////////////////
| 67 | |
| 68 | //////////////////////////////////////////////////////////////////////////////// |
| 69 | void Hooks::initialize() { |
| 70 | _debug = Context::getContext().config.getInteger("debug.hooks"); |
| 71 | |
| 72 | // Scan <rc.hooks.location> |
| 73 | // <rc.data.location>/hooks |
| 74 | Directory d; |
| 75 | if (Context::getContext().config.has("hooks.location")) { |
| 76 | d = Directory(Context::getContext().config.get("hooks.location")); |
| 77 | } else { |
| 78 | d = Directory(Context::getContext().config.get("data.location")); |
| 79 | d += "hooks"; |
| 80 | } |
| 81 | |
| 82 | if (d.is_directory() && d.readable()) { |
| 83 | _scripts = d.list(); |
| 84 | std::sort(_scripts.begin(), _scripts.end()); |
| 85 | |
| 86 | if (_debug >= 1) { |
| 87 | for (auto& i : _scripts) { |
| 88 | Path p(i); |
| 89 | if (!p.is_directory()) { |
| 90 | std::string name = p.name(); |
| 91 | if (name.substr(0, 6) == "on-add" || name.substr(0, 9) == "on-modify" || |
| 92 | name.substr(0, 9) == "on-launch" || name.substr(0, 7) == "on-exit") |
| 93 | Context::getContext().debug("Found hook script " + i); |
| 94 | else |
| 95 | Context::getContext().debug("Found misnamed hook script " + i); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | } else if (_debug >= 1) |
| 100 | Context::getContext().debug("Hook directory not readable: " + d._data); |
| 101 | |
| 102 | _enabled = Context::getContext().config.getBoolean("hooks"); |
| 103 | } |
| 104 | |
| 105 | //////////////////////////////////////////////////////////////////////////////// |
| 106 | bool Hooks::enable(bool value) { |