From db2579df2acfc3dab2568e22b36b64ef55f48146 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Wed, 15 Mar 2023 12:10:50 +0600 Subject: [PATCH] Fixed bug where application crashed when trying to launch it without sections in config file --- source/ubl-settings-manager.c | 50 ++++++++--------------------------- source/ubl-settings-manager.h | 2 +- 2 files changed, 12 insertions(+), 40 deletions(-) diff --git a/source/ubl-settings-manager.c b/source/ubl-settings-manager.c index b91028a..db0addc 100644 --- a/source/ubl-settings-manager.c +++ b/source/ubl-settings-manager.c @@ -946,11 +946,7 @@ int check_categories(apps app, char *catstocheck){ int setup_config(){ FILE *file; GError *err=NULL; - main_config.sections=malloc(sizeof(dictionary)); - main_config.sections->data=NULL; - main_config.sections->next=NULL; - main_config.sections->prev=NULL; - main_config.sections->first=NULL; + main_config.sections=yon_dictionary_create_empty(); GKeyFile *configfile = g_key_file_new(); char *pth=malloc(7+strlen(UserConfigPath)+strlen(getlogin())); sprintf(pth,"%s%s%s","/home/",getlogin(),UserConfigPath); @@ -997,7 +993,7 @@ int setup_config(){ gsize length=0; char **a=g_key_file_get_keys(configfile,"sections",&length,NULL); - if (!a){yon_set_default_sections(&main_config.sections);} else { + if (!a){yon_set_default_sections(main_config.sections);} else { for (int i=0;isection="Personal"; - sec->categories="X-UBL-SettingsManager;X-UBL-PersonalSettings;"; - (*section)->data=sec; - (*section)->first=*section; - (*section)->next=malloc(sizeof(dictionary)); - (*section)->next->prev=*section; - (*section)->next->first=(*section)->first; - *section=(*section)->next; - sec=malloc(sizeof(IconSection)); - sec->section="Hardware"; - sec->categories="X-UBL-SettingsManager;X-UBL-HardwareSettings;"; - (*section)->data=sec; - (*section)->next=malloc(sizeof(dictionary)); - (*section)->next->prev=*section; - (*section)->next->first=(*section)->first; - *section=(*section)->next; - sec=malloc(sizeof(IconSection)); - sec->section="System"; - sec->categories="X-UBL-SettingsManager;X-UBL-SystemSettings;"; - (*section)->data=sec; - (*section)->next=malloc(sizeof(dictionary)); - (*section)->next->prev=*section; - (*section)->next->first=(*section)->first; - *section=(*section)->next; - sec=malloc(sizeof(IconSection)); - sec->section="Misc"; - sec->categories="X-UBL-SettingsManager;"; - (*section)->data=sec; - *section=(*section)->first; +void yon_set_default_sections(dictionary *section){ + yon_section_new(section,"Personal","X-UBL-SettingsManager;X-UBL-PersonalSettings;"); + section=yon_dictionary_create_conneced(section); + yon_section_new(section,"Hardware","X-UBL-SettingsManager;X-UBL-HardwareSettings;"); + section=yon_dictionary_create_conneced(section); + yon_section_new(section,"System","X-UBL-SettingsManager;X-UBL-SystemSettings;"); + section=yon_dictionary_create_conneced(section); + yon_section_new(section,"Misc","X-UBL-SettingsManager;X-UBL-MiscSettings;"); } IVGraphicals *yon_create_single_section_IV(char *name,char *cats){ @@ -1230,7 +1202,7 @@ void yon_check_path(char *path){ dictionary *yon_section_new(dictionary *section, char *section_name, char *categories){ section->next=NULL; IconSection *sct=malloc(sizeof(IconSection)); - dictionary *dict=malloc(sizeof(dictionary)); + dictionary *dict=yon_dictionary_create_empty();//malloc(sizeof(dictionary)); sct->section=section_name; sct->categories=categories; dict->data=sct; diff --git a/source/ubl-settings-manager.h b/source/ubl-settings-manager.h index fc3293e..85ee5c5 100644 --- a/source/ubl-settings-manager.h +++ b/source/ubl-settings-manager.h @@ -202,7 +202,7 @@ dictionary *yon_theme_new(dictionary **widgetss, GtkBuilder *builder, char *them char *yon_char_get_augumented(char *source, char *append); char *yon_cut(char *source, int size, int startpos); int yon_set_sections(IconSection *section); -void yon_set_default_sections(dictionary **section); +void yon_set_default_sections(dictionary *section); char *yon_char_divide_search(char *source, char* dividepos, int delete_divider); char *yon_char_divide(char *source, int dividepos); dictionary *yon_section_new(dictionary *section, char *section_name, char *categories);