예제 #1
0
파일: a.c 프로젝트: franbienjan/same
void compareFiles(const char *name, int level,FILE *f){
    DIR *dir;
    struct dirent *ent;
	char path[1024]="";
	char t[ 512 ] = "";
	int len;

	struct stat b;


    if (!(dir = opendir(name))) return;
    if (!(ent = readdir(dir))) return;
    int i=0;
    do{
    	// if folder
        if (ent->d_type == DT_DIR){
            if(strcmp(ent->d_name,"chunkstempofolder")==0)continue;
			if(strcmp(ent->d_name,"..")==0) len = snprintf(path, sizeof(path)-1, "%s", name);
			else len = snprintf(path, sizeof(path)-1, "%s/%s", name, ent->d_name);
            path[len] = 0;

            if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) continue;
            compareFiles(path, level + 1,f);
        }
        //if file
        else{
        	len = snprintf(path, sizeof(path)-1, "%s", name);
        	//if(strcmp(ent->d_name,"a.c")!=0 && strcmp(ent->d_name,"a.out")!=0 && strcmp(ent->d_name,"sha1.c")!=0 && strcmp(ent->d_name,"sha1.h")!=0 && strcmp(ent->d_name,"out.txt")!=0 && strcmp(ent->d_name,"initFiles.txt")!=0) {
			strcpy(t,getLine(ent->d_name,f));
            printf("\n:%s/%s",path, ent->d_name);

			if(t!=NULL){
                char *sha;

                if(strstr(strrchr(ent->d_name, '.') , ".jpg")!=NULL || strstr(strrchr(ent->d_name, '.') , ".pdf")!=NULL || strstr(strrchr(ent->d_name, '.') , ".mkv")!=NULL || strstr(strrchr(ent->d_name, '.') , ".zip")!=NULL){
                    FILE *tempF, *jpgF;
                    char tempStr[strlen(path)+strlen(ent->d_name)+1];
                    char tempStr2[strlen(ent->d_name)+4];

                    strcpy(tempStr,path);
                    strcat(tempStr,"/");
                    strcat(tempStr,ent->d_name);
                    //printf("\n%s",tempStr);

                    jpgF=fopen(tempStr,"r");
                    strcat(tempStr,".txt");
                    tempF=fopen(tempStr,"w");

                    if(strstr(strrchr(ent->d_name, '.') , ".jpg")!=NULL) convertUTF8ToUnicode(jpgF, tempF,0);
                    while(!feof(jpgF)) convertUTF8ToUnicode(jpgF, tempF,1);
                    strcpy(tempStr2,ent->d_name);
                    strcat(tempStr2,".txt");
                    //strcat(t,getSha(path,tempStr2));
                    sha=getSha(path,tempStr2);
                    //printf("\n=====%s",getSha(path,tempStr2));
                    if(remove(tempStr)==0) /*printf("\nDeleted:%s",tempStr)*/;
                }else 

                sha=getSha(path,ent->d_name);//strcat(t, getSha(path,ent->d_name));

				if(strcmp(t,sha)!=0){
				char file[strlen(path)+strlen(ent->d_name)+1];

				// file path
				strcpy(file,path);
				strcat(file,"/");
                //strcat(file,"\"");
    			strcat(file,ent->d_name);
                //strcat(file,"\"");
    			strcpy(t, file);

    			strcat(t,"|");

    			// file hash
                strcat(t,sha);

				strcat(t,"|");

				// file size
				char buffer[18];
                //printf("\n%s is changed\n",file);

				sprintf(buffer, "%lu", getSize(file));
				strcat(t,buffer);
				strcat(t,"|");

                stat(file, &b);
				strftime(buffer, 100, "%m%d%Y-%H:%M:%S|", localtime(&b.st_ctime));
                //printf("\n%s\n",buffer);
				strcat(t,buffer);

				strftime(buffer, 100, "%m%d%Y-%H:%M:%S|", localtime(&b.st_mtime));
				strcat(t,buffer);

				strftime(buffer, 100, "%m%d%Y-%H:%M:%S", localtime(&b.st_atime));
				strcat(t,buffer);

				fprintf(file2, "%s\n",t);
				}
			}
        	//}	
        }

    } while (ent = readdir(dir));
    
    closedir(dir);
}
예제 #2
0
JsonObject JsonObject::selectChildNode(const string& node_path)
{
	return selectChildNode(convertUTF8ToUnicode(node_path));
}