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


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

本文整理汇总了C++中CCFileUtils::getWriteablePath方法的典型用法代码示例。如果您正苦于以下问题:C++ CCFileUtils::getWriteablePath方法的具体用法?C++ CCFileUtils::getWriteablePath怎么用?C++ CCFileUtils::getWriteablePath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CCFileUtils的用法示例。


在下文中一共展示了CCFileUtils::getWriteablePath方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getDatabaseFilePath

NS_CC_PURCHASE_BEGIN

CCString* getDatabaseFilePath(CCString* prefix)
{
    CCFileUtils* pUtils = CCFileUtils::sharedFileUtils();
    const char* dbPath = prefix->length() == 0 ? DBPATH: CCString::createWithFormat("%s_%s", prefix->getCString(), DBPATH)->getCString();
    std::string documentsDir = pUtils->getWriteablePath();
    return CCString::createWithFormat("%s%s", documentsDir.c_str(), dbPath);
}
开发者ID:akehoyayoi,项目名称:cocos2dx-purchase,代码行数:9,代码来源:StoreDatabase.cpp

示例2: loadChunksFromZip

int CCLuaStack::loadChunksFromZip(lua_State *L)
{
    const char *zipFilename = lua_tostring(L, -1);
    CCFileUtils *utils = CCFileUtils::sharedFileUtils();
    string zipFilePath = utils->fullPathForFilename(zipFilename);
    
    lua_pop(L, 1);
    zipFilename = NULL;
    
    do
    {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
        string tmpFilePath = utils->getWriteablePath().append("cc_load_chunks.tmp");
        unsigned long size = 0;
        unsigned char *buffer = utils->getFileData(zipFilePath.c_str(), "rb", &size);
        bool success = false;
        do
        {
            if (size == 0 || !buffer)
            {
                CCLOG("CCLoadChunksFromZip() - read source file %s failure", zipFilePath.c_str());
                break;
            }
            
            FILE *tmp = fopen(tmpFilePath.c_str(), "wb");
            if (!tmp)
            {
                CCLOG("CCLoadChunksFromZip() - create tmp file %s failure", tmpFilePath.c_str());
                break;
            }
            
            success = fwrite(buffer, 1, size, tmp) > 0;
            fclose(tmp);
            
            if (success)
            {
                zipFilePath = tmpFilePath;
                CCLOG("CCLoadChunksFromZip() - copy zip file to %s ok", tmpFilePath.c_str());
            }
        } while (0);

        if (buffer)
        {
            delete []buffer;
        }

        if (!success)
        {
            lua_pushboolean(L, 0);
            break;
        }
#endif
        
        CCZipFile *zip = CCZipFile::create(zipFilePath.c_str());
        if (zip)
        {
            CCLOG("CCLoadChunksFromZip() - load zip file: %s", zipFilePath.c_str());
            lua_getglobal(L, "package");
            lua_getfield(L, -1, "preload");
            
            CCLOG("CCLoadChunksFromZip() - began");
            int count = 0;
            string filename = zip->getFirstFilename();
            while (filename.length())
            {
                unsigned long bufferSize = 0;
                unsigned char *buffer = zip->getFileData(filename.c_str(), &bufferSize);
                if (bufferSize)
                {
                    luaL_loadbuffer(L, (char*)buffer, bufferSize, filename.c_str());
                    lua_pushcclosure(L, &cc_lua_require, 1);
                    lua_setfield(L, -2, filename.c_str());
                    delete []buffer;
                    ++count;
                    // CCLOG("CCLoadChunksFromZip() - chunk %s", filename.c_str());
                }
                filename = zip->getNextFilename();
            }
            
            CCLOG("CCLoadChunksFromZip() - ended, chunks count %d", count);
            
            lua_pop(L, 2);
            lua_pushboolean(L, 1);
        }
        else
        {
            CCLOG("CCLoadChunksFromZip() - not found zip file: %s", zipFilePath.c_str());
            lua_pushboolean(L, 0);
        }
        
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
        unlink(tmpFilePath.c_str());
#endif
    } while (0);
    
    return 1;
}
开发者ID:ascetic85,项目名称:quick-cocos2d-x-20130509,代码行数:97,代码来源:CCLuaStack.cpp


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