Merge pull request #232 from TsudaKageyu/remove-shlwapi

Removed the dependency on shlwapi.dll in Win32
This commit is contained in:
Tsuda Kageyu 2013-06-05 21:59:11 -07:00
commit 98d010f460
7 changed files with 33 additions and 86 deletions

View File

@ -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.")

View File

@ -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)

View File

@ -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}

View File

@ -29,10 +29,6 @@
#include "taglib_config.h"
#ifdef _WIN32
# include <Shlwapi.h>
#endif
#include <tfile.h>
#include <tstring.h>
#include <tdebug.h>
@ -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

View File

@ -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<const char *>(d->name)));
# endif

View File

@ -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<wchar_t> buf(len);
MultiByteToWideChar(CP_ACP, 0, d->name.c_str(), -1, &buf[0], len);
return String(&buf[0]);
}
else {
return String::null;
}
}
#endif // _WIN32
////////////////////////////////////////////////////////////////////////////////

View File

@ -48,6 +48,8 @@ namespace TagLib {
const std::wstring &wstr() const;
const std::string &str() const;
String toString() const;
private:
class FileNamePrivate;
FileNamePrivate *d;