Начаты работы по реализации сохранения

pull/4/head
Igor Belitskiy 2 years ago
parent 10481f5538
commit fedc0619c6

@ -97,6 +97,7 @@ uninstall:
@echo "Uninstall: OK"
install: check uninstall
@cc source/my_device.c source/my_device.h source/filters.c source/filters.h source/ubl-cmake.h source/view_edit.h source/view_edit.c source/view_add.h source/view_add.c source/ubl-utils.h source/ubl-utils.c source/ubl-strings.h source/ubl-settings-resourcequota.h source/ubl-settings-resourcequota.c -o ubl-settings-resourcequota `pkg-config --cflags --libs gtk+-3.0 vte-2.91 webkit2gtk-4.0 webkit2gtk-web-extension-4.0` -g
@echo "Install ..."
@for FILE_PO in $(wildcard *.po); do \
LANG=$${FILE_PO##*_};LANG=$${LANG%.*}; \

@ -450,7 +450,7 @@ void set_pow_size(char* str_find, int** array_size, char*** array_data , int ind
str_find = yon_char_unite(str_find," ", STR_TB, NULL);
index--;
}
else if (strstr(str_find,"\%") != NULL) {
else if (strstr(str_find,"%%") != NULL) {
*array_size = philos_int_append(*array_size, &index, -1);
str_find = yon_char_divide(str_find, length-1);
index--;
@ -771,72 +771,132 @@ void tree_view_del_line() {
}
}
void wrapper_all_save() {
wrapper_template_save("all");
// template_format_str_save(main_config.load_global_cfg, CMD_LOAD_GLOBAL);
}
void wrapper_global_save() {
wrapper_template_save("global");
template_format_str_save(main_config.load_global_cfg, CMD_SAVE_GLOBAL);
}
void wrapper_system_save() {
wrapper_template_save("system");
template_format_str_save(main_config.load_system_cfg, CMD_SAVE_SYSTEM);
}
void wrapper_template_save(char* check_flag) {
puts(check_flag);
template_format_str_save();
char* save_format_key(int index) {
char* key = NULL;
if (strstr(main_config.quota_volume[index], "-") == NULL) {
key = yon_char_unite("CGROUP_QUOTA[", main_config.quota_volume[index] , "]", NULL);
}
return key;
}
void template_format_str_save() {
yon_dictionary_free_all(main_config.save_cfg_gui, NULL);
for (size_t i = 0; i < main_config.size_tree_view; i++) {
char* key = NULL;
char* value = "";
char split_simvol[2] = {0};
if (strstr(main_config.quota_volume[i], "-") == NULL) {
key = yon_char_unite("CGROUP_QUOTA[", &main_config.type_quota[i] , "]", NULL);
}
else {
key = yon_char_unite("CGROUP_QUOTA[", &main_config.type_quota[i], ".", &main_config.quota_volume[i], "]", NULL);
}
split_simvol[0] = 0;
split_simvol[1] = 0;
if (strstr(main_config.soft_raw_limit[i], "-") != NULL) {
value = yon_char_unite(value, main_config.soft_raw_limit[i], NULL);
split_simvol[0] = ',';
split_simvol[1] = '\0';
}
if (strstr(main_config.hard_raw_limit[i], "-") != NULL) {
value = yon_char_unite(value, split_simvol, main_config.hard_raw_limit[i], NULL);
split_simvol[0] = ',';
split_simvol[1] = '\0';
}
if (strstr(main_config.swap[i], "-") != NULL) {
value = yon_char_unite(value, split_simvol, main_config.swap[i], NULL);
split_simvol[0] = ',';
split_simvol[1] = '\0';
}
if (strstr(main_config.cpu_limit[i], "-") != NULL) {
value = yon_char_unite(value, split_simvol, main_config.cpu_limit[i], NULL);
split_simvol[0] = ',';
split_simvol[1] = '\0';
}
if (strstr(main_config.i_o_limit_read[i], "-") != NULL) {
value = yon_char_unite(value, split_simvol, main_config.i_o_limit_read[i], NULL);
split_simvol[0] = ',';
split_simvol[1] = '\0';
char* save_format_value(int index) {
char* value = NULL;
char split_simvol[2] = {0};
split_simvol[0] = 0;
split_simvol[1] = 0;
if (strstr(main_config.soft_raw_limit[index], "-") == NULL) {
value = yon_char_unite(philos_format_cfg_str_size_memory("MemoryHigh", main_config.soft_raw_limit[index],main_config.soft_raw_limit_size[index]),NULL);
split_simvol[0] = ',';
split_simvol[1] = '\0';
}
if (strstr(main_config.hard_raw_limit[index], "-") == NULL) {
value = yon_char_unite(value ,split_simvol, philos_format_cfg_str_size_memory("MemoryMax", main_config.hard_raw_limit[index],main_config.hard_raw_limit_size[index]), NULL);
split_simvol[0] = ',';
split_simvol[1] = '\0';
}
if (strstr(main_config.swap[index], "-") == NULL) {
value = yon_char_unite(value ,split_simvol, philos_format_cfg_str_size_memory("MemorySwapMax", main_config.swap[index],main_config.swap_size[index]), NULL);
split_simvol[0] = ',';
split_simvol[1] = '\0';
}
if (strstr(main_config.cpu_limit[index], "-") == NULL) {
value = yon_char_unite(value ,split_simvol, philos_format_cfg_str_size_memory("CPUQuota", main_config.cpu_limit[index],main_config.cpu_limit_size[index]), NULL);
split_simvol[0] = ',';
split_simvol[1] = '\0';
}
if (strstr(main_config.i_o_limit_read[index], "-") == NULL) {
value = yon_char_unite(value ,split_simvol, philos_format_cfg_str_size_memory("IOReadBandwidthMax", main_config.i_o_limit_read[index],main_config.i_o_limit_read_size[index]), NULL);
split_simvol[0] = ',';
split_simvol[1] = '\0';
}
if (strstr(main_config.i_o_limit_write[index], "-") == NULL) {
value = yon_char_unite(value ,split_simvol, philos_format_cfg_str_size_memory("IOWriteBandwidthMax", main_config.i_o_limit_write[index],main_config.i_o_limit_write_size[index]), NULL);
}
return value;
}
void pars_terminal() {
}
int check_save(dictionary* load_cfg) {
dictionary* ptr_dict_gui = NULL;
dictionary* ptr_dict_load = NULL;
char* key_gui = NULL;
char* value_gui = NULL;
char* key_load = NULL;
char* value_load = NULL;
int flag_check_key = 0;
int flag_check_value = 0;
size_t size_cfg_gui = yon_dict_len(main_config.save_cfg_gui);
size_t size_cfg_load = yon_dict_len(load_cfg);
if (size_cfg_gui!=size_cfg_load) {
return 1;
}
for_dictionaries(ptr_dict_gui, main_config.save_cfg_gui) {
for_dictionaries(ptr_dict_load, load_cfg) {
key_gui = ptr_dict_gui->key;
value_gui = (char*)ptr_dict_gui->data;
key_load = ptr_dict_load->key;
value_load = (char*)ptr_dict_load->data;
if (key_gui == key_load) {
flag_check_key = 1;
return 1;
}
if (value_gui == value_load) {
// TODO: check
flag_check_value = 1;
return 1;
}
}
if (strstr(main_config.i_o_limit_write[i], "-") != NULL) {
value = yon_char_unite(value, split_simvol, main_config.i_o_limit_write[i], NULL);
split_simvol[0] = ',';
split_simvol[1] = '\0';
if (flag_check_key == 0 || flag_check_value == 0) {
return 1;
}
}
return 1;
}
void template_format_str_save(dictionary* load_cfg, char* source_cmd) {
yon_dictionary_free_all(main_config.save_cfg_gui, NULL);
char* cmd = yon_char_new(source_cmd);
main_config.save_cfg_gui = yon_dictionary_create_empty();
int flag_save = 0;
for (size_t index = 0; index < main_config.size_tree_view; index++) {
char* key = NULL;
char* value = NULL;
key = save_format_key(index);
value = save_format_value(index);
main_config.save_cfg_gui = yon_dictionary_create_with_data_connected(main_config.save_cfg_gui, key, yon_char_new(value));
check_save(load_cfg);
if (key != NULL && value != NULL) {
cmd = yon_char_unite(cmd, " " , key, "=" , value, " ", NULL);
flag_save = 1;
}
puts(key);
free(key);
free(value);
}
if (flag_save) {
puts(cmd);
yon_config_save(cmd);
}
free(cmd);
}
void main_fill_tree_view_after_remove() {
for (int index= 0; index < main_config.size_tree_view; index++) {
GtkTreeIter iter;

@ -34,9 +34,13 @@
#define LocaleName "ubl-settings-resourcequota"
#define CMD_LOAD_GLOBAL "ubconfig --default --source global get security"
#define CMD_LOAD_SYSTEM "ubconfig --default --source system get security"
#define CMD_SAVE_GLOBAL "ubconfig --default --source global set security"
#define CMD_SAVE_SYSTEM "ubconfig --default --source system set security"
#define CMD_GET_SLICE " |grep -E -A 1 \"/sys/|^[a-zA-Z0-9]{1,}\"|grep -oE \"\\\"[\\\"0-9a-zA-Z :,./=]{1,}|/sys/[-/a-zA-z0-9:.]{1,}|^[a-zA-Z0-9]{0,}\""
#define CMD_GET_SERVICE " |grep -E -A 1 \"/sys/|^[a-zA-Z0-9]{1,}\"|grep -oE \"\\\"[\\\"0-9a-zA-Z :,./=]{1,}|/sys/[-/a-zA-z0-9:.]{1,}|^[a-zA-Z0-9]{0,}\""
#define CMD_GET_GROUP "cut -d: -f1 /etc/group"
typedef char* string;
string version_application = "1.0";
string version_application = "";
static char *local;
@ -194,4 +198,4 @@ void wrapper_template_save(char* check_flag);
void wrapper_system_save();
void wrapper_global_save();
void wrapper_all_save();
void template_format_str_save();
void template_format_str_save(dictionary* load_cfg, char* source_cmd);

@ -18,6 +18,15 @@ dictionary *yon_dictionary_create_empty()
return dict;
}
size_t yon_dict_len(dictionary *dict) {
dictionary* ptr_dict = NULL;
size_t size = 0;
for_dictionaries(ptr_dict, dict) {
size+=1;
}
return size;
}
void yon_dictionary_switch_to_last(dictionary **dict)
{
if ((*dict)->next != NULL)
@ -602,6 +611,30 @@ void philos_split_size_memory(char* str_value, int* size, char* pow_memory) {
// pow_memory = yon_char_new(str_value);
(*size) = atoi(yon_char_divide_search(pow_memory, " ", -1));
}
char* philos_format_cfg_str_size_memory(char* str_key, char* str_source_value, int pow_size_memory) {
char* str_value = yon_char_new(str_source_value);
str_value = yon_char_divide_search(str_value, " ", -1);
if (pow_size_memory==0) {
return yon_char_unite(str_key, "=" , str_value, "K" ,NULL);
}
else if (pow_size_memory==1) {
return yon_char_unite(str_key, "=" , str_value, "M" ,NULL);
}
else if (pow_size_memory==2){
return yon_char_unite(str_key, "=" , str_value, "G" ,NULL);
}
else if (pow_size_memory== 3) {
return yon_char_unite(str_key, "=" , str_value, "T" ,NULL);
}
else if (pow_size_memory== -1) {
return yon_char_unite(str_key, "=" , str_value, "%%" ,NULL);
}
else {
return yon_char_unite(str_key, "=" , str_value, "error" ,NULL);
}
}
/**[EN]
* char **yon_char_parse(char *parameters, int *size, char *divider)
* Parses string [parameters], divided by [divider],

@ -92,6 +92,8 @@ typedef char** config_str;
dictionary *yon_dictionary_create_empty();
size_t yon_dict_len(dictionary *dict);
dictionary *yon_dictionary_create_conneced(dictionary *targetdict);
dictionary *yon_dictionary_get_last(dictionary *dict);
@ -140,6 +142,8 @@ char *yon_char_replace(char *source, char *find, char*replace);
void philos_split_size_memory(char* str_value, int* size, char* pow_memory);
char* philos_format_cfg_str_size_memory(char* str_key, char* str_source_value, int pow_size_memory);
char **yon_char_parse(char *parameters, int *size, char *divider);
char** philos_str_split(char *parameters, int *size, char *divider);

@ -267,7 +267,7 @@ void add_generate_cmd() {
str_cmd = yon_char_unite(str_cmd, split_simvol,
"CPUQuota=",
yon_char_from_int(size_bite),
"\%", NULL);
"%%", NULL);
split_simvol[0] = ',';
split_simvol[1] = '\0';
}

@ -261,7 +261,7 @@ void edit_generate_cmd() {
str_cmd = yon_char_unite(str_cmd, split_simvol,
"CPUQuota=",
yon_char_from_int(size_bite),
"\%", NULL);
"%%", NULL);
split_simvol[0] = ',';
split_simvol[1] = '\0';
}

Loading…
Cancel
Save