diff --git a/include/settings/Settings.hpp b/include/settings/Settings.hpp index ed87bf3d..930fb5d1 100644 --- a/include/settings/Settings.hpp +++ b/include/settings/Settings.hpp @@ -114,7 +114,7 @@ public: { //if (next < min) next = min; //if (next > max) next = max; - if (next != value) + if (next != value || string.empty()) { this->fireCallbacks(next); value = next; diff --git a/src/settings/SettingCommands.cpp b/src/settings/SettingCommands.cpp index b761c77e..be94a3fc 100644 --- a/src/settings/SettingCommands.cpp +++ b/src/settings/SettingCommands.cpp @@ -2,6 +2,10 @@ #include #include #include +#include +#include +#include +#include /* Created on 29.07.18. @@ -44,6 +48,38 @@ static CatCommand cat("cat", "", [](const CCommand& args) { } }); +static CatCommand save("save", "", [](const CCommand& args) { + settings::SettingsWriter writer{ settings::Manager::instance() }; + + DIR *config_directory = opendir(DATA_PATH "/configs"); + if (!config_directory) + { + logging::Info("Configs directory doesn't exist, creating one!"); + mkdir(DATA_PATH "/configs", S_IRWXU | S_IRWXG); + } + + if (args.ArgC() == 1) + { + writer.saveTo(DATA_PATH "/configs/default.conf", false); + } + else + { + writer.saveTo(std::string(DATA_PATH "/configs/") + args.Arg(1) + ".conf", false); + } +}); + +static CatCommand load("load", "", [](const CCommand& args) { + settings::SettingsReader loader{ settings::Manager::instance() }; + if (args.ArgC() == 1) + { + loader.loadFrom(DATA_PATH "/configs/default.conf"); + } + else + { + loader.loadFrom(std::string(DATA_PATH "/configs/") + args.Arg(1) + ".conf"); + } +}); + static std::vector sorted{}; static void getAndSortAllVariables()