112 auto sharedFileUtils = FileUtils::getInstance();
116 sharedFileUtils->purgeCachedEntries();
119 std::string writablePath = sharedFileUtils->getWritablePath();
120 std::string fileName = writablePath+
"external.txt";
121 char szBuf[100] =
"Hello Cocos2d-x!";
122 FILE* fp = fopen(fileName.c_str(),
"wb");
125 size_t ret = fwrite(szBuf, 1, strlen(szBuf), fp);
126 CCASSERT(ret != 0,
"fwrite function returned zero value");
129 log(
"Writing file to writable path succeed.");
132 searchPaths.insert(searchPaths.begin(), writablePath);
133 searchPaths.insert(searchPaths.begin()+1,
"Misc/searchpath1");
134 searchPaths.insert(searchPaths.begin()+2,
"Misc/searchpath2");
135 sharedFileUtils->setSearchPaths(searchPaths);
140 resolutionsOrder.insert(resolutionsOrder.begin(),
"resources-ipad");
141 sharedFileUtils->setSearchResolutionsOrder(resolutionsOrder);
143 for(
int i=1; i<3; i++) {
144 auto filename = StringUtils::format(
"file%d.txt", i);
145 ret = sharedFileUtils->fullPathForFilename(filename);
146 log(
"%s -> %s", filename.c_str(), ret.c_str());
150 std::string fullPath = sharedFileUtils->fullPathForFilename(
"external.txt");
151 log(
"external file path = %s", fullPath.c_str());
152 if (fullPath.length() > 0)
154 fp = fopen(fullPath.c_str(),
"rb");
157 char szReadBuf[100] = {0};
158 size_t read = fread(szReadBuf, 1, strlen(szReadBuf), fp);
160 log(
"The content of file from writable path: %s", szReadBuf);
166#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)
169 std::string oldDefaultRootPath = sharedFileUtils->getDefaultResourceRootPath();
170 sharedFileUtils->setDefaultResourceRootPath(oldDefaultRootPath +
"extensions");
171 auto sp1 = Sprite::create(
"orange_edit.png");
176 sharedFileUtils->setDefaultResourceRootPath(oldDefaultRootPath);
178 auto oldSearchPaths = sharedFileUtils->getOriginalSearchPaths();
179 sharedFileUtils->addSearchPath(
"Images");
180 auto sp2 = Sprite::create(
"btn-about-normal.png");
185 sharedFileUtils->setSearchPaths(oldSearchPaths);
virtual void onEnter() override
std::vector< std::string > _defaultSearchPathArray
std::vector< std::string > _defaultResolutionsOrderArray
static cocos2d::Vec2 center()