Use Unicode filenames on Windows.

git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@734944 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
Lukáš Lalinský 2007-11-10 15:16:49 +00:00
parent 5a495c5c11
commit b98be427f9
15 changed files with 208 additions and 1 deletions

View File

@ -119,6 +119,17 @@ FLAC::File::File(const char *file, ID3v2::FrameFactory *frameFactory,
read(readProperties, propertiesStyle);
}
#ifdef TAGLIB_UNICODE_FILENAMES
FLAC::File::File(const wchar_t *file, ID3v2::FrameFactory *frameFactory,
bool readProperties, Properties::ReadStyle propertiesStyle) :
TagLib::File(file)
{
d = new FilePrivate;
d->ID3v2FrameFactory = frameFactory;
read(readProperties, propertiesStyle);
}
#endif
FLAC::File::~File()
{
delete d;

View File

@ -88,6 +88,20 @@ namespace TagLib {
bool readProperties = true,
Properties::ReadStyle propertiesStyle = Properties::Average);
#ifdef TAGLIB_UNICODE_FILENAMES
/*!
* Contructs a FLAC file from \a file. If \a readProperties is true the
* file's audio properties will also be read using \a propertiesStyle. If
* false, \a propertiesStyle is ignored.
*
* If this file contains and ID3v2 tag the frames will be created using
* \a frameFactory.
*/
File(const wchar_t *file, ID3v2::FrameFactory *frameFactory,
bool readProperties = true,
Properties::ReadStyle propertiesStyle = Properties::Average);
#endif
/*!
* Destroys this instance of the File.
*/

View File

@ -100,6 +100,15 @@ MPC::File::File(const char *file, bool readProperties,
read(readProperties, propertiesStyle);
}
#ifdef TAGLIB_UNICODE_FILENAMES
MPC::File::File(const wchar_t *file, bool readProperties,
Properties::ReadStyle propertiesStyle) : TagLib::File(file)
{
d = new FilePrivate;
read(readProperties, propertiesStyle);
}
#endif
MPC::File::~File()
{
delete d;

View File

@ -88,6 +88,16 @@ namespace TagLib {
File(const char *file, bool readProperties = true,
Properties::ReadStyle propertiesStyle = Properties::Average);
#ifdef TAGLIB_UNICODE_FILENAMES
/*!
* Contructs an MPC file from \a file. If \a readProperties is true the
* file's audio properties will also be read using \a propertiesStyle. If
* false, \a propertiesStyle is ignored.
*/
File(const wchar_t *file, bool readProperties = true,
Properties::ReadStyle propertiesStyle = Properties::Average);
#endif
/*!
* Destroys this instance of the File.
*/

View File

@ -246,6 +246,19 @@ MPEG::File::File(const char *file, ID3v2::FrameFactory *frameFactory,
}
}
#ifdef TAGLIB_UNICODE_FILENAMES
MPEG::File::File(const wchar_t *file, ID3v2::FrameFactory *frameFactory,
bool readProperties, Properties::ReadStyle propertiesStyle) :
TagLib::File(file)
{
d = new FilePrivate(frameFactory);
if(isOpen()) {
d->tag = new MPEGTag(this);
read(readProperties, propertiesStyle);
}
}
#endif
MPEG::File::~File()
{
delete d;

View File

@ -91,6 +91,18 @@ namespace TagLib {
bool readProperties = true,
Properties::ReadStyle propertiesStyle = Properties::Average);
#ifdef TAGLIB_UNICODE_FILENAMES
/*!
* Contructs an MPEG file from \a file. If \a readProperties is true the
* file's audio properties will also be read using \a propertiesStyle. If
* false, \a propertiesStyle is ignored. The frames will be created using
* \a frameFactory.
*/
File(const wchar_t *file, ID3v2::FrameFactory *frameFactory,
bool readProperties = true,
Properties::ReadStyle propertiesStyle = Properties::Average);
#endif
/*!
* Destroys this instance of the File.
*/

View File

@ -75,6 +75,15 @@ Ogg::FLAC::File::File(const char *file, bool readProperties,
read(readProperties, propertiesStyle);
}
#ifdef TAGLIB_UNICODE_FILENAMES
Ogg::FLAC::File::File(const wchar_t *file, bool readProperties,
Properties::ReadStyle propertiesStyle) : Ogg::File(file)
{
d = new FilePrivate;
read(readProperties, propertiesStyle);
}
#endif
Ogg::FLAC::File::~File()
{
delete d;

View File

@ -71,6 +71,16 @@ namespace TagLib {
File(const char *file, bool readProperties = true,
Properties::ReadStyle propertiesStyle = Properties::Average);
#ifdef TAGLIB_UNICODE_FILENAMES
/*!
* Contructs an Ogg/FLAC file from \a file. If \a readProperties is true
* the file's audio properties will also be read using \a propertiesStyle.
* If false, \a propertiesStyle is ignored.
*/
File(const wchar_t *file, bool readProperties = true,
Properties::ReadStyle propertiesStyle = Properties::Average);
#endif
/*!
* Destroys this instance of the File.
*/

View File

@ -213,6 +213,13 @@ Ogg::File::File(const char *file) : TagLib::File(file)
d = new FilePrivate;
}
#ifdef TAGLIB_UNICODE_FILENAMES
Ogg::File::File(const wchar_t *file) : TagLib::File(file)
{
d = new FilePrivate;
}
#endif
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////

View File

@ -92,6 +92,19 @@ namespace TagLib {
*/
File(const char *file);
#ifdef TAGLIB_UNICODE_FILENAMES
/*!
* Contructs an Ogg file from \a file. If \a readProperties is true the
* file's audio properties will also be read using \a propertiesStyle. If
* false, \a propertiesStyle is ignored.
*
* \note This constructor is protected since Ogg::File shouldn't be
* instantiated directly but rather should be used through the codec
* specific subclasses.
*/
File(const wchar_t *file);
#endif
private:
File(const File &);
File &operator=(const File &);

View File

@ -68,6 +68,15 @@ Vorbis::File::File(const char *file, bool readProperties,
read(readProperties, propertiesStyle);
}
#ifdef TAGLIB_UNICODE_FILENAMES
Vorbis::File::File(const wchar_t *file, bool readProperties,
Properties::ReadStyle propertiesStyle) : Ogg::File(file)
{
d = new FilePrivate;
read(readProperties, propertiesStyle);
}
#endif
Vorbis::File::~File()
{
delete d;

View File

@ -70,6 +70,16 @@ namespace TagLib {
File(const char *file, bool readProperties = true,
Properties::ReadStyle propertiesStyle = Properties::Average);
#ifdef TAGLIB_UNICODE_FILENAMES
/*!
* Contructs a Vorbis file from \a file. If \a readProperties is true the
* file's audio properties will also be read using \a propertiesStyle. If
* false, \a propertiesStyle is ignored.
*/
File(const wchar_t *file, bool readProperties = true,
Properties::ReadStyle propertiesStyle = Properties::Average);
#endif
/*!
* Destroys this instance of the File.
*/

View File

@ -30,6 +30,10 @@
#define TAGLIB_MINOR_VERSION 4
#define TAGLIB_PATCH_VERSION 0
#ifdef _WIN32
#define TAGLIB_UNICODE_FILENAMES 1
#endif
#include <string>
//! A namespace for all TagLib related classes and functions

View File

@ -45,6 +45,15 @@
# define W_OK 2
#endif
#ifdef TAGLIB_UNICODE_FILENAMES
# ifdef _WIN32
# include <wchar.h>
# include <windows.h>
# else
# error "Unicode filenames are not supported on this platform."
# endif
#endif
using namespace TagLib;
class File::FilePrivate
@ -53,6 +62,9 @@ public:
FilePrivate(const char *fileName) :
file(0),
name(fileName),
#ifdef TAGLIB_UNICODE_FILENAMES
wname(0),
#endif
readOnly(true),
valid(true),
size(0)
@ -61,10 +73,16 @@ public:
~FilePrivate()
{
free((void *)name);
#ifdef TAGLIB_UNICODE_FILENAMES
free((void *)wname);
#endif
}
FILE *file;
const char *name;
#ifdef TAGLIB_UNICODE_FILENAMES
const wchar_t *wname;
#endif
bool readOnly;
bool valid;
ulong size;
@ -87,12 +105,45 @@ File::File(const char *file)
if(d->file)
d->readOnly = false;
else
d->file = fopen(file,"rb");
d->file = fopen(file, "rb");
if(!d->file)
debug("Could not open file " + String(file));
}
#ifdef TAGLIB_UNICODE_FILENAMES
File::File(const wchar_t *file)
{
#ifdef _WIN32
d = new FilePrivate(0);
d->wname = _wcsdup(file);
if(GetVersion() < 0x80000000) {
d->file = _wfopen(file, L"rb+");
if(d->file)
d->readOnly = false;
else
d->file = _wfopen(file, L"rb");
}
else {
size_t size = wcslen(file) + 1;
d->name = (char *)malloc(size);
if(WideCharToMultiByte(CP_ACP, 0, file, -1, (CHAR*)d->name, size,
NULL, NULL) > 0) {
d->file = fopen(d->name, "rb+");
if(d->file)
d->readOnly = false;
else
d->file = fopen(d->name, "rb");
}
}
if(!d->file)
debug("Could not open file " + String(file, String::UTF16LE));
#endif
}
#endif
File::~File()
{
if(d->file)
@ -105,6 +156,13 @@ const char *File::name() const
return d->name;
}
#ifdef TAGLIB_UNICODE_FILENAMES
const wchar_t *File::unicodeName() const
{
return d->wname;
}
#endif
ByteVector File::readBlock(ulong length)
{
if(!d->file) {

View File

@ -69,6 +69,13 @@ namespace TagLib {
*/
const char *name() const;
#ifdef TAGLIB_UNICODE_FILENAMES
/*!
* Returns the file name in UTF-16.
*/
const wchar_t *unicodeName() const;
#endif
/*!
* Returns a pointer to this file's tag. This should be reimplemented in
* the concrete subclasses.
@ -225,6 +232,17 @@ namespace TagLib {
*/
File(const char *file);
#ifdef TAGLIB_UNICODE_FILENAMES
/*!
* Construct a File object and opens the \a file. \a file should be a
* be a null-terminated Unicode string in UTF-16.
*
* \note Constructor is protected since this class should only be
* instantiated through subclasses.
*/
File(const wchar_t *file);
#endif
/*!
* Marks the file as valid or invalid.
*