diff --git a/source/ubl-settings-resourcequota.c b/source/ubl-settings-resourcequota.c index 82b7788..3fc1733 100644 --- a/source/ubl-settings-resourcequota.c +++ b/source/ubl-settings-resourcequota.c @@ -334,24 +334,23 @@ void template_load_cfg(char* cmd, dictionary* load_cfg) { void init_cfg_array(int index) { //main_config.disk = yon_char_parsed_append(main_config.disk, &index, "-"); //index--; - set_pow_size_memory("-", &main_config.type_quota_size, index); - set_size_memory_integer_char("-", &main_config.type_quota, index); + philos_set_pow_size_memory("-", &main_config.type_quota_size, index, array_size_pow); + philos_set_size_memory_integer_char("-", &main_config.type_quota, index); - set_pow_size_memory("-", &main_config.quota_volume_size, index); - set_size_memory_integer_char("-", &main_config.quota_volume, index); + philos_set_pow_size_memory("-", &main_config.quota_volume_size, index, array_size_pow); + philos_set_size_memory_integer_char("-", &main_config.quota_volume, index); - set_pow_size_memory("-", &main_config.cpu_limit_size, index); + philos_set_pow_size_memory("-", &main_config.cpu_limit_size, index, array_size_pow); set_size_memory_integer("-", &main_config.cpu_limit, index); - set_pow_size_memory("-", &main_config.soft_raw_limit_size, index); + philos_set_pow_size_memory("-", &main_config.soft_raw_limit_size, index, array_size_pow); set_size_memory_integer("-", &main_config.soft_raw_limit, index); - set_pow_size_memory("-", &main_config.hard_raw_limit_size, index); + philos_set_pow_size_memory("-", &main_config.hard_raw_limit_size, index, array_size_pow); set_size_memory_integer("-", &main_config.hard_raw_limit, index); - set_pow_size_memory("-", &main_config.swap_size, index); + philos_set_pow_size_memory("-", &main_config.swap_size, index, array_size_pow); set_size_memory_integer("-",&main_config.swap , index); - } void str_split_key(char* source_value, int index) { @@ -431,19 +430,19 @@ void str_split_value(char* values, int index) { get_param_io_limit(arr_values, index_1, size,index, "IOWriteBandwidthMax"); } if (yon_char_find_count(key, "MemoryHigh") != 0) { - set_pow_size_memory(yon_char_new(value), &main_config.soft_raw_limit_size, index); + philos_set_pow_size_memory(yon_char_new(value), &main_config.soft_raw_limit_size, index, array_size_pow); set_size_memory_integer(yon_char_new(value), &main_config.soft_raw_limit, index); } if (yon_char_find_count(key, "MemoryMax") != 0) { - set_pow_size_memory(yon_char_new(value), &main_config.hard_raw_limit_size, index); + philos_set_pow_size_memory(yon_char_new(value), &main_config.hard_raw_limit_size, index, array_size_pow); set_size_memory_integer(yon_char_new(value), &main_config.hard_raw_limit, index); } if (yon_char_find_count(key, "MemorySwapMax") != 0) { - set_pow_size_memory(yon_char_new(value), &main_config.swap_size, index); + philos_set_pow_size_memory(yon_char_new(value), &main_config.swap_size, index, array_size_pow); set_size_memory_integer(yon_char_new(value), &main_config.swap, index); } if (yon_char_find_count(key, "CPUQuota") != 0) { - set_pow_size_memory(yon_char_new(value), &main_config.cpu_limit_size, index); + philos_set_pow_size_memory(yon_char_new(value), &main_config.cpu_limit_size, index, array_size_pow); set_size_memory_integer(yon_char_new(value), &main_config.cpu_limit, index); } } @@ -466,7 +465,7 @@ void get_param_io_limit(char** arr_values, int index_start, int size, int index_ char* disk = yon_char_divide_search(yon_char_new(value), " ", -1); array_disk = yon_char_parsed_append(array_disk, &index_n2, disk); index_n2--; - set_pow_size_memory(yon_char_new(value), &array_limit_size, index_n2); + philos_set_pow_size_memory(yon_char_new(value), &array_limit_size, index_n2, array_size_pow); set_size_memory_integer(yon_char_new(value), &array_limit, index_n2); flag_parsed = 1; index_n2++; @@ -483,7 +482,7 @@ void get_param_io_limit(char** arr_values, int index_start, int size, int index_ char* disk = yon_char_divide_search(yon_char_new(arr_values[i]), " ", -1); array_disk = yon_char_parsed_append(array_disk, &index_n2, disk); index_n2--; - set_pow_size_memory(yon_char_new(arr_values[i]), &array_limit_size, index_n2); + philos_set_pow_size_memory(yon_char_new(arr_values[i]), &array_limit_size, index_n2, array_size_pow); set_size_memory_integer(yon_char_new(arr_values[i]), &array_limit, index_n2); index_n2++; } @@ -539,72 +538,6 @@ void set_size_memory_integer(char* str_find, int** array_data, int index) { } -void set_size_memory_integer_char(char* str_find, char*** array_data, int index) { - char* simv_del_array[10] = {"K","M","G","T","k","m","g","t"," ","%"}; - for (size_t i = 0; i < 10; i++) { - if (strstr(str_find, simv_del_array[i])) { - str_find = yon_char_divide_search(str_find, simv_del_array[i], -1); - } - } - if (strstr(str_find, " ") != NULL) { - char* mem_s = yon_char_new(str_find); - yon_char_divide_search(mem_s, " ", -1); - *array_data = yon_char_parsed_append(*array_data, &index, mem_s); - } - if (strstr(str_find, "-") != NULL) { - *array_data = yon_char_parsed_append(*array_data, &index, "-"); - } - else { - if (str_find[0] == '\"') { - yon_char_divide(str_find, 0); - size_t length = strlen(str_find); - str_find = yon_char_divide(str_find, length-2); - } - if (strstr(str_find, " ") == NULL) { - *array_data = yon_char_parsed_append(*array_data, &index, str_find); - } - - } -} -void set_pow_size_memory(char* str_find, int** array_size,int index) { - size_t length = strlen(str_find); - if (strstr(str_find,"K") != NULL) { - *array_size = philos_int_append(*array_size, &index, 0); - str_find = yon_char_divide(str_find, length-1); - str_find = yon_char_unite(str_find, " ", STR_KB, NULL); - index--; - } - else if (strstr(str_find,"M") != NULL) { - *array_size = philos_int_append(*array_size, &index, 1); - str_find = yon_char_divide(str_find, length-1); - str_find = yon_char_unite(str_find," ", STR_MB, NULL); - index--; - } - else if (strstr(str_find,"G") != NULL) { - *array_size = philos_int_append(*array_size, &index, 2); - str_find = yon_char_divide(str_find, length-1); - str_find = yon_char_unite(str_find," ", STR_GB, NULL); - index--; - } - else if (strstr(str_find,"T") != NULL) { - *array_size = philos_int_append(*array_size, &index, 3); - str_find = yon_char_divide(str_find, length-1); - - str_find = yon_char_unite(str_find," ", STR_TB, NULL); - index--; - } - 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--; - } - else if (strstr(str_find,"-") != NULL) { - *array_size = philos_int_append(*array_size, &index, -1); - index--; - } - -} - void main_cbx_2_event() { int menu_id = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtMainInfoLevel2)); char* cmd_text_param = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->cbtMainInfoLevel2)); @@ -1033,52 +966,36 @@ char* save_format_value(int index) { split_simvol[0] = 0; split_simvol[1] = 0; if (main_config.soft_raw_limit[index]==0) { - char* value1 = yon_char_unite(philos_format_cfg_str_size_memory("MemoryHigh=", main_config.soft_raw_limit[index],main_config.soft_raw_limit_size[index]),NULL); - if (strstr(value1,"-")) { - free(value1); - } - else { - value = yon_char_new(value1); - free(value1); + char* value_size = philos_format_cfg_str_size_memory("MemoryHigh=", main_config.soft_raw_limit[index],main_config.soft_raw_limit_size[index]); + if (!strstr(value_size,"-")) { + value = yon_char_unite(value ,split_simvol, value_size, NULL); split_simvol[0] = ','; split_simvol[1] = '\0'; } + free(value_size); } if (main_config.hard_raw_limit[index]==0) { - char* value1 = 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); - if (strstr(value1,"-")) { - free(value1); - } - else { - value = yon_char_new(value1); - free(value1); + char* value_size = philos_format_cfg_str_size_memory("MemoryMax=", main_config.hard_raw_limit[index],main_config.hard_raw_limit_size[index]); + if (!strstr(value_size,"-")) { + value = yon_char_unite(value ,split_simvol, value_size, NULL); split_simvol[0] = ','; split_simvol[1] = '\0'; } + free(value_size); } if (main_config.swap[index]==0) { - char* value1 = yon_char_unite(value ,split_simvol, philos_format_cfg_str_size_memory("MemorySwapMax=", main_config.swap[index],main_config.swap_size[index]), NULL); - if (strstr(value1,"-")) { - free(value1); - } - else { - value = yon_char_new(value1); - free(value1); + char* value_size = philos_format_cfg_str_size_memory("MemorySwapMax=", main_config.swap[index],main_config.swap_size[index]); + if (!strstr(value_size,"-")) { + value = yon_char_unite(value ,split_simvol, value_size, NULL); split_simvol[0] = ','; split_simvol[1] = '\0'; } + free(value_size); } - if (main_config.cpu_limit[index]==0) { - char* value1 = yon_char_unite(value ,split_simvol,"CPUQuota=", main_config.cpu_limit[index], NULL); - if (strstr(value1,"-")) { - free(value1); - } - else { - value = yon_char_new(value1); - free(value1); - split_simvol[0] = ','; - split_simvol[1] = '\0'; - } + if (main_config.cpu_limit[index]>=0) { + value = yon_char_unite(value ,split_simvol,"CPUQuota=", yon_char_from_int(main_config.cpu_limit[index]), "%", NULL); + split_simvol[0] = ','; + split_simvol[1] = '\0'; } value = add_io_str_format_ubconfig(value, "IOReadBandwidthMax", main_config.i_o_limit_read, main_config.i_o_limit_read_size, main_config.disk, index); value = add_io_str_format_ubconfig(value, "IOWriteBandwidthMax", main_config.i_o_limit_write, main_config.i_o_limit_write_size, main_config.disk, index); @@ -1086,33 +1003,36 @@ char* save_format_value(int index) { } char* add_io_str_format_ubconfig(char* cmd_io, char* key, int** i_o_limit, int** i_o_limit_size, char*** disk, int index) { char split_simvol[2] = {0}; - if (i_o_limit) { - if (i_o_limit[index] != NULL) { - if (i_o_limit[index] != NULL) { - for (int i = 0;i_o_limit[index][i] != -2; i++) { - if (i==0 && strlen(cmd_io) == 0) { - cmd_io = yon_char_unite(cmd_io, ",", key, "=", NULL); - } - if (cmd_io == NULL) { - cmd_io = yon_char_new(""); - } - int read_limit = i_o_limit[index][i]; - char* read_disk = disk[index][i]; - int read_limit_size = i_o_limit_size[index][i]; - if (read_limit >= 0 && read_disk && read_limit_size >= 0) { - char* num_and_pow_size = philos_format_cfg_str_size_memory("",read_limit, read_limit_size); - cmd_io = yon_char_unite(cmd_io, split_simvol, read_disk, " ",num_and_pow_size, NULL); - split_simvol[0] = ','; - split_simvol[1] = '\0'; - } - - } - } + if (i_o_limit== NULL) {return cmd_io;} + if (i_o_limit_size[index] == NULL) {return cmd_io;} + if (i_o_limit[index] == NULL) {return cmd_io;} + int len_array = 0; + for (int i = 0;i_o_limit[index][i] != -2; i++) { + len_array += 1; + } + for (int i=0; i0) { + size_t resurs = get_resurs_total(cmd); + if (value_spin>0) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check),1); } else if (active == 0) { gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), 0); } if (flag_cpu == 0) { - philos_set_spin_adjustment(check, spin, combo, get_resurs_total(cmd)); + philos_set_spin_adjustment(check, spin, combo, resurs); + if (value_spin>resurs) { + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), resurs); + } } else { - philos_set_spin_adjustment(check, spin, NULL, get_resurs_total(cmd)); + philos_set_spin_adjustment(check, spin, NULL, resurs); } } diff --git a/source/ubl-utils.h b/source/ubl-utils.h index 58e0b65..27c2baa 100644 --- a/source/ubl-utils.h +++ b/source/ubl-utils.h @@ -14,6 +14,7 @@ #include #include #include "ubl-cmake.h" + #ifdef WEBKIT_FOUND #include #endif @@ -37,7 +38,7 @@ #define catch(x) ExitJmp:if(__HadError) #define throw(x) {__HadError=true;goto ExitJmp;} #define file_source_login_min_max "/etc/login.defs" - +static char** array_size_pow; typedef enum { #ifdef __GTK_H__ @@ -204,6 +205,10 @@ char** philos_str_split(char *parameters, int *size, char *divider); void philos_array_string_remove_char(char*** array, char* str_remove, int size); +void philos_set_pow_size_memory(char* str_find, int** array_size,int index, char** array_size_pow); + +void philos_set_size_memory_integer_char(char* str_find, char*** array_data, int index); + char **yon_char_parsed_shrink(char **char_string, int *size, int item_to_delete); char*** yon_char_parsed_shrink_n3(char ***char_string, int *size, int item_to_delete); diff --git a/source/view_edit.c b/source/view_edit.c index 3e824fe..c141e18 100644 --- a/source/view_edit.c +++ b/source/view_edit.c @@ -285,15 +285,10 @@ void edit_set_limit_swap(int value, int pow_mem) { edit_widgets->cmbPaddingFLTemp); } void edit_temp_set(int value, int pow_mem, GtkWidget* cheek, GtkWidget* spin, GtkWidget* combo_box_text) { - char* search = "-"; - char* mem_size_pow = yon_char_from_int(value); - if (strstr(mem_size_pow, search) == 0 && pow_mem!=-3 && pow_mem>=-1) { - int value = atoi(yon_char_divide_search(mem_size_pow, " ", -1)); + if (pow_mem!=-3 && pow_mem>=-1 && value>=1) { gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), value); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cheek), 1); if (combo_box_text != NULL) { - // Todo: add code - printf("%d", pow_mem); gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box_text), pow_mem); } }