From c1d4ed7873bf51e271d30a92fcd595efdf994086 Mon Sep 17 00:00:00 2001 From: escherstair Date: Tue, 3 Sep 2019 07:55:27 +0200 Subject: [PATCH 01/15] prefer prefix ++/-- operators for non-primitive types --- code/AMF/AMFImporter_Postprocess.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/AMF/AMFImporter_Postprocess.cpp b/code/AMF/AMFImporter_Postprocess.cpp index 37478d9ec..79b5e15e2 100644 --- a/code/AMF/AMFImporter_Postprocess.cpp +++ b/code/AMF/AMFImporter_Postprocess.cpp @@ -334,7 +334,7 @@ void AMFImporter::PostprocessHelper_SplitFacesByTextureID(std::list Date: Tue, 3 Sep 2019 07:56:37 +0200 Subject: [PATCH 02/15] prefer prefix ++/-- operators for non-primitive types --- code/X3D/X3DImporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/X3D/X3DImporter.cpp b/code/X3D/X3DImporter.cpp index 365761cf6..dcf6092ca 100644 --- a/code/X3D/X3DImporter.cpp +++ b/code/X3D/X3DImporter.cpp @@ -1241,7 +1241,7 @@ void X3DImporter::MeshGeometry_AddTexCoord(aiMesh& pMesh, const std::vector::const_iterator it = pTexCoords.begin(); it != pTexCoords.end(); it++) + for(std::list::const_iterator it = pTexCoords.begin(); it != pTexCoords.end(); ++it) { texcoord_arr_copy.push_back(aiVector3D((*it).x, (*it).y, 0)); } From 53d795c1c923cb9fafb07389df68ea85e8518c03 Mon Sep 17 00:00:00 2001 From: escherstair Date: Tue, 3 Sep 2019 07:57:08 +0200 Subject: [PATCH 03/15] possible inefficient checking for 'tlist' emptiness --- code/X3D/X3DImporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/X3D/X3DImporter.cpp b/code/X3D/X3DImporter.cpp index dcf6092ca..0d48d00b7 100644 --- a/code/X3D/X3DImporter.cpp +++ b/code/X3D/X3DImporter.cpp @@ -684,7 +684,7 @@ void X3DImporter::XML_ReadNode_GetAttrVal_AsArrVec2f(const int pAttrIdx, std::ve XML_ReadNode_GetAttrVal_AsListVec2f(pAttrIdx, tlist);// read as list // and copy to array - if(tlist.size() > 0) + if(!tlist.empty()) { pValue.reserve(tlist.size()); for ( std::list::iterator it = tlist.begin(); it != tlist.end(); ++it ) From 75993ad653d99c343b412d7b6059d919712a9529 Mon Sep 17 00:00:00 2001 From: escherstair Date: Tue, 3 Sep 2019 07:57:58 +0200 Subject: [PATCH 04/15] prefer prefix ++/-- operators for non-primitive types --- code/X3D/X3DImporter_Geometry3D.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/X3D/X3DImporter_Geometry3D.cpp b/code/X3D/X3DImporter_Geometry3D.cpp index 9716f78d1..e12cbd3ab 100644 --- a/code/X3D/X3DImporter_Geometry3D.cpp +++ b/code/X3D/X3DImporter_Geometry3D.cpp @@ -230,7 +230,7 @@ void X3DImporter::ParseNode_Geometry3D_Cylinder() if(top) { - for(std::vector::iterator it = tcir.begin(); it != tcir.end(); it++) + for(std::vector::iterator it = tcir.begin(); it != tcir.end(); ++it) { (*it).y = height;// y - because circle made in oXZ. vlist.push_back(*it); From 33e71ee8df9327130ec5f91b4fe997ab502e0f46 Mon Sep 17 00:00:00 2001 From: escherstair Date: Tue, 3 Sep 2019 07:59:17 +0200 Subject: [PATCH 05/15] prefer prefix ++/-- operators for non-primitive types --- code/X3D/X3DImporter_Postprocess.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/X3D/X3DImporter_Postprocess.cpp b/code/X3D/X3DImporter_Postprocess.cpp index 8fcdbb9d6..59a085c74 100644 --- a/code/X3D/X3DImporter_Postprocess.cpp +++ b/code/X3D/X3DImporter_Postprocess.cpp @@ -89,7 +89,7 @@ aiMatrix4x4 X3DImporter::PostprocessHelper_Matrix_GlobalToCurrent() const void X3DImporter::PostprocessHelper_CollectMetadata(const CX3DImporter_NodeElement& pNodeElement, std::list& pList) const { // walk through childs and find for metadata. - for(std::list::const_iterator el_it = pNodeElement.Child.begin(); el_it != pNodeElement.Child.end(); el_it++) + for(std::list::const_iterator el_it = pNodeElement.Child.begin(); el_it != pNodeElement.Child.end(); ++el_it) { if(((*el_it)->Type == CX3DImporter_NodeElement::ENET_MetaBoolean) || ((*el_it)->Type == CX3DImporter_NodeElement::ENET_MetaDouble) || ((*el_it)->Type == CX3DImporter_NodeElement::ENET_MetaFloat) || ((*el_it)->Type == CX3DImporter_NodeElement::ENET_MetaInteger) || @@ -255,7 +255,7 @@ void X3DImporter::Postprocess_BuildMesh(const CX3DImporter_NodeElement& pNodeEle std::vector tarr; tarr.reserve(tnemesh.Vertices.size()); - for(std::list::iterator it = tnemesh.Vertices.begin(); it != tnemesh.Vertices.end(); it++) tarr.push_back(*it); + for(std::list::iterator it = tnemesh.Vertices.begin(); it != tnemesh.Vertices.end(); ++it) tarr.push_back(*it); *pMesh = StandardShapes::MakeMesh(tarr, static_cast(tnemesh.NumIndices));// create mesh from vertices using Assimp help. return;// mesh is build, nothing to do anymore. @@ -438,7 +438,7 @@ void X3DImporter::Postprocess_BuildMesh(const CX3DImporter_NodeElement& pNodeEle vec_copy.reserve(((CX3DImporter_NodeElement_Coordinate*)*ch_it)->Value.size()); for(std::list::const_iterator it = ((CX3DImporter_NodeElement_Coordinate*)*ch_it)->Value.begin(); - it != ((CX3DImporter_NodeElement_Coordinate*)*ch_it)->Value.end(); it++) + it != ((CX3DImporter_NodeElement_Coordinate*)*ch_it)->Value.end(); ++it) { vec_copy.push_back(*it); } @@ -580,7 +580,7 @@ void X3DImporter::Postprocess_BuildMesh(const CX3DImporter_NodeElement& pNodeEle CX3DImporter_NodeElement_Set& tnemesh = *((CX3DImporter_NodeElement_Set*)&pNodeElement);// create alias for convenience // at first search for node and create mesh. - for(std::list::iterator ch_it = tnemesh.Child.begin(); ch_it != tnemesh.Child.end(); ch_it++) + for(std::list::iterator ch_it = tnemesh.Child.begin(); ch_it != tnemesh.Child.end(); ++ch_it) { if((*ch_it)->Type == CX3DImporter_NodeElement::ENET_Coordinate) { From ceacad237f3a5546820295cc7ef9f908e208dd35 Mon Sep 17 00:00:00 2001 From: escherstair Date: Tue, 3 Sep 2019 08:00:12 +0200 Subject: [PATCH 06/15] prefer prefix ++/-- operators for non-primitive types --- code/X3D/X3DImporter_Rendering.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/X3D/X3DImporter_Rendering.cpp b/code/X3D/X3DImporter_Rendering.cpp index b6cbb2499..fe54a7891 100644 --- a/code/X3D/X3DImporter_Rendering.cpp +++ b/code/X3D/X3DImporter_Rendering.cpp @@ -413,7 +413,7 @@ void X3DImporter::ParseNode_Rendering_IndexedTriangleSet() ne_alias.CoordIndex.clear(); int counter = 0; int32_t idx[3]; - for(std::vector::const_iterator idx_it = index.begin(); idx_it != index.end(); idx_it++) + for(std::vector::const_iterator idx_it = index.begin(); idx_it != index.end(); ++idx_it) { idx[counter++] = *idx_it; if (counter > 2) @@ -765,7 +765,7 @@ void X3DImporter::ParseNode_Rendering_TriangleFanSet() // assign indices for first triangle coord_num_first = 0; coord_num_prev = 1; - for(std::vector::const_iterator vc_it = ne_alias.VertexCount.begin(); vc_it != ne_alias.VertexCount.end(); vc_it++) + for(std::vector::const_iterator vc_it = ne_alias.VertexCount.begin(); vc_it != ne_alias.VertexCount.end(); ++vc_it) { if(*vc_it < 3) throw DeadlyImportError("TriangleFanSet. fanCount shall be greater than or equal to three."); From bbb1f6a1dcdefdb785caa2b884a91dd080ff9743 Mon Sep 17 00:00:00 2001 From: escherstair Date: Tue, 3 Sep 2019 08:01:05 +0200 Subject: [PATCH 07/15] prefer prefix ++/-- operators for non-primitive types --- contrib/gtest/test/gtest-param-test_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/gtest/test/gtest-param-test_test.cc b/contrib/gtest/test/gtest-param-test_test.cc index 8b278bb94..8aacfce72 100644 --- a/contrib/gtest/test/gtest-param-test_test.cc +++ b/contrib/gtest/test/gtest-param-test_test.cc @@ -215,7 +215,7 @@ TEST(IteratorTest, ParamIteratorConformsToForwardIteratorConcept) { // Verifies that prefix and postfix operator++() advance an iterator // all the same. it2 = it; - it++; + ++it; ++it2; EXPECT_TRUE(*it == *it2); } From e317fbfbb652c178b828faa967f0f997beed21c8 Mon Sep 17 00:00:00 2001 From: escherstair Date: Tue, 3 Sep 2019 08:01:56 +0200 Subject: [PATCH 08/15] prefer prefix ++/-- operators for non-primitive types --- test/unit/SceneDiffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/SceneDiffer.cpp b/test/unit/SceneDiffer.cpp index fb000db29..684d9fee6 100644 --- a/test/unit/SceneDiffer.cpp +++ b/test/unit/SceneDiffer.cpp @@ -123,7 +123,7 @@ void SceneDiffer::showReport() { return; } - for ( std::vector::iterator it = m_diffs.begin(); it != m_diffs.end(); it++ ) { + for ( std::vector::iterator it = m_diffs.begin(); it != m_diffs.end(); ++it ) { std::cout << *it << "\n"; } From c4ce8cec962daf2f6618485df703bb7392cfb652 Mon Sep 17 00:00:00 2001 From: escherstair Date: Tue, 3 Sep 2019 08:02:56 +0200 Subject: [PATCH 09/15] prefer prefix ++/-- operators for non-primitive types --- tools/assimp_qt_viewer/glview.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/assimp_qt_viewer/glview.cpp b/tools/assimp_qt_viewer/glview.cpp index 97eba83a1..6ecdb0f4d 100644 --- a/tools/assimp_qt_viewer/glview.cpp +++ b/tools/assimp_qt_viewer/glview.cpp @@ -203,7 +203,7 @@ void CGLView::Matrix_NodeToRoot(const aiNode* pNode, aiMatrix4x4& pOutMatrix) } // multiply all matrices in reverse order - for ( std::list::reverse_iterator rit = mat_list.rbegin(); rit != mat_list.rend(); rit++) + for ( std::list::reverse_iterator rit = mat_list.rbegin(); rit != mat_list.rend(); ++rit) { pOutMatrix = pOutMatrix * (*rit); } @@ -729,7 +729,7 @@ void CGLView::FreeScene() { GLuint* id_tex = new GLuint[id_tex_size]; QMap::iterator it = mTexture_IDMap.begin(); - for(int idx = 0; idx < id_tex_size; idx++, it++) + for(int idx = 0; idx < id_tex_size; idx++, ++it) { id_tex[idx] = it.value(); } From 727cf0c49f552073fe022c4ec24526dc0c561df0 Mon Sep 17 00:00:00 2001 From: Ryan McCampbell Date: Mon, 8 Jul 2019 23:21:57 -0700 Subject: [PATCH 10/15] Fixed unicode on windows --- code/Common/DefaultIOSystem.cpp | 80 +++++++++------------------------ 1 file changed, 20 insertions(+), 60 deletions(-) diff --git a/code/Common/DefaultIOSystem.cpp b/code/Common/DefaultIOSystem.cpp index d40b67de3..7606d8ced 100644 --- a/code/Common/DefaultIOSystem.cpp +++ b/code/Common/DefaultIOSystem.cpp @@ -73,28 +73,14 @@ using namespace Assimp; // Tests for the existence of a file at the given path. bool DefaultIOSystem::Exists( const char* pFile) const { -#ifdef _WIN32 +#if defined(_WIN32) && !defined(WindowsStore) wchar_t fileName16[PATHLIMIT]; -#ifndef WindowsStore - bool isUnicode = IsTextUnicode(pFile, static_cast(strlen(pFile)), NULL) != 0; - if (isUnicode) { - - MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, pFile, -1, fileName16, PATHLIMIT); - struct __stat64 filestat; - if (0 != _wstat64(fileName16, &filestat)) { - return false; - } - } else { -#endif - FILE* file = ::fopen(pFile, "rb"); - if (!file) - return false; - - ::fclose(file); -#ifndef WindowsStore + MultiByteToWideChar(CP_UTF8, 0, pFile, -1, fileName16, PATHLIMIT); + struct __stat64 filestat; + if (0 != _wstat64(fileName16, &filestat)) { + return false; } -#endif #else FILE* file = ::fopen( pFile, "rb"); if( !file) @@ -112,27 +98,19 @@ IOStream* DefaultIOSystem::Open( const char* strFile, const char* strMode) ai_assert(NULL != strFile); ai_assert(NULL != strMode); FILE* file; -#ifdef _WIN32 +#if defined(_WIN32) && !defined(WindowsStore) wchar_t fileName16[PATHLIMIT]; -#ifndef WindowsStore - bool isUnicode = IsTextUnicode(strFile, static_cast(strlen(strFile)), NULL) != 0; - if (isUnicode) { - 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 { -#endif - file = ::fopen(strFile, strMode); -#ifndef WindowsStore - } -#endif + MultiByteToWideChar(CP_UTF8, 0, strFile, -1, fileName16, PATHLIMIT); + std::string mode8(strMode); + std::wstring mode16(mode8.begin(), mode8.end()); + file = ::_wfopen(fileName16, mode16.c_str()); #else file = ::fopen(strFile, strMode); #endif if (nullptr == file) return nullptr; - return new DefaultIOStream(file, (std::string) strFile); + return new DefaultIOStream(file, strFile); } // ------------------------------------------------------------------------------------------------ @@ -167,44 +145,26 @@ inline static void MakeAbsolutePath (const char* in, char* _out) ai_assert(in && _out); #if defined( _MSC_VER ) || defined( __MINGW32__ ) #ifndef WindowsStore - bool isUnicode = IsTextUnicode(in, static_cast(strlen(in)), NULL) != 0; - if (isUnicode) { - wchar_t out16[PATHLIMIT]; - wchar_t in16[PATHLIMIT]; - MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, in, -1, out16, PATHLIMIT); - wchar_t* ret = ::_wfullpath(out16, in16, PATHLIMIT); - 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) - ASSIMP_LOG_WARN_F("Invalid path: ", std::string(in)); - strcpy(_out, in); - } - - } else { -#endif - 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) - ASSIMP_LOG_WARN_F("Invalid path: ", std::string(in)); - strcpy(_out, in); - } -#ifndef WindowsStore + wchar_t in16[PATHLIMIT]; + wchar_t out16[PATHLIMIT]; + MultiByteToWideChar(CP_UTF8, 0, in, -1, in16, PATHLIMIT); + wchar_t* ret = ::_wfullpath(out16, in16, PATHLIMIT); + if (ret) { + WideCharToMultiByte(CP_UTF8, 0, out16, -1, _out, PATHLIMIT, nullptr, nullptr); } +#else + char* ret = ::_fullpath(_out, in, PATHLIMIT); #endif #else // use realpath char* ret = realpath(in, _out); +#endif 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) ASSIMP_LOG_WARN_F("Invalid path: ", std::string(in)); strcpy(_out,in); } -#endif } // ------------------------------------------------------------------------------------------------ From 6c65b5b5496638c149907a605003f9a74f7bceb7 Mon Sep 17 00:00:00 2001 From: Ryan McCampbell Date: Tue, 9 Jul 2019 02:17:45 -0700 Subject: [PATCH 11/15] Cleaned up unicode code and removed fixed-size buffers --- code/Common/DefaultIOSystem.cpp | 74 ++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/code/Common/DefaultIOSystem.cpp b/code/Common/DefaultIOSystem.cpp index 7606d8ced..da7376809 100644 --- a/code/Common/DefaultIOSystem.cpp +++ b/code/Common/DefaultIOSystem.cpp @@ -61,12 +61,22 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; -// maximum path length -// XXX http://insanecoding.blogspot.com/2007/11/pathmax-simply-isnt.html -#ifdef PATH_MAX -# define PATHLIMIT PATH_MAX -#else -# define PATHLIMIT 4096 +#ifdef _WIN32 +static std::wstring Utf8ToWide(const char* in) +{ + int size = MultiByteToWideChar(CP_UTF8, 0, in, -1, nullptr, 0); + std::wstring out(size, L'\0'); + MultiByteToWideChar(CP_UTF8, 0, in, -1, &out[0], size); + return out; +} + +static std::string WideToUtf8(const wchar_t* in) +{ + int size = WideCharToMultiByte(CP_UTF8, 0, in, -1, nullptr, 0, nullptr, nullptr); + std::string out(size, '\0'); + WideCharToMultiByte(CP_UTF8, 0, in, -1, &out[0], size, nullptr, nullptr); + return out; +} #endif // ------------------------------------------------------------------------------------------------ @@ -74,11 +84,8 @@ using namespace Assimp; bool DefaultIOSystem::Exists( const char* pFile) const { #if defined(_WIN32) && !defined(WindowsStore) - wchar_t fileName16[PATHLIMIT]; - - MultiByteToWideChar(CP_UTF8, 0, pFile, -1, fileName16, PATHLIMIT); struct __stat64 filestat; - if (0 != _wstat64(fileName16, &filestat)) { + if (0 != _wstat64(Utf8ToWide(pFile).c_str(), &filestat)) { return false; } #else @@ -99,11 +106,7 @@ IOStream* DefaultIOSystem::Open( const char* strFile, const char* strMode) ai_assert(NULL != strMode); FILE* file; #if defined(_WIN32) && !defined(WindowsStore) - wchar_t fileName16[PATHLIMIT]; - MultiByteToWideChar(CP_UTF8, 0, strFile, -1, fileName16, PATHLIMIT); - std::string mode8(strMode); - std::wstring mode16(mode8.begin(), mode8.end()); - file = ::_wfopen(fileName16, mode16.c_str()); + file = ::_wfopen(Utf8ToWide(strFile).c_str(), Utf8ToWide(strMode).c_str()); #else file = ::fopen(strFile, strMode); #endif @@ -140,31 +143,39 @@ bool IOSystem::ComparePaths (const char* one, const char* second) const // ------------------------------------------------------------------------------------------------ // Convert a relative path into an absolute path -inline static void MakeAbsolutePath (const char* in, char* _out) +inline static std::string MakeAbsolutePath (const char* in) { - ai_assert(in && _out); -#if defined( _MSC_VER ) || defined( __MINGW32__ ) + ai_assert(in); + std::string out; +#ifdef _WIN32 #ifndef WindowsStore - wchar_t in16[PATHLIMIT]; - wchar_t out16[PATHLIMIT]; - MultiByteToWideChar(CP_UTF8, 0, in, -1, in16, PATHLIMIT); - wchar_t* ret = ::_wfullpath(out16, in16, PATHLIMIT); + wchar_t* ret = ::_wfullpath(nullptr, Utf8ToWide(in).c_str(), 0); if (ret) { - WideCharToMultiByte(CP_UTF8, 0, out16, -1, _out, PATHLIMIT, nullptr, nullptr); + out = WideToUtf8(ret); + free(ret); } #else - char* ret = ::_fullpath(_out, in, PATHLIMIT); + char* ret = ::_fullpath(nullptr, in, 0); + if (ret) { + out = ret; + free(ret); + } #endif #else // use realpath - char* ret = realpath(in, _out); + char* ret = realpath(in, nullptr); + if (ret) { + out = ret; + free(ret); + } #endif - if(!ret) { + 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) ASSIMP_LOG_WARN_F("Invalid path: ", std::string(in)); - strcpy(_out,in); + out = in; } + return out; } // ------------------------------------------------------------------------------------------------ @@ -176,11 +187,8 @@ bool DefaultIOSystem::ComparePaths (const char* one, const char* second) const if( !ASSIMP_stricmp(one,second) ) return true; - char temp1[PATHLIMIT]; - char temp2[PATHLIMIT]; - - MakeAbsolutePath (one, temp1); - MakeAbsolutePath (second, temp2); + std::string temp1 = MakeAbsolutePath(one); + std::string temp2 = MakeAbsolutePath(second); return !ASSIMP_stricmp(temp1,temp2); } @@ -213,5 +221,3 @@ std::string DefaultIOSystem::absolutePath( const std::string &path ) } // ------------------------------------------------------------------------------------------------ - -#undef PATHLIMIT From 0685e415ad6b32b23eef89315bd5658d9bf021c1 Mon Sep 17 00:00:00 2001 From: Ryan McCampbell Date: Mon, 19 Aug 2019 12:00:01 -0400 Subject: [PATCH 12/15] removed extra null character in Utf8ToWide and WideToUtf8 --- code/Common/DefaultIOSystem.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/code/Common/DefaultIOSystem.cpp b/code/Common/DefaultIOSystem.cpp index da7376809..7e26ec4b2 100644 --- a/code/Common/DefaultIOSystem.cpp +++ b/code/Common/DefaultIOSystem.cpp @@ -64,16 +64,18 @@ using namespace Assimp; #ifdef _WIN32 static std::wstring Utf8ToWide(const char* in) { - int size = MultiByteToWideChar(CP_UTF8, 0, in, -1, nullptr, 0); - std::wstring out(size, L'\0'); + size_t size = MultiByteToWideChar(CP_UTF8, 0, in, -1, nullptr, 0); + // size includes terminating null; std::wstring adds null automatically + std::wstring out(size - 1, L'\0'); MultiByteToWideChar(CP_UTF8, 0, in, -1, &out[0], size); return out; } static std::string WideToUtf8(const wchar_t* in) { - int size = WideCharToMultiByte(CP_UTF8, 0, in, -1, nullptr, 0, nullptr, nullptr); - std::string out(size, '\0'); + size_t size = WideCharToMultiByte(CP_UTF8, 0, in, -1, nullptr, 0, nullptr, nullptr); + // size includes terminating null; std::string adds null automatically + std::string out(size - 1, '\0'); WideCharToMultiByte(CP_UTF8, 0, in, -1, &out[0], size, nullptr, nullptr); return out; } From a8822a2b29514700202d586a5397481de93bcbd2 Mon Sep 17 00:00:00 2001 From: Ryan McCampbell Date: Mon, 19 Aug 2019 15:36:45 -0400 Subject: [PATCH 13/15] Cleaned up formatting in DefaultIOSystem.cpp --- code/Common/DefaultIOSystem.cpp | 40 ++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/code/Common/DefaultIOSystem.cpp b/code/Common/DefaultIOSystem.cpp index 7e26ec4b2..ce5996fa8 100644 --- a/code/Common/DefaultIOSystem.cpp +++ b/code/Common/DefaultIOSystem.cpp @@ -83,36 +83,36 @@ static std::string WideToUtf8(const wchar_t* in) // ------------------------------------------------------------------------------------------------ // Tests for the existence of a file at the given path. -bool DefaultIOSystem::Exists( const char* pFile) const +bool DefaultIOSystem::Exists(const char* pFile) const { #if defined(_WIN32) && !defined(WindowsStore) struct __stat64 filestat; - if (0 != _wstat64(Utf8ToWide(pFile).c_str(), &filestat)) { + if (_wstat64(Utf8ToWide(pFile).c_str(), &filestat) != 0) { return false; } #else - FILE* file = ::fopen( pFile, "rb"); - if( !file) + FILE* file = ::fopen(pFile, "rb"); + if (!file) return false; - ::fclose( file); + ::fclose(file); #endif return true; } // ------------------------------------------------------------------------------------------------ // Open a new file with a given path. -IOStream* DefaultIOSystem::Open( const char* strFile, const char* strMode) +IOStream* DefaultIOSystem::Open(const char* strFile, const char* strMode) { - ai_assert(NULL != strFile); - ai_assert(NULL != strMode); + ai_assert(strFile != nullptr); + ai_assert(strMode != nullptr); FILE* file; #if defined(_WIN32) && !defined(WindowsStore) file = ::_wfopen(Utf8ToWide(strFile).c_str(), Utf8ToWide(strMode).c_str()); #else file = ::fopen(strFile, strMode); #endif - if (nullptr == file) + if (!file) return nullptr; return new DefaultIOStream(file, strFile); @@ -120,7 +120,7 @@ IOStream* DefaultIOSystem::Open( const char* strFile, const char* strMode) // ------------------------------------------------------------------------------------------------ // Closes the given file and releases all resources associated with it. -void DefaultIOSystem::Close( IOStream* pFile) +void DefaultIOSystem::Close(IOStream* pFile) { delete pFile; } @@ -138,14 +138,14 @@ char DefaultIOSystem::getOsSeparator() const // ------------------------------------------------------------------------------------------------ // IOSystem default implementation (ComparePaths isn't a pure virtual function) -bool IOSystem::ComparePaths (const char* one, const char* second) const +bool IOSystem::ComparePaths(const char* one, const char* second) const { - return !ASSIMP_stricmp(one,second); + return !ASSIMP_stricmp(one, second); } // ------------------------------------------------------------------------------------------------ // Convert a relative path into an absolute path -inline static std::string MakeAbsolutePath (const char* in) +inline static std::string MakeAbsolutePath(const char* in) { ai_assert(in); std::string out; @@ -182,21 +182,21 @@ inline static std::string MakeAbsolutePath (const char* in) // ------------------------------------------------------------------------------------------------ // DefaultIOSystem's more specialized implementation -bool DefaultIOSystem::ComparePaths (const char* one, const char* second) const +bool DefaultIOSystem::ComparePaths(const char* one, const char* second) const { // chances are quite good both paths are formatted identically, // so we can hopefully return here already - if( !ASSIMP_stricmp(one,second) ) + if (!ASSIMP_stricmp(one, second)) return true; std::string temp1 = MakeAbsolutePath(one); std::string temp2 = MakeAbsolutePath(second); - return !ASSIMP_stricmp(temp1,temp2); + return !ASSIMP_stricmp(temp1, temp2); } // ------------------------------------------------------------------------------------------------ -std::string DefaultIOSystem::fileName( const std::string &path ) +std::string DefaultIOSystem::fileName(const std::string& path) { std::string ret = path; std::size_t last = ret.find_last_of("\\/"); @@ -205,16 +205,16 @@ std::string DefaultIOSystem::fileName( const std::string &path ) } // ------------------------------------------------------------------------------------------------ -std::string DefaultIOSystem::completeBaseName( const std::string &path ) +std::string DefaultIOSystem::completeBaseName(const std::string& path) { std::string ret = fileName(path); std::size_t pos = ret.find_last_of('.'); - if(pos != ret.npos) ret = ret.substr(0, pos); + if (pos != std::string::npos) ret = ret.substr(0, pos); return ret; } // ------------------------------------------------------------------------------------------------ -std::string DefaultIOSystem::absolutePath( const std::string &path ) +std::string DefaultIOSystem::absolutePath(const std::string& path) { std::string ret = path; std::size_t last = ret.find_last_of("\\/"); From a16906686f498cf4360c54ce41ef7838b1fecc84 Mon Sep 17 00:00:00 2001 From: Ryan McCampbell Date: Tue, 3 Sep 2019 21:06:48 -0400 Subject: [PATCH 14/15] Fixed type conversion warnings --- code/Common/DefaultIOSystem.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/Common/DefaultIOSystem.cpp b/code/Common/DefaultIOSystem.cpp index ce5996fa8..c0d356689 100644 --- a/code/Common/DefaultIOSystem.cpp +++ b/code/Common/DefaultIOSystem.cpp @@ -64,18 +64,18 @@ using namespace Assimp; #ifdef _WIN32 static std::wstring Utf8ToWide(const char* in) { - size_t size = MultiByteToWideChar(CP_UTF8, 0, in, -1, nullptr, 0); + int size = MultiByteToWideChar(CP_UTF8, 0, in, -1, nullptr, 0); // size includes terminating null; std::wstring adds null automatically - std::wstring out(size - 1, L'\0'); + std::wstring out(static_cast(size) - 1, L'\0'); MultiByteToWideChar(CP_UTF8, 0, in, -1, &out[0], size); return out; } static std::string WideToUtf8(const wchar_t* in) { - size_t size = WideCharToMultiByte(CP_UTF8, 0, in, -1, nullptr, 0, nullptr, nullptr); + int size = WideCharToMultiByte(CP_UTF8, 0, in, -1, nullptr, 0, nullptr, nullptr); // size includes terminating null; std::string adds null automatically - std::string out(size - 1, '\0'); + std::string out(static_cast(size) - 1, '\0'); WideCharToMultiByte(CP_UTF8, 0, in, -1, &out[0], size, nullptr, nullptr); return out; } From eb762e654eb73bf31220f1879d74254fb9332803 Mon Sep 17 00:00:00 2001 From: Ryan McCampbell Date: Tue, 3 Sep 2019 23:13:44 -0400 Subject: [PATCH 15/15] Removed WindowsStore checks --- code/Common/DefaultIOSystem.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/code/Common/DefaultIOSystem.cpp b/code/Common/DefaultIOSystem.cpp index c0d356689..6fdc24dd8 100644 --- a/code/Common/DefaultIOSystem.cpp +++ b/code/Common/DefaultIOSystem.cpp @@ -85,7 +85,7 @@ static std::string WideToUtf8(const wchar_t* in) // Tests for the existence of a file at the given path. bool DefaultIOSystem::Exists(const char* pFile) const { -#if defined(_WIN32) && !defined(WindowsStore) +#ifdef _WIN32 struct __stat64 filestat; if (_wstat64(Utf8ToWide(pFile).c_str(), &filestat) != 0) { return false; @@ -107,7 +107,7 @@ IOStream* DefaultIOSystem::Open(const char* strFile, const char* strMode) ai_assert(strFile != nullptr); ai_assert(strMode != nullptr); FILE* file; -#if defined(_WIN32) && !defined(WindowsStore) +#ifdef _WIN32 file = ::_wfopen(Utf8ToWide(strFile).c_str(), Utf8ToWide(strMode).c_str()); #else file = ::fopen(strFile, strMode); @@ -150,21 +150,12 @@ inline static std::string MakeAbsolutePath(const char* in) ai_assert(in); std::string out; #ifdef _WIN32 -#ifndef WindowsStore wchar_t* ret = ::_wfullpath(nullptr, Utf8ToWide(in).c_str(), 0); if (ret) { out = WideToUtf8(ret); free(ret); } #else - char* ret = ::_fullpath(nullptr, in, 0); - if (ret) { - out = ret; - free(ret); - } -#endif -#else - // use realpath char* ret = realpath(in, nullptr); if (ret) { out = ret;