mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 02:23:01 +08:00
重构Configer
This commit is contained in:
43
MeoAssistance/AbstractConfiger.cpp
Normal file
43
MeoAssistance/AbstractConfiger.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "AbstractConfiger.h"
|
||||
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
#include <json.h>
|
||||
|
||||
#include "Logger.hpp"
|
||||
|
||||
bool asst::AbstractConfiger::load(const std::string& filename)
|
||||
{
|
||||
DebugTraceFunction;
|
||||
DebugTrace("Configer::load | ", filename);
|
||||
|
||||
std::ifstream ifs(filename, std::ios::in);
|
||||
if (!ifs.is_open()) {
|
||||
return false;
|
||||
}
|
||||
std::stringstream iss;
|
||||
iss << ifs.rdbuf();
|
||||
ifs.close();
|
||||
std::string content(iss.str());
|
||||
|
||||
auto&& ret = json::parser::parse(content);
|
||||
if (!ret) {
|
||||
DebugTrace("parse error", content);
|
||||
return false;
|
||||
}
|
||||
|
||||
json::value root = std::move(ret.value());
|
||||
|
||||
try {
|
||||
parse(std::move(root));
|
||||
}
|
||||
catch (json::exception& e) {
|
||||
DebugTraceError("Load config json error!", e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
DebugTrace("Load config succeed");
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user