Исправлено сохранение

pull/11/head
Igor Belitskiy 3 years ago
parent 416dcc550d
commit 65f13c4662

@ -17,6 +17,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissin
set(SOURCE_FILES
ubl-settings-bootloader.h
ubl-settings-bootloader.cc
my_cmd.h
save.h
save.cc
load.h

@ -1,21 +1,16 @@
#include "load.h"
namespace Lib_Load{
void Load::set_sections(string sections){
this->sections = sections;
}
void Load::set_count_error(int count_error) {
process.set_count_error(count_error);
}
string Load::get_cmd_error() {
return process.get_cmd_error();
}
map<string, string>& Load::get_load_data(std::map <string, string> &map_temp, string str_flag_load) {
string cmd = "";
map<string, string>& Load::get_load_data(std::map <string, string> &map_temp, string cmd) {
string response = "";
string key = "";
string value = "";
cmd = "ubconfig --default --source " + str_flag_load + " get " + this->sections;
response = process.call_all_sections(cmd);
vector<string> vec_str_key_value = Utils::split(response, '\n');
for (const string &param: vec_str_key_value) {

@ -9,7 +9,6 @@ namespace Lib_Load{
string sections;
My_Process::My_Process_call process = My_Process::My_Process_call();
public:
void set_sections(string sections);
int get_count_error();
void set_count_error(int count_error);
string get_cmd_error();

@ -0,0 +1,13 @@
#ifndef CMD_H
#define CMD_H
#define global_load "ubconfig --default --source global get boot"
#define system_load "ubconfig --default --source system get boot"
#define global_save "ubconfig --target global set boot "
#define system_save "ubconfig --target system set boot "
#define global_remove "ubconfig --target global remove boot "
#define system_remove "ubconfig --target system remove boot "
#endif

@ -107,42 +107,38 @@ void Save::save(string sections, string str_flag_save) {
}
}
void Save::save_all(string sections, string str_flag_save) {
void Save::save_one_cmd(string cmd1, string cmd_remove, string str_flag_save) {
string key = "";
string value = "";
string cmd_all = "ubconfig --target " + str_flag_save + " set " + sections;
size_t len_start_cmd_all = cmd_all.length();
string str_error = "";
this->flag_no_save = true;
string cmd = "";
string cmd_remove = "";
this->flag_no_save = true;
cmd = cmd1;
string remove = cmd_remove;
for (const auto &key: *vec_param_names) {
if (map_gui->find(key) != map_gui->end()) {
value = (*map_gui)[key];
if (this->check_save(str_flag_save, key)) {
if (value.length() != 0) {
cmd_all += " " + key + "=\"" + value + "\"";
cmd = cmd + key + "=\"" + value + "\" ";
}
else if (value.length() == 0) {
cmd = "ubconfig --target " + str_flag_save + " remove " + sections + " " + key;
remove = remove + key + " ";
}
else {
cmd = "";
}
if (cmd.length() != 0) {
process.call(cmd, "");
this->flag_no_save = false;
str_error = process.get_cmd_error();
if (str_error.length() != 0) {
this->vec_errors.push_back(str_error);
str_error = "";
}
}
if (cmd.length() != cmd1.length()) {
this->template_save(cmd);
}
if (cmd_remove.length() != remove.length()) {
this->template_save(remove);
}
}
if (len_start_cmd_all != cmd_all.length()) {
void Save::template_save(string cmd) {
string str_error = "";
cout << cmd << endl;
process.call(cmd, "");
this->flag_no_save = false;
str_error = process.get_cmd_error();
@ -150,6 +146,7 @@ void Save::save_all(string sections, string str_flag_save) {
this->vec_errors.push_back(str_error);
str_error = "";
}
}
}
}

@ -13,15 +13,17 @@ private:
vector<string>* vec_param_names;
My_Process::My_Process_system process = My_Process::My_Process_system();
bool flag_no_save;
void template_save(string cmd);
public:
void set_data_global(std::map <string, string> &map_global);
void set_data_local(std::map <string, string> &map_local);
void set_data_gui(std::map <string, string> &map_gui);
bool check_save(string flag_save, string key_name);
bool get_state_save();
void save_one_cmd(string cmd1, string cmd_remove, string str_flag_save);
int get_count_error();
string get_cmd_error();
void save_all(string sections, string str_flag_save);
void set_count_error(int count_error);
void set_vec_params(vector<string>& vec_param_names);
void save(string sections, string str_flag_save) ;

@ -669,8 +669,8 @@ void MainWindow::set_active_boot_second() {
void MainWindow::wrapper_save_all_cfg() {
this->set_data_cfg();
bool _flag_save_global = this->save_template("boot", "global");;
bool _flag_save_local = this->save_template("boot", "system");
bool _flag_save_global = this->save_template(global_save, global_remove , "global");
bool _flag_save_local = this->save_template(system_save, system_remove , "global");
if (_flag_save_global && _flag_save_local) {
this->info_warning_error(5);
}
@ -684,7 +684,7 @@ void MainWindow::wrapper_save_all_cfg() {
void MainWindow::wrapper_save_global_cfg() {
this->set_data_cfg();
if (this->save_template("boot", "global")) {
if (this->save_template(global_save, global_remove , "global")) {
this->info_warning_error(5);
}
else {
@ -694,13 +694,13 @@ void MainWindow::wrapper_save_global_cfg() {
}
bool MainWindow::save_template(string section, string flag_save) {
bool MainWindow::save_template(string cmd, string cmd_remove, string flag_save) {
bool flag_no_save = true;
obj_save.set_data_local(map_local_cmd_selection);
obj_save.set_data_global(map_global_cmd_selection);
obj_save.set_data_gui(map_cmd_selection);
obj_save.set_vec_params(vec_param_names);
obj_save.save(section, flag_save);
obj_save.save_one_cmd(cmd, cmd_remove ,flag_save);
vector<string> obj_vec_error = obj_save.get_error();
flag_no_save = obj_save.get_state_save();
return flag_no_save;
@ -708,7 +708,7 @@ bool MainWindow::save_template(string section, string flag_save) {
void MainWindow::wrapper_save_local_cfg() {
this->set_data_cfg();
if (this->save_template("boot", "system")) {
if (this->save_template(system_save, system_remove , "global")) {
this->info_warning_error(5);
}
else {
@ -751,26 +751,28 @@ void MainWindow::set_data_cfg() {
}
void MainWindow::download_globl_cfg() {
this->load_template(&map_global_cmd_selection, "global");
this->load_template(&map_global_cmd_selection, global_load);
info_warning_error(1);
map_cmd_selection = map_global_cmd_selection;
}
void MainWindow::download_local_cfg() {
this->load_template(&map_local_cmd_selection, "system");
this->load_template(&map_local_cmd_selection, system_load);
info_warning_error(0);
map_cmd_selection = map_local_cmd_selection;
}
void MainWindow::load_template(std::map<string, string>* map_temp, string str_load) {
this->init_dict(str_load);
void MainWindow::load_template(std::map<string, string>* map_temp, string cmd) {
if (cmd.find("system") != string::npos) {
this->init_dict("system");
}
else {
this->init_dict("global");
}
entryKernel->set_text("");
entryOTT->set_text("");
entryIPT->set_text("");
string sections;
sections = "boot";
obj_load.set_sections(sections);
*map_temp = obj_load.get_load_data(*map_temp, str_load);
*map_temp = obj_load.get_load_data(*map_temp, cmd);
this->get_menu_boot(*map_temp);
this->get_setting_entry_all("GRUB_CMDLINE_LINUX", map_temp);
this->get_setting_entry_all("GRUB_TERMINAL_INPUT", map_temp);

@ -12,6 +12,7 @@
#include <libintl.h>
#include <glibmm/i18n.h>
#include <map>
#include "my_cmd.h"
#include "ubl-util-standard.c"
#include "util.h"
#include "save.h"
@ -163,7 +164,7 @@ class MainWindow : public Gtk::ApplicationWindow {
void wrapper_save_all_cfg();
void wrapper_save_local_cfg();
void wrapper_save_global_cfg();
bool save_template(string section, string flag_save);
bool save_template(string cmd, string cmd_remove, string flag_save);
void view_add_colums(Gtk::TreeView &treeView);
vector<string> read_file_and_view(string file_name ,Gtk::TreeModel::Row &row, Glib::RefPtr<Gtk::ListStore> list_store_m);
void download_local_cfg();
@ -188,7 +189,7 @@ class MainWindow : public Gtk::ApplicationWindow {
void get_password_protec(std::map <string, string> &map_temp);
void set_password_protec();
void set_entry(Gtk::Entry* entry , std::map<string, string> &map_temp, string key);
void load_template(std::map<string, string>* map_temp, string str_load);
void load_template(std::map<string, string>* map_temp, string cmd);
vector<string> get_setting_entry_all(string key, std::map <string, string>* map_temp);
void cmd_entry_all(Gtk::Entry &entry, string cmd_settings, string cmd_remove);
void item_selected_kernel(const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator&);

Loading…
Cancel
Save