abaddon/settings.cpp
ouwou 43f87b4bca allow limiting concurrent http requests
add Semaphore
update SettingsManager a little
2020-10-04 02:28:48 -04:00

32 lines
870 B
C++

#include "settings.hpp"
#include <filesystem>
#include <fstream>
SettingsManager::SettingsManager(std::string filename)
: m_filename(filename) {
if (!std::filesystem::exists(filename)) {
std::fstream fs;
fs.open(filename, std::ios::out);
fs.close();
}
auto rc = m_ini.LoadFile(filename.c_str());
m_ok = rc == SI_OK;
}
std::string SettingsManager::GetSettingString(std::string section, std::string key, std::string fallback) const {
return m_ini.GetValue(section.c_str(), key.c_str(), fallback.c_str());
}
int SettingsManager::GetSettingInt(std::string section, std::string key, int fallback) const {
return std::stoul(GetSettingString(section, key, std::to_string(fallback)));
}
bool SettingsManager::IsValid() const {
return m_ok;
}
void SettingsManager::Close() {
m_ini.SaveFile(m_filename.c_str());
}