mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-29 16:31:05 +02:00
file.cpp|h: port filetypes handling from martii
Signed-off-by: Thilo Graf <dbt@novatux.de>
Origin commit data
------------------
Commit: 37e2efb3ed
Author: vanhofen <vanhofen@gmx.de>
Date: 2017-06-07 (Wed, 07 Jun 2017)
Origin message was:
------------------
- file.cpp|h: port filetypes handling from martii
Signed-off-by: Thilo Graf <dbt@novatux.de>
This commit is contained in:
committed by
Michael Liebmann
parent
be6c64a4a9
commit
ba3313b04f
@@ -34,43 +34,65 @@
|
||||
#include <config.h>
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <driver/file.h>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
|
||||
/* ATTENTION: the array file_extension_list MUST BE SORTED ASCENDING (cf. sort, man bsearch) - otherwise bsearch will not work correctly! */
|
||||
const char * const file_extension_list[] =
|
||||
{
|
||||
"aac", "asf", "avi", "bin", "bmp", "cdr", "crw",
|
||||
"dts", "flac", "flv", "gif", "imu", "ipk", "iso", "jpeg", "jpg",
|
||||
"m2a", "m3u", "m3u8", "m4a", "mkv", "mp2", "mp3",
|
||||
"mp4", "mpa", "mpeg", "mpg", "ogg", "opk", "pls", "png", "sh",
|
||||
"ts", "txt", "url", "vob", "wav", "xml"
|
||||
struct file_ext_s {
|
||||
const char *ext;
|
||||
const CFile::FileType type;
|
||||
};
|
||||
/* ATTENTION: the array file_extension_list MUST BE SORTED ASCENDING (cf. sort, man bsearch) - otherwise bsearch will not work correctly! */
|
||||
|
||||
const CFile::FileType file_type_list[] =
|
||||
// ATTENTION: the array MUST BE SORTED ASCENDING (cf. sort, man bsearch) - otherwise bsearch will not work correctly!
|
||||
static const file_ext_s file_ext[] =
|
||||
{
|
||||
CFile::FILE_AAC , CFile::FILE_ASF , CFile::FILE_AVI , CFile::FILE_BIN_PACKAGE , CFile::FILE_PICTURE , CFile::FILE_CDR , CFile::FILE_PICTURE ,
|
||||
CFile::FILE_WAV , CFile::FILE_FLAC , CFile::FILE_MPG , CFile::FILE_PICTURE , CFile::STREAM_PICTURE , CFile::FILE_PKG_PACKAGE , CFile::FILE_ISO , CFile::FILE_PICTURE , CFile::FILE_PICTURE ,
|
||||
CFile::FILE_MP3 , CFile::FILE_PLAYLIST , CFile::FILE_PLAYLIST , CFile::FILE_AAC , CFile::FILE_MKV , CFile::FILE_MP3 , CFile::FILE_MP3 ,
|
||||
CFile::FILE_MPG , CFile::FILE_MP3 , CFile::FILE_MPG , CFile::FILE_MPG , CFile::FILE_OGG , CFile::FILE_PKG_PACKAGE , CFile::FILE_PLAYLIST , CFile::FILE_PICTURE , CFile::FILE_TEXT ,
|
||||
CFile::FILE_TS , CFile::FILE_TEXT , CFile::STREAM_AUDIO , CFile::FILE_VOB , CFile::FILE_WAV , CFile::FILE_XML
|
||||
{ "aac", CFile::FILE_AAC },
|
||||
{ "asf", CFile::FILE_ASF },
|
||||
{ "avi", CFile::FILE_AVI },
|
||||
{ "bin", CFile::FILE_BIN_PACKAGE },
|
||||
{ "bmp", CFile::FILE_PICTURE },
|
||||
{ "cdr", CFile::FILE_CDR },
|
||||
{ "crw", CFile::FILE_PICTURE },
|
||||
{ "dts", CFile::FILE_WAV },
|
||||
{ "flac", CFile::FILE_FLAC },
|
||||
{ "flv", CFile::FILE_MPG },
|
||||
{ "gif", CFile::FILE_PICTURE },
|
||||
{ "imu", CFile::STREAM_PICTURE },
|
||||
{ "ipk", CFile::FILE_PKG_PACKAGE },
|
||||
{ "iso", CFile::FILE_ISO },
|
||||
{ "jpeg", CFile::FILE_PICTURE },
|
||||
{ "jpg", CFile::FILE_PICTURE },
|
||||
{ "m2a", CFile::FILE_MP3 },
|
||||
{ "m3u", CFile::FILE_PLAYLIST },
|
||||
{ "m3u8", CFile::FILE_PLAYLIST },
|
||||
{ "m4a", CFile::FILE_AAC },
|
||||
{ "mkv", CFile::FILE_MKV },
|
||||
{ "mp2", CFile::FILE_MP3 },
|
||||
{ "mp3", CFile::FILE_MP3 },
|
||||
{ "mp4", CFile::FILE_MPG },
|
||||
{ "mpa", CFile::FILE_MP3 },
|
||||
{ "mpeg", CFile::FILE_MPG },
|
||||
{ "mpg", CFile::FILE_MPG },
|
||||
{ "ogg", CFile::FILE_OGG },
|
||||
{ "opk", CFile::FILE_PKG_PACKAGE },
|
||||
{ "pls", CFile::FILE_PLAYLIST },
|
||||
{ "png", CFile::FILE_PICTURE },
|
||||
{ "sh", CFile::FILE_TEXT },
|
||||
{ "ts", CFile::FILE_TS },
|
||||
{ "txt", CFile::FILE_TEXT },
|
||||
{ "url", CFile::STREAM_AUDIO },
|
||||
{ "vob", CFile::FILE_VOB },
|
||||
{ "wav", CFile::FILE_WAV },
|
||||
{ "xml", CFile::FILE_XML }
|
||||
};
|
||||
|
||||
int mycasecmp(const void * a, const void * b)
|
||||
{
|
||||
return strcasecmp(*(const char * *)a, *(const char * *)b);
|
||||
return strcasecmp(((file_ext_s *)a)->ext, ((file_ext_s *)b)->ext);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
CFile::CFile()
|
||||
: Size( 0 ), Mode( 0 ), Marked( false ), Time( 0 )
|
||||
CFile::CFile() : Size( 0 ), Mode( 0 ), Marked( false ), Time( 0 )
|
||||
{
|
||||
Type = -1;
|
||||
}
|
||||
|
||||
CFile::FileType CFile::getType(void) const
|
||||
@@ -78,24 +100,17 @@ CFile::FileType CFile::getType(void) const
|
||||
if(S_ISDIR(Mode))
|
||||
return FILE_DIR;
|
||||
|
||||
if (Type < 0) {
|
||||
Type = (int) FILE_UNKNOWN;
|
||||
std::string::size_type ext_pos = Name.rfind('.');
|
||||
std::string::size_type ext_pos = Name.rfind('.');
|
||||
|
||||
if (ext_pos != std::string::npos) {
|
||||
const char * key = &(Name.c_str()[ext_pos + 1]);
|
||||
|
||||
void * result = ::bsearch(&key, file_extension_list, sizeof(file_extension_list) / sizeof(const char *), sizeof(const char *), mycasecmp);
|
||||
|
||||
if (result != NULL)
|
||||
Type = (int) file_type_list[(const char * *)result - (const char * *)&file_extension_list];
|
||||
}
|
||||
if (ext_pos != std::string::npos) {
|
||||
const char * key = &(Name.c_str()[ext_pos + 1]);
|
||||
void * result = ::bsearch(&key, file_ext, sizeof(file_ext) / sizeof(file_ext_s), sizeof(file_ext_s), mycasecmp);
|
||||
if (result)
|
||||
return ((file_ext_s *)result)->type;
|
||||
}
|
||||
return (CFile::FileType) Type;
|
||||
return FILE_UNKNOWN;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
std::string CFile::getFileName(void) const // return name.extension or folder name without trailing /
|
||||
{
|
||||
std::string::size_type namepos = Name.rfind('/');
|
||||
@@ -103,8 +118,6 @@ std::string CFile::getFileName(void) const // return name.extension or folder n
|
||||
return (namepos == std::string::npos) ? Name : Name.substr(namepos + 1);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
std::string CFile::getPath(void) const // return complete path including trailing /
|
||||
{
|
||||
int pos = 0;
|
||||
|
@@ -55,28 +55,28 @@ class CFile
|
||||
{
|
||||
FILE_UNKNOWN = 0,
|
||||
FILE_AAC,
|
||||
FILE_AVI,
|
||||
FILE_ASF,
|
||||
FILE_DIR,
|
||||
FILE_ISO,
|
||||
FILE_TEXT,
|
||||
FILE_AVI,
|
||||
FILE_BIN_PACKAGE,
|
||||
FILE_CDR,
|
||||
FILE_MP3,
|
||||
FILE_MKV,
|
||||
FILE_OGG,
|
||||
FILE_WAV,
|
||||
FILE_DIR,
|
||||
FILE_FLAC,
|
||||
FILE_FLV,
|
||||
FILE_XML,
|
||||
FILE_PLAYLIST,
|
||||
STREAM_AUDIO,
|
||||
FILE_PICTURE,
|
||||
STREAM_PICTURE,
|
||||
FILE_VOB,
|
||||
FILE_ISO,
|
||||
FILE_MKV,
|
||||
FILE_MP3,
|
||||
FILE_MPG,
|
||||
FILE_OGG,
|
||||
FILE_PICTURE,
|
||||
FILE_PKG_PACKAGE,
|
||||
FILE_PLAYLIST,
|
||||
FILE_TEXT,
|
||||
FILE_TS,
|
||||
FILE_BIN_PACKAGE,
|
||||
FILE_PKG_PACKAGE
|
||||
FILE_VOB,
|
||||
FILE_WAV,
|
||||
FILE_XML,
|
||||
STREAM_AUDIO,
|
||||
STREAM_PICTURE
|
||||
};
|
||||
|
||||
FileType getType(void) const;
|
||||
|
Reference in New Issue
Block a user