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() CFile::CFile()
: Size( 0 ), Mode( 0 ), Marked( false ), Time( 0 ) : Size( 0 ), Mode( 0 ), Marked( false ), Time( 0 )
{ {
Type = -1;
} }
CFile::FileType CFile::getType(void) const CFile::FileType CFile::getType(void) const
@@ -77,18 +78,20 @@ CFile::FileType CFile::getType(void) const
if(S_ISDIR(Mode)) if(S_ISDIR(Mode))
return FILE_DIR; 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) if (ext_pos != std::string::npos) {
{ const char * key = &(Name.c_str()[ext_pos + 1]);
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) if (result != NULL)
return file_type_list[(const char * *)result - (const char * *)&file_extension_list]; 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 class CFile
{ {
public: private:
enum FileType mutable int Type;
{ public:
FILE_UNKNOWN = 0, enum FileType
FILE_AAC, {
FILE_AVI, FILE_UNKNOWN = 0,
FILE_ASF, FILE_AAC,
FILE_DIR, FILE_AVI,
FILE_ISO, FILE_ASF,
FILE_TEXT, FILE_DIR,
FILE_CDR, FILE_ISO,
FILE_MP3, FILE_TEXT,
FILE_MKV, FILE_CDR,
FILE_OGG, FILE_MP3,
FILE_WAV, FILE_MKV,
FILE_FLAC, FILE_OGG,
FILE_XML, FILE_WAV,
FILE_PLAYLIST, FILE_FLAC,
STREAM_AUDIO, FILE_XML,
FILE_PICTURE, FILE_PLAYLIST,
STREAM_PICTURE STREAM_AUDIO,
}; FILE_PICTURE,
STREAM_PICTURE
};
FileType getType(void) const; FileType getType(void) const;
std::string getFileName(void) const; std::string getFileName(void) const;
std::string getPath(void) const; std::string getPath(void) const;
bool isDir(void) { return S_ISDIR(Mode); }; bool isDir(void) { return S_ISDIR(Mode); };
CFile(); CFile();
off_t Size; off_t Size;
std::string Name; std::string Name;
std::string Url; std::string Url;
mode_t Mode; mode_t Mode;
bool Marked; bool Marked;
time_t Time; time_t Time;
}; };
typedef std::vector<CFile> CFileList; typedef std::vector<CFile> CFileList;