tpl_doc *tpl_ctx_get_tpl_doc(tpl_ctx *t, const char *inpath) { char tpath[MAXPATHLEN] = { 0 }; int err; tpl_doc *tdoc = NULL; tpl_doc *ndoc; tpl_doc *mdoc; const char *ext = NULL; char pext[MAXPATHLEN] = { 0 }; const char *next = NULL; int off = 0; ext = getext(inpath); if(ext == NULL) { seterrmsg(t, "File path has no extensions"); return NULL; } do { if(next != NULL) { if(strcmp(next, pext) != 0) off = 0; ext = next; } err = get_tpl_path(t, ext, tpath, &off); if(err) { if(tdoc != NULL) return tdoc; seterrmsg(t, "Did not find template for file extension '%s'", ext); return NULL; } ndoc = tpl_doc_parse(t, tpath); if(ndoc == NULL) { seterrmsg(t, "Failed to parse template file '%s': %s", tpath, tpl_ctx_error(t)); return NULL; } if(tdoc == NULL) tdoc = ndoc; else { mdoc = tpl_doc_merge(ndoc, tdoc); strncpy(pext, ext, sizeof(pext)); tpl_doc_destroy(tdoc); tpl_doc_destroy(ndoc); tdoc = mdoc; } } while((next = tpl_doc_get_definition(tdoc, "-template")) != NULL); return tdoc; }
long CDownload::retrieveLocalFile(const MYCHAR* _url,int _order,MyString& _path, MyString& _short) { MyString url = _url; MyString ext(getext(url)); if (!ext.CompareNoCase("zip")) { if (!retrieveZippedFile(url,_order,_path,_short)) { if (!unzipFile(url,url)) { // unzip failed... outputInfo("unzip failed (%s)\n",_url); return 0; } if (!retrieveZippedFile(url,_order,_path,_short)) { outputInfo("could not find zip (%s)\n",_url); return 0; } } } else { _path = url; _short = getfile(url); } FILE* f = fopen(_path.c_str(),"rb"); if (f) { /*int err =*/ fseek(f,0,SEEK_END); long size = ftell(f); fclose(f); return size; } else { outputInfo("could not find file (%s)\n",_url); ::showStatus("Failed to load %s",getfile(_url)); return 0; } }
void fileListSortBySize(){ int numberOfFiles = getNumberFilesInDirectory(); struct FileType files[numberOfFiles]; int index =0; struct dirent *dptr = NULL; DIR *dirp = opendir("."); printf("File_Type Size (Kb) File_Name\n"); writeToLog("File_Type Size (Kb) File_Name"); while(NULL != (dptr = readdir(dirp))){ struct FileType fileType; strcpy(fileType.file_name , dptr->d_name); strcpy(fileType.file_type , getext(dptr->d_name)); fileType.size = getFileSize(dptr ->d_name); files[index++] = fileType; } closedir(dirp); qsort(files, sizeof(files)/sizeof(files[0]), sizeof(files[0]), compareBySize ); printFileList(files, numberOfFiles); }
/* Open the next extension in a split sequence */ static void open_split(split_t *split) { int fd; int splitnum = split->total_bytes / split->max_bytes; mode_t perms = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; char *ext, *fname; ext = getext(split->format, splitnum); asprintf(&fname, "%s.%s", split->name, ext); free(ext); fd = open(fname, O_WRONLY | O_CREAT, perms); if (fd < 0) syscall_error(fname); split->currfd = fd; split->curr_bytes = 0; free(fname); }
int tpl_ctx_get_outpath(tpl_ctx *ctx, const char *inpath, char outpath[MAXPATHLEN]) { tpl_doc *t; char *outext; char *inext; t = tpl_ctx_get_tpl_doc(ctx, inpath); if(t == NULL) { seterrmsg(ctx, "Did not find templates for file '%s': %s", inpath, tpl_ctx_error(ctx)); return -1; } outext = tpl_doc_get_definition(t, "-output"); if(outext == NULL) { seterrmsg(ctx, "Template output file extension not defined for '%s'", inpath); return -1; } strncpy(outpath, inpath, MAXPATHLEN); inext = (char *)getext(outpath); strncpy(inext, outext, MAXPATHLEN - strlen(inpath)); return 0; }
bool CDownload::retrieveDistantFile(const char* _url,int _order,MyString& _path, MyString& _short) { MyString url; normalize(_url,url); MyString ext(getext(url.c_str())); bool bZip = !ext.CompareNoCase("zip"); bool bRet; if (bZip) { // essaie de rÈcupÈrer la version existante ? bRet = retrieveZippedFile(url.c_str(),_order,_path,_short); if (!bRet) { if (bTestOnly) return false; // essaie de downloader bRet = downloadHTTPFile(url.c_str(),_path); if (bRet) { if (!unzipFile(url.c_str(),_path.c_str())) { // unzip failed... outputInfo("unzip failed (%s)\n",getfile(url.c_str())); bRet=false; deleteFile(_path.c_str()); outputInfo("deleting file (%s) for recovery next time \n",getfile(_path.c_str())); } if (bRet) bRet = retrieveZippedFile(url.c_str(),_order,_path,_short); } } } else { // if (bUsePersistentPath) { // fichier distant non zip MyString dir; MyString local; dir = getPersistentDir(url.c_str()); createDirectory(dir.c_str()); local = dir.c_str(); local += ACTIVEGS_DIRECTORY_SEPARATOR; local += getfile(url.c_str()) ; // regarde si le fichier existe ? // QUID SI LE FICHIER EST CORROMPU ? FILE* f = fopen(local.c_str(),"rb"); if (f) { fclose(f); bRet=true; } else { // retŽlŽcharge le fichier if (bTestOnly) return false; bRet = GetFile(url.c_str(),local.c_str()); } if (bRet) _path = local; } /* else bRet = downloadHTTPFile(url.c_str(),_path); */ if (bRet) _short = getfile(_path.c_str()); } if (!bRet) { // showProgress(url.c_str(),-1); ::showStatus("Failed to download %s\n",getfile(url.c_str())); } return bRet; }