博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
cocos2dx-2.x CCFileUtils文件管理类分析(4)
阅读量:4217 次
发布时间:2019-05-26

本文共 1888 字,大约阅读时间需要 6 分钟。

在3中,我们又分析了几个函数,在这一篇中我们继续分析其他一些函数。1、android平台unsigned char* CCFileUtilsAndroid::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize){        return doGetFileData(pszFileName, pszMode, pSize, false);}-->>//pszFileName 文件名//pszMode 读取模式,只有对绝对路径有用,参数就是C API的类型//pSize 读出的字节大小//forAsync 同步还是异步unsigned char* CCFileUtilsAndroid::doGetFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize, bool forAsync){    unsigned char * pData = 0;        if ((! pszFileName) || (! pszMode) || 0 == strlen(pszFileName))    {        return 0;    }        //先获取文件的全路径    string fullPath = fullPathForFilename(pszFileName);        if (fullPath[0] != '/')    {        //如果以"assets/"开头,即文件在安装包里,那么通过压缩文件类从压缩包中读取,	//其实android的安装包就是压缩包。        if (forAsync)        {            pData = s_pZipFile->getFileData(fullPath.c_str(), pSize, s_pZipFile->_dataThread);        }        else        {            pData = s_pZipFile->getFileData(fullPath.c_str(), pSize);        }    }    else    {        do        {   	     //如果是绝对路径,则通过C API读取。            // read rrom other path than user set it	        //CCLOG("GETTING FILE ABSOLUTE DATA: %s", pszFileName);            FILE *fp = fopen(fullPath.c_str(), pszMode);            CC_BREAK_IF(!fp);                        unsigned long size;            fseek(fp,0,SEEK_END);            size = ftell(fp);            fseek(fp,0,SEEK_SET);            pData = new unsigned char[size];            size = fread(pData,sizeof(unsigned char), size,fp);            fclose(fp);                        if (pSize)            {                *pSize = size;            }        } while (0);    }        if (! pData)    {        std::string msg = "Get data from file(";        msg.append(pszFileName).append(") failed!");        CCLOG("%s", msg.c_str());    }        return pData;}总结:到此为止,cocos2dx-2.X android平台的文件读出我已经通过源码的形式分析完了,做个记录,以防忘记。

转载地址:http://cxsmi.baihongyu.com/

你可能感兴趣的文章
STM32开源代码——光敏传感器
查看>>
STM32开源代码——UART串口程序
查看>>
个人项目——STM32接入机智云教程
查看>>
FreeRTOS学习笔记——FreeRTOS任务挂起和恢复实验
查看>>
人工智能学习笔记——案例实战信用卡欺诈检测(逻辑回归)
查看>>
FreeRTOS学习笔记——FreeRTOS 列表和列表项
查看>>
FreeRTOS学习笔记——任务壮态或信息查询与任务运行时间统计
查看>>
FreeRTOS学习笔记——FreeRTOS 系统内核控制函数
查看>>
FreeRTOS学习笔记——FreeRTOS 时间管理
查看>>
STemWin学习笔记——STemWin无操作系统移植
查看>>
STemWin学习笔记——在PC上仿真STemWin
查看>>
LwIP学习笔记——LwIP无操作系统移植
查看>>
LwIP学习笔记——RAW编程接口UDP实验
查看>>
STemWin学习笔记——文本显示
查看>>
STemWin学习笔记——数值显示
查看>>
STemWin学习笔记——2D绘图
查看>>
STemWin学习笔记——显示位图
查看>>
STemWin学习笔记——存储设备
查看>>
基于MATLAB/Simulink的电力电子电路仿真技术——Simulink仿真环境与模型库
查看>>
基于MATLAB/Simulink的电力电子电路仿真技术——Simulink仿真实践基础
查看>>