diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2021-08-21 10:23:29 +0100 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2021-08-22 15:24:51 +0100 |
commit | a59a629514c5084e23848157671a336202955b53 (patch) | |
tree | 09bcfdf580fd8084f497c20128834eb6721308c6 | |
parent | d282424ef2a17d9c5c91a18284eb897365fc3fa0 (diff) |
filetypes: handle missing or empty viewers.config
We want to load builtin filetypes and other config files even if
there is a problem loading viewers.config. A lot of menus expect
the builtin types to be there and don't work if they're missing.
Change-Id: Ie39c8b9ef184fe0d638bacbe18e5f2d22900bd81
-rw-r--r-- | apps/filetypes.c | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/apps/filetypes.c b/apps/filetypes.c index b6a557a6d2..530ab18683 100644 --- a/apps/filetypes.c +++ b/apps/filetypes.c @@ -338,6 +338,29 @@ void read_viewer_theme_file(void) custom_icons_loaded = true; } +static void read_viewers_config(void) +{ + int fd = open(VIEWERS_CONFIG, O_RDONLY); + if(fd < 0) + return; + + off_t filesz = filesize(fd); + if(filesz <= 0) + goto out; + + /* estimate bufsize with the filesize, will not be larger */ + strdup_bufsize = (size_t)filesz; + strdup_handle = core_alloc_ex("filetypes", strdup_bufsize, &ops); + if(strdup_handle <= 0) + goto out; + + read_config(fd); + core_shrink(strdup_handle, core_get_data(strdup_handle), strdup_cur_idx); + + out: + close(fd); +} + void filetype_init(void) { /* set the directory item first */ @@ -346,36 +369,15 @@ void filetype_init(void) filetypes[0].attr = 0; filetypes[0].icon = Icon_Folder; - /* estimate bufsize with the filesize, will not be larger */ viewer_count = 0; filetype_count = 1; - int fd = open(VIEWERS_CONFIG, O_RDONLY); - if (fd < 0) - return; - - off_t filesz = filesize(fd); - - if (filesz > 0) - { - strdup_bufsize = (size_t)filesz; - strdup_handle = core_alloc_ex("filetypes", strdup_bufsize, &ops); - } - - if (filesz <= 0 || strdup_handle <= 0) - { - close(fd); - return; - } - read_builtin_types(); - read_config(fd); - close(fd); + read_viewers_config(); read_viewer_theme_file(); #ifdef HAVE_LCD_COLOR read_color_theme_file(); #endif - core_shrink(strdup_handle, core_get_data(strdup_handle), strdup_cur_idx); } /* remove all white spaces from string */ |