void UpdateManager::getDownloadInfo() { //string currentVersion,newVersion; //currentVersion=UpDateData::sharedInstance()->getVersion(); //newVersion=UpDateData::sharedInstance()->getNewVersion(); vector<VersionInfo> data; VersionInfo vi; UpDateData::sharedInstance()->getVersionDataVector(data); for(unsigned int i=0;i<data.size();++i) { vi=data[i]; CCLog("getDownloadInfo-------------------------------------------name is %s,path is %s",vi.getName(),vi.getPath()); if(getFileExtention(vi.getPath())==string("apk")) { downloadInfo.clear(); haveApk=true; #if(CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID) // Dependence::removeData(); #endif } downloadInfo.push_back(vi); } for(unsigned int i=0;i<downloadInfo.size();i++) { vi=downloadInfo[i]; CCLog("really download is %s",vi.getName()); } }
std::vector<std::string> VirusScan::findFiles(char devName) { std::vector<std::string> files; std::string dirPath; dirPath += devName; dirPath += ":\\"; for (boost::filesystem::recursive_directory_iterator end, dir(dirPath); dir != end; dir++) { std::string fileExt = getFileExtention(dir->path().filename().string()); boost::to_upper(fileExt); for (int i = 0; i < fTypesSz; i++) { if (fileExt.compare(fTypes[i]) == 0) { files.push_back(dir->path().string()); break; } } } return files; }
bool UpdateManager::uncompressFile(int index) { VersionInfo vi=downloadInfo[index]; CCLog("start to uncompressed name %s",vi.getName()); string outFileName=getFileFullName(vi.getPath()); if(getFileExtention(vi.getPath())==string("apk")) { haveApk=true; return true; } // Open the zip file unzFile zipfile = unzOpen(outFileName.c_str()); if (! zipfile) { CCLog("can not open downloaded zip file %s", outFileName.c_str()); return false; } // Get info about the zip file unz_global_info global_info; if (unzGetGlobalInfo(zipfile, &global_info) != UNZ_OK) { CCLog("can not read file global info of %s", outFileName.c_str()); unzClose(zipfile); return false; } // Buffer to hold data read from the zip file char readBuffer[BUFFER_SIZE]; CCLog("start uncompressing"); // Loop to extract all files. uLong i; for (i = 0; i < global_info.number_entry; ++i) { // Get info about current file. unz_file_info fileInfo; char fileName[MAX_FILENAME]; if (unzGetCurrentFileInfo(zipfile, &fileInfo, fileName, MAX_FILENAME, NULL, 0, NULL, 0) != UNZ_OK) { CCLog("can not read file info"); unzClose(zipfile); return false; } string fullPath = resourcesPath +"/"+ fileName; CCLog("uncompressed dir is %s",fullPath.c_str()); // Check if this entry is a directory or a file. const size_t filenameLength = strlen(fileName); if (fileName[filenameLength-1] == '/') { // Entry is a direcotry, so create it. // If the directory exists, it will failed scilently. if (!createDirectory(fullPath.c_str())) { CCLog("can not create directory %s", fullPath.c_str()); unzClose(zipfile); return false; } } else { // Entry is a file, so extract it. // Open current file. if (unzOpenCurrentFile(zipfile) != UNZ_OK) { CCLog("can not open file %s", fileName); unzClose(zipfile); return false; } // Create a file to store current file. FILE *out = fopen(fullPath.c_str(), "wb"); if (! out) { CCLog("can not open destination file %s", fullPath.c_str()); unzCloseCurrentFile(zipfile); unzClose(zipfile); return false; } // Write current file content to destinate file. int error = UNZ_OK; do { error = unzReadCurrentFile(zipfile, readBuffer, BUFFER_SIZE); if (error < 0) { CCLog("can not read zip file %s, error code is %d", fileName, error); unzCloseCurrentFile(zipfile); unzClose(zipfile); return false; } if (error > 0) { fwrite(readBuffer, error, 1, out); } } while(error > 0); fclose(out); } unzCloseCurrentFile(zipfile); // Goto next entry listed in the zip file. if ((i+1) < global_info.number_entry) { if (unzGoToNextFile(zipfile) != UNZ_OK) { CCLog("can not read next file"); unzClose(zipfile); return false; } } } CCLog("end uncompressing"); return true; }
bool UpdateManager::downloadFile(int index) { this->downloadIndex=index; VersionInfo vi=downloadInfo[index]; string filename=vi.getFullpath();//getFileFullName(vi.getPath()); createDirForFile(filename); long sourcesLength=vi.getFileLength(); int fileLength=getFileLength(filename); if(sourcesLength==fileLength) return true; CCLog("downloadFile name is %s,path is %s",vi.getName(),vi.getPath()); CCLog("filename is %s",filename.c_str()); FILE* f; if(fileLength&&getFileExtention(filename)==string("apk")) { f=fopen(filename.c_str(),"ab+"); } else { f=fopen(filename.c_str(),"wb"); } if(!f) { MessageInfo *networkerror=new MessageInfo(); networkerror->obj=this->protocol; networkerror->what=MessageInfo::CREATE_FILE_FAILED; this->helper->sendMessage(networkerror); CCLog("file pointer create failed"); return false; } CURLcode res; curl_easy_setopt(curl, CURLOPT_URL,vi.getPath()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeFile); //curl_easy_setopt(curl,CURLOPT_RESUME_FROM_LARGE,fileLength?fileLength:0); if(getFileExtention(filename)==string("apk")) { char temp[64]={0}; SPRINTF(temp,"%d-",fileLength); curl_easy_setopt(curl, CURLOPT_RANGE,temp); } curl_easy_setopt(curl, CURLOPT_WRITEDATA, f); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, false); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, assetsManagerProgressFunc); curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, this); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, timeOut); res = curl_easy_perform(curl); if (res != 0) { CCLog("error when download package"); fclose(f); MessageInfo *networkerror=new MessageInfo(); networkerror->obj=this->protocol; networkerror->what=MessageInfo::NET_WORK_ERROR; this->helper->sendMessage(networkerror); CCLog("downloadFile fialed network error"); return false; } CCLog("succeed downloading file %s",filename.c_str()); fclose(f); //发送消息,下载成功 MessageInfo *msg=new MessageInfo(); msg->what=MessageInfo::ONE_SUCCEED; msg->obj=this->protocol; msg->filename=string(vi.getName()); msg->md5=vi.getMd5(); msg->respath=vi.getRespath(); helper->sendMessage(msg); return true; }
int loadFileSub1(uint8 **ptr, const char *name, uint8 *ptr2) { int i; char buffer[256]; int fileIdx; int unpackedSize; uint8 *unpackedBuffer; for (i = 0; i < 64; i++) { if (preloadData[i].ptr) { if (!strcmp(preloadData[i].name, name)) { error("Unsupported code in loadFIleSub1"); } } } getFileExtention(name, buffer); if (!strcmp(buffer, ".SPL")) { removeExtention(name, buffer); /* if (useH32) *{ * strcat(buffer, ".H32"); *} * else * if (useAdLib) * { */ strcat(buffer,".ADL"); /* } * else * { * strcatuint8(buffer,".HP"); * } */ } else { strcpy(buffer, name); } fileIdx = findFileInDisks(buffer); if (fileIdx < 0) return (-18); unpackedSize = loadFileVar1 = volumePtrToFileDescriptor[fileIdx].extSize + 2; unpackedBuffer = (uint8 *)mallocAndZero(unpackedSize); if (!unpackedBuffer) { return (-2); } lastFileSize = unpackedSize; if (volumePtrToFileDescriptor[fileIdx].size + 2 != unpackedSize) { uint8 *pakedBuffer = (uint8 *) mallocAndZero(volumePtrToFileDescriptor[fileIdx].size + 2); loadPackedFileToMem(fileIdx, pakedBuffer); uint32 realUnpackedSize = READ_BE_UINT32(pakedBuffer + volumePtrToFileDescriptor[fileIdx].size - 4); lastFileSize = realUnpackedSize; delphineUnpack(unpackedBuffer, pakedBuffer, volumePtrToFileDescriptor[fileIdx].size); MemFree(pakedBuffer); } else { loadPackedFileToMem(fileIdx, unpackedBuffer); } *ptr = unpackedBuffer; return (1); }