Написал загрузку конфигурации, не работает

pull/2/head
Igor Belitskiy 2 years ago
parent f1399da08f
commit 19f2b94777

@ -260,7 +260,7 @@ void load_global_cfg() {
void template_cfg(char* cmd) { void template_cfg(char* cmd) {
int size = 0; int size = 0;
int index = 0; int index_quotas = 0;
char** cfg = yon_config_load(cmd, &size); char** cfg = yon_config_load(cmd, &size);
for (int index = 0; index < size; index++) { for (int index = 0; index < size; index++) {
char* str_key_value = yon_char_new(cfg[index]); char* str_key_value = yon_char_new(cfg[index]);
@ -271,12 +271,73 @@ void template_cfg(char* cmd) {
size_t length = strlen(str_key_value); size_t length = strlen(str_key_value);
str_key_value = yon_char_divide(str_key_value, length-2); str_key_value = yon_char_divide(str_key_value, length-2);
} }
str_split_key(str_key, index_quotas);
str_split_value(str_key_value, index); str_split_value(str_key_value, index);
index++; index_quotas++;
} }
} }
if (index_quotas != 0) {
fill_tree_view(0, size);
} }
}
void str_split_key(char* value, int index) {
yon_char_divide_search(value, "[", -1);
value = yon_char_divide_search(value, "]", -1);
if (strstr(value, ".") != NULL) {
if (strstr(value, ".slice") != NULL) {
main_config.quota_volume = yon_char_parsed_append(main_config.quota_volume, &index, value);
index--;
main_config.type_quota_size = philos_int_append(main_config.type_quota_size, &index, 4);
index--;
main_config.quota_volume = yon_char_parsed_append(main_config.type_quota, &index, STR_PROCESS);
index--;
}
else if (strstr(value, ".service") != NULL) {
main_config.quota_volume = yon_char_parsed_append(main_config.quota_volume, &index, value);
index--;
main_config.type_quota_size = philos_int_append(main_config.type_quota_size, &index, 3);
index--;
main_config.quota_volume = yon_char_parsed_append(main_config.type_quota, &index, STR_SLICE);
index--;
}
else {
main_config.quota_volume = yon_char_parsed_append(main_config.quota_volume, &index, value);
index--;
main_config.type_quota_size = philos_int_append(main_config.type_quota_size, &index, -1);
index--;
main_config.quota_volume = yon_char_parsed_append(main_config.type_quota, &index, "-");
index--;
}
}
else {
int user_size = 0;
char** arr_users = philos_list_user(&user_size);
for (int user_index = 0; user_index < user_size; user_index++) {
// Пользователь
if (strcmp(arr_users[user_index], value) != 0) {
main_config.type_quota_size = philos_int_append(main_config.type_quota_size, &index, 0);
index--;
main_config.quota_volume = yon_char_parsed_append(main_config.quota_volume, &index, value);
index--;
main_config.quota_volume = yon_char_parsed_append(main_config.type_quota, &index, STR_USER);
index--;
}
// Группа
else {
main_config.type_quota_size = philos_int_append(main_config.type_quota_size, &index, 1);
index--;
main_config.quota_volume = yon_char_parsed_append(main_config.quota_volume, &index, value);
index--;
main_config.quota_volume = yon_char_parsed_append(main_config.type_quota, &index, STR_GROUP);
index--;
}
}
}
}
void str_split_value(char* values, int index) { void str_split_value(char* values, int index) {
char* new_value = yon_char_new(values); char* new_value = yon_char_new(values);
int size = 0; int size = 0;
@ -358,6 +419,11 @@ void set_pow_size(char* str_find, int* array_size, char** array_data , int index
index--; index--;
} }
if (strstr(str_find,"-") == NULL) { if (strstr(str_find,"-") == NULL) {
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);
}
size_t length = strlen(str_find); size_t length = strlen(str_find);
str_find = yon_char_divide(str_find, length-2); str_find = yon_char_divide(str_find, length-2);
array_data = yon_char_parsed_append(array_data, &index, str_find); array_data = yon_char_parsed_append(array_data, &index, str_find);
@ -365,16 +431,6 @@ void set_pow_size(char* str_find, int* array_size, char** array_data , int index
else { else {
array_data = yon_char_parsed_append(array_data, &index, "-"); array_data = yon_char_parsed_append(array_data, &index, "-");
} }
GtkTreeIter iter;
gtk_list_store_append(main_config.list,&iter);
gtk_list_store_set(main_config.list,&iter,0,main_config.type_quota[index],
1,main_config.quota_volume[index],
2,main_config.soft_raw_limit[index],
3,main_config.hard_raw_limit[index],
4,main_config.swap[index],
5,main_config.cpu_limit[index],
6,main_config.i_o_limit_read[index],
7,main_config.i_o_limit_write[index],-1);
} }
@ -453,6 +509,11 @@ void tree_view_add(int index) {
main_config.i_o_limit_read_size = philos_int_append(main_config.i_o_limit_read_size, &main_config.size_tree_view, add_get_read_device_size()); main_config.i_o_limit_read_size = philos_int_append(main_config.i_o_limit_read_size, &main_config.size_tree_view, add_get_read_device_size());
main_config.size_tree_view--; main_config.size_tree_view--;
main_config.i_o_limit_write_size = philos_int_append(main_config.i_o_limit_write_size, &main_config.size_tree_view, add_get_write_device_size()); main_config.i_o_limit_write_size = philos_int_append(main_config.i_o_limit_write_size, &main_config.size_tree_view, add_get_write_device_size());
fill_tree_view(main_config.size_tree_view-1, main_config.size_tree_view);
}
void fill_tree_view(int start, int size) {
for (int index = start; index < size; index++) {
GtkTreeIter iter; GtkTreeIter iter;
gtk_list_store_append(main_config.list,&iter); gtk_list_store_append(main_config.list,&iter);
gtk_list_store_set(main_config.list,&iter,0,main_config.type_quota[index], gtk_list_store_set(main_config.list,&iter,0,main_config.type_quota[index],
@ -464,6 +525,8 @@ void tree_view_add(int index) {
6,main_config.i_o_limit_read[index], 6,main_config.i_o_limit_read[index],
7,main_config.i_o_limit_write[index],-1); 7,main_config.i_o_limit_write[index],-1);
} }
}
int tree_view_edit() { int tree_view_edit() {
int index = 0; int index = 0;
GtkTreeIter iter; GtkTreeIter iter;

@ -182,3 +182,5 @@ void load_global_cfg();
void template_cfg(char* cmd); void template_cfg(char* cmd);
void str_split_value(char* values, int index); void str_split_value(char* values, int index);
void set_pow_size(char* str_find, int* array_size, char** array_data, int index); void set_pow_size(char* str_find, int* array_size, char** array_data, int index);
void str_split_key(char* value, int index);
void fill_tree_view(int start, int size);

@ -23,6 +23,10 @@
#define PROJECT_HOME_LABEL _("Project Home Page") #define PROJECT_HOME_LABEL _("Project Home Page")
#define NOTHING_CHOSEN_LABEL _("Nothing were chosen") #define NOTHING_CHOSEN_LABEL _("Nothing were chosen")
#define STR_USER _("User")
#define STR_GROUP _("Group")
#define STR_PROCESS _("Process")
#define STR_SLICE _("Slice")
#define GLOBAL_LOAD_SUCCESS _("Global configuration loading succseeded.") #define GLOBAL_LOAD_SUCCESS _("Global configuration loading succseeded.")
#define LOCAL_LOAD_SUCCESS _("Local configuration loading succseeded.") #define LOCAL_LOAD_SUCCESS _("Local configuration loading succseeded.")

@ -2736,9 +2736,10 @@ translated and supported by community.</property>
<property name="width-request">640</property> <property name="width-request">640</property>
<property name="height-request">500</property> <property name="height-request">500</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="default-width">800</property> <property name="default-width">700</property>
<property name="default-height">600</property> <property name="default-height">500</property>
<property name="icon-name">com.ublinux.ubl-settings-resourcequota</property> <property name="icon-name">com.ublinux.ubl-settings-resourcequota</property>
<property name="gravity">center</property>
<child> <child>
<object class="GtkBox" id="plugBox"> <object class="GtkBox" id="plugBox">
<property name="visible">True</property> <property name="visible">True</property>

Loading…
Cancel
Save