summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/filetypes.c46
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
341static 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
341void filetype_init(void) 364void 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 */