From 16ef70c069c58b7fc76b8b1ca2829e7e31c22572 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 28 Jan 2013 17:43:53 +0800 Subject: [PATCH] issue #1683: Updating FileUtilsTest.cpp. --- .../Classes/FileUtilsTest/FileUtilsTest.cpp | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.cpp b/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.cpp index a8c7a69038..17b485d27d 100644 --- a/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.cpp @@ -144,7 +144,7 @@ void TestResolutionDirectories::onEnter() sharedFileUtils->setSearchPath(searchPaths); m_defaultResolutionsOrderArray = sharedFileUtils->getSearchResolutionsOrder(); - vector resolutionsOrder = m_defaultSearchPathArray; + vector resolutionsOrder = m_defaultResolutionsOrderArray; resolutionsOrder.insert(resolutionsOrder.begin(), "resources-ipadhd"); resolutionsOrder.insert(resolutionsOrder.begin()+1, "resources-ipad"); @@ -194,11 +194,24 @@ void TestSearchPath::onEnter() sharedFileUtils->purgeCachedEntries(); m_defaultSearchPathArray = sharedFileUtils->getSearchPath(); vector searchPaths = m_defaultSearchPathArray; - searchPaths.insert(searchPaths.begin(), "Misc/searchpath1"); - searchPaths.insert(searchPaths.begin()+1, "Misc/searchpath2"); + string writablePath = sharedFileUtils->getWriteablePath(); + string fileName = writablePath+"external.txt"; + char szBuf[100] = "Hello Cocos2d-x!"; + FILE* fp = fopen(fileName.c_str(), "wb"); + if (fp) + { + fwrite(szBuf, 1, strlen(szBuf), fp); + fclose(fp); + CCLog("Writing file to writable path succeed."); + } + + searchPaths.insert(searchPaths.begin(), writablePath); + searchPaths.insert(searchPaths.begin()+1, "Misc/searchpath1"); + searchPaths.insert(searchPaths.begin()+2, "Misc/searchpath2"); sharedFileUtils->setSearchPath(searchPaths); + m_defaultResolutionsOrderArray = sharedFileUtils->getSearchResolutionsOrder(); - vector resolutionsOrder = m_defaultSearchPathArray; + vector resolutionsOrder = m_defaultResolutionsOrderArray; resolutionsOrder.insert(resolutionsOrder.begin(), "resources-ipad"); sharedFileUtils->setSearchResolutionsOrder(resolutionsOrder); @@ -208,6 +221,20 @@ void TestSearchPath::onEnter() ret = sharedFileUtils->fullPathForFilename(filename->getCString()); CCLog("%s -> %s", filename->getCString(), ret.c_str()); } + + // Gets external.txt from writable path + string fullPath = sharedFileUtils->fullPathForFilename("external.txt"); + CCLog("\nexternal file path = %s\n", fullPath.c_str()); + if (fullPath.length() > 0) { + fp = fopen(fullPath.c_str(), "rb"); + if (fp) + { + char szReadBuf[100] = {0}; + fread(szReadBuf, 1, strlen(szBuf), fp); + CCLog("The content of file from writable path: %s", szReadBuf); + fclose(fp); + } + } } void TestSearchPath::onExit()