closes https://github.com/assimp/assimp/issues/1612: make wstaring handling depend from encoding of the filename.
parent
2294390917
commit
5a30bccdae
|
@ -74,10 +74,22 @@ bool DefaultIOSystem::Exists( const char* pFile) const
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
wchar_t fileName16[PATHLIMIT];
|
wchar_t fileName16[PATHLIMIT];
|
||||||
|
|
||||||
|
bool isUnicode = IsTextUnicode(pFile, strlen(pFile), NULL);
|
||||||
|
if (isUnicode) {
|
||||||
|
|
||||||
MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, pFile, -1, fileName16, PATHLIMIT);
|
MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, pFile, -1, fileName16, PATHLIMIT);
|
||||||
struct _stat64 filestat;
|
struct _stat64 filestat;
|
||||||
if (0 != _wstat64(fileName16, &filestat))
|
if (0 != _wstat64(fileName16, &filestat)) {
|
||||||
return false;
|
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];
|
||||||
|
bool isUnicode = IsTextUnicode(strFile, strlen(strFile), NULL );
|
||||||
|
if (isUnicode) {
|
||||||
MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, strFile, -1, fileName16, PATHLIMIT);
|
MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, strFile, -1, fileName16, PATHLIMIT);
|
||||||
std::string mode8(strMode);
|
std::string mode8(strMode);
|
||||||
file = ::_wfopen(fileName16, std::wstring(mode8.begin(), mode8.end()).c_str());
|
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__ )
|
||||||
|
bool isUnicode = IsTextUnicode(in, strlen(in), NULL);
|
||||||
|
if (isUnicode) {
|
||||||
wchar_t out16[PATHLIMIT];
|
wchar_t out16[PATHLIMIT];
|
||||||
wchar_t in16[PATHLIMIT];
|
wchar_t in16[PATHLIMIT];
|
||||||
MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, in, -1, out16, PATHLIMIT);
|
MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, in, -1, out16, PATHLIMIT);
|
||||||
wchar_t* ret = ::_wfullpath( out16, in16, PATHLIMIT );
|
wchar_t* ret = ::_wfullpath(out16, in16, PATHLIMIT);
|
||||||
if (ret)
|
if (ret) {
|
||||||
{
|
|
||||||
WideCharToMultiByte(CP_UTF8, MB_PRECOMPOSED, out16, -1, _out, PATHLIMIT, nullptr, nullptr);
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue