当前位置: 首页>>代码示例>>C++>>正文


C++ CCFileUtils::getWritablePath方法代码示例

本文整理汇总了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
}
开发者ID:DPigpen,项目名称:cocos2dx_recipe,代码行数:31,代码来源:Recipe76.cpp

示例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);
}
开发者ID:doanhtdpl,项目名称:game-larva-ver2,代码行数:11,代码来源:User.cpp

示例3:

XFileAssist::XFileAssist()
{
    CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
    
    std::string strWritePath = pFileUtils->getWritablePath();
    
    std::vector<std::string> pathTable;
    
    pathTable.push_back(strWritePath);
    
    pFileUtils->setSearchPaths(pathTable);
}
开发者ID:StevenFm,项目名称:bbt,代码行数:12,代码来源:FileAssist.cpp

示例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);
}
开发者ID:StevenFm,项目名称:bbt,代码行数:12,代码来源:FileAssist.cpp

示例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);
        }
    }
}
开发者ID:PavolSatala,项目名称:cocos2d-x,代码行数:52,代码来源:FileUtilsTest.cpp

示例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);

}
开发者ID:axierjhtjz,项目名称:Jakina-mobile,代码行数:23,代码来源:SQLHelper.cpp


注:本文中的CCFileUtils::getWritablePath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。