]> granicus.if.org Git - taglib/commitdiff
Fix improper string handling
authorTsuda kageyu <tsuda.kageyu@gmail.com>
Wed, 17 Apr 2013 14:47:09 +0000 (23:47 +0900)
committerTsuda kageyu <tsuda.kageyu@gmail.com>
Wed, 17 Apr 2013 14:47:09 +0000 (23:47 +0900)
taglib/CMakeLists.txt
taglib/fileref.cpp
taglib/toolkit/tiostream.h

index a940caf5def3d2d4a726bfb897b6e0fb68db22ec..63b88bb7695b701046ce5253dff7b63860054162 100644 (file)
@@ -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}
index 859f3155bd72993f824e5f6e46db320086d8c11a..a6c96c0798e82f644340fd401908f00eb25dc1d7 100644 (file)
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
-#include <config.h>
+# include <config.h>
 #endif
 
+#ifdef _WIN32
+# include <Shlwapi.h>
+#endif 
+
+
 #include <tfile.h>
 #include <tstring.h>
 #include <tdebug.h>
@@ -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")
index 3e7de22aa5189b9419c81c79250101211d4129bc..1508e40290a77698f5f5d46e09ce78442f5c7a6e 100644 (file)
@@ -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;