2004-05-21 20:08:24 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Henrik Backe
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
#include "sprintf.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "lang.h"
|
|
|
|
#include "language.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "plugin.h"
|
|
|
|
#include "filetypes.h"
|
|
|
|
#include "screens.h"
|
|
|
|
#include "icons.h"
|
|
|
|
#include "dir.h"
|
|
|
|
#include "file.h"
|
|
|
|
#include "icons.h"
|
2005-11-16 15:12:15 +00:00
|
|
|
#include "splash.h"
|
2004-05-21 20:08:24 +00:00
|
|
|
|
|
|
|
/* max plugin name size without extensions and path */
|
|
|
|
#define MAX_PLUGIN_LENGTH 32
|
|
|
|
|
|
|
|
/* max filetypes (plugins & icons stored here) */
|
2005-08-29 21:15:27 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2005-06-11 12:37:36 +00:00
|
|
|
#define MAX_FILETYPES 64
|
|
|
|
#else
|
2006-04-02 11:58:25 +00:00
|
|
|
#define MAX_FILETYPES 48
|
2005-06-11 12:37:36 +00:00
|
|
|
#endif
|
2004-05-21 20:08:24 +00:00
|
|
|
|
|
|
|
/* max exttypes (extensions stored here) */
|
2005-08-29 21:15:27 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2005-06-07 19:41:40 +00:00
|
|
|
/* Software codecs require more file extensions */
|
|
|
|
#define MAX_EXTTYPES 64
|
|
|
|
#else
|
2004-05-21 20:08:24 +00:00
|
|
|
#define MAX_EXTTYPES 32
|
2005-06-07 19:41:40 +00:00
|
|
|
#endif
|
2004-05-21 20:08:24 +00:00
|
|
|
|
|
|
|
/* string buffer length */
|
2006-11-30 22:29:48 +00:00
|
|
|
#define STRING_BUFFER_SIZE 548
|
2004-05-21 20:08:24 +00:00
|
|
|
|
|
|
|
/* number of bytes for the binary icon */
|
|
|
|
#define ICON_LENGTH 6
|
|
|
|
|
|
|
|
/* mask for dynamic filetype info in attribute */
|
|
|
|
#define FILETYPES_MASK 0xFF00
|
|
|
|
|
|
|
|
/* filenames */
|
|
|
|
#define ROCK_EXTENSION ".rock"
|
|
|
|
#define VIEWERS_CONFIG ROCKBOX_DIR "/viewers.config"
|
|
|
|
#define VIEWERS_DIR ROCKBOX_DIR "/viewers"
|
|
|
|
|
|
|
|
/* global variables */
|
|
|
|
static int cnt_filetypes;
|
|
|
|
static int cnt_exttypes;
|
|
|
|
static struct ext_type exttypes [MAX_EXTTYPES];
|
|
|
|
static struct file_type filetypes[MAX_FILETYPES];
|
|
|
|
static int first_soft_exttype;
|
|
|
|
static int first_soft_filetype;
|
|
|
|
static char* next_free_string;
|
|
|
|
static char plugin_name[sizeof(VIEWERS_DIR) + 7 + MAX_PLUGIN_LENGTH];
|
|
|
|
static char string_buffer[STRING_BUFFER_SIZE];
|
|
|
|
|
|
|
|
/* prototypes */
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2004-08-18 01:09:31 +00:00
|
|
|
static char* string2icon(const char*);
|
2005-03-07 20:40:36 +00:00
|
|
|
static int add_plugin(char*,char*);
|
|
|
|
#else
|
|
|
|
static int add_plugin(char*);
|
2004-05-21 20:08:24 +00:00
|
|
|
#endif
|
2004-08-18 01:09:31 +00:00
|
|
|
static char* get_string(const char*);
|
2004-05-21 20:08:24 +00:00
|
|
|
static int find_attr_index(int);
|
2004-08-18 01:09:31 +00:00
|
|
|
static bool read_config(const char*);
|
2004-05-21 20:08:24 +00:00
|
|
|
static void rm_whitespaces(char*);
|
|
|
|
static void scan_plugins(void);
|
|
|
|
|
|
|
|
/* initialize dynamic filetypes (called at boot from tree.c) */
|
|
|
|
void filetype_init(void)
|
|
|
|
{
|
|
|
|
int cnt,i,ix;
|
2004-08-01 23:34:44 +00:00
|
|
|
const struct filetype* ftypes;
|
2004-05-21 20:08:24 +00:00
|
|
|
|
|
|
|
memset(exttypes,0,sizeof(exttypes));
|
|
|
|
memset(filetypes,0,sizeof(filetypes));
|
|
|
|
next_free_string=string_buffer;
|
|
|
|
|
|
|
|
/* The special filetype folder must always be stored at index 0 */
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
if (!filetypes[0].icon)
|
2005-08-24 00:09:42 +00:00
|
|
|
filetypes[0].icon = bitmap_icons_6x8[Icon_Folder];
|
2004-05-21 20:08:24 +00:00
|
|
|
#else
|
|
|
|
if (!filetypes[0].icon)
|
2005-08-24 00:09:42 +00:00
|
|
|
filetypes[0].icon = Icon_Folder;
|
2004-05-21 20:08:24 +00:00
|
|
|
for (i=1; i < MAX_FILETYPES; i++)
|
|
|
|
filetypes[i].icon = -1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* register hardcoded filetypes */
|
|
|
|
tree_get_filetypes(&ftypes, &cnt);
|
|
|
|
cnt_exttypes=0;
|
|
|
|
cnt_filetypes=0;
|
|
|
|
|
|
|
|
for (i = 0; i < cnt ; i++)
|
|
|
|
{
|
|
|
|
ix = ((ftypes[i].tree_attr & FILETYPES_MASK) >> 8);
|
|
|
|
if (ix < MAX_FILETYPES && i < MAX_EXTTYPES)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
if (filetypes[ix].icon == NULL)
|
|
|
|
filetypes[ix].icon=bitmap_icons_6x8[ftypes[i].icon];
|
|
|
|
#else
|
|
|
|
if (filetypes[ix].icon == -1)
|
|
|
|
filetypes[ix].icon=ftypes[i].icon;
|
|
|
|
#endif
|
|
|
|
if (ix > cnt_filetypes)
|
|
|
|
cnt_filetypes=ix;
|
|
|
|
exttypes[cnt_exttypes].type=&filetypes[ix];
|
|
|
|
exttypes[cnt_exttypes].extension=ftypes[i].extension;
|
|
|
|
cnt_exttypes++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
first_soft_exttype=cnt_exttypes;
|
|
|
|
cnt_filetypes++;
|
|
|
|
first_soft_filetype=cnt_filetypes;
|
|
|
|
|
|
|
|
/* register dynamic filetypes */
|
|
|
|
read_config(VIEWERS_CONFIG);
|
|
|
|
scan_plugins();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get icon */
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2005-12-05 22:44:42 +00:00
|
|
|
const unsigned char* filetype_get_icon(int attr)
|
2004-05-21 20:08:24 +00:00
|
|
|
#else
|
|
|
|
int filetype_get_icon(int attr)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
int ix;
|
|
|
|
|
|
|
|
ix = find_attr_index(attr);
|
|
|
|
|
|
|
|
if (ix < 0)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
return NULL;
|
|
|
|
#else
|
2005-11-09 01:17:57 +00:00
|
|
|
return Icon_Unknown;
|
2004-05-21 20:08:24 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return filetypes[ix].icon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get plugin */
|
2004-08-18 01:09:31 +00:00
|
|
|
char* filetype_get_plugin(const struct entry* file)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
|
|
|
int ix;
|
|
|
|
|
|
|
|
ix=find_attr_index(file->attr);
|
|
|
|
|
|
|
|
if (ix < 0)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((filetypes[ix].plugin == NULL) ||
|
|
|
|
(strlen(filetypes[ix].plugin) > MAX_PLUGIN_LENGTH))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
snprintf(plugin_name, sizeof(plugin_name),
|
2005-10-05 08:02:10 +00:00
|
|
|
"%s/%s.rock", ROCKBOX_DIR, filetypes[ix].plugin);
|
2004-05-21 20:08:24 +00:00
|
|
|
|
|
|
|
return plugin_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if filetype is supported */
|
|
|
|
bool filetype_supported(int attr)
|
|
|
|
{
|
|
|
|
int ix;
|
|
|
|
|
|
|
|
ix=find_attr_index(attr);
|
|
|
|
|
|
|
|
/* hard filetypes and soft filetypes with plugins is supported */
|
|
|
|
if (ix > 0)
|
|
|
|
if (filetypes[ix].plugin || ix < first_soft_filetype)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the "dynamic" attribute for an extension */
|
2005-09-02 16:50:51 +00:00
|
|
|
int filetype_get_attr(const char* name)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
|
|
|
int i;
|
2005-09-02 16:50:51 +00:00
|
|
|
const char *cp = strrchr(name,'.');
|
|
|
|
|
|
|
|
if (!cp) /* no extension? -> can't be a supported type */
|
|
|
|
return 0;
|
|
|
|
cp++;
|
2004-05-21 20:08:24 +00:00
|
|
|
|
|
|
|
for (i=0; i < cnt_exttypes; i++)
|
|
|
|
{
|
|
|
|
if (exttypes[i].extension)
|
|
|
|
{
|
2005-09-02 16:50:51 +00:00
|
|
|
if (!strcasecmp(cp,exttypes[i].extension))
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2005-02-09 10:56:54 +00:00
|
|
|
return ((((unsigned long)exttypes[i].type -
|
|
|
|
(unsigned long)&filetypes[0]) /
|
2004-05-21 20:08:24 +00:00
|
|
|
sizeof(struct file_type)) << 8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fill a menu list with viewers (used in onplay.c) */
|
2005-03-06 18:26:34 +00:00
|
|
|
int filetype_load_menu(struct menu_item* menu,int max_items)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
|
|
|
int i;
|
2005-10-09 13:37:35 +00:00
|
|
|
char *cp;
|
2004-05-21 20:08:24 +00:00
|
|
|
int cnt=0;
|
|
|
|
|
2005-03-06 18:26:34 +00:00
|
|
|
for (i=0; i < cnt_filetypes; i++)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2005-03-06 18:26:34 +00:00
|
|
|
if (filetypes[i].plugin)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2006-03-13 07:33:30 +00:00
|
|
|
int j;
|
|
|
|
for (j=0;j<cnt;j++) /* check if the plugin is in the list yet */
|
|
|
|
{
|
|
|
|
if (!strcmp(menu[j].desc,filetypes[i].plugin))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (j<cnt) continue; /* it is so grab the next plugin */
|
2005-10-09 13:37:35 +00:00
|
|
|
cp=strrchr(filetypes[i].plugin,'/');
|
|
|
|
if (cp) cp++;
|
|
|
|
else cp=filetypes[i].plugin;
|
2005-12-05 22:44:42 +00:00
|
|
|
menu[cnt].desc = (unsigned char *)cp;
|
2005-03-06 18:26:34 +00:00
|
|
|
cnt++;
|
|
|
|
if (cnt == max_items)
|
|
|
|
break;
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* start a plugin with an argument (called from onplay.c) */
|
2004-08-18 01:09:31 +00:00
|
|
|
int filetype_load_plugin(const char* plugin, char* file)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2006-03-13 07:33:30 +00:00
|
|
|
int fd;
|
2004-05-21 20:08:24 +00:00
|
|
|
snprintf(plugin_name,sizeof(plugin_name),"%s/%s.rock",
|
|
|
|
VIEWERS_DIR,plugin);
|
2006-03-13 07:33:30 +00:00
|
|
|
if ((fd = open(plugin_name,O_RDONLY))>=0)
|
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
return plugin_load(plugin_name,file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
snprintf(plugin_name,sizeof(plugin_name),"%s/%s.rock",
|
|
|
|
PLUGIN_DIR,plugin);
|
|
|
|
if ((fd = open(plugin_name,O_RDONLY))>=0)
|
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
return plugin_load(plugin_name,file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PLUGIN_ERROR;
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get index to filetypes[] from the file attribute */
|
|
|
|
static int find_attr_index(int attr)
|
|
|
|
{
|
|
|
|
int ix;
|
|
|
|
ix = ((attr & FILETYPES_MASK) >> 8);
|
|
|
|
|
|
|
|
if ((attr & ATTR_DIRECTORY)==ATTR_DIRECTORY)
|
|
|
|
{
|
|
|
|
ix=0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ix==0)
|
|
|
|
ix=-1;
|
|
|
|
if (ix > cnt_filetypes)
|
|
|
|
ix=-1;
|
|
|
|
else
|
|
|
|
if ((filetypes[ix].plugin == NULL) &&
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
(filetypes[ix].icon == NULL)
|
|
|
|
#else
|
|
|
|
(filetypes[ix].icon == -1)
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
ix=-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ix;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* scan the plugin directory and register filetypes */
|
|
|
|
static void scan_plugins(void)
|
|
|
|
{
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *entry;
|
|
|
|
char* cp;
|
|
|
|
char* dot;
|
|
|
|
char* dash;
|
|
|
|
int ix;
|
|
|
|
int i;
|
|
|
|
bool found;
|
|
|
|
|
|
|
|
dir = opendir(VIEWERS_DIR);
|
|
|
|
if(!dir)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
/* exttypes[] full, bail out */
|
|
|
|
if (cnt_exttypes >= MAX_EXTTYPES)
|
|
|
|
{
|
2005-12-05 22:44:42 +00:00
|
|
|
gui_syncsplash(HZ, true, str(LANG_FILETYPES_EXTENSION_FULL));
|
2004-05-21 20:08:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* filetypes[] full, bail out */
|
|
|
|
if (cnt_filetypes >= MAX_FILETYPES)
|
|
|
|
{
|
2005-12-05 22:44:42 +00:00
|
|
|
gui_syncsplash(HZ, true, str(LANG_FILETYPES_FULL));
|
2004-05-21 20:08:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry = readdir(dir);
|
|
|
|
|
|
|
|
if (!entry)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* skip directories */
|
|
|
|
if ((entry->attribute & ATTR_DIRECTORY))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Skip FAT volume ID */
|
|
|
|
if (entry->attribute & ATTR_VOLUME_ID)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* filter out dotfiles and hidden files */
|
|
|
|
if ((entry->d_name[0]=='.') ||
|
|
|
|
(entry->attribute & ATTR_HIDDEN)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* filter out non rock files */
|
2005-12-05 22:44:42 +00:00
|
|
|
if (strcasecmp((char *)&entry->d_name[strlen((char *)entry->d_name) -
|
|
|
|
sizeof(ROCK_EXTENSION) + 1],
|
|
|
|
ROCK_EXTENSION)) {
|
2004-05-21 20:08:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* filter out to long filenames */
|
2005-12-05 22:44:42 +00:00
|
|
|
if (strlen((char *)entry->d_name) > MAX_PLUGIN_LENGTH + 5)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2005-12-05 22:44:42 +00:00
|
|
|
gui_syncsplash(HZ, true, str(LANG_FILETYPES_PLUGIN_NAME_LONG));
|
2004-05-21 20:08:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-12-05 22:44:42 +00:00
|
|
|
dot=strrchr((char *)entry->d_name,'.');
|
2004-05-21 20:08:24 +00:00
|
|
|
*dot='\0';
|
2005-12-05 22:44:42 +00:00
|
|
|
dash=strchr((char *)entry->d_name,'-');
|
2004-05-21 20:08:24 +00:00
|
|
|
|
|
|
|
/* add plugin and extension */
|
|
|
|
if (dash)
|
|
|
|
{
|
|
|
|
*dash='\0';
|
2005-12-05 22:44:42 +00:00
|
|
|
ix=(filetype_get_attr((char *)entry->d_name) >> 8);
|
2004-05-21 20:08:24 +00:00
|
|
|
if (!ix)
|
|
|
|
{
|
2005-12-05 22:44:42 +00:00
|
|
|
cp=get_string((char *)entry->d_name);
|
2004-05-21 20:08:24 +00:00
|
|
|
if (cp)
|
|
|
|
{
|
|
|
|
exttypes[cnt_exttypes].extension=cp;
|
|
|
|
exttypes[cnt_exttypes].type=&filetypes[cnt_filetypes];
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2005-08-24 00:09:42 +00:00
|
|
|
exttypes[cnt_exttypes].type->icon = bitmap_icons_6x8[Icon_Plugin];
|
2004-05-21 20:08:24 +00:00
|
|
|
#else
|
2005-08-24 00:09:42 +00:00
|
|
|
exttypes[cnt_exttypes].type->icon = Icon_Plugin;
|
2004-05-21 20:08:24 +00:00
|
|
|
#endif
|
|
|
|
cnt_exttypes++;
|
|
|
|
|
|
|
|
*dash='-';
|
2005-12-05 22:44:42 +00:00
|
|
|
cp=get_string((char *)entry->d_name);
|
2004-05-21 20:08:24 +00:00
|
|
|
if (cp)
|
|
|
|
{
|
|
|
|
filetypes[cnt_filetypes].plugin=cp;
|
|
|
|
cnt_filetypes++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*dash='-';
|
|
|
|
if (!filetypes[ix].plugin)
|
|
|
|
{
|
2005-12-05 22:44:42 +00:00
|
|
|
cp=get_string((char *)entry->d_name);
|
2004-05-21 20:08:24 +00:00
|
|
|
if (cp)
|
|
|
|
{
|
|
|
|
filetypes[cnt_filetypes].plugin=cp;
|
|
|
|
cnt_filetypes++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*dash='-';
|
|
|
|
}
|
|
|
|
/* add plugin only */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
found=false;
|
|
|
|
for (i = first_soft_filetype; i < cnt_filetypes; i++)
|
|
|
|
{
|
|
|
|
if (filetypes[i].plugin)
|
2005-12-05 22:44:42 +00:00
|
|
|
if (!strcasecmp(filetypes[i].plugin, (char *)entry->d_name))
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
|
|
|
found=true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
2005-12-05 22:44:42 +00:00
|
|
|
cp=get_string((char *)entry->d_name);
|
2004-05-21 20:08:24 +00:00
|
|
|
if (cp)
|
|
|
|
{
|
|
|
|
filetypes[cnt_filetypes].plugin=cp;
|
|
|
|
filetypes[cnt_filetypes].no_extension=true;
|
|
|
|
cnt_filetypes++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*dot='.';
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
}
|
|
|
|
|
2005-03-07 20:40:36 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
static int add_plugin(char *plugin, char *icon)
|
|
|
|
#else
|
|
|
|
static int add_plugin(char *plugin)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!plugin)
|
|
|
|
return 0;
|
|
|
|
|
2005-10-05 08:02:10 +00:00
|
|
|
#if 0
|
|
|
|
/* starting now, Oct 2005, the plugins are given without extension in the
|
|
|
|
viewers.config file */
|
2005-03-07 20:40:36 +00:00
|
|
|
cp=strrchr(plugin, '.');
|
|
|
|
if (cp)
|
|
|
|
*cp='\0';
|
2005-10-05 08:02:10 +00:00
|
|
|
#endif
|
2005-03-07 20:40:36 +00:00
|
|
|
|
|
|
|
for (i=first_soft_filetype; i < cnt_filetypes; i++)
|
|
|
|
{
|
|
|
|
if (filetypes[i].plugin)
|
|
|
|
{
|
|
|
|
if (!strcasecmp(plugin, filetypes[i].plugin))
|
|
|
|
{
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
if (filetypes[i].icon == NULL && icon)
|
|
|
|
{
|
|
|
|
cp = string2icon(icon);
|
|
|
|
if (cp)
|
2005-12-05 22:44:42 +00:00
|
|
|
filetypes[cnt_filetypes].icon = (unsigned char *)cp;
|
2005-03-07 20:40:36 +00:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* new plugin */
|
|
|
|
cp = get_string(plugin);
|
|
|
|
if (cp)
|
|
|
|
{
|
|
|
|
filetypes[cnt_filetypes].plugin = cp;
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
/* add icon */
|
|
|
|
if (icon)
|
|
|
|
{
|
|
|
|
cp = string2icon(icon);
|
|
|
|
if (cp)
|
2005-12-05 22:44:42 +00:00
|
|
|
filetypes[cnt_filetypes].icon = (unsigned char *)cp;
|
2005-03-07 20:40:36 +00:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cnt_filetypes++;
|
|
|
|
return cnt_filetypes - 1;
|
|
|
|
}
|
|
|
|
|
2004-05-21 20:08:24 +00:00
|
|
|
/* read config file (or cahe file) */
|
2006-12-12 22:22:21 +00:00
|
|
|
static bool read_config(const char* file)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
|
|
|
enum {extension,
|
|
|
|
plugin,
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
icon,
|
|
|
|
#endif
|
|
|
|
last};
|
|
|
|
|
2005-03-07 20:40:36 +00:00
|
|
|
int i,ix;
|
2004-05-21 20:08:24 +00:00
|
|
|
int fd;
|
|
|
|
char* end;
|
|
|
|
char* cp;
|
|
|
|
char* str[last];
|
|
|
|
char buf[80];
|
|
|
|
|
|
|
|
fd = open(file, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
while (read_line(fd, buf, sizeof(buf)))
|
|
|
|
{
|
|
|
|
if (cnt_exttypes >= MAX_EXTTYPES)
|
|
|
|
{
|
2005-12-05 22:44:42 +00:00
|
|
|
gui_syncsplash(HZ, true, str(LANG_FILETYPES_EXTENSION_FULL));
|
2004-05-21 20:08:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cnt_filetypes >= MAX_FILETYPES)
|
|
|
|
{
|
2005-12-05 22:44:42 +00:00
|
|
|
gui_syncsplash(HZ, true, str(LANG_FILETYPES_FULL));
|
2004-05-21 20:08:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parse buffer */
|
|
|
|
rm_whitespaces(buf);
|
|
|
|
|
|
|
|
if (strlen(buf) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (buf[0] == '#')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
memset(str,0,sizeof(str));
|
|
|
|
i=0;
|
|
|
|
cp=buf;
|
|
|
|
while (*cp==',') {
|
|
|
|
cp++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
str[i] = strtok_r(cp, ",", &end);
|
|
|
|
i++;
|
|
|
|
|
|
|
|
while (end && i < last)
|
|
|
|
{
|
|
|
|
if (end)
|
|
|
|
{
|
|
|
|
cp=end;
|
|
|
|
while (*cp==',') {
|
|
|
|
cp++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
str[i] = strtok_r(NULL, ",", &end);
|
2005-03-07 20:40:36 +00:00
|
|
|
if (str[i])
|
|
|
|
if (!strlen(str[i]))
|
|
|
|
str[i]=NULL;
|
2004-05-21 20:08:24 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* bail out if no icon and no plugin */
|
2005-03-07 20:40:36 +00:00
|
|
|
if (!str[plugin]
|
2004-05-21 20:08:24 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2005-03-07 20:40:36 +00:00
|
|
|
&& !str[icon]
|
2004-05-21 20:08:24 +00:00
|
|
|
#endif
|
2005-03-07 20:40:36 +00:00
|
|
|
)
|
2004-05-21 20:08:24 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* bail out if no plugin and icon is incorrect*/
|
2005-03-07 20:40:36 +00:00
|
|
|
if (!str[plugin]
|
2004-05-21 20:08:24 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2005-03-07 20:40:36 +00:00
|
|
|
&& strlen(str[icon]) != ICON_LENGTH*2
|
2004-05-21 20:08:24 +00:00
|
|
|
#endif
|
2005-03-07 20:40:36 +00:00
|
|
|
)
|
2004-05-21 20:08:24 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* bail out if no icon and no plugin and no extension*/
|
2005-03-07 20:40:36 +00:00
|
|
|
if (!str[plugin] &&
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
!str[icon] &&
|
|
|
|
#endif
|
|
|
|
!str[extension])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* bail out if we are not able to start plugin from onplay.c ?*/
|
|
|
|
if (str[plugin])
|
|
|
|
{
|
|
|
|
if (strlen(str[plugin]) > MAX_PLUGIN_LENGTH)
|
|
|
|
{
|
2005-11-16 15:12:15 +00:00
|
|
|
gui_syncsplash(HZ, true, str(LANG_FILETYPES_PLUGIN_NAME_LONG));
|
2005-03-07 20:40:36 +00:00
|
|
|
str[plugin] = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ix=0;
|
|
|
|
/* if extension already exist don't add a new one */
|
|
|
|
for (i=0; i < cnt_exttypes; i++)
|
|
|
|
{
|
|
|
|
if (!strcasecmp(str[extension],exttypes[i].extension))
|
|
|
|
{
|
2004-05-21 20:08:24 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2005-03-07 20:40:36 +00:00
|
|
|
ix=add_plugin(str[plugin],NULL);
|
|
|
|
if (ix)
|
|
|
|
{
|
|
|
|
if (str[icon] && filetypes[ix].icon == NULL)
|
|
|
|
{
|
|
|
|
if (exttypes[i].type->icon == NULL)
|
|
|
|
{
|
|
|
|
cp = string2icon(str[icon]);
|
|
|
|
if (cp)
|
2005-12-05 22:44:42 +00:00
|
|
|
exttypes[i].type->icon = (unsigned char *)cp;
|
2005-03-07 20:40:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
ix=add_plugin(str[plugin]);
|
2004-05-21 20:08:24 +00:00
|
|
|
#endif
|
2005-03-07 20:40:36 +00:00
|
|
|
if (exttypes[i].type == NULL)
|
|
|
|
{
|
|
|
|
exttypes[i].type = &filetypes[ix];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ix)
|
2004-05-21 20:08:24 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* add extension */
|
|
|
|
if (str[extension])
|
|
|
|
{
|
2005-03-07 20:40:36 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
ix=add_plugin(str[plugin],str[icon]);
|
|
|
|
#else
|
|
|
|
ix=add_plugin(str[plugin]);
|
|
|
|
#endif
|
|
|
|
if (ix)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
|
|
|
cp=get_string(str[extension]);
|
|
|
|
if (cp)
|
|
|
|
{
|
|
|
|
exttypes[cnt_exttypes].extension = cp;
|
2005-03-07 20:40:36 +00:00
|
|
|
|
|
|
|
exttypes[cnt_exttypes].type = &filetypes[ix];
|
2004-05-21 20:08:24 +00:00
|
|
|
cnt_exttypes++;
|
2005-03-07 20:40:36 +00:00
|
|
|
filetypes[i].no_extension=false;
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-03-07 20:40:36 +00:00
|
|
|
break;
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
2005-03-07 20:40:36 +00:00
|
|
|
else
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2005-03-07 20:40:36 +00:00
|
|
|
break;
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
2005-03-07 20:40:36 +00:00
|
|
|
else
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2005-03-07 20:40:36 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
ix=add_plugin(str[plugin],str[icon]);
|
|
|
|
#else
|
|
|
|
ix=add_plugin(str[plugin]);
|
|
|
|
#endif
|
|
|
|
filetypes[ix].no_extension=true;
|
|
|
|
if (!i)
|
|
|
|
break;
|
2004-05-21 20:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
/* convert an ascii hexadecimal icon to a binary icon */
|
2004-08-18 01:09:31 +00:00
|
|
|
static char* string2icon(const char* str)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
|
|
|
char tmp[ICON_LENGTH*2];
|
|
|
|
char *cp;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (strlen(str)!=ICON_LENGTH*2)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if ((sizeof(string_buffer) +
|
2005-02-09 10:56:54 +00:00
|
|
|
(unsigned long) string_buffer -
|
|
|
|
(unsigned long) next_free_string) < ICON_LENGTH)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2005-12-05 22:44:42 +00:00
|
|
|
gui_syncsplash(HZ, true, str(LANG_FILETYPES_STRING_BUFFER_EMPTY));
|
2004-05-21 20:08:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<12; i++)
|
|
|
|
{
|
|
|
|
if (str[i] >= '0' && str[i] <= '9')
|
|
|
|
{
|
|
|
|
tmp[i]=str[i]-'0';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str[i] >= 'a' && str[i] <= 'f')
|
|
|
|
{
|
|
|
|
tmp[i]=str[i]-'a'+10;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str[i] >= 'A' && str[i] <= 'F')
|
|
|
|
{
|
|
|
|
tmp[i]=str[i]-'A'+10;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cp=next_free_string;
|
|
|
|
for (i = 0; i < ICON_LENGTH; i++)
|
|
|
|
cp[i]=((tmp[i*2]<<4) | tmp[i*2+1]);
|
|
|
|
|
|
|
|
next_free_string=&next_free_string[ICON_LENGTH];
|
|
|
|
return cp;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get string from buffer */
|
2004-08-18 01:09:31 +00:00
|
|
|
static char* get_string(const char* str)
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
|
|
|
unsigned int l=strlen(str)+1;
|
|
|
|
char* cp;
|
|
|
|
|
|
|
|
if (!str)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (l <= (sizeof(string_buffer) +
|
2005-02-09 10:56:54 +00:00
|
|
|
(unsigned long) string_buffer -
|
|
|
|
(unsigned long) next_free_string))
|
2004-05-21 20:08:24 +00:00
|
|
|
{
|
2005-12-05 22:44:42 +00:00
|
|
|
strcpy(next_free_string, str);
|
2004-05-21 20:08:24 +00:00
|
|
|
cp=next_free_string;
|
|
|
|
next_free_string=&next_free_string[l];
|
|
|
|
return cp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-12-05 22:44:42 +00:00
|
|
|
gui_syncsplash(HZ, true, str(LANG_FILETYPES_STRING_BUFFER_EMPTY));
|
2004-05-21 20:08:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove all white spaces from string */
|
|
|
|
static void rm_whitespaces(char* str)
|
|
|
|
{
|
|
|
|
char *cp, *free;
|
|
|
|
|
|
|
|
cp=str;
|
|
|
|
free=cp;
|
|
|
|
|
|
|
|
while (cp < &str[strlen(str)])
|
|
|
|
{
|
|
|
|
switch (*cp)
|
|
|
|
{
|
|
|
|
case ' ' :
|
|
|
|
case '\t' :
|
|
|
|
case '\r' :
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
*free=*cp;
|
|
|
|
free++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*free='\0';
|
|
|
|
}
|