/*** Adivinha o formato de arquivo de acordo com seu conteúdo ou extensão Guess file type from its data content or extension ***/ FILETYPE FileFormat::GuessType(QFile *fp) { for ( int tryes=0; tryes<2; tryes++ ) { if ( (!tryes && (fp->fileName().endsWith( ".cbr", Qt::CaseInsensitive ) || fp->fileName().endsWith( ".rar", Qt::CaseInsensitive )) ) || tryes ) { if ( IsRar(fp) ) return TYPE_RAR; fp->seek(0); } if ( ( !tryes && (fp->fileName().endsWith( ".cbz", Qt::CaseInsensitive ) || fp->fileName().endsWith( ".zip", Qt::CaseInsensitive )) ) || tryes ) { if ( IsZip(fp) ) return TYPE_ZIP; fp->seek(0); } if ( ( !tryes && (fp->fileName().endsWith( ".pdf", Qt::CaseInsensitive ))) || tryes ) { if ( IsPdf(fp) ) return TYPE_PDF; fp->seek(0); } //Para imagem levar em consideração apenas a extensão if ( ( !tryes && (fp->fileName().endsWith( ".png", Qt::CaseInsensitive ) || fp->fileName().endsWith( ".gif", Qt::CaseInsensitive ) || fp->fileName().endsWith( ".jpg", Qt::CaseInsensitive )) ) ) return TYPE_IMG; //File with wrong Extension } return TYPE_UNKNOWN; }
int IsArchve(const char * fullname) { if(IsTar(fullname)) return 1; if(IsZip(fullname)) return 1; if(IsRar(fullname)) return 1; if(IsDeb(fullname)) return 1; return 0; }
gchar * Untar(const char * name,const char * destdir) { ClassString archve = GetArchivePath(); const char mes[]="Не в архиве "; if(strncmp(name,archve.s,strlen(archve.s))) { printf("%s '%s' \n",mes,name); return 0; } struct stat file_stat; if(!lstat(name, &file_stat)) { if(S_ISLNK(file_stat.st_mode)) { return g_strdup(name); } } ClassString zip=g_strdup(&name[strlen(archve.s)]); ClassString inzip=g_strdup(zip.s); int inside=0; if(lstat(zip.s, &file_stat)) { inside=1; while(lstat(zip.s, &file_stat)) { zip=g_path_get_dirname(zip.s); } inzip=g_strdup(&inzip.s[strlen(zip.s)+1]); } else { printf("%s\n%s",mes,name); return 0; } ClassString cache=g_build_filename(PATH_CACHE_ARCHIVE,zip.s,NULL); CreateDirInDir(cache.s); ClassString com; const char * unpack_dir; if(!destdir) unpack_dir=cache.s; else unpack_dir=destdir; if(IsTar(zip.s)) { // ClassString base=g_path_get_dirname(inzip.s); // printf("`%s` base `%s`",inzip.s,base.s); // if(!strcmp(base.s,".")) // { // com=g_strdup_printf("cd '%s'; tar -x --file='%s' './%s'", unpack_dir,zip.s,inzip.s); // } else com=g_strdup_printf("cd '%s'; tar -x --file='%s' '%s'", unpack_dir,zip.s,inzip.s); Execute(com.s); } else if(IsDeb(zip.s)) { com=g_strdup_printf("cd '%s'; ar x '%s' '%s'", unpack_dir,zip.s,inzip.s); Execute(com.s); } else if(IsZip(zip.s)) { if(!lstat(name, &file_stat)) { if(S_ISDIR(file_stat.st_mode) ) com=g_strdup_printf("cd '%s'; unzip -o '%s' '%s/*'", unpack_dir, zip.s, inzip.s); else com=g_strdup_printf("cd '%s'; unzip -o '%s' '%s'", unpack_dir, zip.s, inzip.s); } Execute(com.s); } else if(IsRar(zip.s)) { if(inzip.s[0]=='*') { ClassString password=InputPassword(); printf("Треба пассворд <%s>\n",password.s); com=g_strdup_printf("cd '%s'; unrar -p'%s' x '%s' '%s'", unpack_dir,password.s,zip.s,&inzip.s[1]); printf("%s\n",com.s); } else com=g_strdup_printf("cd '%s'; unrar -p- x '%s' '%s'", unpack_dir,zip.s,inzip.s); Execute(com.s); } else return 0; cache=g_build_filename(unpack_dir,inzip.s,NULL); if(!destdir) { if(!lstat(cache.s, &file_stat)) { unlink(name); symlink(cache.s,name); return g_strdup(name); } else printf("file not create - '%s'\n",cache.s); } return g_strdup(cache.s); }
int main( int argc, char **argv ) { app_path=g_path_get_dirname(argv[0]); int operation=TASK_COPY; gtk_init( &argc, &argv ); ClassString uid=g_strdup_printf("%d",geteuid()); InitListDisk(g_get_home_dir(),uid.s); f=fopen("/tmp/billfm.txt","rt"); if(!f) { printf("Not open file /tmp/billfm.txt !\n"); exit(0); } NexString(); if(!strcmp(buffer,"MOVE")) { operation=TASK_MOVE; } else if(!strcmp(buffer,"COPY")) { operation=TASK_COPY; } else if(!strcmp(buffer,"CREATE_DIR")) { operation=TASK_CREATE_DIR; } else if(!strcmp(buffer,"CLEAR_TRASH")) { operation=TASK_CLEAR_TRASH; } else if(!strcmp(buffer,"FIND")) { operation=TASK_FIND; } else if(!strcmp(buffer,"SMB_MOUNT")) { operation=TASK_SMB_MOUNT; } else if(!strcmp(buffer,"READ_TAR")) { operation=TASK_READ_TAR; } else { printf("Operation unknow\n"); exit(0); } NexString(); DestDir=g_strdup(buffer); // printf("dest %s\n",PanelGetDestDir()); const char * dest_dir=PanelGetDestDir(); if(operation==TASK_COPY) { LoadList(); DialogCopy(operation, dest_dir,list_source); } else if(operation==TASK_MOVE) { LoadList(); DialogCopy(operation, dest_dir,list_source); } else if(operation==TASK_CREATE_DIR) { CreateNewDirDialog(dest_dir); } else if(operation==TASK_CLEAR_TRASH) { NexString(); const char * homedir =g_strdup(buffer); NexString(); const char * uid =g_strdup(buffer); InitListDisk(homedir,uid); UtilsClearTrash(); } else if(operation==TASK_FIND) { NexString(); const char * mask =g_strdup(buffer); NexString(); const char * text =g_strdup(buffer); NexString(); const char * mode =g_strdup(buffer); LoadSearch(mask,text,DestDir,mode); } else if(operation==TASK_SMB_MOUNT) { NexString(); const char * source =g_strdup(buffer); NexString(); const char * opt =g_strdup(buffer); if(!strcmp(opt,"rw")) opt=rw_opt; else opt=ro_opt; ClassString com=g_strdup_printf("mount -t cifs \"%s\" \"%s\" -o %s", source,DestDir,opt); printf("%s\n",com.s); system(com.s); } else if(operation==TASK_READ_TAR) { chdir(DestDir); NexString(); SourceTar =g_strdup(buffer); ClassString outfile=g_build_filename(DestDir,".dir.lst",NULL); if(IsTar(SourceTar)) { ClassString com=g_strdup_printf("tar -tvf '%s' > .dir.lst",SourceTar); system(com.s); LoadGets(outfile.s,PrintTar); } else if(IsZip(SourceTar)) { ClassString com=g_strdup_printf("unzip -l '%s' > .dir.lst",SourceTar); system(com.s); ClassString outfile=g_build_filename(DestDir,".dir.lst",NULL); CountReadStrings=0; LoadGets(outfile.s,PrintZip); } if(IsRar(SourceTar)) { ClassString com=g_strdup_printf("unrar vt '%s' > .dir.lst",SourceTar); system(com.s); ClassString outfile=g_build_filename(DestDir,".dir.lst",NULL); CountReadStrings=0; RarPassword=0; LoadGets(outfile.s,PrintRar); } if(IsDeb(SourceTar)) { ClassString com=g_strdup_printf("ar vt '%s' > .dir.lst",SourceTar); system(com.s); ClassString outfile=g_build_filename(DestDir,".dir.lst",NULL); CountReadStrings=0; RarPassword=0; LoadGets(outfile.s,PrintDeb); } } fclose(f); }