本文整理汇总了C++中CCFileUtils::getWritablePath方法的典型用法代码示例。如果您正苦于以下问题:C++ CCFileUtils::getWritablePath方法的具体用法?C++ CCFileUtils::getWritablePath怎么用?C++ CCFileUtils::getWritablePath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCFileUtils
的用法示例。
在下文中一共展示了CCFileUtils::getWritablePath方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CCMessageBox
void Recipe76::doStep2()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
CCMessageBox("iOS Only", "RecipeBook");
return;
#else
std::string zipFilename = "archive.zip";
CCFileUtils* fileUtils = CCFileUtils::sharedFileUtils();
// フルパスを取得
std::string fullPath = fileUtils->fullPathForFilename(zipFilename.c_str());
// 書き込み可能なディレクトリを取得
std::string path = fileUtils->getWritablePath();
std::string unzipdPath = path + "unzipd/";
// zipの展開
unzipFileToDir(fullPath.c_str(), unzipdPath.c_str());
// 展開したzip中のテキストファイル取得
std::string txtPath = unzipdPath + "test-step2.txt";
unsigned long size;
unsigned char* data = fileUtils->getFileData(txtPath.c_str(), "rb", &size);
std::string text;
if (data != NULL) {
text.assign((const char*)data, size);
delete [] data;
}
CCString *msg = CCString::createWithFormat("read from zip file'%s'", text.c_str());
CCLabelTTF *label = (CCLabelTTF*)this->getChildByTag(10);
label->setString(msg->getCString());
#endif
}
示例2: Save
void User::Save()
{
CCFileUtils* fileUtils = CCFileUtils::sharedFileUtils();
bugsCatched->writeToFile("BugsCatched.plist");
item->writeToFile("Item.plist");
string writablePath = fileUtils->getWritablePath() + "User.txt";
FILE *fp = fopen(writablePath.c_str(), "w");
string data = name + "\n" + ConvertInt(score) + "\n" + ConvertInt(level);
fputs(data.c_str(), fp);
fclose(fp);
}
示例3:
XFileAssist::XFileAssist()
{
CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
std::string strWritePath = pFileUtils->getWritablePath();
std::vector<std::string> pathTable;
pathTable.push_back(strWritePath);
pFileUtils->setSearchPaths(pathTable);
}
示例4: WriteFileData
BOOL XFileAssist::WriteFileData(const char szFileName[], const void* pvData, size_t uDataLen)
{
CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
std::string strWritePath = pFileUtils->getWritablePath();
strWritePath.push_back(DIR_SPRIT);
strWritePath += szFileName;
return XFileHelper::WriteFileData(strWritePath.c_str(), pvData, uDataLen);
}
示例5: onEnter
void TestSearchPath::onEnter()
{
FileUtilsDemo::onEnter();
CCFileUtils *sharedFileUtils = CCFileUtils::sharedFileUtils();
string ret;
sharedFileUtils->purgeCachedEntries();
m_defaultSearchPathArray = sharedFileUtils->getSearchPaths();
vector<string> searchPaths = m_defaultSearchPathArray;
string writablePath = sharedFileUtils->getWritablePath();
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->setSearchPaths(searchPaths);
m_defaultResolutionsOrderArray = sharedFileUtils->getSearchResolutionsOrder();
vector<string> resolutionsOrder = m_defaultResolutionsOrderArray;
resolutionsOrder.insert(resolutionsOrder.begin(), "resources-ipad");
sharedFileUtils->setSearchResolutionsOrder(resolutionsOrder);
for( int i=1; i<3; i++) {
CCString *filename = CCString::createWithFormat("file%d.txt", i);
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);
}
}
}
示例6: init
void SQLHelper::init()
{
int result;
//Check database if exist
CCFileUtils *fileUtils = CCFileUtils::sharedFileUtils();
_dbPath = fileUtils->getWritablePath();
_dbPath.append("TrivialJokoa.db");
std::ifstream f(_dbPath.c_str());
if(!f)
{
//Database not exist
result = sqlite3_open(_dbPath.c_str(),&_db);
createDB();
} else {
CCLOG("DB EXIST");
result = sqlite3_open(_dbPath.c_str(),&_db);
}
if (result != SQLITE_OK)
CCLOG("OPENING WRONG, %d", result);
}