[win32] Fixes cpp-tests/FileUtilsTest crash. (#17551)

This commit is contained in:
James Chen 2017-03-22 11:17:52 +08:00 committed by minggo
parent a493456770
commit 3bd09ae286
3 changed files with 6 additions and 17 deletions

View File

@ -35,7 +35,7 @@ void TestResolutionDirectories::onEnter()
std::string ret;
sharedFileUtils->purgeCachedEntries();
_defaultSearchPathArray = sharedFileUtils->getSearchPaths();
_defaultSearchPathArray = sharedFileUtils->getOriginalSearchPaths();
std::vector<std::string> searchPaths = _defaultSearchPathArray;
searchPaths.insert(searchPaths.begin(), "Misc");
sharedFileUtils->setSearchPaths(searchPaths);
@ -89,7 +89,7 @@ void TestSearchPath::onEnter()
std::string ret;
sharedFileUtils->purgeCachedEntries();
_defaultSearchPathArray = sharedFileUtils->getSearchPaths();
_defaultSearchPathArray = sharedFileUtils->getOriginalSearchPaths();
std::vector<std::string> searchPaths = _defaultSearchPathArray;
std::string writablePath = sharedFileUtils->getWritablePath();
std::string fileName = writablePath+"external.txt";
@ -139,7 +139,7 @@ void TestSearchPath::onEnter()
// Save old resource root path
std::string oldDefaultRootPath = sharedFileUtils->getDefaultResourceRootPath();
sharedFileUtils->setDefaultResourceRootPath("extensions");
sharedFileUtils->setDefaultResourceRootPath(oldDefaultRootPath + "extensions");
auto sp1 = Sprite::create("orange_edit.png");
sp1->setPosition(VisibleRect::center());
addChild(sp1);
@ -147,7 +147,7 @@ void TestSearchPath::onEnter()
// Recover resource root path
sharedFileUtils->setDefaultResourceRootPath(oldDefaultRootPath);
auto oldSearchPaths = sharedFileUtils->getSearchPaths();
auto oldSearchPaths = sharedFileUtils->getOriginalSearchPaths();
sharedFileUtils->addSearchPath("Images");
auto sp2 = Sprite::create("btn-about-normal.png");
sp2->setPosition(VisibleRect::center() + Vec2(0, -50));

View File

@ -952,7 +952,7 @@ void AudioPlayFileInWritablePath::onEnter()
std::string musicFile = "background.mp3";
std::string saveFilePath = writablePath + "background_in_writable_dir.mp3";
_oldSearchPaths = fileUtils->getSearchPaths();
_oldSearchPaths = fileUtils->getOriginalSearchPaths();
fileUtils->addSearchPath(writablePath, true);
if (!fileUtils->isFileExist(saveFilePath))

View File

@ -113,18 +113,7 @@ static int lua_cocos2dx_addSearchPath(lua_State* L)
#endif
std::string pathToSave = tolua_tostring(L, 1, "");
bool before = tolua_toboolean(L, 2, 0);
std::vector<std::string> searchPaths = FileUtils::getInstance()->getSearchPaths();
if (before)
{
searchPaths.insert(searchPaths.begin(), pathToSave);
}
else
{
searchPaths.push_back(pathToSave);
}
FileUtils::getInstance()->setSearchPaths(searchPaths);
FileUtils::getInstance()->addSearchPath(pathToSave, before);
return 0;
}
CCLOG("'addSearchPath' function wrong number of arguments: %d, was expecting %d\n", argc, 2);