driver/file.cpp: cache file type

This commit is contained in:
[CST] Focus
2014-10-01 16:13:04 +04:00
parent 6ad1a64f73
commit b70a2998f5
2 changed files with 47 additions and 42 deletions

View File

@@ -70,6 +70,7 @@ int mycasecmp(const void * a, const void * b)
CFile::CFile()
: Size( 0 ), Mode( 0 ), Marked( false ), Time( 0 )
{
Type = -1;
}
CFile::FileType CFile::getType(void) const
@@ -77,18 +78,20 @@ CFile::FileType CFile::getType(void) const
if(S_ISDIR(Mode))
return FILE_DIR;
std::string::size_type ext_pos = Name.rfind('.');
if (Type < 0) {
Type = (int) FILE_UNKNOWN;
std::string::size_type ext_pos = Name.rfind('.');
if (ext_pos != std::string::npos)
{
const char * key = &(Name.c_str()[ext_pos + 1]);
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);
void * result = ::bsearch(&key, file_extension_list, sizeof(file_extension_list) / sizeof(const char *), sizeof(const char *), mycasecmp);
if (result != NULL)
return file_type_list[(const char * *)result - (const char * *)&file_extension_list];
if (result != NULL)
Type = (int) file_type_list[(const char * *)result - (const char * *)&file_extension_list];
}
}
return FILE_UNKNOWN;
return (CFile::FileType) Type;
}
//------------------------------------------------------------------------

View File

@@ -48,41 +48,43 @@
class CFile
{
public:
enum FileType
{
FILE_UNKNOWN = 0,
FILE_AAC,
FILE_AVI,
FILE_ASF,
FILE_DIR,
FILE_ISO,
FILE_TEXT,
FILE_CDR,
FILE_MP3,
FILE_MKV,
FILE_OGG,
FILE_WAV,
FILE_FLAC,
FILE_XML,
FILE_PLAYLIST,
STREAM_AUDIO,
FILE_PICTURE,
STREAM_PICTURE
};
private:
mutable int Type;
public:
enum FileType
{
FILE_UNKNOWN = 0,
FILE_AAC,
FILE_AVI,
FILE_ASF,
FILE_DIR,
FILE_ISO,
FILE_TEXT,
FILE_CDR,
FILE_MP3,
FILE_MKV,
FILE_OGG,
FILE_WAV,
FILE_FLAC,
FILE_XML,
FILE_PLAYLIST,
STREAM_AUDIO,
FILE_PICTURE,
STREAM_PICTURE
};
FileType getType(void) const;
std::string getFileName(void) const;
std::string getPath(void) const;
bool isDir(void) { return S_ISDIR(Mode); };
FileType getType(void) const;
std::string getFileName(void) const;
std::string getPath(void) const;
bool isDir(void) { return S_ISDIR(Mode); };
CFile();
off_t Size;
std::string Name;
std::string Url;
mode_t Mode;
bool Marked;
time_t Time;
CFile();
off_t Size;
std::string Name;
std::string Url;
mode_t Mode;
bool Marked;
time_t Time;
};
typedef std::vector<CFile> CFileList;