From 36d7f9ba32db33e5847786b96af23a41a82a1a01 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Thu, 6 Jun 2013 13:45:23 +0900 Subject: [PATCH] Removed the dependency on shlwapi.dll in Win32 --- ConfigureChecks.cmake | 9 --------- cmake/modules/FindShlwapi.cmake | 14 -------------- taglib/CMakeLists.txt | 12 ------------ taglib/fileref.cpp | 30 +++++++++--------------------- taglib/toolkit/tfilestream.cpp | 31 +------------------------------ taglib/toolkit/tiostream.cpp | 21 +++++++++++++++++++++ taglib/toolkit/tiostream.h | 2 ++ 7 files changed, 33 insertions(+), 86 deletions(-) delete mode 100755 cmake/modules/FindShlwapi.cmake diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 192c1441..b0f164a9 100755 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -219,15 +219,6 @@ endif() set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) -if(WIN32 AND NOT MSVC) - find_package(SHLWAPI) - if(SHLWAPI_FOUND) - set(HAVE_SHLWAPI 1) - else() - set(HAVE_SHLWAPI 0) - endif() -endif() - find_package(CppUnit) if(NOT CppUnit_FOUND AND BUILD_TESTS) message(STATUS "CppUnit not found, disabling tests.") diff --git a/cmake/modules/FindShlwapi.cmake b/cmake/modules/FindShlwapi.cmake deleted file mode 100755 index cba253f0..00000000 --- a/cmake/modules/FindShlwapi.cmake +++ /dev/null @@ -1,14 +0,0 @@ -# * -# * It is what it is, you can do with it as you please. -# * -# * Just don't blame me if it teaches your computer to smoke! -# * -# * -Enjoy -# * fh :)_~ -# * -FIND_PATH(SHLWAPI_INCLUDE_DIR shlwapi.h) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SHLWAPI REQUIRED_VARS SHLWAPI_LIBRARY SHLWAPI_INCLUDE_DIR) -IF(SHLWAPI_FOUND) - SET(SHLWAPI_LIBRARIES ${SHLWAPI_LIBRARY} ) -ENDIF(SHLWAPI_FOUND) - diff --git a/taglib/CMakeLists.txt b/taglib/CMakeLists.txt index 1753fa33..352f7e2e 100755 --- a/taglib/CMakeLists.txt +++ b/taglib/CMakeLists.txt @@ -30,10 +30,6 @@ if(ZLIB_FOUND) include_directories(${ZLIB_INCLUDE_DIR}) endif() -if(NOT MSVC AND SHLWAPI_FOUND) - include_directories(${SHLWAPI_INCLUDE_DIR}) -endif() - set(tag_HDRS tag.h fileref.h @@ -315,14 +311,6 @@ if(ZLIB_FOUND) target_link_libraries(tag ${ZLIB_LIBRARIES}) endif() -if(MSVC) - target_link_libraries(tag shlwapi.lib) -else() - if(SHLWAPI_FOUND) - target_link_libraries(tag ${SHLWAPI_LIBRARIES}) - endif() -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 157ba2ee..d13a2837 100644 --- a/taglib/fileref.cpp +++ b/taglib/fileref.cpp @@ -29,10 +29,6 @@ #include "taglib_config.h" -#ifdef _WIN32 -# include -#endif - #include #include #include @@ -222,29 +218,21 @@ File *FileRef::create(FileName fileName, bool readAudioProperties, // Ok, this is really dumb for now, but it works for testing. String ext; - -#ifdef _WIN32 - // 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 { +#ifdef _WIN32 + + String s = fileName.toString(); + +#else + String s = fileName; + + #endif + 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 diff --git a/taglib/toolkit/tfilestream.cpp b/taglib/toolkit/tfilestream.cpp index 3bf68e0e..eae52573 100644 --- a/taglib/toolkit/tfilestream.cpp +++ b/taglib/toolkit/tfilestream.cpp @@ -83,35 +83,6 @@ namespace return 0; } -# ifndef NDEBUG - - // Convert a string in a local encoding into a UTF-16 string. - - // Debugging use only. In actual use, file names in local encodings are passed to - // CreateFileA() without any conversions. - - String fileNameToString(const FileName &name) - { - if(!name.wstr().empty()) { - return String(name.wstr()); - } - else if(!name.str().empty()) { - const int len = MultiByteToWideChar(CP_ACP, 0, name.str().c_str(), -1, NULL, 0); - if(len == 0) - return String::null; - - wstring wstr(len, L'\0'); - MultiByteToWideChar(CP_ACP, 0, name.str().c_str(), -1, &wstr[0], len); - - return String(wstr); - } - else { - return String::null; - } - } - -# endif - #else // _WIN32 struct FileNameHandle : public std::string @@ -183,7 +154,7 @@ FileStream::FileStream(FileName fileName, bool openReadOnly) if(d->file == InvalidFileHandle) { # ifdef _WIN32 - debug("Could not open file " + fileNameToString(fileName)); + debug("Could not open file " + fileName.toString()); # else debug("Could not open file " + String(static_cast(d->name))); # endif diff --git a/taglib/toolkit/tiostream.cpp b/taglib/toolkit/tiostream.cpp index ee4e4a61..3069bb53 100644 --- a/taglib/toolkit/tiostream.cpp +++ b/taglib/toolkit/tiostream.cpp @@ -124,6 +124,27 @@ const std::string &FileName::str() const return d->name; } +String FileName::toString() const +{ + if(!d->wname.empty()) { + return String(d->wname); + } + else if(!d->name.empty()) { + const int len = MultiByteToWideChar(CP_ACP, 0, d->name.c_str(), -1, NULL, 0); + if(len == 0) + return String::null; + + std::vector buf(len); + MultiByteToWideChar(CP_ACP, 0, d->name.c_str(), -1, &buf[0], len); + + return String(&buf[0]); + } + else { + return String::null; + } +} + + #endif // _WIN32 //////////////////////////////////////////////////////////////////////////////// diff --git a/taglib/toolkit/tiostream.h b/taglib/toolkit/tiostream.h index 498b3a45..22147f8a 100644 --- a/taglib/toolkit/tiostream.h +++ b/taglib/toolkit/tiostream.h @@ -48,6 +48,8 @@ namespace TagLib { const std::wstring &wstr() const; const std::string &str() const; + String toString() const; + private: class FileNamePrivate; FileNamePrivate *d;