diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index e3caf3b..73f1eb7 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -16,11 +16,11 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissin -fstack-clash-protection -fcf-protection -g") set(SOURCE_FILES + ubl-settings-quotas.h + ubl-settings-quotas.cc my_device.h my_device.cc project_lib.h - ubl-settings-quotas.h - ubl-settings-quotas.cc my_type.h save.h save.cc diff --git a/source/my_device.cc b/source/my_device.cc index 8385e69..5005baf 100644 --- a/source/my_device.cc +++ b/source/my_device.cc @@ -1,43 +1,28 @@ #include "my_device.h" + namespace Devices { -std::vector Get_device::get_all_device() { - std::vector vec_mount_devices; - std::vector vec_str; - std::ifstream file("/proc/mounts"); - if (file.is_open()) { - std::string line; - while (std::getline(file, line)) { - vec_str = Utils::split(line, ' '); - struct Mount mount; - mount.device = vec_str[0]; - mount.destination = vec_str[1]; - mount.fstype = vec_str[2]; - mount.options = vec_str[3]; - mount.dump = vec_str[4]; - mount.pass = vec_str[5]; - vec_mount_devices.push_back(mount); + + map_str_str Parted::get_parted() { + string cmd = "lsblk --fs --raw --output PATH,FSTYPE --exclude 7,11,253"; + string response = obj_process_call.call_all_sections(cmd); + vector vec_parted = Utils::split(response, '\n'); + map_str_str dict_parted; + string key = ""; + if (vec_parted.size()>1) { + vec_parted.erase(vec_parted.begin()); } - } - file.close(); - return vec_mount_devices; - -} -std::vector Get_device::get_part_devices(string find_device_name) { - std::vector vec_mount_devices; - for (const auto &device: this->get_all_device()) { - if (device.device.find(find_device_name) != std::string::npos) { - vec_mount_devices.push_back(device); + for (const string& str_parted : vec_parted) { + key = str_parted.substr(0, str_parted.find(" ")); + if (str_parted.find(" ") != string::npos) { + dict_parted[key] = str_parted.substr(str_parted.find(" ") + 1, str_parted.length()); + } + else { + dict_parted[key] = ""; + } } + + return dict_parted; } - return vec_mount_devices; -} - -map_str_device Get_device::get_map_part_devices(string find_device_name) { - map_str_device map_device; - for (const auto &device: this->get_part_devices(find_device_name)) { - map_device[device.device] = device; - } - return map_device; - } + } \ No newline at end of file diff --git a/source/my_device.h b/source/my_device.h index 6cabfb6..1db5317 100644 --- a/source/my_device.h +++ b/source/my_device.h @@ -2,18 +2,19 @@ #define MY_DEVICE_H #include "project_lib.h" +#include "my_process.h" #include "util.h" #include "my_type.h" namespace Devices { -class Get_device { - - public: - map_str_device get_map_part_devices(string find_device_name); - std::vector get_part_devices(string find_device_name); - std::vector get_all_device(); + class Parted{ + protected: + My_Process::My_Process_call obj_process_call = My_Process::My_Process_call(); + public: + map_str_str get_parted(); }; + } #endif diff --git a/source/save.h b/source/save.h index bdc2f56..5449b69 100644 --- a/source/save.h +++ b/source/save.h @@ -1,7 +1,8 @@ -#ifndef MY_PROCESS_H -#define MY_PROCESS_H +#ifndef SAVE_H +#define SAVE_H #include "my_process.h" +#include "project_lib.h" namespace Lib_save { class Save { diff --git a/source/ubl-settings-quotas.cc b/source/ubl-settings-quotas.cc index 34c4ff2..aa38d13 100755 --- a/source/ubl-settings-quotas.cc +++ b/source/ubl-settings-quotas.cc @@ -32,7 +32,7 @@ void MainWindow::settings() { btnBoxAboutDialog->set_visible(false); this->entry_generalGroupsEnableCheck(); this->entry_generalUsersEnableCheck(); - map_device = obj_device.get_map_part_devices("/dev/"); + map_device = obj_device.get_parted(); this->filling_device_combo_box_template(generalDeviceCombo, map_device); this->filling_device_combo_box_template(groupsDeviceCombo, map_device); this->filling_device_combo_box_template(usersDeviceCombo, map_device); @@ -246,7 +246,7 @@ void MainWindow::view_add_columns(Gtk::TreeView &treeView) { treeView.append_column(_("Hard limit\nactivation\ntime (files)"), m_columns.hard_limit_files_activ_time); } -void MainWindow::filling_device_combo_box_template(Gtk::ComboBoxText *combo_box, map_str_device &map_device) { +void MainWindow::filling_device_combo_box_template(Gtk::ComboBoxText *combo_box, map_str_str &map_device) { if (map_device.size() != 0) { for (const auto &device : map_device) { combo_box->append(device.first.c_str()); @@ -258,8 +258,7 @@ void MainWindow::filling_device_combo_box_template(Gtk::ComboBoxText *combo_box, void MainWindow::entry_combo_box_temp(Gtk::ComboBoxText *combo_box, Gtk::Label *label) { string text = combo_box->get_active_text(); if (map_device.find(text) != map_device.end()){ - auto value_device = map_device[text]; - label->set_text(value_device.fstype); + label->set_text(map_device[text]); } } diff --git a/source/ubl-settings-quotas.h b/source/ubl-settings-quotas.h index b68274b..5f83161 100644 --- a/source/ubl-settings-quotas.h +++ b/source/ubl-settings-quotas.h @@ -185,14 +185,14 @@ class MainWindow : public Gtk::ApplicationWindow { public: Lib_save::Save obj_save = Lib_save::Save(); Lib_Load::Load obj_load = Lib_Load::Load(); - Devices::Get_device obj_device = Devices::Get_device(); + Devices::Parted obj_device = Devices::Parted(); 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(); map_str_str map_gui_cfg; map_str_str map_global_cfg; map_str_str map_system_cfg; vector vec_param_names; - map_str_device map_device; + map_str_str map_device; string str_cmd_error; public: MainWindow(BaseObjectType* obj, Glib::RefPtr const& builder); @@ -219,7 +219,7 @@ class MainWindow : public Gtk::ApplicationWindow { void init_spin_all(); void load_global_cfg(); void load_system_cfg(); - void filling_device_combo_box_template(Gtk::ComboBoxText *combo_box, map_str_device &map_device); + void filling_device_combo_box_template(Gtk::ComboBoxText *combo_box, map_str_str &map_device); bool save_template(string section, string flag_save); void view_add_columns(Gtk::TreeView &treeView);