You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.5 KiB
88 lines
2.5 KiB
#include "save.h"
|
|
|
|
namespace Lib_save {
|
|
|
|
vector<string> Save::get_error() {
|
|
return this->vec_errors;
|
|
}
|
|
|
|
bool Save::get_state_save() {
|
|
return this->flag_no_save;
|
|
}
|
|
|
|
void Save::set_data_global(std::map <string, string> &map_global) {
|
|
this->map_global = &map_global;
|
|
}
|
|
|
|
void Save::set_data_local(std::map <string, string> &map_local) {
|
|
this->map_local = &map_local;
|
|
}
|
|
|
|
void Save::set_data_gui(std::map <string, string> &map_gui) {
|
|
this->map_gui = &map_gui;
|
|
}
|
|
|
|
bool Save::check_save(string flag_save, string key_name) {
|
|
std::map <string, string>:: iterator iter_map_data;
|
|
std::map <string, string>:: iterator iter_map_data_old;
|
|
std::map <string, string> *map_data_old;
|
|
if (flag_save == "system") {
|
|
map_data_old = map_local;
|
|
}
|
|
else if (flag_save == "global") {
|
|
map_data_old = map_global;
|
|
}
|
|
iter_map_data = (*map_gui).find(key_name);
|
|
iter_map_data_old = (*map_data_old).find(key_name);
|
|
if (iter_map_data_old == (*map_data_old).end() && iter_map_data != (*map_gui).end()) {
|
|
return true;
|
|
}
|
|
else if (iter_map_data->second != iter_map_data_old->second) {
|
|
return true;
|
|
}
|
|
else if (iter_map_data->second.length() == 0 && iter_map_data_old->second.length() == 0) {
|
|
return false;
|
|
}
|
|
else if (iter_map_data->second == iter_map_data_old->second) {
|
|
return false;
|
|
}
|
|
else {
|
|
return true;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void Save::save(std::map <string, string> &map_gui, string sections, string str_flag_save) {
|
|
string key = "";
|
|
string value = "";
|
|
string cmd = "";
|
|
string str_error = "";
|
|
this->flag_no_save = false;
|
|
for (const auto &map_iter: map_gui) {
|
|
key = map_iter.first;
|
|
value = map_iter.second;
|
|
if (this->check_save(str_flag_save, key) == true) {
|
|
if (value.length() != 0) {
|
|
cmd = "ubconfig --target " + str_flag_save + " set " + sections + " " +
|
|
key + "=\"" + value + "\"";
|
|
}
|
|
else if (value.length() == 0) {
|
|
cmd = "ubconfig --target " + str_flag_save + " remove " + sections + " " + key;
|
|
}
|
|
else {
|
|
cmd = "";
|
|
}
|
|
if (cmd.length() != 0) {
|
|
process.call(cmd, "");
|
|
this->flag_no_save = true;
|
|
str_error = process.get_cmd_error();
|
|
if (str_error.length() != 0) {
|
|
this->vec_errors.push_back(str_error);
|
|
str_error = "";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|