From daf43d2e8b90d302e318872639fddf34eb62e79a Mon Sep 17 00:00:00 2001 From: Igor Belitskiy Date: Thu, 6 Apr 2023 14:14:37 +0600 Subject: [PATCH] =?UTF-8?q?=D0=A7=D0=B0=D1=81=D1=82=D0=B8=D1=87=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/load.cc | 3 +- source/save.cc | 54 ++++--- source/save.h | 4 +- source/ubl-settings-bootloader.cc | 237 ++++++------------------------ source/ubl-settings-bootloader.h | 2 +- 5 files changed, 85 insertions(+), 215 deletions(-) diff --git a/source/load.cc b/source/load.cc index 88cfbe9..87f438a 100644 --- a/source/load.cc +++ b/source/load.cc @@ -12,7 +12,6 @@ namespace Lib_Load{ for (const string §ion: this->vec_sections) { cmd = "ubconfig --default --source " + str_flag_load + " get " + section; response = process.call_all_sections(cmd); - cout << response << endl; vector vec_str_key_value = Utils::split(response, '\n'); for (const string ¶m: vec_str_key_value) { if ((param.find("(null)") == std::string::npos) && (param.length() != 0 )) { @@ -20,6 +19,8 @@ namespace Lib_Load{ size_t index = param.find("="); key = param.substr(0, index); value = param.substr(index + 1, param.length()); + Utils::str_replace_all(value, " \"",""); + Utils::str_replace_all(value, "\"",""); map_temp[key] = value; } } diff --git a/source/save.cc b/source/save.cc index 3c155db..55343ae 100644 --- a/source/save.cc +++ b/source/save.cc @@ -34,6 +34,7 @@ bool Save::check_save(string flag_save, string key_name) { } iter_map_data = (*map_gui).find(key_name); iter_map_data_old = (*map_data_old).find(key_name); + cout << iter_map_data->second << " ||| " << iter_map_data_old->second << endl; if (iter_map_data_old == (*map_data_old).end() && iter_map_data != (*map_gui).end()) { return true; } @@ -52,36 +53,43 @@ bool Save::check_save(string flag_save, string key_name) { return true; } -void Save::save(std::map &map_gui, string sections, string str_flag_save) { +void Save::set_vec_params(vector& vec_param_names) { + this->vec_param_names = &vec_param_names; +} + +void Save::save(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 = ""; + this->flag_no_save = true; + 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 = "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 = ""; + } + cout << cmd << endl; + 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 = ""; + } } } } + } } } diff --git a/source/save.h b/source/save.h index ff32a29..e26f4ca 100644 --- a/source/save.h +++ b/source/save.h @@ -10,6 +10,7 @@ private: std::map *map_local; std::map *map_gui; vector vec_errors; + vector* vec_param_names; My_Process::My_Process_system process = My_Process::My_Process_system(); bool flag_no_save; public: @@ -18,7 +19,8 @@ public: void set_data_gui(std::map &map_gui); bool check_save(string flag_save, string key_name); bool get_state_save(); - void save(std::map &map_gui, string sections, string str_flag_save) ; + void set_vec_params(vector& vec_param_names); + void save(string sections, string str_flag_save) ; vector get_error(); }; } diff --git a/source/ubl-settings-bootloader.cc b/source/ubl-settings-bootloader.cc index 4a84409..7000711 100755 --- a/source/ubl-settings-bootloader.cc +++ b/source/ubl-settings-bootloader.cc @@ -69,6 +69,14 @@ MainWindow::MainWindow(Glib::RefPtr const& builder) { void MainWindow::settings(){ map_cmd_error[""] = ""; + vec_param_names.push_back("GRUB_TIMEOUT"); + vec_param_names.push_back("GRUB_CMDLINE_LINUX"); + vec_param_names.push_back("GRUB_TERMINAL_INPUT"); + vec_param_names.push_back("GRUB_TERMINAL_OUTPUT"); + vec_param_names.push_back("GRUB_BOOT_SILENT"); + vec_param_names.push_back("GRUB_USER"); + vec_param_names.push_back("GRUB_PASSWORD"); + vec_param_names.push_back("GRUB_DEFAULT"); this->get_builder(); this->localization(); this->add_CSS(); @@ -216,8 +224,6 @@ void MainWindow::set_download_mode(string cmd="") { return; } if (cmd.length() !=0 ) { - cmd += "\"" + key + "\""; - obj_process_system.call(cmd, ""); } else { flag_save_local = true; @@ -233,7 +239,6 @@ void MainWindow::set_security_login(string cmd = "", string cmd_remove = "") { if (index == 0) { key = ""; if (cmd_remove.length() != 0) { - obj_process_system.call(cmd_remove, ""); } else { flag_save_local = true; @@ -245,8 +250,6 @@ void MainWindow::set_security_login(string cmd = "", string cmd_remove = "") { key = entrySecurityLogin->get_text(); if (cmd.length() != 0) { entrySecurityLogin->set_text(key); - cmd = cmd + "\"" + key + "\""; - obj_process_system.call(cmd, ""); } else { flag_save_local = true; @@ -291,7 +294,6 @@ void MainWindow::set_password_protec(string cmd = "", string cmd_remove = "") { if (index == 0){ key = ""; if (cmd_remove.length() != 0) { - obj_process_system.call(cmd_remove, ""); } else { flag_save_local = true; @@ -303,8 +305,6 @@ void MainWindow::set_password_protec(string cmd = "", string cmd_remove = "") { key = entryPasswordProtecc->get_text(); if (cmd.length() != 0 and key != "************") { entryPasswordProtecc->set_text(key); - cmd = cmd + "\"" + key + "\""; - obj_process_system.call(cmd, ""); } else { flag_save_local = true; @@ -318,7 +318,6 @@ void MainWindow::set_password_protec(string cmd = "", string cmd_remove = "") { if (key!= "************") { map_cmd_selection["GRUB_PASSWORD"] = key; } - } void MainWindow::get_password_protec(std::map &map_temp) { @@ -607,51 +606,20 @@ void MainWindow::get_menu_boot(std::map &map_temp) { lblInfoSeconds->set_sensitive(true); } else { + spbSecond->set_value(1); chbLoadVariantSelectionTimer->set_active(false); spbSecond->set_sensitive(false); lblInfoSeconds->set_sensitive(true); } } else { + spbSecond->set_value(1); chbLoadVariantSelectionTimer->set_active(false); spbSecond->set_sensitive(false); lblInfoSeconds->set_sensitive(true); } } -void MainWindow::set_menu_boot(string cmd = "", string cmd_remove = "") { - if (chbLoadVariantSelectionTimer->get_active()) { - int value = spbSecond->get_value(); - if (cmd.length() != 0) { - cmd += to_string(value); - obj_process_system.call(cmd, ""); - } - else { - flag_save_local = true; - flag_save_global = true; - flag_save_all = true; - } - map_cmd_selection["GRUB_TIMEOUT"] = to_string(value); - } - else if (chbLoadVariantSelectionTimer->get_active() == false) { - if (cmd_remove.length() != 0) { - obj_process_system.call(cmd_remove, ""); - } - else { - flag_save_local = true; - flag_save_global = true; - flag_save_all = true; - } - map_cmd_selection["GRUB_TIMEOUT"] = ""; - } - else { - flag_save_local = true; - flag_save_global = true; - flag_save_all = true; - map_cmd_selection["GRUB_TIMEOUT"] = ""; - } -} - void MainWindow::cmd_entry_all(Gtk::Entry &entry, string cmd_settings, string cmd_remove) { string cmds = entry.get_text(); Utils::str_remove(cmds, ","); @@ -679,12 +647,8 @@ void MainWindow::event(){ entryOTT->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_OTT)); entrySecurityLogin->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_login)); entryPasswordProtecc->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_password)); - chbPasswordProtecc->signal_changed().connect([&]() {change_password_protecc();set_password_protec();}); + chbPasswordProtecc->signal_changed().connect([&]() {change_password_protecc();}); chbSecurityLogin->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::change_security_login)); - cmbDownloadMode->signal_changed().connect([&]() {set_download_mode();}); - chbSecurityLogin->signal_changed().connect([&]() {set_security_login();}); - cmbDefaultDonw->signal_changed().connect([&]() {set_default_load("","");}); - spbSecond->signal_changed().connect([&]() {set_menu_boot();}); if (this->check_root() == 0) { Glib::RefPtr treeViewKernelModel = treeViewKernel->get_model(); treeViewKernelModel->signal_row_changed().connect(sigc::mem_fun(*this, &MainWindow::item_selected_kernel)); @@ -721,7 +685,6 @@ void MainWindow::set_default_load(string cmd = "", string cmd_remove = "") { int index = cmbDefaultDonw->get_active_row_number(); if (index == 0) { if (cmd.length() != 0) { - obj_process_system.call(cmd, ""); } else { flag_save_local = true; @@ -731,7 +694,6 @@ void MainWindow::set_default_load(string cmd = "", string cmd_remove = "") { } else if (index > 0) { if (cmd_remove.length() != 0) { - obj_process_system.call(cmd_remove, ""); } else { flag_save_local = true; @@ -784,7 +746,14 @@ void MainWindow::change_password_protecc() { void MainWindow::set_active_boot_second() { spbSecond->set_sensitive(chbLoadVariantSelectionTimer->get_active()); lblInfoSeconds->set_sensitive(chbLoadVariantSelectionTimer->get_active()); - this->set_menu_boot(); + if (chbLoadVariantSelectionTimer->get_active()) { + int second = spbSecond->get_value(); + map_cmd_selection["GRUB_TIMEOUT"] = to_string(second); + } + else { + spbSecond->set_value(1); + map_cmd_selection["GRUB_TIMEOUT"] = ""; + } } void MainWindow::wrapper_save_all_cfg() { @@ -801,6 +770,7 @@ void MainWindow::wrapper_save_all_cfg() { } void MainWindow::wrapper_save_global_cfg() { + this->set_data_cfg(); if (this->save_global_cfg()) { this->info_warning_error(5); } @@ -810,104 +780,25 @@ void MainWindow::wrapper_save_global_cfg() { } bool MainWindow::save_global_cfg() { - string flag_save = "global"; bool flag_no_save = true; if (flag_save_global) { if (flag_save_all) { flag_save_global = false; - this->set_data_cfg(); - if (this->check_save(flag_save, "GRUB_TIMEOUT")) { - std::string cmd_boot_time = "ubconfig --target global set boot GRUB_TIMEOUT="; - string cmd_remove = "ubconfig --target global remove boot GRUB_TIMEOUT"; - this->set_menu_boot(cmd_boot_time, cmd_remove); - flag_no_save = false; - } - if (this->check_save(flag_save, "GRUB_CMDLINE_LINUX")) { - string cmd_settings_kernel = "ubconfig --target global set boot GRUB_CMDLINE_LINUX="; - string cmd_remove = "ubconfig --target global remove boot GRUB_CMDLINE_LINUX"; - this->cmd_entry_all(*entryKernel, cmd_settings_kernel, cmd_remove); - flag_no_save = false; - } - if (this->check_save(flag_save, "GRUB_TERMINAL_OUTPUT")) { - string cmd_settings_IPT = "ubconfig --target global set boot GRUB_TERMINAL_OUTPUT="; - string cmd_remove = "ubconfig --target global remove boot GRUB_TERMINAL_OUTPUT"; - this->cmd_entry_all(*entryIPT, cmd_settings_IPT,cmd_remove); - flag_no_save = false; - } - if (this->check_save(flag_save, "GRUB_TERMINAL_INPUT")) { - string cmd_settings_OTT = "ubconfig --target global set boot GRUB_TERMINAL_INPUT="; - string cmd_remove = "ubconfig --target global remove boot GRUB_TERMINAL_INPUT"; - this->cmd_entry_all(*entryOTT, cmd_settings_OTT, cmd_remove); - flag_no_save = false; - } - if (this->check_save(flag_save, "GRUB_BOOT_SILENT")) { - this->set_download_mode("ubconfig --target global set boot GRUB_BOOT_SILENT="); - flag_no_save = false; - } - if (this->check_save(flag_save, "GRUB_USER")) { - string cmd_login = "ubconfig --target global set boot GRUB_USER="; - string cmd_remove_login = "ubconfig --target system remove boot GRUB_USER"; - this->set_security_login(cmd_login, cmd_remove_login); - flag_no_save = false; - } - if (this->check_save(flag_save, "GRUB_PASSWORD")) { - string cmd_password = "ubconfig --target global set boot GRUB_PASSWORD="; - string cmd_password_remove = "ubconfig --target global remove boot GRUB_PASSWORD"; - this->set_password_protec(cmd_password, cmd_password_remove); - flag_no_save = false; - } - if (this->check_save(flag_save, "GRUB_DEFAULT")) { - string cmd_load = "ubconfig --target global set boot GRUB_DEFAULT="; - string cmd_load_remove = "ubconfig --target global remove boot GRUB_DEFAULT"; - this->set_default_load(cmd_load, cmd_load_remove); - flag_no_save = false; - } + obj_save.set_data_local(map_cmd_selection); + obj_save.set_data_global(map_local_cmd_selection); + obj_save.set_data_gui(map_cmd_selection); + obj_save.set_vec_params(vec_param_names); + obj_save.save("boot", "global"); + vector obj_vec_error = obj_save.get_error(); + flag_no_save = obj_save.get_state_save(); } } - map_global_cmd_selection = map_cmd_selection; + map_local_cmd_selection = map_cmd_selection; return flag_no_save; } -bool MainWindow::check_save(string flag_save, string key_name="") { - std::map :: iterator iter_map_data; - std::map :: iterator iter_map_data_old; - std::map map_config_data_old; - if (flag_save == "local") { - map_config_data_old = map_local_cmd_selection; - } - else if (flag_save == "global") { - map_config_data_old = map_global_cmd_selection; - } - iter_map_data = map_cmd_selection.find(key_name); - iter_map_data_old = map_config_data_old.find(key_name); - - if (iter_map_data_old == map_config_data_old.end() && iter_map_data != map_cmd_selection.end()) { - cout << 2 << endl; - return true; - } - else if (iter_map_data->second != iter_map_data_old->second) { - cout << iter_map_data->second << " ||| " << iter_map_data_old->second << endl; - cout << 3 << endl; - return true; - } - else if (iter_map_data->second.length() == 0 && iter_map_data_old->second.length() == 0) { - cout << 4 << " " << key_name << endl; - return false; - } - else if (iter_map_data->second == iter_map_data_old->second) { - cout << 5 << " " << key_name << endl; - return false; - } - else { - cout << 6 << endl; - return true; - } - cout << 7 << endl; - return true; - -} - void MainWindow::wrapper_save_local_cfg() { + this->set_data_cfg(); if (this->save_local_cfg()){ this->info_warning_error(5); } @@ -917,59 +808,17 @@ void MainWindow::wrapper_save_local_cfg() { } bool MainWindow::save_local_cfg() { - string flag_save = "local"; bool flag_no_save = true; if (flag_save_local) { if (flag_save_all) { flag_save_local = false; - this->set_data_cfg(); - if (this->check_save(flag_save, "GRUB_TIMEOUT")) { - std::string cmd_boot_time = "ubconfig --target system set boot GRUB_TIMEOUT="; - string cmd_remove = "ubconfig --target system remove boot GRUB_TIMEOUT"; - this->set_menu_boot(cmd_boot_time, cmd_remove); - flag_no_save = false; - } - if (this->check_save(flag_save, "GRUB_CMDLINE_LINUX")) { - string cmd_settings_kernel = "ubconfig --target system set boot GRUB_CMDLINE_LINUX="; - string cmd_remove = "ubconfig --target system remove boot GRUB_CMDLINE_LINUX"; - this->cmd_entry_all(*entryKernel, cmd_settings_kernel, cmd_remove); - flag_no_save = false; - } - if (this->check_save(flag_save, "GRUB_TERMINAL_OUTPUT")) { - string cmd_settings_IPT = "ubconfig --target system set boot GRUB_TERMINAL_OUTPUT="; - string cmd_remove = "ubconfig --target system remove boot GRUB_TERMINAL_OUTPUT"; - this->cmd_entry_all(*entryIPT, cmd_settings_IPT, cmd_remove); - flag_no_save = false; - } - if (this->check_save(flag_save, "GRUB_TERMINAL_INPUT")) { - string cmd_settings_OTT = "ubconfig --target system set boot GRUB_TERMINAL_INPUT="; - string cmd_remove = "ubconfig --target system remove boot GRUB_TERMINAL_INPUT"; - this->cmd_entry_all(*entryOTT, cmd_settings_OTT, cmd_remove); - flag_no_save = false; - } - if (this->check_save(flag_save, "GRUB_BOOT_SILENT")) { - this->set_download_mode("ubconfig --target system set boot GRUB_BOOT_SILENT="); - flag_no_save = false; - } - if (this->check_save(flag_save, "GRUB_USER")) { - string cmd_login = "ubconfig --target system set boot GRUB_USER="; - string cmd_remove_login = "ubconfig --target system remove boot GRUB_USER"; - this->set_security_login(cmd_login, cmd_remove_login); - flag_no_save = false; - } - if (this->check_save(flag_save, "GRUB_PASSWORD")) { - string cmd_password = "ubconfig --target system set boot GRUB_PASSWORD="; - string cmd_password_remove = "ubconfig --target system remove boot GRUB_PASSWORD"; - this->set_password_protec(cmd_password, cmd_password_remove); - flag_no_save = false; - } - if (this->check_save(flag_save, "GRUB_DEFAULT")) { - string cmd_load = "ubconfig --target system set boot GRUB_DEFAULT="; - string cmd_load_remove = "ubconfig --target system remove boot GRUB_DEFAULT"; - this->set_default_load(cmd_load, cmd_load_remove); - flag_no_save = false; - } - + obj_save.set_data_local(map_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("boot", "system"); + vector obj_vec_error = obj_save.get_error(); + flag_no_save = obj_save.get_state_save(); } } map_local_cmd_selection = map_cmd_selection; @@ -989,6 +838,18 @@ void MainWindow::set_data_cfg() { Utils::str_remove(str_flags, ","); Utils::str_replace_all(str_flags, " \"", "\""); map_cmd_selection["GRUB_TERMINAL_OUTPUT"] = str_flags; + if (chbLoadVariantSelectionTimer->get_active()) { + int second = spbSecond->get_value(); + map_cmd_selection["GRUB_TIMEOUT"] = to_string(second); + } + else { + map_cmd_selection["GRUB_TIMEOUT"] = ""; + } + + this->set_default_load(); + this->set_download_mode(); + this->set_security_login(); + this->set_password_protec(); } void MainWindow::download_globl_cfg() { @@ -999,7 +860,6 @@ void MainWindow::download_globl_cfg() { flag_save_local = true; flag_save_global = true; flag_save_all = true; - flag_load = true; vector vec_sections; vec_sections.push_back("boot"); @@ -1043,7 +903,6 @@ void MainWindow::download_local_cfg() { flag_save_local = true; flag_save_global = true; flag_save_all = true; - flag_load = false; this->init_dict(); vector vec_sections; diff --git a/source/ubl-settings-bootloader.h b/source/ubl-settings-bootloader.h index f7b7f89..13e2ec7 100644 --- a/source/ubl-settings-bootloader.h +++ b/source/ubl-settings-bootloader.h @@ -119,6 +119,7 @@ class MainWindow : public Gtk::ApplicationWindow { Lib_save::Save obj_save = Lib_save::Save(); Lib_Load::Load obj_load = Lib_Load::Load(); + vector vec_param_names; My_Process::My_Process_system obj_process_system = My_Process::My_Process_system(); My_Process::My_Process_call obj_process_call = My_Process::My_Process_call(); bool flag_load = false; @@ -143,7 +144,6 @@ class MainWindow : public Gtk::ApplicationWindow { MainWindow(BaseObjectType* obj, Glib::RefPtr const& builder); MainWindow(Glib::RefPtr const& builder); void get_menu_boot(std::map &map_temp); - void set_menu_boot(string cmd, string cmd_remove); void set_default_load(string cmd, string cmd_remove); void set_row_all(std::map &map_cmd, Glib::RefPtr &list_store, vector &list_params, size_t size); void set_row(Glib::RefPtr &list_store, int size, std::string name, bool flag_chbox);