2024-05-15 10:59:43 +08:00
|
|
|
#include "config.h"
|
|
|
|
#include <filesystem>
|
|
|
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
|
|
|
bool ConfigIni::set_work_exe(const std::string& dir)
|
|
|
|
{
|
|
|
|
work_dir_ = dir;
|
|
|
|
|
|
|
|
auto ini_path = fs::path(work_dir_).parent_path().append("xmlopr.ini");
|
|
|
|
if (!fs::exists(ini_path)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ini_path_ = ini_path.string();
|
|
|
|
|
|
|
|
if (!parse_ini()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-05-17 22:46:33 +08:00
|
|
|
void ConfigIni::set_xml_path(const std::string& path)
|
|
|
|
{
|
|
|
|
if (ini_.IsEmpty()) {
|
2024-05-19 23:33:06 +08:00
|
|
|
return;
|
2024-05-17 22:46:33 +08:00
|
|
|
}
|
|
|
|
ini_.SetValue("Basic", "xml_path", path.c_str());
|
|
|
|
ini_.SaveFile(ini_path_.c_str());
|
|
|
|
}
|
|
|
|
|
2024-05-15 10:59:43 +08:00
|
|
|
OprBase ConfigIni::get_config()
|
|
|
|
{
|
|
|
|
return opr_base_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ConfigIni::parse_ini()
|
|
|
|
{
|
|
|
|
if (ini_.LoadFile(ini_path_.c_str()) != SI_OK) {
|
|
|
|
return false;
|
|
|
|
}
|
2024-05-19 23:33:06 +08:00
|
|
|
ini_.SetUnicode();
|
2024-05-15 10:59:43 +08:00
|
|
|
opr_base_.node_path = ini_.GetValue("Basic", "oper_node");
|
|
|
|
opr_base_.purpose = ini_.GetValue("Basic", "purpose");
|
|
|
|
opr_base_.the_node = ini_.GetValue("Basic", "the_node");
|
|
|
|
opr_base_.xml_path = ini_.GetValue("Basic", "xml_path");
|
|
|
|
return true;
|
|
|
|
}
|