Исправлена чтений имён дисков

pull/3/head
Igor Belitskiy 2 years ago
parent 4acb8c8bba
commit 65894da802

@ -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

@ -1,43 +1,28 @@
#include "my_device.h"
namespace Devices {
std::vector<Mount> Get_device::get_all_device() {
std::vector<Mount> vec_mount_devices;
std::vector<string> 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<string> 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<Mount> Get_device::get_part_devices(string find_device_name) {
std::vector<Mount> 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;
}
}

@ -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<Mount> get_part_devices(string find_device_name);
std::vector<Mount> 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

@ -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 {

@ -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]);
}
}

@ -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<string> vec_param_names;
map_str_device map_device;
map_str_str map_device;
string str_cmd_error;
public:
MainWindow(BaseObjectType* obj, Glib::RefPtr<Gtk::Builder> 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);

Loading…
Cancel
Save