mirai/lib/mirai-core/Config.cpp

36 lines
875 B
C++
Raw Normal View History

2024-08-16 21:35:12 +02:00
/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
*/
#include "Config.h"
#include "nlohmann/json.hpp"
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
namespace mirai
{
Config::Config(const std::string &path) : path_(path)
{
std::ifstream file(path_);
configJson_ = nlohmann::json::parse(file);
}
std::vector<std::string> Config::sources() const
{
std::vector<std::string> sources;
assert(configJson_.is_object());
assert(configJson_["files"].is_array());
auto jsonSources = configJson_["files"];
for (const auto &filePath : jsonSources) {
assert(filePath.is_string());
sources.push_back(filePath.get<std::string>());
}
return sources;
}
}; // namespace mirai