[CONF] Resurrected config files
This commit is contained in:
@@ -23,7 +23,7 @@ Please note some media files may require significant CPU usage to be transcoded.
|
|||||||
### Debian or Ubuntu packages
|
### Debian or Ubuntu packages
|
||||||
|
|
||||||
```sh
|
```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
|
## Build
|
||||||
|
|||||||
@@ -109,6 +109,11 @@ AC_CHECK_LIB( [tag],
|
|||||||
,
|
,
|
||||||
[AC_MSG_ERROR([libtag not found!])])
|
[AC_MSG_ERROR([libtag not found!])])
|
||||||
|
|
||||||
|
AC_CHECK_LIB( [config++],
|
||||||
|
[main],
|
||||||
|
,
|
||||||
|
[AC_MSG_ERROR([libtag not found!])])
|
||||||
|
|
||||||
AC_CONFIG_FILES([Makefile
|
AC_CONFIG_FILES([Makefile
|
||||||
src/Makefile
|
src/Makefile
|
||||||
test/Makefile])
|
test/Makefile])
|
||||||
|
|||||||
+2
-1
@@ -3,7 +3,8 @@ bin_PROGRAMS = lms
|
|||||||
lms_SOURCES = \
|
lms_SOURCES = \
|
||||||
$(srcdir)/main/main.cpp \
|
$(srcdir)/main/main.cpp \
|
||||||
$(srcdir)/av/AvInfo.cpp \
|
$(srcdir)/av/AvInfo.cpp \
|
||||||
$(srcdir)/av/AvTranscoder.cpp \
|
$(srcdir)/av/AvTranscoder.cpp \
|
||||||
|
$(srcdir)/config/Config.cpp \
|
||||||
$(srcdir)/cover/CoverArtGrabber.cpp \
|
$(srcdir)/cover/CoverArtGrabber.cpp \
|
||||||
$(srcdir)/database/Artist.cpp \
|
$(srcdir)/database/Artist.cpp \
|
||||||
$(srcdir)/database/DatabaseClassifier.cpp \
|
$(srcdir)/database/DatabaseClassifier.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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#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<unsigned int>(_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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <libconfig.h++>
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
Reference in New Issue
Block a user