From ccaac6c336858d398eb8638cd8f46cb1357c855c Mon Sep 17 00:00:00 2001 From: Tsuda kageyu Date: Wed, 17 Apr 2013 23:47:09 +0900 Subject: [PATCH] Fix improper string handling --- taglib/CMakeLists.txt | 4 ++++ taglib/fileref.cpp | 34 +++++++++++++++++++++++++++------- taglib/toolkit/tiostream.h | 5 +++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/taglib/CMakeLists.txt b/taglib/CMakeLists.txt index a940caf5..63b88bb7 100644 --- a/taglib/CMakeLists.txt +++ b/taglib/CMakeLists.txt @@ -311,6 +311,10 @@ if(ZLIB_FOUND) target_link_libraries(tag ${ZLIB_LIBRARIES}) endif() +if(WIN32 AND NOT TAGLIB_STATIC) + target_link_libraries(tag shlwapi.lib) +endif() + set_target_properties(tag PROPERTIES VERSION ${TAGLIB_SOVERSION_MAJOR}.${TAGLIB_SOVERSION_MINOR}.${TAGLIB_SOVERSION_PATCH} SOVERSION ${TAGLIB_SOVERSION_MAJOR} diff --git a/taglib/fileref.cpp b/taglib/fileref.cpp index 859f3155..a6c96c07 100644 --- a/taglib/fileref.cpp +++ b/taglib/fileref.cpp @@ -28,9 +28,14 @@ ***************************************************************************/ #ifdef HAVE_CONFIG_H -#include +# include #endif +#ifdef _WIN32 +# include +#endif + + #include #include #include @@ -218,21 +223,36 @@ File *FileRef::create(FileName fileName, bool readAudioProperties, // Ok, this is really dumb for now, but it works for testing. - String s; + String ext; #ifdef _WIN32 - s = (wcslen((const wchar_t *) fileName) > 0) ? String((const wchar_t *) fileName) : String((const char *) fileName); + // Avoids direct conversion from FileName to String + // because String can't decode strings in local encodings properly. + + if(!fileName.wstr().empty()) { + const wchar_t *pext = PathFindExtensionW(fileName.wstr().c_str()); + if(*pext == L'.') + ext = String(pext + 1).upper(); + } + else { + const char *pext = PathFindExtensionA(fileName.str().c_str()); + if(*pext == '.') + ext = String(pext + 1).upper(); + } #else - s = fileName; + { + String s = fileName; + const int pos = s.rfind("."); + if(pos != -1) + ext = s.substr(pos + 1).upper(); + } #endif // If this list is updated, the method defaultFileExtensions() should also be // updated. However at some point that list should be created at the same time // that a default file type resolver is created. - int pos = s.rfind("."); - if(pos != -1) { - String ext = s.substr(pos + 1).upper(); + if(!ext.isEmpty()) { if(ext == "MP3") return new MPEG::File(fileName, readAudioProperties, audioPropertiesStyle); if(ext == "OGG") diff --git a/taglib/toolkit/tiostream.h b/taglib/toolkit/tiostream.h index 3e7de22a..1508e402 100644 --- a/taglib/toolkit/tiostream.h +++ b/taglib/toolkit/tiostream.h @@ -38,8 +38,13 @@ namespace TagLib { public: FileName(const wchar_t *name) : m_wname(name) {} FileName(const char *name) : m_name(name) {} + operator const wchar_t *() const { return m_wname.c_str(); } operator const char *() const { return m_name.c_str(); } + + const std::wstring &wstr() const { return m_wname; } + const std::string &str() const { return m_name; } + private: std::string m_name; std::wstring m_wname; -- 2.40.0