109 lines
2.8 KiB
C++
109 lines
2.8 KiB
C++
#include "config.h"
|
|
#include <QDir>
|
|
#include <filesystem>
|
|
|
|
namespace fs = std::filesystem;
|
|
CGroupIni::CGroupIni()
|
|
{
|
|
default_set();
|
|
}
|
|
|
|
void CGroupIni::default_set()
|
|
{
|
|
QDir dir;
|
|
std::string path = dir.homePath().toStdString();
|
|
fs::path p(path);
|
|
p.append(".config");
|
|
|
|
if (!fs::exists(p)) {
|
|
fs::create_directories(p);
|
|
}
|
|
|
|
work_dir_ = p.string();
|
|
p.append("OneLevelXmlOpr.ini");
|
|
work_file_ = p.string();
|
|
}
|
|
|
|
bool CGroupIni::load_ini()
|
|
{
|
|
SI_Error rc = ini_.LoadFile(work_file_.c_str());
|
|
if (rc != SI_OK) {
|
|
rc = ini_.SaveFile(work_file_.c_str());
|
|
if (rc < 0) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void CGroupIni::get_all_node(StrVec_t& vec)
|
|
{
|
|
vec.clear();
|
|
|
|
CSimpleIni::TNamesDepend secs;
|
|
ini_.GetAllSections(secs);
|
|
for (const auto& sec : secs) {
|
|
vec.push_back(sec.pItem);
|
|
}
|
|
}
|
|
|
|
bool CGroupIni::add_item(const OneGroupIni& group)
|
|
{
|
|
ini_.SetValue(group.name.c_str(), "MainNodes", group.main_nodes.c_str());
|
|
ini_.SetValue(group.name.c_str(), "RelativeNodes", group.relative_nodes.c_str());
|
|
ini_.SetValue(group.name.c_str(), "ItemKey", group.item_key.c_str());
|
|
ini_.SetValue(group.name.c_str(), "Properties", group.propertis.c_str());
|
|
ini_.SetLongValue(group.name.c_str(), "MaxColLen", group.max_col_len);
|
|
ini_.SetLongValue(group.name.c_str(), "MaxBlankAdd", group.max_blank_add);
|
|
ini_.SetBoolValue(group.name.c_str(), "IsSameStruct", group.is_same);
|
|
|
|
if (ini_.SaveFile(work_file_.c_str()) != SI_OK) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool CGroupIni::get_item(OneGroupIni& group)
|
|
{
|
|
StrVec_t vec;
|
|
get_all_node(vec);
|
|
|
|
bool find = false;
|
|
for (const auto& item : vec) {
|
|
if (group.name != item) {
|
|
continue;
|
|
}
|
|
find = true;
|
|
break;
|
|
}
|
|
|
|
if (!find) {
|
|
return false;
|
|
}
|
|
|
|
group.main_nodes = ini_.GetValue(group.name.c_str(), "MainNodes");
|
|
group.relative_nodes = ini_.GetValue(group.name.c_str(), "RelativeNodes");
|
|
group.item_key = ini_.GetValue(group.name.c_str(), "ItemKey");
|
|
group.propertis = ini_.GetValue(group.name.c_str(), "Properties");
|
|
group.max_col_len = ini_.GetLongValue(group.name.c_str(), "MaxColLen");
|
|
group.max_blank_add = ini_.GetLongValue(group.name.c_str(), "MaxBlankAdd");
|
|
group.is_same = ini_.GetBoolValue(group.name.c_str(), "IsSameStruct");
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CGroupIni::del_item(const std::string &key)
|
|
{
|
|
ini_.Delete(key.c_str(), "MainNodes", true);
|
|
ini_.Delete(key.c_str(), "RelativeNodes", true);
|
|
ini_.Delete(key.c_str(), "ItemKey", true);
|
|
ini_.Delete(key.c_str(), "Properties", true);
|
|
ini_.Delete(key.c_str(), "MaxColLen", true);
|
|
ini_.Delete(key.c_str(), "MaxBlankAdd", true);
|
|
if (ini_.SaveFile(work_file_.c_str()) != SI_OK) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|