diff --git a/src/driver/file.cpp b/src/driver/file.cpp index aa3002c98..21e94f8ee 100644 --- a/src/driver/file.cpp +++ b/src/driver/file.cpp @@ -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); - - if (result != NULL) - return file_type_list[(const char * *)result - (const char * *)&file_extension_list]; + 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]; + } } - return FILE_UNKNOWN; + return (CFile::FileType) Type; } //------------------------------------------------------------------------ diff --git a/src/driver/file.h b/src/driver/file.h index 46be83b89..7beabac1e 100644 --- a/src/driver/file.h +++ b/src/driver/file.h @@ -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 CFileList;