示例#1
0
文件: KFile.cpp 项目: korman/Temp
int KFile::getAllFileData(char* pFileKData)
{
	int iRead = 0;
	long fileLen = getFileLen();
	seekTo(0, KFILE_BEGIN);
	while (iRead < fileLen)
	{
		int iReaded = 0;
		if ((iReaded = read((unsigned char*) pFileKData + iRead, 2048)) > 0)
		{
			iRead += iReaded;
		}
		else
		{
			break;
		}
	}
	if (iRead != fileLen)
	{
		delete[] pFileKData;
		return -1;
	}
	else
	{
		return fileLen;
	}
}
示例#2
0
/*
** ASE_Load
*/
void ASE_Loader::ASE_Load( const char *filename, bool verbose)
{
	FILE *fp = fopen( filename, "rb" );
        
	if ( !fp )
		LOGE( ("File not found '%s'", filename) );

	memset( &ase, 0, sizeof( ase ) );
	ase.len = getFileLen( fp );

	ase.curpos = ase.buffer = new char[ase.len];

	LOGI( "Processing '%s'\n", filename );

	if ( fread( ase.buffer, ase.len, 1, fp ) != 1 )
	{
		fclose( fp );
		LOGE( "fread() != -1 for '%s'", filename );
	}

	fclose( fp );

	ASE_Process();
}
std::unordered_map<std::string, ModuleManifest::AssetDiff> ModuleManifest::genDiff()
{
    std::unordered_map<std::string, AssetDiff> diff_map;
    
    std::string key;
    Asset valueA;
    std::unordered_map<std::string, Asset>::const_iterator valueIt, it;
    
    int64_t diffLen = 0;
    for (it = _assets.begin(); it != _assets.end(); ++it)
    {
        key = it->first;
        valueA = it->second;
        
        if (valueA.compressed) {
            int64_t maxExistTime = 0;
            int64_t maxNoFileTime = 0;
            
            for (auto bit : valueA.content) {
                auto fLen = getFileLen(FileUtils::getInstance()->getWritablePath() + bit.second.path);
                if (fLen >= 0) {
                    auto fTime = getFileTime(FileUtils::getInstance()->getWritablePath() + bit.second.path);
                    if (fTime > maxExistTime) {
                        maxExistTime = fTime;
                    }
                }
                else {
                    auto fTime = bit.second.timestamp;
                    if (fTime > maxNoFileTime) {
                        maxNoFileTime = fTime;
                    }
                }
            }
            
            for (auto bit : valueA.content) {
                auto fLen = getFileLen(FileUtils::getInstance()->getWritablePath() + bit.second.path);
                if (fLen >= 0) {
                    if (fLen != bit.second.len) {
                        cocos2d::log("ModuleManifest::genDiff path: %s fTime: %lld bit.second.timestamp: %lld", bit.second.path.c_str(), getFileTime(FileUtils::getInstance()->getWritablePath() + bit.second.path) + 60, bit.second.timestamp);
                        auto fTime = getFileTime(FileUtils::getInstance()->getWritablePath() + bit.second.path) + 60;
                        if (fTime < bit.second.timestamp) {
                            AssetDiff diff;
                            diff.asset = valueA;
                            diff.type = DiffType::MODIFIED;
                            diff_map.emplace(key, diff);
                            diffLen += valueA.len;
                            break;
                        }
                    }
                }
                else {
                    cocos2d::log("ModuleManifest::genDiff path: %s file not exist bit.second.timestamp: %lld maxNoFileTime %lld maxExistTime %lld", bit.second.path.c_str(), bit.second.timestamp, maxNoFileTime, maxExistTime);
                    if (maxNoFileTime > maxExistTime) {
                        AssetDiff diff;
                        diff.asset = valueA;
                        diff.type = DiffType::MODIFIED;
                        diff_map.emplace(key, diff);
                        diffLen += valueA.len;
                        break;
                    }
                }
            }
        }
        else {
            auto fLen = getFileLen(FileUtils::getInstance()->getWritablePath() + valueA.path);
            if (fLen != valueA.len) {
                cocos2d::log("ModuleManifest::genDiff path: %s fTime: %lld valueA.timestamp: %lld", valueA.path.c_str(), getFileTime(FileUtils::getInstance()->getWritablePath() + valueA.path) + 60, valueA.timestamp);
                auto fTime = getFileTime(FileUtils::getInstance()->getWritablePath() + valueA.path) + 60;
                if (fTime < valueA.timestamp) {
                    AssetDiff diff;
                    diff.asset = valueA;
                    diff.type = DiffType::MODIFIED;
                    diff_map.emplace(key, diff);
                    diffLen += valueA.len;
                }
            }
        }
    }
    
    CCLOG("ModuleManifest::genDiff diff_map");
    for (auto it : diff_map) {
        CCLOG("ModuleManifest::genDiff %s", it.first.c_str());
    }
    
    setDiffLength(diffLen);
    return diff_map;
}
示例#4
0
int main(){
	FILE* fp;
	fp=fopen("send.jpg","rb+");
	//这里先定死了
	sendLoc = '0';
	int iResult = 0;
	int ConnectSocket = 0;
struct hostent *host;
	//初始化套接字 
	
	//puts("1");
	//创建Socket,使用TCP协议
   ConnectSocket = socket(AF_INET, SOCK_STREAM, 0);
   if (ConnectSocket == -1)
   {
        perror("socket创建出错!");
        return -1;
   }
   //puts("2");
   //构建服务器地址信息
   struct sockaddr_in saServer; //地址信息 
   saServer.sin_family = AF_INET; //地址家族
   saServer.sin_port = htons(SERVER_PORT); //注意转化为网络节序
   saServer.sin_addr.s_addr = inet_addr(SERVER_IP);
   //saServer.sin_addr = *((struct in_addr *)host->h_addr);
   //puts("3");
   //连接服务器,直到成功
   while(1){
		iResult = connect(ConnectSocket, (struct sockaddr *)&saServer, sizeof(saServer));
   		if (iResult == -1) 
   		{	
   			close(ConnectSocket);
			ConnectSocket = -1;
			continue;
		}
		break;
   }

   //发送位置
   iResult = send(ConnectSocket, &sendLoc, 1, 0);
   if (iResult == -1) {
        perror("send位置出错!");
        close(ConnectSocket);
        return -1;
    } 
   
   //发送文件大小
   sendLength =  getFileLen(fp); 
   iResult = send(ConnectSocket, (char*)(&sendLength), sizeof(sendLength), 0);
   if (iResult == -1) {
        perror("send大小出错!");
        close(ConnectSocket);
        return -1;
    } 
    
    //发送文件,如果发送失败就重新发送! 
    int i;
	for (i=sendLength; i > 0 ; )
	{
		if (i <= PER)
		{
			fread(sendJPG, i, 1, fp);
			iResult = send(ConnectSocket, sendJPG , i, 0);
			//如果这段发送失败则重新发送 
			if (iResult == -1) {
        		perror("send文件出错!");
        		printf("i=%d\n",i); 
    		}
			else {
				i = 0;
			} 
		}
		else{
			fread(sendJPG,PER,1,fp);
			iResult = send(ConnectSocket, sendJPG , PER, 0);
			//如果这段发送失败则重新发送 
			if (iResult == -1) {
        		perror("send文件出错!");
        		printf("i=%d\n",i); 
    		}
			else {
				i -= PER;
			} 
		}
	}
	puts("发送图片成功!");
	
   	
	//接收数据
	iResult = recv(ConnectSocket, (char*)&data, sizeof(data), 0);
	if (iResult > 0) 
	{ 
		//情况1:成功接收到数据
		printf("番数=%d\n",data.fan);
		for(i=0;i<data.num;i++){
			printf("%d ",data.fanXing[i]);
		}
        puts("");
 
    } 
	else if (iResult == 0) 
	{
		//情况2:连接关闭
        printf("Connection closed...\n");
		return 0; 
	}
    else 
	{ 
		//情况3:接收发生错误
		perror("recv文件出错!"); 
        return 0; 
    }
	
   	
	//结束处理
	// 关闭套接字
    close(ConnectSocket);
	// 释放资源
    
    return 0; 
}