diff --git a/README.md b/README.md index 9572e688..8cadbd8e 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Please note some media files may require significant CPU usage to be transcoded. ### Debian or Ubuntu packages ```sh -$ apt-get install g++ autoconf automake libboost-dev libboost-locale-dev libboost-iostreams-dev libavcodec-dev libwtdbosqlite-dev libwthttp-dev libwtdbo-dev libwt-dev libmagick++-dev libavcodec-dev libavformat-dev libav-tools libpstreams-dev libcurl-dev libcurlpp-dev +$ apt-get install g++ autoconf automake libboost-dev libboost-locale-dev libboost-iostreams-dev libavcodec-dev libwtdbosqlite-dev libwthttp-dev libwtdbo-dev libwt-dev libmagick++-dev libavcodec-dev libavformat-dev libav-tools libpstreams-dev libcurl-dev libcurlpp-dev libconfig++-dev ``` ## Build diff --git a/configure.ac b/configure.ac index 3cd2b78a..fe932bb4 100644 --- a/configure.ac +++ b/configure.ac @@ -109,6 +109,11 @@ AC_CHECK_LIB( [tag], , [AC_MSG_ERROR([libtag not found!])]) +AC_CHECK_LIB( [config++], + [main], + , + [AC_MSG_ERROR([libtag not found!])]) + AC_CONFIG_FILES([Makefile src/Makefile test/Makefile]) diff --git a/src/Makefile.am b/src/Makefile.am index ba001bef..ecdd454f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,7 +3,8 @@ bin_PROGRAMS = lms lms_SOURCES = \ $(srcdir)/main/main.cpp \ $(srcdir)/av/AvInfo.cpp \ - $(srcdir)/av/AvTranscoder.cpp \ + $(srcdir)/av/AvTranscoder.cpp \ + $(srcdir)/config/Config.cpp \ $(srcdir)/cover/CoverArtGrabber.cpp \ $(srcdir)/database/Artist.cpp \ $(srcdir)/database/DatabaseClassifier.cpp \ diff --git a/src/config/Config.cpp b/src/config/Config.cpp new file mode 100644 index 00000000..61c2fda2 --- /dev/null +++ b/src/config/Config.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2016 Emeric Poupon + * + * This file is part of LMS. + * + * LMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LMS. If not, see . + */ + +#include + +#include "Config.hpp" + +namespace { + +} + +Config::Config() +: _config (nullptr) +{ +} + +Config& +Config::instance() +{ + static Config instance; + return instance; +} + +void +Config::setFile(boost::filesystem::path p) +{ + if (_config != nullptr) + delete _config; + + _config = new libconfig::Config(); + + _config->readFile(p.string().c_str()); +} + +std::string +Config::getString(std::string setting, std::string def) +{ + try { + return _config->lookup(setting); + } + catch (std::exception &e) + { + return def; + } +} + +unsigned long +Config::getULong(std::string setting, unsigned long def) +{ + try { + return static_cast(_config->lookup(setting)); + } + catch (...) + { + return def; + } +} + +long +Config::getLong(std::string setting, long def) +{ + try { + return _config->lookup(setting); + } + catch (...) + { + return def; + } +} + +bool +Config::getBool(std::string setting, bool def) +{ + try { + return _config->lookup(setting); + } + catch (...) + { + return def; + } +} + + diff --git a/src/config/Config.hpp b/src/config/Config.hpp new file mode 100644 index 00000000..fef75058 --- /dev/null +++ b/src/config/Config.hpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2016 Emeric Poupon + * + * This file is part of LMS. + * + * LMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LMS. If not, see . + */ +#pragma once + + +#include +#include + +class Config +{ + public: + + Config(const Config&) = delete; + Config& operator=(const Config&) = delete; + + static Config& instance(); + + void setFile(boost::filesystem::path p); + + // Default values are returned in case of setting not found + std::string getString(std::string setting, std::string def = ""); + unsigned long getULong(std::string setting, unsigned long def = 0); + long getLong(std::string setting, long def = 0); + bool getBool(std::string setting, bool def = false); + + private: + + Config(); + + libconfig::Config *_config; +}; +