Fix improper string handling

This commit is contained in:
Tsuda kageyu
2013-04-17 23:47:09 +09:00
parent 88005640d5
commit ccaac6c336
3 changed files with 36 additions and 7 deletions

View File

@ -28,9 +28,14 @@
***************************************************************************/
#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")