mirror of
https://github.com/taglib/taglib.git
synced 2025-06-04 01:28:21 -04:00
Merge branch 'master' into merge-master-to-taglib2
# Conflicts: # taglib/toolkit/tbytevector.cpp # taglib/toolkit/tfilestream.cpp # taglib/toolkit/tiostream.cpp # taglib/toolkit/tstring.cpp
This commit is contained in:
commit
f355110d18
2
NEWS
2
NEWS
@ -1,6 +1,8 @@
|
||||
============================
|
||||
|
||||
* Added support for WinRT.
|
||||
* Dropped support for Windows 9x and NT 4.0 or older.
|
||||
* Several smaller bug fixes and performance improvements.
|
||||
|
||||
TagLib 1.11.1 (Oct 24, 2016)
|
||||
============================
|
||||
|
@ -49,11 +49,10 @@ namespace TagLib
|
||||
|
||||
void debugData(const ByteVector &v)
|
||||
{
|
||||
for(size_t i = 0; i < v.size(); ++i)
|
||||
{
|
||||
std::string bits = std::bitset<8>(v[i]).to_string();
|
||||
String msg = Utils::formatString(
|
||||
"*** [%d] - char '%c' - int %d, 0x%02x, 0b%s\n",
|
||||
for(unsigned int i = 0; i < v.size(); ++i) {
|
||||
const std::string bits = std::bitset<8>(v[i]).to_string();
|
||||
const String msg = Utils::formatString(
|
||||
"*** [%u] - char '%c' - int %d, 0x%02x, 0b%s\n",
|
||||
i, v[i], v[i], v[i], bits.c_str());
|
||||
|
||||
debugListener->printMessage(msg);
|
||||
|
@ -57,14 +57,9 @@ namespace
|
||||
const DWORD access = readOnly ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE);
|
||||
|
||||
#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)
|
||||
return CreateFile2(path.toString().toCWString(), access, FILE_SHARE_READ, OPEN_EXISTING, NULL);
|
||||
return CreateFile2(path.wstr(), access, FILE_SHARE_READ, OPEN_EXISTING, NULL);
|
||||
#else
|
||||
if(!path.wstr().empty())
|
||||
return CreateFileW(path.wstr().c_str(), access, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
||||
else if(!path.str().empty())
|
||||
return CreateFileA(path.str().c_str(), access, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
||||
else
|
||||
return InvalidFileHandle;
|
||||
return CreateFileW(path.wstr(), access, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -159,7 +154,7 @@ FileStream::FileStream(FileName fileName, bool openReadOnly) :
|
||||
if(d->file == InvalidFileHandle)
|
||||
{
|
||||
# ifdef _WIN32
|
||||
debug("Could not open file " + fileName.toString());
|
||||
debug("Could not open file " + String(fileName.wstr()));
|
||||
# else
|
||||
debug("Could not open file " + String(static_cast<const char *>(d->name)));
|
||||
# endif
|
||||
@ -269,7 +264,7 @@ void FileStream::insert(const ByteVector &data, long long start, size_t replace)
|
||||
// to overwrite. Appropriately increment the readPosition.
|
||||
|
||||
seek(readPosition);
|
||||
const size_t bytesRead = readFile(d->file, aboutToOverwrite);
|
||||
const unsigned int bytesRead = static_cast<unsigned int>(readFile(d->file, aboutToOverwrite));
|
||||
aboutToOverwrite.resize(bytesRead);
|
||||
readPosition += bufferLength;
|
||||
|
||||
@ -312,10 +307,10 @@ void FileStream::removeBlock(long long start, size_t length)
|
||||
|
||||
ByteVector buffer(bufferLength, 0);
|
||||
|
||||
for(size_t bytesRead = -1; bytesRead != 0;)
|
||||
for(unsigned int bytesRead = -1; bytesRead != 0;)
|
||||
{
|
||||
seek(readPosition);
|
||||
bytesRead = readFile(d->file, buffer);
|
||||
bytesRead = static_cast<unsigned int>(readFile(d->file, buffer));
|
||||
readPosition += bytesRead;
|
||||
|
||||
// Check to see if we just read the last block. We need to call clear()
|
||||
@ -373,12 +368,9 @@ void FileStream::seek(long long offset, Position p)
|
||||
LARGE_INTEGER liOffset;
|
||||
liOffset.QuadPart = offset;
|
||||
|
||||
SetLastError(NO_ERROR);
|
||||
SetFilePointer(d->file, liOffset.LowPart, &liOffset.HighPart, whence);
|
||||
|
||||
const int lastError = GetLastError();
|
||||
if(lastError != NO_ERROR && lastError != ERROR_NEGATIVE_SEEK)
|
||||
if(!SetFilePointerEx(d->file, liOffset, NULL, whence)) {
|
||||
debug("FileStream::seek() -- Failed to set the file pointer.");
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@ -420,13 +412,10 @@ long long FileStream::tell() const
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
||||
const LARGE_INTEGER zero = {};
|
||||
LARGE_INTEGER position;
|
||||
position.QuadPart = 0;
|
||||
|
||||
SetLastError(NO_ERROR);
|
||||
position.LowPart = SetFilePointer(
|
||||
d->file, position.LowPart, &position.HighPart, FILE_CURRENT);
|
||||
if(GetLastError() == NO_ERROR) {
|
||||
if(SetFilePointerEx(d->file, zero, &position, FILE_CURRENT)) {
|
||||
return position.QuadPart;
|
||||
}
|
||||
else {
|
||||
@ -450,16 +439,10 @@ long long FileStream::length()
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
SetLastError(NO_ERROR);
|
||||
#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)
|
||||
LARGE_INTEGER fileSize;
|
||||
GetFileSizeEx(d->file, &fileSize);
|
||||
#else
|
||||
ULARGE_INTEGER fileSize;
|
||||
fileSize.LowPart = GetFileSize(d->file, &fileSize.HighPart);
|
||||
#endif
|
||||
if(GetLastError() == NO_ERROR) {
|
||||
return static_cast<long long>(fileSize.QuadPart);
|
||||
|
||||
if(GetFileSizeEx(d->file, &fileSize)) {
|
||||
return fileSize.QuadPart;
|
||||
}
|
||||
else {
|
||||
debug("FileStream::length() -- Failed to get the file size.");
|
||||
@ -497,9 +480,7 @@ void FileStream::truncate(long long length)
|
||||
|
||||
seek(length);
|
||||
|
||||
SetLastError(NO_ERROR);
|
||||
SetEndOfFile(d->file);
|
||||
if(GetLastError() != NO_ERROR) {
|
||||
if(!SetEndOfFile(d->file)) {
|
||||
debug("FileStream::truncate() -- Failed to truncate the file.");
|
||||
}
|
||||
|
||||
|
@ -23,93 +23,56 @@
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <windows.h>
|
||||
# include <tstring.h>
|
||||
# include <tsmartptr.h>
|
||||
#endif
|
||||
|
||||
#include "tiostream.h"
|
||||
|
||||
using namespace TagLib;
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
# include "tstring.h"
|
||||
# include "tdebug.h"
|
||||
# include "tsmartptr.h"
|
||||
# include <windows.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
// Check if the running system has CreateFileW() function.
|
||||
// Windows9x systems don't have CreateFileW() or can't accept Unicode file names.
|
||||
|
||||
bool supportsUnicode()
|
||||
std::wstring ansiToUnicode(const char *str)
|
||||
{
|
||||
#ifdef UNICODE
|
||||
return true;
|
||||
#else
|
||||
const FARPROC p = GetProcAddress(GetModuleHandleA("kernel32"), "CreateFileW");
|
||||
return (p != NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Indicates whether the system supports Unicode file names.
|
||||
|
||||
const bool SystemSupportsUnicode = supportsUnicode();
|
||||
|
||||
// Converts a UTF-16 string into a local encoding.
|
||||
// This function should only be used in Windows9x systems which don't support
|
||||
// Unicode file names.
|
||||
|
||||
std::string unicodeToAnsi(const wchar_t *wstr)
|
||||
{
|
||||
if(SystemSupportsUnicode) {
|
||||
debug("unicodeToAnsi() - Should not be used on WinNT systems.");
|
||||
}
|
||||
|
||||
const int len = ::WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
|
||||
const int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
|
||||
if(len == 0)
|
||||
return std::string();
|
||||
return std::wstring();
|
||||
|
||||
std::string str(len, '\0');
|
||||
::WideCharToMultiByte(CP_ACP, 0, wstr, -1, &str[0], len, NULL, NULL);
|
||||
std::wstring wstr(len - 1, L'\0');
|
||||
MultiByteToWideChar(CP_ACP, 0, str, -1, &wstr[0], len);
|
||||
|
||||
return str;
|
||||
return wstr;
|
||||
}
|
||||
|
||||
struct FileNameData
|
||||
{
|
||||
std::wstring wname;
|
||||
std::string name;
|
||||
};
|
||||
}
|
||||
|
||||
class FileName::FileNamePrivate
|
||||
{
|
||||
public:
|
||||
FileNamePrivate() :
|
||||
data(new FileNameData()) {}
|
||||
data(new std::wstring()) {}
|
||||
|
||||
SHARED_PTR<FileNameData> data;
|
||||
FileNamePrivate(const wchar_t *name) :
|
||||
data(new std::wstring(name)) {}
|
||||
|
||||
FileNamePrivate(const char *name) :
|
||||
data(new std::wstring(ansiToUnicode(name))) {}
|
||||
|
||||
SHARED_PTR<std::wstring> data;
|
||||
};
|
||||
|
||||
FileName::FileName() :
|
||||
d(new FileNamePrivate())
|
||||
{
|
||||
}
|
||||
|
||||
FileName::FileName(const wchar_t *name) :
|
||||
d(new FileNamePrivate())
|
||||
d(new FileNamePrivate(name))
|
||||
{
|
||||
// If WinNT, stores a Unicode string into wname directly.
|
||||
// If Win9x, converts and stores it into name to avoid calling Unicode version functions.
|
||||
|
||||
if(SystemSupportsUnicode)
|
||||
d->data->wname = name;
|
||||
else
|
||||
d->data->name = unicodeToAnsi(name);
|
||||
}
|
||||
|
||||
FileName::FileName(const char *name) :
|
||||
d(new FileNamePrivate())
|
||||
d(new FileNamePrivate(name))
|
||||
{
|
||||
d->data->name = name;
|
||||
}
|
||||
|
||||
FileName::FileName(const FileName &name) :
|
||||
@ -129,34 +92,9 @@ FileName &FileName::operator=(const FileName &name)
|
||||
return *this;
|
||||
}
|
||||
|
||||
const std::wstring &FileName::wstr() const
|
||||
const wchar_t *FileName::wstr() const
|
||||
{
|
||||
return d->data->wname;
|
||||
}
|
||||
|
||||
const std::string &FileName::str() const
|
||||
{
|
||||
return d->data->name;
|
||||
}
|
||||
|
||||
String FileName::toString() const
|
||||
{
|
||||
if(!d->data->wname.empty()) {
|
||||
return String(d->data->wname);
|
||||
}
|
||||
else if(!d->data->name.empty()) {
|
||||
const int len = ::MultiByteToWideChar(CP_ACP, 0, d->data->name.c_str(), -1, NULL, 0);
|
||||
if(len == 0)
|
||||
return String();
|
||||
|
||||
std::vector<wchar_t> buf(len);
|
||||
::MultiByteToWideChar(CP_ACP, 0, d->data->name.c_str(), -1, &buf[0], len);
|
||||
|
||||
return String(&buf[0]);
|
||||
}
|
||||
else {
|
||||
return String();
|
||||
}
|
||||
return d->data->c_str();
|
||||
}
|
||||
|
||||
#endif // _WIN32
|
||||
|
@ -37,7 +37,6 @@ namespace TagLib {
|
||||
class TAGLIB_EXPORT FileName
|
||||
{
|
||||
public:
|
||||
FileName();
|
||||
FileName(const wchar_t *name);
|
||||
FileName(const char *name);
|
||||
FileName(const FileName &name);
|
||||
@ -46,10 +45,7 @@ namespace TagLib {
|
||||
|
||||
FileName &operator=(const FileName &name);
|
||||
|
||||
const std::wstring &wstr() const;
|
||||
const std::string &str() const;
|
||||
|
||||
String toString() const;
|
||||
const wchar_t *wstr() const;
|
||||
|
||||
private:
|
||||
class FileNamePrivate;
|
||||
|
@ -511,8 +511,7 @@ ByteVector String::data(Type t) const
|
||||
{
|
||||
ByteVector v(size() * 4 + 1, 0);
|
||||
|
||||
const size_t len = UTF16toUTF8(
|
||||
d->data->c_str(), d->data->size(), v.data(), v.size());
|
||||
const size_t len = UTF16toUTF8(d->data->c_str(), d->data->size(), v.data(), v.size());
|
||||
v.resize(len);
|
||||
|
||||
return v;
|
||||
|
Loading…
x
Reference in New Issue
Block a user