From 428c65a1890959abfb538e4f9366e4f8ddca3bdb Mon Sep 17 00:00:00 2001 From: Igor Belitskiy Date: Thu, 6 Apr 2023 11:30:26 +0600 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/CMakeLists.txt | 12 +- source/load.cc | 9 +- source/load.h | 4 +- source/my_process.cc | 18 +- source/my_process.h | 2 - source/save.h | 2 - source/ubl-settings-bootloader.cc | 449 +++++++++++++----------------- source/ubl-settings-bootloader.h | 22 +- 8 files changed, 234 insertions(+), 284 deletions(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 3886b8b..b698bb7 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -15,13 +15,19 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissin -fstack-clash-protection -fcf-protection") set(SOURCE_FILES + ubl-settings-bootloader.h + ubl-settings-bootloader.cc + save.h + save.cc + load.h + load.cc + my_process.h + my_process.cc util.h util.cc ubl-util-standard.h ubl-util-standard.c - main.cc - ubl-settings-bootloader.cc - ubl-settings-bootloader.h) + main.cc) set(LIBRARIES ${GTK_LIBRARIES} diff --git a/source/load.cc b/source/load.cc index 558f211..88cfbe9 100644 --- a/source/load.cc +++ b/source/load.cc @@ -4,15 +4,15 @@ namespace Lib_Load{ void Load::set_sections(vector vec_sections){ this->vec_sections = vec_sections; } - map Load::get_load_data(string str_flag_load) { + map& Load::get_load_data(std::map &map_temp, string str_flag_load) { string cmd = ""; string response = ""; string key = ""; string value = ""; - map map_data; 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,14 +20,13 @@ namespace Lib_Load{ size_t index = param.find("="); key = param.substr(0, index); value = param.substr(index + 1, param.length()); - map_data[key] = value; - cout << key << "=" << value << endl; + map_temp[key] = value; } } } } - return map_data; + return map_temp; } } \ No newline at end of file diff --git a/source/load.h b/source/load.h index 0a42947..0ec7cac 100644 --- a/source/load.h +++ b/source/load.h @@ -9,10 +9,8 @@ namespace Lib_Load{ vector vec_sections; My_Process::My_Process_call process = My_Process::My_Process_call(); public: - Load(/* args */); - ~Load(); void set_sections(vector vec_sections); - map get_load_data(string str_flag_load); + map& get_load_data(std::map &map_temp, string str_flag_load); }; diff --git a/source/my_process.cc b/source/my_process.cc index 79dad92..8845d86 100644 --- a/source/my_process.cc +++ b/source/my_process.cc @@ -1,7 +1,7 @@ #include "my_process.h" #include "util.h" -namespace My_Process{ +namespace My_Process { #define debug false struct Utils::Result My_Process_call::call(string cmd) { this->i_error_old = this->i_error; @@ -66,7 +66,19 @@ string My_Process::get_cmd_error() { return this->str_cmd_error; } string My_Process_call::call_all_sections(string cmd) { - string response = Utils::call(cmd); - return response; + char buffer[PATH_MAX]; + std::string result = ""; + FILE* pipe = popen(cmd.c_str(), "r"); + if (!pipe) throw std::runtime_error("popen() failed!"); + try { + while (fgets(buffer, sizeof buffer, pipe) != NULL) { + result += buffer; + } + } catch (...) { + pclose(pipe); + throw; + } + pclose(pipe); + return result; } } \ No newline at end of file diff --git a/source/my_process.h b/source/my_process.h index 809afe5..f780860 100644 --- a/source/my_process.h +++ b/source/my_process.h @@ -18,7 +18,6 @@ class My_Process { class My_Process_call: public My_Process { public: - My_Process_call(); struct Utils::Result call(string cmd); string call_all_sections(string cmd); @@ -26,7 +25,6 @@ class My_Process_call: public My_Process { class My_Process_system: public My_Process { public: - My_Process_system(); void call(string cmd, string thread_str); }; diff --git a/source/save.h b/source/save.h index 8a9e90e..ff32a29 100644 --- a/source/save.h +++ b/source/save.h @@ -13,8 +13,6 @@ private: My_Process::My_Process_system process = My_Process::My_Process_system(); bool flag_no_save; public: - Save(/* args */); - ~Save(); void set_data_global(std::map &map_global); void set_data_local(std::map &map_local); void set_data_gui(std::map &map_gui); diff --git a/source/ubl-settings-bootloader.cc b/source/ubl-settings-bootloader.cc index 241e9ca..4a84409 100755 --- a/source/ubl-settings-bootloader.cc +++ b/source/ubl-settings-bootloader.cc @@ -165,42 +165,35 @@ void MainWindow::item_selected_IPT(const Gtk::TreeModel::Path& path, const Gtk:: } } -void MainWindow::get_download_mode(string cmd, std::map &map_temp) { - int start_error = index_error; - struct Result res_response = this->wrapper_call(cmd); - if (res_response.error == 0) { - Utils::str_replace_all(res_response.response, "\"",""); - if (res_response.response == "splash") { - cmbDownloadMode->set_active(0); - map_temp["GRUB_BOOT_SILENT"] = "splash"; - } - else if (res_response.response == "splash quiet ub.silent") { - cmbDownloadMode->set_active(1); - map_temp["GRUB_BOOT_SILENT"] = "splash quiet ub.silent"; - } - else if (res_response.response == "quiet ub.silent") { - cmbDownloadMode->set_active(2); - map_temp["GRUB_BOOT_SILENT"] = "quiet ub.silent"; - } - else if (res_response.response == "plymouth.enable=0") { - cmbDownloadMode->set_active(3); - map_temp["GRUB_BOOT_SILENT"] = "plymouth.enable=0"; +void MainWindow::get_download_mode(std::map &map_temp) { + std::map :: iterator iter_map_data; + iter_map_data = map_temp.find("GRUB_BOOT_SILENT"); + if (iter_map_data != map_temp.end()) { + string value = iter_map_data->second; + if (value.length() != 0) { + Utils::str_replace_all(value, "\"",""); + if (value == "splash") { + cmbDownloadMode->set_active(0); + } + else if (value == "splash quiet ub.silent") { + cmbDownloadMode->set_active(1); + } + else if (value == "quiet ub.silent") { + cmbDownloadMode->set_active(2); + } + else if (value == "plymouth.enable=0") { + cmbDownloadMode->set_active(3); + } + else{ + cmbDownloadMode->set_active(-1); + } } - else{ + else { cmbDownloadMode->set_active(-1); - map_temp["GRUB_BOOT_SILENT"] = ""; - } - } - else if (res_response.error == 3) { - cmbDownloadMode->set_active(-1); - map_temp["GRUB_BOOT_SILENT"] = ""; - if (start_error != index_error) { - index_error = start_error; } } else { cmbDownloadMode->set_active(-1); - map_temp["GRUB_BOOT_SILENT"] = ""; } } @@ -224,7 +217,7 @@ void MainWindow::set_download_mode(string cmd="") { } if (cmd.length() !=0 ) { cmd += "\"" + key + "\""; - wrapper_system(cmd, ""); + obj_process_system.call(cmd, ""); } else { flag_save_local = true; @@ -240,7 +233,7 @@ void MainWindow::set_security_login(string cmd = "", string cmd_remove = "") { if (index == 0) { key = ""; if (cmd_remove.length() != 0) { - wrapper_system(cmd_remove, ""); + obj_process_system.call(cmd_remove, ""); } else { flag_save_local = true; @@ -253,7 +246,7 @@ void MainWindow::set_security_login(string cmd = "", string cmd_remove = "") { if (cmd.length() != 0) { entrySecurityLogin->set_text(key); cmd = cmd + "\"" + key + "\""; - wrapper_system(cmd, ""); + obj_process_system.call(cmd, ""); } else { flag_save_local = true; @@ -267,40 +260,29 @@ void MainWindow::set_security_login(string cmd = "", string cmd_remove = "") { map_cmd_selection["GRUB_USER"] = key; } -void MainWindow::get_security_login(string cmd, std::map &map_temp) { - int start_error = index_error; - struct Result res_response = this->wrapper_call(cmd); - // TODO: - // Убрать в будущем - string default_login = "superadmin"; - if (res_response.error == 0) { - Utils::str_replace_all(res_response.response, " ",""); - Utils::str_replace_all(res_response.response, "\"",""); - if (res_response.response.length() > 0) { - chbSecurityLogin->set_active(1); - map_temp["GRUB_USER"] = res_response.response; - entrySecurityLogin->set_sensitive(true); - entrySecurityLogin->set_text(res_response.response); +void MainWindow::get_security_login(std::map &map_temp) { + std::map :: iterator iter_map_data; + iter_map_data = map_temp.find("GRUB_USER"); + if (iter_map_data != map_temp.end()) { + string value = iter_map_data->second; + if (value.length() != 0) { + Utils::str_replace_all(value, " ",""); + Utils::str_replace_all(value, "\"",""); + chbSecurityLogin->set_active(1); + entrySecurityLogin->set_sensitive(true); + entrySecurityLogin->set_text(value); } else { - chbSecurityLogin->set_active(-1); - map_temp["GRUB_USER"] = ""; - + chbSecurityLogin->set_active(0); + entrySecurityLogin->set_text(""); + entrySecurityLogin->set_sensitive(false); } } - else if (res_response.error == 3) { - map_temp["GRUB_USER"] = ""; - if (start_error != index_error) { - index_error = start_error; - } + else { chbSecurityLogin->set_active(0); entrySecurityLogin->set_text(""); entrySecurityLogin->set_sensitive(false); } - else { - chbSecurityLogin->set_active(-1); - map_temp["GRUB_USER"] = ""; - } } void MainWindow::set_password_protec(string cmd = "", string cmd_remove = "") { @@ -309,7 +291,7 @@ void MainWindow::set_password_protec(string cmd = "", string cmd_remove = "") { if (index == 0){ key = ""; if (cmd_remove.length() != 0) { - wrapper_system(cmd_remove, ""); + obj_process_system.call(cmd_remove, ""); } else { flag_save_local = true; @@ -322,7 +304,7 @@ void MainWindow::set_password_protec(string cmd = "", string cmd_remove = "") { if (cmd.length() != 0 and key != "************") { entryPasswordProtecc->set_text(key); cmd = cmd + "\"" + key + "\""; - wrapper_system(cmd, ""); + obj_process_system.call(cmd, ""); } else { flag_save_local = true; @@ -339,32 +321,23 @@ void MainWindow::set_password_protec(string cmd = "", string cmd_remove = "") { } -void MainWindow::get_password_protec(string cmd, std::map &map_temp) { - int start_error = index_error; - struct Result res_response = this->wrapper_call(cmd); - if (res_response.error == 0) { - Utils::str_replace_all(res_response.response, "\"",""); - if (res_response.response.length() != 0) { +void MainWindow::get_password_protec(std::map &map_temp) { + std::map :: iterator iter_map_data; + iter_map_data = map_temp.find("GRUB_PASSWORD"); + if (iter_map_data != map_temp.end()) { + string value = iter_map_data->second; + if (value.length() != 0) { + Utils::str_replace_all(value, "\"",""); chbPasswordProtecc->set_active(1); - map_temp["GRUB_PASSWORD"] = res_response.response; entryPasswordProtecc->set_text("************"); entryPasswordProtecc->set_sensitive(true); } else{ - map_temp["GRUB_PASSWORD"] = ""; - chbPasswordProtecc->set_active(-1); - } - } - else if (res_response.error == 3) { - chbPasswordProtecc->set_active(0); - map_temp["GRUB_PASSWORD"] = ""; - entryPasswordProtecc->set_text(""); - if (start_error != index_error) { - index_error = start_error; + chbPasswordProtecc->set_active(0); + entryPasswordProtecc->set_text(""); } } else { - map_temp["GRUB_PASSWORD"] = ""; chbPasswordProtecc->set_active(-1); } } @@ -535,30 +508,33 @@ void MainWindow::localization(){ cmbDefaultDonw->append(_("Last Successful Download")); } -vector MainWindow::get_setting_entry_all(string key, string cmd, Gtk::Entry &entry_text, std::map &map_temp) { - int start_error = index_error; +vector MainWindow::get_setting_entry_all(string key, Gtk::Entry &entry_text, std::map &map_temp) { vector vec_params; - struct Result res_response = this->wrapper_call(cmd); - if (res_response.error == 0) { - Utils::str_replace_all(res_response.response, "\"", ""); - vec_params = Utils::split(res_response.response, ' '); - Utils::str_replace_all(res_response.response, " ", ", "); - entry_text.set_text(res_response.response); - for (auto ¶m: vec_params) { - map_cmd_selection[param] = "1"; - map_temp[param] = "1"; + std::map :: iterator iter_map_data; + iter_map_data = map_temp.find(key); + if (iter_map_data != map_temp.end()) { + string value = iter_map_data->second; + if (value.length() != 0) { + Utils::str_replace_all(value, "\"", ""); + vec_params = Utils::split(value, ' '); + Utils::str_replace_all(value, " ", ", "); + entry_text.set_text(value); + for (auto ¶m: vec_params) { + map_cmd_selection[param] = "1"; + map_temp[param] = "1"; + } + Utils::str_remove(value, ","); + map_temp[key] = value; } - Utils::str_remove(res_response.response, ","); - map_temp[key] = res_response.response; - } - else if (res_response.error == 3) { - if (start_error != index_error) { - index_error = start_error; + else { + entry_text.set_text(""); } + } else { - + entry_text.set_text(""); } + return vec_params; } @@ -619,30 +595,28 @@ void MainWindow::set_entry_to_tree_view(Glib::RefPtr &list_store } flag_blocked_tree_view = false; } -void MainWindow::get_menu_boot(string cmd, std::map &map_temp) { - int start_error = index_error; - struct Result res_response = this->wrapper_call(cmd); - if (res_response.error == 0) { - map_temp["GRUB_TIMEOUT"] = res_response.response; - spbSecond->set_value(atoi(res_response.response.c_str())); - chbLoadVariantSelectionTimer->set_active(true); - spbSecond->set_sensitive(true); - lblInfoSeconds->set_sensitive(true); - - } - else if (res_response.error == 3) { - if (start_error != index_error) { - index_error = start_error; + +void MainWindow::get_menu_boot(std::map &map_temp) { + std::map :: iterator iter_map_data; + iter_map_data = map_temp.find("GRUB_TIMEOUT"); + if (iter_map_data != map_temp.end()) { + if (iter_map_data->second.length() > 0) { + spbSecond->set_value(atoi(iter_map_data->second.c_str())); + chbLoadVariantSelectionTimer->set_active(true); + spbSecond->set_sensitive(true); + lblInfoSeconds->set_sensitive(true); + } + else { + chbLoadVariantSelectionTimer->set_active(false); + spbSecond->set_sensitive(false); + lblInfoSeconds->set_sensitive(true); } - map_temp["GRUB_TIMEOUT"] = ""; + } + else { chbLoadVariantSelectionTimer->set_active(false); spbSecond->set_sensitive(false); lblInfoSeconds->set_sensitive(true); } - else { - map_temp["GRUB_TIMEOUT"] = ""; - } - } void MainWindow::set_menu_boot(string cmd = "", string cmd_remove = "") { @@ -650,7 +624,7 @@ void MainWindow::set_menu_boot(string cmd = "", string cmd_remove = "") { int value = spbSecond->get_value(); if (cmd.length() != 0) { cmd += to_string(value); - this->wrapper_system(cmd, ""); + obj_process_system.call(cmd, ""); } else { flag_save_local = true; @@ -661,7 +635,7 @@ void MainWindow::set_menu_boot(string cmd = "", string cmd_remove = "") { } else if (chbLoadVariantSelectionTimer->get_active() == false) { if (cmd_remove.length() != 0) { - this->wrapper_system(cmd_remove, ""); + obj_process_system.call(cmd_remove, ""); } else { flag_save_local = true; @@ -684,10 +658,10 @@ void MainWindow::cmd_entry_all(Gtk::Entry &entry, string cmd_settings, string cm if (cmds.length() != 0) { cmd_settings += "\"" + cmds + "\""; Utils::str_replace_all(cmd_settings, " \"", "\""); - this->wrapper_system(cmd_settings, ""); + obj_process_system.call(cmd_settings, ""); } else { - this->wrapper_system(cmd_remove, ""); + obj_process_system.call(cmd_remove, ""); } } @@ -747,7 +721,7 @@ void MainWindow::set_default_load(string cmd = "", string cmd_remove = "") { int index = cmbDefaultDonw->get_active_row_number(); if (index == 0) { if (cmd.length() != 0) { - wrapper_system(cmd, ""); + obj_process_system.call(cmd, ""); } else { flag_save_local = true; @@ -757,7 +731,7 @@ void MainWindow::set_default_load(string cmd = "", string cmd_remove = "") { } else if (index > 0) { if (cmd_remove.length() != 0) { - wrapper_system(cmd_remove, ""); + obj_process_system.call(cmd_remove, ""); } else { flag_save_local = true; @@ -773,23 +747,20 @@ void MainWindow::set_default_load(string cmd = "", string cmd_remove = "") { } } -void MainWindow::get_default_load(string cmd, std::map &map_temp) { - int start_error = index_error; - struct Result res_response = this->wrapper_call(cmd); - if (res_response.error == 0) { - map_temp["GRUB_DEFAULT"] = res_response.response; - cmbDefaultDonw->set_active_text(res_response.response); - } - else if (res_response.error == 3) { - if (start_error != index_error) { - index_error = start_error; +void MainWindow::get_default_load(std::map &map_temp) { + std::map :: iterator iter_map_data; + iter_map_data = map_temp.find("GRUB_DEFAULT"); + if (iter_map_data != map_temp.end()) { + string value = iter_map_data->second; + if (value.length() != 0) { + cmbDefaultDonw->set_active_text(value); + } + else { cmbDefaultDonw->set_active(0); } - map_temp["GRUB_DEFAULT"] = ""; - } else { - map_temp["GRUB_DEFAULT"] = ""; + cmbDefaultDonw->set_active(-1); } } @@ -897,6 +868,45 @@ bool MainWindow::save_global_cfg() { 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() { if (this->save_local_cfg()){ this->info_warning_error(5); @@ -982,6 +992,7 @@ void MainWindow::set_data_cfg() { } void MainWindow::download_globl_cfg() { + this->init_dict(); entryKernel->set_text(""); entryOTT->set_text(""); entryIPT->set_text(""); @@ -989,26 +1000,42 @@ void MainWindow::download_globl_cfg() { flag_save_global = true; flag_save_all = true; flag_load = true; - std::string cmd_boot_time = "ubconfig --default --source global get boot GRUB_TIMEOUT"; - this->get_menu_boot(cmd_boot_time, map_global_cmd_selection); - string cmd_kernel_entry = "ubconfig --default --source global get boot GRUB_CMDLINE_LINUX"; - this->get_setting_entry_all("GRUB_CMDLINE_LINUX",cmd_kernel_entry, *entryKernel, map_global_cmd_selection); - string cmd_ipt_entry = "ubconfig --default --source global get boot GRUB_TERMINAL_INPUT"; - this->get_setting_entry_all("GRUB_TERMINAL_INPUT",cmd_ipt_entry, *entryIPT, map_global_cmd_selection); - string cmd_opt_entry = "ubconfig --default --source global get boot GRUB_TERMINAL_OUTPUT"; - this->get_setting_entry_all("GRUB_TERMINAL_OUTPUT", cmd_opt_entry, *entryOTT, map_global_cmd_selection); + + vector vec_sections; + vec_sections.push_back("boot"); + obj_load.set_sections(vec_sections); + map_local_cmd_selection = obj_load.get_load_data(map_global_cmd_selection, "global"); + this->get_menu_boot(map_global_cmd_selection); + + this->get_setting_entry_all("GRUB_CMDLINE_LINUX",*entryKernel, map_global_cmd_selection); + this->get_setting_entry_all("GRUB_TERMINAL_INPUT",*entryIPT, map_global_cmd_selection); + this->get_setting_entry_all("GRUB_TERMINAL_OUTPUT", *entryOTT, map_global_cmd_selection); this->set_row_all(map_global_cmd_selection, list_store_kernel, vec_Option_kernel, size_kernel); this->set_row_all(map_global_cmd_selection, list_store_IPT, vec_Option_IPT, size_IPT); this->set_row_all(map_global_cmd_selection, list_store_OTT, vec_Option_OTT, size_OTT); - this->get_download_mode("ubconfig --default --source global get boot GRUB_BOOT_SILENT", map_global_cmd_selection); - this->get_security_login("ubconfig --default --source global get boot GRUB_USER", map_global_cmd_selection); - this->get_password_protec("ubconfig --default --source global get boot GRUB_PASSWORD", map_global_cmd_selection); - this->get_default_load("ubconfig --default --source global get boot GRUB_DEFAULT", map_global_cmd_selection); + this->get_download_mode(map_global_cmd_selection); + this->get_security_login(map_global_cmd_selection); + this->get_password_protec(map_global_cmd_selection); + this->get_default_load(map_global_cmd_selection); info_warning_error(1); map_cmd_selection = map_global_cmd_selection; } +void MainWindow::init_dict() { + map_cmd_selection["GRUB_TIMEOUT"] = ""; + map_cmd_selection["GRUB_CMDLINE_LINUX"] = ""; + map_cmd_selection["GRUB_TERMINAL_INPUT"] = ""; + map_cmd_selection["GRUB_TERMINAL_OUTPUT"] = ""; + map_cmd_selection["GRUB_BOOT_SILENT"] = ""; + map_cmd_selection["GRUB_USER"] = ""; + map_cmd_selection["GRUB_PASSWORD"] = ""; + map_cmd_selection["GRUB_DEFAULT"] = ""; + map_global_cmd_selection = map_cmd_selection; + map_local_cmd_selection = map_cmd_selection; +} + + void MainWindow::download_local_cfg() { entryKernel->set_text(""); entryOTT->set_text(""); @@ -1017,63 +1044,28 @@ void MainWindow::download_local_cfg() { flag_save_global = true; flag_save_all = true; flag_load = false; - std::string cmd_boot_time = "ubconfig --default --source system get boot GRUB_TIMEOUT"; - this->get_menu_boot(cmd_boot_time, map_local_cmd_selection); - string cmd_kernel_entry = "ubconfig --default --source system get boot GRUB_CMDLINE_LINUX"; - this->get_setting_entry_all("GRUB_CMDLINE_LINUX", cmd_kernel_entry, *entryKernel, map_local_cmd_selection); - string cmd_ipt_entry = "ubconfig --default --source system get boot GRUB_TERMINAL_INPUT"; - this->get_setting_entry_all("GRUB_TERMINAL_INPUT", cmd_ipt_entry, *entryIPT, map_local_cmd_selection); - string cmd_opt_entry = "ubconfig --default --source system get boot GRUB_TERMINAL_OUTPUT"; - this->get_setting_entry_all("GRUB_TERMINAL_OUTPUT", cmd_opt_entry, *entryOTT, map_local_cmd_selection); + this->init_dict(); + + vector vec_sections; + vec_sections.push_back("boot"); + obj_load.set_sections(vec_sections); + map_local_cmd_selection = obj_load.get_load_data(map_local_cmd_selection, "system"); + + this->get_menu_boot(map_local_cmd_selection); + this->get_setting_entry_all("GRUB_CMDLINE_LINUX", *entryKernel, map_local_cmd_selection); + this->get_setting_entry_all("GRUB_TERMINAL_INPUT", *entryIPT, map_local_cmd_selection); + this->get_setting_entry_all("GRUB_TERMINAL_OUTPUT", *entryOTT, map_local_cmd_selection); this->set_row_all(map_local_cmd_selection, list_store_kernel, vec_Option_kernel, size_kernel); this->set_row_all(map_local_cmd_selection, list_store_IPT, vec_Option_IPT, size_IPT); this->set_row_all(map_local_cmd_selection, list_store_OTT, vec_Option_OTT, size_OTT); - this->get_download_mode("ubconfig --default --source system get boot GRUB_BOOT_SILENT", map_local_cmd_selection); - this->get_security_login("ubconfig --default --source system get boot GRUB_USER", map_local_cmd_selection); - this->get_password_protec("ubconfig --default --source system get boot GRUB_PASSWORD", map_local_cmd_selection); - this->get_default_load("ubconfig --default --source system get boot GRUB_DEFAULT", map_local_cmd_selection); + this->get_download_mode(map_local_cmd_selection); + this->get_security_login(map_local_cmd_selection); + this->get_password_protec(map_local_cmd_selection); + this->get_default_load(map_local_cmd_selection); info_warning_error(0); map_cmd_selection = map_local_cmd_selection; } -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::set_row_all(std::map &map_cmd, Glib::RefPtr &list_store, vector &list_params, size_t size) { for (auto &name: list_params) { @@ -1103,17 +1095,9 @@ void MainWindow::synopsis_show() { string response_user = getlogin(); cmd = "su -l " + response_user + " -c \" DISPLAY=$DISPLAY " + cmd + " \""; } - wrapper_system(cmd, "&"); + obj_process_system.call(cmd, "&"); } -void MainWindow::wrapper_system(string cmd, string thread_str = "") { - string cmd_new = cmd + " " + thread_str; - int response_cmd = system(cmd_new.c_str()); - if (response_cmd != 0) { - index_error += 1; - this->log_mess_error(cmd); - } -} void MainWindow::info_status_app(string stule) { boxInfo->remove_class("boxInfoMessOK"); @@ -1173,59 +1157,6 @@ void MainWindow::info_warning_error(int mess) { } } -struct MainWindow::Result MainWindow::wrapper_call(string cmd) { - struct Result obj_result; - string response = Utils::call(cmd); - if ((response.find("(null)") == std::string::npos) && (response.length() != 0 )) { - if (response.find("=") != std::string::npos) { - if (response.find("\n") != std::string::npos) { - response = response.substr(response.find("=")+1,response.length()); - response = response.substr(0,response.find("\n")); - obj_result.response = response; - obj_result.error = 0; - - } - else { - obj_result.response = response; - obj_result.error = 1; - index_error += 1; - this->log_mess_error(cmd); - } - } - else { - obj_result.response = response; - obj_result.error = 2; - index_error += 1; - str_cmd_error = cmd; - this->log_mess_error(cmd); - } - } - else { - obj_result.response = response; - obj_result.error = 3; - index_error += 1; - str_cmd_error = cmd; - this->log_mess_error(cmd); - } - return obj_result; -} - -void MainWindow::log_mess_error(string &cmd) { - string key = ""; - if (map_cmd_error.find(cmd) != map_cmd_error.end()){ - str_cmd_error = map_cmd_error[cmd]; - } - else { - for (const auto &map_iter: map_cmd_error) { - key = map_iter.first; - if (cmd.find(key) != std::string::npos){ - str_cmd_error = map_iter.second; - break; - } - } - } -} - void MainWindow::add_CSS(){ Glib::RefPtr cssProvider = Gtk::CssProvider::create(); cssProvider->load_from_path(path_css); diff --git a/source/ubl-settings-bootloader.h b/source/ubl-settings-bootloader.h index 63466d1..f7b7f89 100644 --- a/source/ubl-settings-bootloader.h +++ b/source/ubl-settings-bootloader.h @@ -14,6 +14,9 @@ #include #include "ubl-util-standard.c" #include "util.h" +#include "save.h" +#include "load.h" +#include "my_process.h" using namespace std; extern string path_app; @@ -114,6 +117,10 @@ class MainWindow : public Gtk::ApplicationWindow { Gtk::Label *lblSecurityLogin; Gtk::Label *lblPasswordProtec; + Lib_save::Save obj_save = Lib_save::Save(); + Lib_Load::Load obj_load = Lib_Load::Load(); + 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; bool flag_save_all = false; bool flag_save_global = false; @@ -132,15 +139,16 @@ class MainWindow : public Gtk::ApplicationWindow { int error; }; std::map map_cmd_error; - + MainWindow(BaseObjectType* obj, Glib::RefPtr const& builder); MainWindow(Glib::RefPtr const& builder); - void get_menu_boot(string cmd, std::map &map_temp); + 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); void get_builder(); + void init_dict(); void add_CSS(); void show_pass(); void localization(); @@ -151,7 +159,7 @@ class MainWindow : public Gtk::ApplicationWindow { void synopsis_show(); void set_data_cfg(); void set_active_boot_second(); - void get_download_mode(string cmd, std::map &map_temp); + void get_download_mode(std::map &map_temp); void view_add_cell(Gtk::TreeModel::Row &row, Glib::RefPtr list_store_m , std::array, 5> &arr_view, size_t index); void wrapper_system(string cmd, string thread_str); struct Result wrapper_call(string cmd); @@ -174,17 +182,17 @@ class MainWindow : public Gtk::ApplicationWindow { bool focus_out_txt_OTT(GdkEventFocus*); void fill_in_view(); void set_security_login(string cmd, string cmd_remove); - void get_security_login(string cmd, std::map &map_temp); + void get_security_login(std::map &map_temp); bool check_flag_save(string flag_save); void set_download_mode(string cmd); void change_password_protecc(); bool focus_out_txt_login(GdkEventFocus*); void change_security_login(); - void get_default_load(string cmd, std::map &map_temp); + void get_default_load(std::map &map_temp); bool focus_out_txt_password(GdkEventFocus*); - void get_password_protec(string cmd, std::map &map_temp); + void get_password_protec(std::map &map_temp); void set_password_protec(string cmd, string cmd_remove); - vector get_setting_entry_all(string key, string cmd, Gtk::Entry &entry_text, std::map &map_temp); + vector get_setting_entry_all(string key, Gtk::Entry &entry_text, std::map &map_temp); void cmd_entry_all(Gtk::Entry &entry, string cmd_settings, string cmd_remove); string dynamic_update_entry(std::map &map_view, vector &vec_allowed); void item_selected_kernel(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator&);