diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp index b17fa67ea3..0b55e3d9bf 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp @@ -37,7 +37,6 @@ THE SOFTWARE. #include "editor-support/cocostudio/CSParseBinary_generated.h" #include "flatbuffers/flatbuffers.h" -#include "flatbuffers/util.h" #include "editor-support/cocostudio/FlatBuffersSerialize.h" diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp index e4395820cf..6e1c1fd4d2 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp @@ -86,7 +86,6 @@ #include "editor-support/cocostudio/CCComExtensionData.h" #include "flatbuffers/flatbuffers.h" -#include "flatbuffers/util.h" #include "editor-support/cocostudio/FlatBuffersSerialize.h" diff --git a/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp b/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp index 1590c6ca86..4f9517f6f5 100644 --- a/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp +++ b/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp @@ -62,9 +62,6 @@ #include "editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldExReader.h" #include "flatbuffers/flatbuffers.h" -#include "flatbuffers/util.h" - - USING_NS_CC; using namespace cocos2d::ui; @@ -328,10 +325,9 @@ std::string FlatBuffersSerialize::serializeFlatBuffersWithOpaque(void* opaque, std::string outFullPath = FileUtils::getInstance()->fullPathForFilename(flatbuffersFileName); size_t pos = outFullPath.find_last_of('.'); std::string convert = outFullPath.substr(0, pos).append(".csb"); - auto save = flatbuffers::SaveFile(convert.c_str(), - reinterpret_cast(thiz->_builder->GetBufferPointer()), + auto save = FileUtils::writeBinaryToFile(thiz->_builder->GetBufferPointer(), thiz->_builder->GetSize(), - true); + convert); if (!save) { return "couldn't save files!"; @@ -1668,10 +1664,8 @@ std::string FlatBuffersSerialize::serializeFlatBuffersWithXMLFileForLanguageData auto langSet = CreateLanguageSet(*_builder, _builder->CreateVector(langItemList)); _builder->Finish(langSet); - bool isSuccess = flatbuffers::SaveFile(flatBuffersFilePath.c_str(), - reinterpret_cast(_builder->GetBufferPointer()), - _builder->GetSize(), - true); + bool isSuccess = FileUtils::writeBinaryToFile(_builder->GetBufferPointer(), + _builder->GetSize(), flatBuffersFilePath); if (isSuccess) return ""; diff --git a/cocos/platform/CCFileUtils.cpp b/cocos/platform/CCFileUtils.cpp index dc6290ebf0..3304521638 100644 --- a/cocos/platform/CCFileUtils.cpp +++ b/cocos/platform/CCFileUtils.cpp @@ -497,27 +497,7 @@ void FileUtils::writeStringToFile(std::string dataStr, const std::string& fullPa bool FileUtils::writeDataToFile(const Data& data, const std::string& fullPath) const { - size_t size = 0; - const char* mode = "wb"; - - CCASSERT(!fullPath.empty() && data.getSize() != 0, "Invalid parameters."); - - auto fileutils = FileUtils::getInstance(); - do - { - // Read the file from hardware - FILE *fp = fopen(fullPath.c_str(), mode); - CC_BREAK_IF(!fp); - size = data.getSize(); - - fwrite(data.getBytes(), size, 1, fp); - - fclose(fp); - - return true; - } while (0); - - return false; + return FileUtils::writeBinaryToFile(data.getBytes(), data.getSize(), fullPath); } void FileUtils::writeDataToFile(Data data, const std::string& fullPath, std::function callback) const @@ -527,6 +507,28 @@ void FileUtils::writeDataToFile(Data data, const std::string& fullPath, std::fun }, std::move(callback), std::move(data)); } +bool FileUtils::writeBinaryToFile(const void* data, size_t dataSize, const std::string& fullPath) +{ + const char* mode = "wb"; + + CCASSERT(!fullPath.empty() && dataSize > 0, "Invalid parameters."); + + auto fileutils = FileUtils::getInstance(); + do + { + // Read the file from hardware + FILE* fp = fopen(fullPath.c_str(), mode); + CC_BREAK_IF(!fp); + fwrite(data, dataSize, 1, fp); + + fclose(fp); + + return true; + } while (0); + + return false; +} + bool FileUtils::init() { DECLARE_GUARD; diff --git a/cocos/platform/CCFileUtils.h b/cocos/platform/CCFileUtils.h index 799d798437..80ea4d6f1d 100644 --- a/cocos/platform/CCFileUtils.h +++ b/cocos/platform/CCFileUtils.h @@ -542,6 +542,11 @@ public: *@return bool */ virtual bool writeDataToFile(const Data& data, const std::string& fullPath) const; + + /** + * save data to file + */ + static bool writeBinaryToFile(const void* data, size_t dataSize, const std::string& fullPath); /** diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index cbabb94767..5c40d70ff6 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -432,3 +432,13 @@ if(WINDOWS) set_target_properties(${APP_NAME} PROPERTIES COMPILE_FLAGS "/Yuprecheader.h /FIprecheader.h") set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/Classes/precheader.cpp" PROPERTIES COMPILE_FLAGS "/Ycprecheader.h") endif() + +if(WIN32) + add_custom_command(TARGET ${APP_NAME} + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${COCOS2DX_ROOT_PATH}/external/angle/prebuilt/win32/libGLESv2.dll + ${COCOS2DX_ROOT_PATH}/external/angle/prebuilt/win32/libEGL.dll + ${COCOS2DX_ROOT_PATH}/external/angle/prebuilt/win32/d3dcompiler_47.dll + $ + ) +endif()