closes https://github.com/assimp/assimp/issues/1612: make wstaring handling depend from encoding of the filename.

pull/1652/head
Kim Kulling 2017-12-22 16:45:07 +01:00
parent 2294390917
commit 5a30bccdae
1 changed files with 49 additions and 15 deletions

View File

@ -74,10 +74,22 @@ bool DefaultIOSystem::Exists( const char* pFile) const
{ {
#ifdef _WIN32 #ifdef _WIN32
wchar_t fileName16[PATHLIMIT]; wchar_t fileName16[PATHLIMIT];
MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, pFile, -1, fileName16, PATHLIMIT);
struct _stat64 filestat; bool isUnicode = IsTextUnicode(pFile, strlen(pFile), NULL);
if (0 != _wstat64(fileName16, &filestat)) if (isUnicode) {
return false;
MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, pFile, -1, fileName16, PATHLIMIT);
struct _stat64 filestat;
if (0 != _wstat64(fileName16, &filestat)) {
return false;
}
} else {
FILE* file = ::fopen(pFile, "rb");
if (!file)
return false;
::fclose(file);
}
#else #else
FILE* file = ::fopen( pFile, "rb"); FILE* file = ::fopen( pFile, "rb");
if( !file) if( !file)
@ -97,9 +109,14 @@ IOStream* DefaultIOSystem::Open( const char* strFile, const char* strMode)
FILE* file; FILE* file;
#ifdef _WIN32 #ifdef _WIN32
wchar_t fileName16[PATHLIMIT]; wchar_t fileName16[PATHLIMIT];
MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, strFile, -1, fileName16, PATHLIMIT); bool isUnicode = IsTextUnicode(strFile, strlen(strFile), NULL );
std::string mode8(strMode); if (isUnicode) {
file = ::_wfopen(fileName16, std::wstring(mode8.begin(), mode8.end()).c_str()); MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, strFile, -1, fileName16, PATHLIMIT);
std::string mode8(strMode);
file = ::_wfopen(fileName16, std::wstring(mode8.begin(), mode8.end()).c_str());
} else {
file = ::fopen(strFile, strMode);
}
#else #else
file = ::fopen(strFile, strMode); file = ::fopen(strFile, strMode);
#endif #endif
@ -140,24 +157,41 @@ inline static void MakeAbsolutePath (const char* in, char* _out)
{ {
ai_assert(in && _out); ai_assert(in && _out);
#if defined( _MSC_VER ) || defined( __MINGW32__ ) #if defined( _MSC_VER ) || defined( __MINGW32__ )
wchar_t out16[PATHLIMIT]; bool isUnicode = IsTextUnicode(in, strlen(in), NULL);
wchar_t in16[PATHLIMIT]; if (isUnicode) {
MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, in, -1, out16, PATHLIMIT); wchar_t out16[PATHLIMIT];
wchar_t* ret = ::_wfullpath( out16, in16, PATHLIMIT ); wchar_t in16[PATHLIMIT];
if (ret) MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, in, -1, out16, PATHLIMIT);
{ wchar_t* ret = ::_wfullpath(out16, in16, PATHLIMIT);
WideCharToMultiByte(CP_UTF8, MB_PRECOMPOSED, out16, -1, _out, PATHLIMIT, nullptr, nullptr); if (ret) {
WideCharToMultiByte(CP_UTF8, MB_PRECOMPOSED, out16, -1, _out, PATHLIMIT, nullptr, nullptr);
}
if (!ret) {
// preserve the input path, maybe someone else is able to fix
// the path before it is accessed (e.g. our file system filter)
DefaultLogger::get()->warn("Invalid path: " + std::string(in));
strcpy(_out, in);
}
} else {
char* ret = :: _fullpath(_out, in, PATHLIMIT);
if (!ret) {
// preserve the input path, maybe someone else is able to fix
// the path before it is accessed (e.g. our file system filter)
DefaultLogger::get()->warn("Invalid path: " + std::string(in));
strcpy(_out, in);
}
} }
#else #else
// use realpath // use realpath
char* ret = realpath(in, _out); char* ret = realpath(in, _out);
#endif
if(!ret) { if(!ret) {
// preserve the input path, maybe someone else is able to fix // preserve the input path, maybe someone else is able to fix
// the path before it is accessed (e.g. our file system filter) // the path before it is accessed (e.g. our file system filter)
DefaultLogger::get()->warn("Invalid path: "+std::string(in)); DefaultLogger::get()->warn("Invalid path: "+std::string(in));
strcpy(_out,in); strcpy(_out,in);
} }
#endif
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------