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) | |
download | rockbox-a59a629514c5084e23848157671a336202955b53.tar.gz rockbox-a59a629514c5084e23848157671a336202955b53.zip |
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) | |||
338 | custom_icons_loaded = true; | 338 | custom_icons_loaded = true; |
339 | } | 339 | } |
340 | 340 | ||
341 | static void read_viewers_config(void) | ||
342 | { | ||
343 | int fd = open(VIEWERS_CONFIG, O_RDONLY); | ||
344 | if(fd < 0) | ||
345 | return; | ||
346 | |||
347 | off_t filesz = filesize(fd); | ||
348 | if(filesz <= 0) | ||
349 | goto out; | ||
350 | |||
351 | /* estimate bufsize with the filesize, will not be larger */ | ||
352 | strdup_bufsize = (size_t)filesz; | ||
353 | strdup_handle = core_alloc_ex("filetypes", strdup_bufsize, &ops); | ||
354 | if(strdup_handle <= 0) | ||
355 | goto out; | ||
356 | |||
357 | read_config(fd); | ||
358 | core_shrink(strdup_handle, core_get_data(strdup_handle), strdup_cur_idx); | ||
359 | |||
360 | out: | ||
361 | close(fd); | ||
362 | } | ||
363 | |||
341 | void filetype_init(void) | 364 | void filetype_init(void) |
342 | { | 365 | { |
343 | /* set the directory item first */ | 366 | /* set the directory item first */ |
@@ -346,36 +369,15 @@ void filetype_init(void) | |||
346 | filetypes[0].attr = 0; | 369 | filetypes[0].attr = 0; |
347 | filetypes[0].icon = Icon_Folder; | 370 | filetypes[0].icon = Icon_Folder; |
348 | 371 | ||
349 | /* estimate bufsize with the filesize, will not be larger */ | ||
350 | viewer_count = 0; | 372 | viewer_count = 0; |
351 | filetype_count = 1; | 373 | filetype_count = 1; |
352 | 374 | ||
353 | int fd = open(VIEWERS_CONFIG, O_RDONLY); | ||
354 | if (fd < 0) | ||
355 | return; | ||
356 | |||
357 | off_t filesz = filesize(fd); | ||
358 | |||
359 | if (filesz > 0) | ||
360 | { | ||
361 | strdup_bufsize = (size_t)filesz; | ||
362 | strdup_handle = core_alloc_ex("filetypes", strdup_bufsize, &ops); | ||
363 | } | ||
364 | |||
365 | if (filesz <= 0 || strdup_handle <= 0) | ||
366 | { | ||
367 | close(fd); | ||
368 | return; | ||
369 | } | ||
370 | |||
371 | read_builtin_types(); | 375 | read_builtin_types(); |
372 | read_config(fd); | 376 | read_viewers_config(); |
373 | close(fd); | ||
374 | read_viewer_theme_file(); | 377 | read_viewer_theme_file(); |
375 | #ifdef HAVE_LCD_COLOR | 378 | #ifdef HAVE_LCD_COLOR |
376 | read_color_theme_file(); | 379 | read_color_theme_file(); |
377 | #endif | 380 | #endif |
378 | core_shrink(strdup_handle, core_get_data(strdup_handle), strdup_cur_idx); | ||
379 | } | 381 | } |
380 | 382 | ||
381 | /* remove all white spaces from string */ | 383 | /* remove all white spaces from string */ |