diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index b698bb7..93b3c4d 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -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 diff --git a/source/load.cc b/source/load.cc index e8a361b..77873dc 100644 --- a/source/load.cc +++ b/source/load.cc @@ -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& Load::get_load_data(std::map &map_temp, string str_flag_load) { - string cmd = ""; + map& Load::get_load_data(std::map &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 vec_str_key_value = Utils::split(response, '\n'); for (const string ¶m: vec_str_key_value) { diff --git a/source/load.h b/source/load.h index 26aaf96..b4d4a38 100644 --- a/source/load.h +++ b/source/load.h @@ -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(); diff --git a/source/my_cmd.h b/source/my_cmd.h new file mode 100644 index 0000000..177897b --- /dev/null +++ b/source/my_cmd.h @@ -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 \ No newline at end of file diff --git a/source/save.cc b/source/save.cc index 584e7ea..1b9949f 100644 --- a/source/save.cc +++ b/source/save.cc @@ -107,49 +107,46 @@ 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; - } - 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 = ""; - } + remove = remove + key + " "; } + } } - } - if (len_start_cmd_all != cmd_all.length()) { - 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); } } + +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(); + if (str_error.length() != 0) { + this->vec_errors.push_back(str_error); + str_error = ""; + } + +} + } diff --git a/source/save.h b/source/save.h index bdc2f56..40b13a1 100644 --- a/source/save.h +++ b/source/save.h @@ -13,15 +13,17 @@ private: vector* 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 &map_global); void set_data_local(std::map &map_local); void set_data_gui(std::map &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& vec_param_names); void save(string sections, string str_flag_save) ; diff --git a/source/ubl-settings-bootloader.cc b/source/ubl-settings-bootloader.cc index ce9b768..e89f94a 100755 --- a/source/ubl-settings-bootloader.cc +++ b/source/ubl-settings-bootloader.cc @@ -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 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* map_temp, string str_load) { - this->init_dict(str_load); +void MainWindow::load_template(std::map* 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); diff --git a/source/ubl-settings-bootloader.h b/source/ubl-settings-bootloader.h index aea4d16..5d4a3ae 100644 --- a/source/ubl-settings-bootloader.h +++ b/source/ubl-settings-bootloader.h @@ -12,6 +12,7 @@ #include #include #include +#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 read_file_and_view(string file_name ,Gtk::TreeModel::Row &row, Glib::RefPtr list_store_m); void download_local_cfg(); @@ -188,7 +189,7 @@ class MainWindow : public Gtk::ApplicationWindow { void get_password_protec(std::map &map_temp); void set_password_protec(); void set_entry(Gtk::Entry* entry , std::map &map_temp, string key); - void load_template(std::map* map_temp, string str_load); + void load_template(std::map* map_temp, string cmd); vector get_setting_entry_all(string key, std::map * 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&);