2004-05-21 20:08:24 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
2007-03-29 06:16:00 +00:00
|
|
|
* Copyright (C) 2007 Jonathan Gordon
|
2004-05-21 20:08:24 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2004-05-21 20:08:24 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
2007-03-29 06:16:00 +00:00
|
|
|
#include "string.h"
|
|
|
|
#include <ctype.h>
|
2004-05-21 20:08:24 +00:00
|
|
|
|
|
|
|
#include "settings.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "lang.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "plugin.h"
|
|
|
|
#include "filetypes.h"
|
|
|
|
#include "screens.h"
|
|
|
|
#include "dir.h"
|
|
|
|
#include "file.h"
|
2005-11-16 15:12:15 +00:00
|
|
|
#include "splash.h"
|
2011-08-30 14:01:33 +00:00
|
|
|
#include "core_alloc.h"
|
2007-06-17 21:16:34 +00:00
|
|
|
#include "icons.h"
|
2007-06-17 23:10:01 +00:00
|
|
|
#include "logf.h"
|
2004-05-21 20:08:24 +00:00
|
|
|
|
2007-08-12 09:53:41 +00:00
|
|
|
/* max filetypes (plugins & icons stored here) */
|
2010-05-12 12:41:31 +00:00
|
|
|
#define MAX_FILETYPES 192
|
2010-11-09 14:35:19 +00:00
|
|
|
/* max viewer plugins */
|
|
|
|
#define MAX_VIEWERS 56
|
2007-08-12 09:53:41 +00:00
|
|
|
|
2010-11-09 14:35:19 +00:00
|
|
|
/* a table for the known file types */
|
2008-05-24 20:56:19 +00:00
|
|
|
static const struct filetype inbuilt_filetypes[] = {
|
2007-04-18 13:03:01 +00:00
|
|
|
{ "mp3", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "mp2", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "mpa", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "mp1", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "ogg", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2008-10-30 01:17:26 +00:00
|
|
|
{ "oga", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2007-04-18 13:03:01 +00:00
|
|
|
{ "wma", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2007-07-03 13:16:49 +00:00
|
|
|
{ "wmv", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "asf", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2007-04-18 13:03:01 +00:00
|
|
|
{ "wav", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "flac",FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "ac3", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "a52", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "mpc", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "wv", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "m4a", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "m4b", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "mp4", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2008-05-21 11:19:58 +00:00
|
|
|
{ "mod", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2007-04-18 13:03:01 +00:00
|
|
|
{ "shn", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "aif", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "aiff",FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "spx" ,FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2012-07-26 12:38:32 +00:00
|
|
|
{ "opus",FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2007-04-18 13:03:01 +00:00
|
|
|
{ "sid", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "adx", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "nsf", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "nsfe",FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "spc", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2007-06-05 16:58:29 +00:00
|
|
|
{ "ape", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "mac", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2008-07-26 15:16:10 +00:00
|
|
|
{ "sap" ,FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2009-07-06 22:40:45 +00:00
|
|
|
{ "rm", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "ra", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2009-07-27 11:36:26 +00:00
|
|
|
{ "rmvb",FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2010-02-06 12:49:03 +00:00
|
|
|
{ "cmc", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "cm3", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "cmr", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "cms", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "dmc", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "dlt", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "mpt", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "mpd", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "rmt", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "tmc", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "tm8", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "tm2", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2010-02-12 03:21:37 +00:00
|
|
|
{ "oma", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "aa3", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2010-02-16 03:34:39 +00:00
|
|
|
{ "at3", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2010-02-24 11:46:29 +00:00
|
|
|
{ "mmf", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2010-02-28 07:22:20 +00:00
|
|
|
{ "au", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "snd", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2010-02-28 08:13:30 +00:00
|
|
|
{ "vox", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2010-02-28 08:48:07 +00:00
|
|
|
{ "w64", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2010-05-13 12:40:09 +00:00
|
|
|
{ "tta", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2011-08-07 20:01:04 +00:00
|
|
|
{ "ay", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2020-09-26 21:19:07 +00:00
|
|
|
{ "vtx", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2011-08-07 20:01:04 +00:00
|
|
|
{ "gbs", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "hes", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "sgc", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "vgm", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "vgz", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
|
|
|
{ "kss", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2018-12-23 01:01:42 +00:00
|
|
|
{ "aac", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
|
2007-04-18 13:03:01 +00:00
|
|
|
{ "m3u", FILE_ATTR_M3U, Icon_Playlist, LANG_PLAYLIST },
|
|
|
|
{ "m3u8",FILE_ATTR_M3U, Icon_Playlist, LANG_PLAYLIST },
|
|
|
|
{ "cfg", FILE_ATTR_CFG, Icon_Config, VOICE_EXT_CFG },
|
|
|
|
{ "wps", FILE_ATTR_WPS, Icon_Wps, VOICE_EXT_WPS },
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
{ "rwps",FILE_ATTR_RWPS, Icon_Wps, VOICE_EXT_RWPS },
|
|
|
|
#endif
|
|
|
|
#if CONFIG_TUNER
|
|
|
|
{ "fmr", FILE_ATTR_FMR, Icon_Preset, LANG_FMR },
|
2010-05-12 10:38:00 +00:00
|
|
|
{ "fms", FILE_ATTR_FMS, Icon_Wps, VOICE_EXT_FMS },
|
2007-04-18 13:03:01 +00:00
|
|
|
#endif
|
|
|
|
{ "lng", FILE_ATTR_LNG, Icon_Language, LANG_LANGUAGE },
|
|
|
|
{ "rock",FILE_ATTR_ROCK,Icon_Plugin, VOICE_EXT_ROCK },
|
2009-10-28 23:31:42 +00:00
|
|
|
{ "lua", FILE_ATTR_LUA, Icon_Plugin, VOICE_EXT_ROCK },
|
2020-08-01 02:45:10 +00:00
|
|
|
{ "opx", FILE_ATTR_OPX, Icon_Plugin, VOICE_EXT_ROCK },
|
2007-04-18 13:03:01 +00:00
|
|
|
{ "fnt", FILE_ATTR_FONT,Icon_Font, VOICE_EXT_FONT },
|
|
|
|
{ "kbd", FILE_ATTR_KBD, Icon_Keyboard, VOICE_EXT_KBD },
|
|
|
|
{ "bmark",FILE_ATTR_BMARK, Icon_Bookmark, VOICE_EXT_BMARK },
|
2007-08-05 19:19:39 +00:00
|
|
|
{ "cue", FILE_ATTR_CUE, Icon_Bookmark, VOICE_EXT_CUESHEET },
|
2009-10-19 15:28:15 +00:00
|
|
|
{ "sbs", FILE_ATTR_SBS, Icon_Wps, VOICE_EXT_SBS },
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
{ "rsbs", FILE_ATTR_RSBS, Icon_Wps, VOICE_EXT_RSBS },
|
2010-05-12 10:38:00 +00:00
|
|
|
#if CONFIG_TUNER
|
|
|
|
{ "rfms", FILE_ATTR_RFMS, Icon_Wps, VOICE_EXT_RFMS },
|
2010-11-09 14:35:19 +00:00
|
|
|
#endif
|
2009-10-19 15:28:15 +00:00
|
|
|
#endif
|
2007-04-18 13:03:01 +00:00
|
|
|
#ifdef BOOTFILE_EXT
|
|
|
|
{ BOOTFILE_EXT, FILE_ATTR_MOD, Icon_Firmware, VOICE_EXT_AJZ },
|
2008-08-15 08:27:39 +00:00
|
|
|
#endif
|
2009-10-10 11:46:23 +00:00
|
|
|
#ifdef BOOTFILE_EXT2
|
|
|
|
{ BOOTFILE_EXT2, FILE_ATTR_MOD, Icon_Firmware, VOICE_EXT_AJZ },
|
|
|
|
#endif
|
2007-04-18 13:03:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void tree_get_filetypes(const struct filetype** types, int* count)
|
|
|
|
{
|
|
|
|
*types = inbuilt_filetypes;
|
|
|
|
*count = sizeof(inbuilt_filetypes) / sizeof(*inbuilt_filetypes);
|
|
|
|
}
|
2004-05-21 20:08:24 +00:00
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
#define ROCK_EXTENSION "rock"
|
|
|
|
|
|
|
|
struct file_type {
|
2011-06-20 19:32:48 +00:00
|
|
|
enum themable_icons icon; /* the icon which shall be used for it, NOICON if unknown */
|
2009-10-28 23:31:45 +00:00
|
|
|
unsigned char attr; /* FILE_ATTR_MASK >> 8 */
|
2007-03-29 06:16:00 +00:00
|
|
|
char* plugin; /* Which plugin to use, NULL if unknown, or builtin */
|
|
|
|
char* extension; /* NULL for none */
|
|
|
|
};
|
2007-08-12 09:53:41 +00:00
|
|
|
static struct file_type filetypes[MAX_FILETYPES];
|
|
|
|
static int custom_filetype_icons[MAX_FILETYPES];
|
2007-04-16 14:33:29 +00:00
|
|
|
static bool custom_icons_loaded = false;
|
2007-06-17 21:16:34 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
2013-01-20 11:29:43 +00:00
|
|
|
static int custom_colors[MAX_FILETYPES];
|
2007-06-17 21:16:34 +00:00
|
|
|
#endif
|
2013-01-20 11:29:43 +00:00
|
|
|
struct filetype_unknown {
|
2013-01-20 22:07:04 +00:00
|
|
|
int icon;
|
2013-01-20 11:29:43 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
int color;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
static struct filetype_unknown unknown_file = {
|
|
|
|
.icon = Icon_NOICON,
|
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
.color = -1,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2010-11-09 14:35:19 +00:00
|
|
|
/* index array to filetypes used in open with list. */
|
|
|
|
static int viewers[MAX_VIEWERS];
|
2007-08-12 09:53:41 +00:00
|
|
|
static int filetype_count = 0;
|
2008-05-24 20:56:19 +00:00
|
|
|
static unsigned char highest_attr = 0;
|
2010-11-09 14:35:19 +00:00
|
|
|
static int viewer_count = 0;
|
2004-05-21 20:08:24 +00:00
|
|
|
|
2011-08-30 14:01:33 +00:00
|
|
|
static int strdup_handle, strdup_bufsize, strdup_cur_idx;
|
2011-08-30 14:01:45 +00:00
|
|
|
static int move_callback(int handle, void* current, void* new)
|
|
|
|
{
|
|
|
|
/*could compare to strdup_handle, but ops is only used once */
|
|
|
|
(void)handle;
|
|
|
|
size_t diff = new - current;
|
|
|
|
#define FIX_PTR(x) \
|
2011-09-21 13:32:37 +00:00
|
|
|
{ if ((void*)x >= current && (void*)x < (current+strdup_bufsize)) x+= diff; }
|
2011-08-30 14:01:45 +00:00
|
|
|
for(int i = 0; i < filetype_count; i++)
|
|
|
|
{
|
|
|
|
FIX_PTR(filetypes[i].extension);
|
|
|
|
FIX_PTR(filetypes[i].plugin);
|
|
|
|
}
|
|
|
|
return BUFLIB_CB_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct buflib_callbacks ops = {
|
|
|
|
.move_callback = move_callback,
|
|
|
|
.shrink_callback = NULL,
|
|
|
|
};
|
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
static char *filetypes_strdup(char* string)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2011-08-30 14:01:33 +00:00
|
|
|
char *buffer = core_get_data(strdup_handle) + strdup_cur_idx;
|
|
|
|
strdup_cur_idx += strlcpy(buffer, string, strdup_bufsize-strdup_cur_idx)+1;
|
2007-03-29 06:16:00 +00:00
|
|
|
return buffer;
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
2011-08-30 14:01:33 +00:00
|
|
|
|
2010-11-09 14:35:19 +00:00
|
|
|
static char *filetypes_store_plugin(char *plugin, int n)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
/* if the plugin is in the list already, use it. */
|
|
|
|
for (i=0; i<viewer_count; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp(filetypes[viewers[i]].plugin, plugin))
|
|
|
|
return filetypes[viewers[i]].plugin;
|
|
|
|
}
|
|
|
|
/* otherwise, allocate buffer */
|
|
|
|
if (viewer_count < MAX_VIEWERS)
|
|
|
|
viewers[viewer_count++] = n;
|
|
|
|
return filetypes_strdup(plugin);
|
|
|
|
}
|
2010-11-27 12:57:19 +00:00
|
|
|
|
|
|
|
static int find_extension(const char* extension)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (!extension)
|
|
|
|
return -1;
|
|
|
|
for (i=1; i<filetype_count; i++)
|
|
|
|
{
|
|
|
|
if (filetypes[i].extension &&
|
|
|
|
!strcasecmp(extension, filetypes[i].extension))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
static void read_builtin_types(void);
|
2011-08-30 14:01:33 +00:00
|
|
|
static void read_config(int fd);
|
2007-06-17 21:16:34 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
/* Colors file format is similar to icons:
|
|
|
|
* ext:hex_color
|
|
|
|
* load a colors file from a theme with:
|
2007-06-19 04:21:06 +00:00
|
|
|
* filetype colours: filename.colours */
|
2007-06-17 21:16:34 +00:00
|
|
|
void read_color_theme_file(void) {
|
2010-12-06 22:26:31 +00:00
|
|
|
char buffer[MAX_PATH];
|
2007-06-17 21:16:34 +00:00
|
|
|
int fd;
|
|
|
|
char *ext, *color;
|
|
|
|
int i;
|
2013-01-20 11:29:43 +00:00
|
|
|
for (i = 0; i < MAX_FILETYPES; i++) {
|
2007-06-17 21:16:34 +00:00
|
|
|
custom_colors[i] = -1;
|
|
|
|
}
|
2021-03-01 23:39:12 +00:00
|
|
|
unknown_file.color = -1;
|
2021-03-01 09:19:20 +00:00
|
|
|
if (!global_settings.colors_file[0] || global_settings.colors_file[0] == '-')
|
|
|
|
return;
|
2010-12-06 22:26:31 +00:00
|
|
|
snprintf(buffer, MAX_PATH, THEME_DIR "/%s.colours",
|
2007-06-17 21:16:34 +00:00
|
|
|
global_settings.colors_file);
|
|
|
|
fd = open(buffer, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
return;
|
|
|
|
while (read_line(fd, buffer, MAX_PATH) > 0)
|
|
|
|
{
|
|
|
|
if (!settings_parseline(buffer, &ext, &color))
|
|
|
|
continue;
|
2007-06-17 23:10:01 +00:00
|
|
|
if (!strcasecmp(ext, "folder"))
|
|
|
|
{
|
2008-03-21 13:41:35 +00:00
|
|
|
hex_to_rgb(color, &custom_colors[0]);
|
2007-06-17 23:10:01 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-06-18 22:41:39 +00:00
|
|
|
if (!strcasecmp(ext, "???"))
|
|
|
|
{
|
2013-01-20 11:29:43 +00:00
|
|
|
hex_to_rgb(color, &unknown_file.color);
|
2007-06-18 22:41:39 +00:00
|
|
|
continue;
|
|
|
|
}
|
2010-11-27 12:57:19 +00:00
|
|
|
i = find_extension(ext);
|
|
|
|
if (i >= 0)
|
|
|
|
hex_to_rgb(color, &custom_colors[i]);
|
2007-06-17 21:16:34 +00:00
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
#endif
|
2007-04-16 09:14:36 +00:00
|
|
|
void read_viewer_theme_file(void)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
int fd;
|
|
|
|
char *ext, *icon;
|
|
|
|
int i;
|
2013-01-20 11:29:43 +00:00
|
|
|
int *icon_dest;
|
2007-04-26 05:30:46 +00:00
|
|
|
global_status.viewer_icon_count = 0;
|
2007-04-16 14:33:29 +00:00
|
|
|
custom_icons_loaded = false;
|
2007-04-16 14:52:47 +00:00
|
|
|
custom_filetype_icons[0] = Icon_Folder;
|
|
|
|
for (i=1; i<filetype_count; i++)
|
2007-04-17 09:17:23 +00:00
|
|
|
{
|
2007-04-22 08:50:24 +00:00
|
|
|
custom_filetype_icons[i] = filetypes[i].icon;
|
2007-04-17 09:17:23 +00:00
|
|
|
}
|
2007-04-16 14:33:29 +00:00
|
|
|
|
2007-04-16 09:14:36 +00:00
|
|
|
snprintf(buffer, MAX_PATH, "%s/%s.icons", ICON_DIR,
|
|
|
|
global_settings.viewers_icon_file);
|
|
|
|
fd = open(buffer, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
return;
|
|
|
|
while (read_line(fd, buffer, MAX_PATH) > 0)
|
|
|
|
{
|
|
|
|
if (!settings_parseline(buffer, &ext, &icon))
|
|
|
|
continue;
|
2010-11-27 12:57:19 +00:00
|
|
|
i = find_extension(ext);
|
|
|
|
if (i >= 0)
|
2013-01-20 11:29:43 +00:00
|
|
|
icon_dest = &custom_filetype_icons[i];
|
|
|
|
else if (!strcmp(ext, "???"))
|
|
|
|
icon_dest = &unknown_file.icon;
|
|
|
|
else
|
|
|
|
icon_dest = NULL;
|
|
|
|
|
|
|
|
if (icon_dest)
|
2007-04-16 09:14:36 +00:00
|
|
|
{
|
2010-11-27 12:57:19 +00:00
|
|
|
if (*icon == '*')
|
2013-01-20 11:29:43 +00:00
|
|
|
*icon_dest = atoi(icon+1);
|
2010-11-27 12:57:19 +00:00
|
|
|
else if (*icon == '-')
|
2013-01-20 11:29:43 +00:00
|
|
|
*icon_dest = Icon_NOICON;
|
2010-11-27 12:57:19 +00:00
|
|
|
else if (*icon >= '0' && *icon <= '9')
|
2007-04-16 09:14:36 +00:00
|
|
|
{
|
2010-11-27 12:57:19 +00:00
|
|
|
int number = atoi(icon);
|
|
|
|
if (number > global_status.viewer_icon_count)
|
|
|
|
global_status.viewer_icon_count++;
|
2013-01-20 11:29:43 +00:00
|
|
|
*icon_dest = Icon_Last_Themeable + number;
|
2007-04-16 09:14:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(fd);
|
2007-04-16 14:33:29 +00:00
|
|
|
custom_icons_loaded = true;
|
2007-04-16 09:14:36 +00:00
|
|
|
}
|
2004-05-21 20:08:24 +00:00
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
void filetype_init(void)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
/* set the directory item first */
|
|
|
|
filetypes[0].extension = NULL;
|
|
|
|
filetypes[0].plugin = NULL;
|
|
|
|
filetypes[0].attr = 0;
|
2007-04-16 09:14:36 +00:00
|
|
|
filetypes[0].icon = Icon_Folder;
|
2010-11-09 14:35:19 +00:00
|
|
|
|
2011-08-30 14:01:33 +00:00
|
|
|
/* estimate bufsize with the filesize, will not be larger */
|
2010-11-09 14:35:19 +00:00
|
|
|
viewer_count = 0;
|
2007-03-29 06:16:00 +00:00
|
|
|
filetype_count = 1;
|
2011-08-30 14:01:33 +00:00
|
|
|
|
|
|
|
int fd = open(VIEWERS_CONFIG, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
strdup_bufsize = filesize(fd);
|
2011-08-30 14:01:45 +00:00
|
|
|
strdup_handle = core_alloc_ex("filetypes", strdup_bufsize, &ops);
|
2012-06-10 15:15:47 +00:00
|
|
|
if (strdup_handle <= 0)
|
2011-10-02 20:04:44 +00:00
|
|
|
{
|
|
|
|
close(fd);
|
2011-08-30 14:01:33 +00:00
|
|
|
return;
|
2011-10-02 20:04:44 +00:00
|
|
|
}
|
2007-03-29 06:16:00 +00:00
|
|
|
read_builtin_types();
|
2011-08-30 14:01:33 +00:00
|
|
|
read_config(fd);
|
2011-10-02 20:04:44 +00:00
|
|
|
close(fd);
|
2007-04-16 09:14:36 +00:00
|
|
|
read_viewer_theme_file();
|
2007-06-17 21:16:34 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
read_color_theme_file();
|
|
|
|
#endif
|
2011-08-30 14:01:33 +00:00
|
|
|
core_shrink(strdup_handle, core_get_data(strdup_handle), strdup_cur_idx);
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
/* remove all white spaces from string */
|
|
|
|
static void rm_whitespaces(char* str)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
char *s = str;
|
|
|
|
while (*str)
|
2006-03-13 07:33:30 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
if (!isspace(*str))
|
2006-03-13 07:33:30 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
*s = *str;
|
|
|
|
s++;
|
2006-03-13 07:33:30 +00:00
|
|
|
}
|
2007-03-29 06:16:00 +00:00
|
|
|
str++;
|
2006-03-13 07:33:30 +00:00
|
|
|
}
|
2007-03-29 06:16:00 +00:00
|
|
|
*s = '\0';
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
static void read_builtin_types(void)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-04-18 13:03:01 +00:00
|
|
|
int count = sizeof(inbuilt_filetypes)/sizeof(*inbuilt_filetypes), i;
|
2007-08-12 09:53:41 +00:00
|
|
|
for(i=0; i<count && (filetype_count < MAX_FILETYPES); i++)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-04-18 13:03:01 +00:00
|
|
|
filetypes[filetype_count].extension = inbuilt_filetypes[i].extension;
|
2007-03-29 06:16:00 +00:00
|
|
|
filetypes[filetype_count].plugin = NULL;
|
2007-08-12 09:53:41 +00:00
|
|
|
filetypes[filetype_count].attr = inbuilt_filetypes[i].tree_attr>>8;
|
2008-05-24 20:56:19 +00:00
|
|
|
if (filetypes[filetype_count].attr > highest_attr)
|
|
|
|
highest_attr = filetypes[filetype_count].attr;
|
2007-08-12 09:53:41 +00:00
|
|
|
filetypes[filetype_count].icon = inbuilt_filetypes[i].icon;
|
2007-03-29 06:16:00 +00:00
|
|
|
filetype_count++;
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-30 14:01:33 +00:00
|
|
|
static void read_config(int fd)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
char line[64], *s, *e;
|
2010-11-09 14:35:19 +00:00
|
|
|
char *extension, *plugin;
|
|
|
|
/* config file is in the format
|
2007-03-29 06:16:00 +00:00
|
|
|
<extension>,<plugin>,<icon code>
|
|
|
|
ignore line if either of the first two are missing */
|
2010-11-09 14:35:19 +00:00
|
|
|
while (read_line(fd, line, sizeof line) > 0)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-08-12 09:53:41 +00:00
|
|
|
if (filetype_count >= MAX_FILETYPES)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ, ID2P(LANG_FILETYPES_FULL));
|
2004-05-21 20:08:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-03-29 06:16:00 +00:00
|
|
|
rm_whitespaces(line);
|
2010-11-27 12:57:19 +00:00
|
|
|
/* get the extension */
|
2007-03-29 06:16:00 +00:00
|
|
|
s = line;
|
|
|
|
e = strchr(s, ',');
|
|
|
|
if (!e)
|
2004-05-21 20:08:24 +00:00
|
|
|
continue;
|
2007-03-29 06:16:00 +00:00
|
|
|
*e = '\0';
|
2010-11-09 14:35:19 +00:00
|
|
|
extension = s;
|
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
/* get the plugin */
|
|
|
|
s = e+1;
|
|
|
|
e = strchr(s, ',');
|
|
|
|
if (!e)
|
2004-05-21 20:08:24 +00:00
|
|
|
continue;
|
2007-03-29 06:16:00 +00:00
|
|
|
*e = '\0';
|
2010-11-09 14:35:19 +00:00
|
|
|
plugin = s;
|
|
|
|
|
2013-01-20 11:29:43 +00:00
|
|
|
if (!strcmp("???", extension))
|
|
|
|
{
|
|
|
|
/* get the icon */
|
|
|
|
s = e+1;
|
|
|
|
if (*s == '*')
|
|
|
|
unknown_file.icon = atoi(s+1);
|
|
|
|
else if (*s == '-')
|
|
|
|
unknown_file.icon = Icon_NOICON;
|
|
|
|
else if (*s >= '0' && *s <= '9')
|
|
|
|
unknown_file.icon = Icon_Last_Themeable + atoi(s);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
/* ok, store this plugin/extension, check icon after */
|
2010-11-09 14:35:19 +00:00
|
|
|
struct file_type *file_type = &filetypes[filetype_count];
|
|
|
|
file_type->extension = filetypes_strdup(extension);
|
|
|
|
file_type->plugin = filetypes_store_plugin(plugin, filetype_count);
|
|
|
|
file_type->attr = highest_attr +1;
|
|
|
|
file_type->icon = Icon_Questionmark;
|
2008-05-24 20:56:19 +00:00
|
|
|
highest_attr++;
|
2007-03-29 06:16:00 +00:00
|
|
|
/* get the icon */
|
|
|
|
s = e+1;
|
2007-04-16 09:14:36 +00:00
|
|
|
if (*s == '*')
|
2010-11-09 14:35:19 +00:00
|
|
|
file_type->icon = atoi(s+1);
|
2007-04-16 09:14:36 +00:00
|
|
|
else if (*s == '-')
|
2010-11-09 14:35:19 +00:00
|
|
|
file_type->icon = Icon_NOICON;
|
2007-04-16 12:26:49 +00:00
|
|
|
else if (*s >= '0' && *s <= '9')
|
2010-11-09 14:35:19 +00:00
|
|
|
file_type->icon = Icon_Last_Themeable + atoi(s);
|
2007-03-29 06:16:00 +00:00
|
|
|
filetype_count++;
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
int filetype_get_attr(const char* file)
|
2005-03-07 20:40:36 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
char *extension = strrchr(file, '.');
|
2005-03-07 20:40:36 +00:00
|
|
|
int i;
|
2007-03-29 06:16:00 +00:00
|
|
|
if (!extension)
|
2005-03-07 20:40:36 +00:00
|
|
|
return 0;
|
2007-03-29 06:16:00 +00:00
|
|
|
extension++;
|
2010-11-27 12:57:19 +00:00
|
|
|
|
|
|
|
i = find_extension(extension);
|
|
|
|
if (i >= 0)
|
|
|
|
return (filetypes[i].attr<<8)&FILE_ATTR_MASK;
|
2007-03-29 06:16:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-03-07 20:40:36 +00:00
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
static int find_attr(int attr)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
/* skip the directory item */
|
|
|
|
if ((attr & ATTR_DIRECTORY)==ATTR_DIRECTORY)
|
2005-03-07 20:40:36 +00:00
|
|
|
return 0;
|
2007-03-29 06:16:00 +00:00
|
|
|
for (i=1; i<filetype_count; i++)
|
|
|
|
{
|
|
|
|
if ((attr>>8) == filetypes[i].attr)
|
|
|
|
return i;
|
2005-03-07 20:40:36 +00:00
|
|
|
}
|
2007-03-29 06:16:00 +00:00
|
|
|
return -1;
|
2005-03-07 20:40:36 +00:00
|
|
|
}
|
|
|
|
|
2007-06-17 21:16:34 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
2007-06-17 23:10:01 +00:00
|
|
|
int filetype_get_color(const char * name, int attr)
|
2007-06-17 21:16:34 +00:00
|
|
|
{
|
2007-06-17 23:10:01 +00:00
|
|
|
char *extension;
|
|
|
|
int i;
|
|
|
|
if ((attr & ATTR_DIRECTORY)==ATTR_DIRECTORY)
|
|
|
|
return custom_colors[0];
|
|
|
|
extension = strrchr(name, '.');
|
|
|
|
if (!extension)
|
2013-06-05 22:35:09 +00:00
|
|
|
return unknown_file.color;
|
2007-06-17 23:10:01 +00:00
|
|
|
extension++;
|
2010-11-27 12:57:19 +00:00
|
|
|
|
|
|
|
i = find_extension(extension);
|
|
|
|
if (i >= 0)
|
|
|
|
return custom_colors[i];
|
2013-01-20 11:29:43 +00:00
|
|
|
return unknown_file.color;
|
2007-06-17 21:16:34 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-04-16 09:14:36 +00:00
|
|
|
int filetype_get_icon(int attr)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-03-29 06:16:00 +00:00
|
|
|
int index = find_attr(attr);
|
|
|
|
if (index < 0)
|
2013-01-20 11:29:43 +00:00
|
|
|
return unknown_file.icon;
|
2007-04-16 14:33:29 +00:00
|
|
|
if (custom_icons_loaded)
|
|
|
|
return custom_filetype_icons[index];
|
2007-04-16 09:14:36 +00:00
|
|
|
return filetypes[index].icon;
|
2007-03-29 06:16:00 +00:00
|
|
|
}
|
2004-05-21 20:08:24 +00:00
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
char* filetype_get_plugin(const struct entry* file)
|
|
|
|
{
|
|
|
|
static char plugin_name[MAX_PATH];
|
|
|
|
int index = find_attr(file->attr);
|
|
|
|
if (index < 0)
|
|
|
|
return NULL;
|
2007-04-16 11:10:41 +00:00
|
|
|
if (filetypes[index].plugin == NULL)
|
2007-04-16 11:01:41 +00:00
|
|
|
return NULL;
|
2007-03-29 06:16:00 +00:00
|
|
|
snprintf(plugin_name, MAX_PATH, "%s/%s.%s",
|
2007-08-06 13:42:52 +00:00
|
|
|
PLUGIN_DIR, filetypes[index].plugin, ROCK_EXTENSION);
|
2007-03-29 06:16:00 +00:00
|
|
|
return plugin_name;
|
|
|
|
}
|
2004-05-21 20:08:24 +00:00
|
|
|
|
2010-11-09 14:35:19 +00:00
|
|
|
bool filetype_supported(int attr)
|
2007-03-29 06:16:00 +00:00
|
|
|
{
|
|
|
|
return find_attr(attr) >= 0;
|
|
|
|
}
|
2004-05-21 20:08:24 +00:00
|
|
|
|
2007-08-07 07:55:18 +00:00
|
|
|
/**** Open With Screen ****/
|
2007-10-21 00:11:47 +00:00
|
|
|
struct cb_data {
|
2008-05-24 20:56:19 +00:00
|
|
|
const char *current_file;
|
2007-10-21 00:11:47 +00:00
|
|
|
};
|
2008-04-09 15:25:17 +00:00
|
|
|
|
|
|
|
static enum themable_icons openwith_get_icon(int selected_item, void * data)
|
2007-08-07 07:55:18 +00:00
|
|
|
{
|
2010-11-09 14:35:19 +00:00
|
|
|
(void)data;
|
|
|
|
return filetypes[viewers[selected_item]].icon;
|
2007-08-07 07:55:18 +00:00
|
|
|
}
|
2008-04-09 15:25:17 +00:00
|
|
|
|
2009-08-20 16:47:44 +00:00
|
|
|
static const char* openwith_get_name(int selected_item, void * data,
|
|
|
|
char * buffer, size_t buffer_len)
|
2007-08-07 07:55:18 +00:00
|
|
|
{
|
2010-11-09 14:35:19 +00:00
|
|
|
(void)data; (void)buffer; (void)buffer_len;
|
|
|
|
const char *s = strrchr(filetypes[viewers[selected_item]].plugin, '/');
|
2007-08-07 07:55:18 +00:00
|
|
|
if (s)
|
|
|
|
return s+1;
|
2010-11-09 14:35:19 +00:00
|
|
|
else return filetypes[viewers[selected_item]].plugin;
|
2007-08-07 07:55:18 +00:00
|
|
|
}
|
2008-04-09 15:25:17 +00:00
|
|
|
|
2018-10-30 13:45:26 +00:00
|
|
|
static int openwith_get_talk(int selected_item, void * data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
char viewer_filename[MAX_FILENAME];
|
|
|
|
snprintf(viewer_filename, MAX_FILENAME, "%s.%s",
|
|
|
|
filetypes[viewers[selected_item]].plugin, ROCK_EXTENSION);
|
|
|
|
talk_file_or_spell(PLUGIN_DIR, viewer_filename,
|
|
|
|
NULL, false);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-09 15:25:17 +00:00
|
|
|
static int openwith_action_callback(int action, struct gui_synclist *lists)
|
2007-10-21 00:11:47 +00:00
|
|
|
{
|
2007-12-17 02:37:21 +00:00
|
|
|
struct cb_data *info = (struct cb_data *)lists->data;
|
2007-10-21 00:11:47 +00:00
|
|
|
int i;
|
|
|
|
if (action == ACTION_STD_OK)
|
|
|
|
{
|
|
|
|
char plugin[MAX_PATH];
|
2010-11-09 14:35:19 +00:00
|
|
|
i = viewers[gui_synclist_get_sel_pos(lists)];
|
2007-10-21 00:11:47 +00:00
|
|
|
snprintf(plugin, MAX_PATH, "%s/%s.%s",
|
|
|
|
PLUGIN_DIR, filetypes[i].plugin, ROCK_EXTENSION);
|
|
|
|
plugin_load(plugin, info->current_file);
|
|
|
|
return ACTION_STD_CANCEL;
|
|
|
|
}
|
|
|
|
return action;
|
|
|
|
}
|
2008-04-09 15:25:17 +00:00
|
|
|
|
2007-03-29 06:16:00 +00:00
|
|
|
int filetype_list_viewers(const char* current_file)
|
|
|
|
{
|
2007-10-21 00:11:47 +00:00
|
|
|
struct simplelist_info info;
|
2010-11-09 14:35:19 +00:00
|
|
|
struct cb_data data = { current_file };
|
|
|
|
simplelist_info_init(&info, str(LANG_ONPLAY_OPEN_WITH), viewer_count, &data);
|
2007-10-21 00:11:47 +00:00
|
|
|
info.action_callback = openwith_action_callback;
|
|
|
|
info.get_name = openwith_get_name;
|
2009-12-16 08:36:46 +00:00
|
|
|
info.get_icon = global_settings.show_icons?openwith_get_icon:NULL;
|
2018-10-30 13:45:26 +00:00
|
|
|
info.get_talk = openwith_get_talk;
|
2007-10-21 00:11:47 +00:00
|
|
|
return simplelist_show_list(&info);
|
2007-03-29 06:16:00 +00:00
|
|
|
}
|
2004-05-21 20:08:24 +00:00
|
|
|
|
2011-12-05 19:23:46 +00:00
|
|
|
int filetype_load_plugin(const char* plugin, const char* file)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-08-07 07:55:18 +00:00
|
|
|
int i;
|
2007-03-29 06:16:00 +00:00
|
|
|
char plugin_name[MAX_PATH];
|
2007-08-07 07:55:18 +00:00
|
|
|
char *s;
|
2010-11-09 14:35:19 +00:00
|
|
|
|
2007-08-07 07:55:18 +00:00
|
|
|
for (i=0;i<filetype_count;i++)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-08-07 07:55:18 +00:00
|
|
|
if (filetypes[i].plugin)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2007-08-07 07:55:18 +00:00
|
|
|
s = strrchr(filetypes[i].plugin, '/');
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
if (!strcmp(s+1, plugin))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (!strcmp(filetypes[i].plugin, plugin))
|
|
|
|
break;
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
2007-08-07 07:55:18 +00:00
|
|
|
if (i >= filetype_count)
|
|
|
|
return PLUGIN_ERROR;
|
|
|
|
snprintf(plugin_name, MAX_PATH, "%s/%s.%s",
|
|
|
|
PLUGIN_DIR, filetypes[i].plugin, ROCK_EXTENSION);
|
2008-05-12 17:52:50 +00:00
|
|
|
return plugin_load(plugin_name, file);
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|