| 45 | } |
| 46 | |
| 47 | unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize) |
| 48 | { |
| 49 | unsigned char * pBuffer = NULL; |
| 50 | CCAssert(pszFileName != NULL && pSize != NULL && pszMode != NULL, "Invalid parameters."); |
| 51 | *pSize = 0; |
| 52 | do |
| 53 | { |
| 54 | // read the file from hardware |
| 55 | std::string fullPath = fullPathForFilename(pszFileName); |
| 56 | FILE *fp = fopen(fullPath.c_str(), pszMode); |
| 57 | CC_BREAK_IF(!fp); |
| 58 | |
| 59 | fseek(fp,0,SEEK_END); |
| 60 | *pSize = ftell(fp); |
| 61 | fseek(fp,0,SEEK_SET); |
| 62 | pBuffer = new unsigned char[*pSize]; |
| 63 | *pSize = fread(pBuffer,sizeof(unsigned char), *pSize,fp); |
| 64 | fclose(fp); |
| 65 | } while (0); |
| 66 | |
| 67 | if (! pBuffer) |
| 68 | { |
| 69 | std::string msg = "Get data from file("; |
| 70 | msg.append(pszFileName).append(") failed!"); |
| 71 | |
| 72 | CCLOG("%s", msg.c_str()); |
| 73 | } |
| 74 | return pBuffer; |
| 75 | } |
| 76 | |
| 77 | unsigned char* CCFileUtils::getFileDataFromZip(const char* pszZipFilePath, const char* pszFileName, unsigned long * pSize) |
| 78 | { |