void InstallLogger::LoadParamFile(const char* parameter_filename) { init_done = 0; ABSTRACTFILE *af_fin = af_fopen_unlogged((parameter_filename != NULL) ? parameter_filename : "unitex_logging_parameters.txt","rb"); if (af_fin!=NULL) { size_t size_param=0; if (af_fseek(af_fin, 0, SEEK_END) == 0) { size_param = af_ftell(af_fin); af_fseek(af_fin, 0, SEEK_SET); } char* param=(char*)malloc(size_param+1); *(param+size_param)=0; if (af_fread(param,1,size_param,af_fin) == size_param) { int write_file_out=0; char*szPath = (char*)malloc(size_param+1); *szPath=0; sscanf(param,"%s\n%u",szPath,&write_file_out); write_file_out+=0; if ((*szPath) != 0) { ClearUniLoggerSpaceStruct(0); ule.szPathLog = szPath; ule.szNameLog = NULL; ule.store_file_out_content = write_file_out; if (AddActivityLogger(&ule) != 0) init_done = 1; else { ClearUniLoggerSpaceStruct(1); } } else free(szPath); } af_fclose(af_fin); free(param); } }
/** * Write an Unitex file content (to system filesystem or filespace) * it write from two buffer (prefix and suffix). This is useful for writing both header and footer (or BOM and text...) */ UNITEX_FUNC int UNITEX_CALL WriteUnitexFile(const char*name,const void*buffer_prefix,size_t size_prefix,const void*buffer_suffix,size_t size_suffix) { ABSTRACTFILE* vfWrite = af_fopen(name, "wb"); if (vfWrite == NULL) { return 1; } int retValue = 0; if (size_prefix > 0) if (size_prefix != af_fwrite(buffer_prefix,1,size_prefix,vfWrite)) retValue = 1; if (retValue==0 && (size_suffix > 0)) if (size_suffix != af_fwrite(buffer_suffix,1,size_suffix,vfWrite)) retValue = 1; af_fclose(vfWrite); return retValue; }
static int do_extract_from_opened_pack_archive_currentfile( unzFile uf, const int* popt_extract_without_path, const char* prefix_extracting_name, int transform_path_separator, int quiet) { char filename_inzip[0x200]; char* filename_withoutpath; char* p; int err=UNZ_OK; ABSTRACTFILE *fout=NULL; void* buf; uInt size_buf; unz_file_info file_info; err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); if (err!=UNZ_OK) { error("error %d with zipfile in unzGetCurrentFileInfo\n",err); return err; } size_buf = UNPACK_WRITEBUFFERSIZE; buf = (void*)malloc(size_buf); if (buf==NULL) { error("Error allocating memory\n"); return UNZ_INTERNALERROR; } p = filename_withoutpath = filename_inzip; while ((*p) != '\0') { if (((*p)=='/') || ((*p)=='\\')) filename_withoutpath = p+1; p++; } if ((*filename_withoutpath)=='\0') { if ((*popt_extract_without_path)==0) { { size_t len_prefix = strlen(prefix_extracting_name); size_t len_directory_in_zip = strlen(filename_inzip); size_t total_len = len_prefix + len_directory_in_zip; char* provis_dir_name = NULL; if (len_directory_in_zip > 0) provis_dir_name = (char*)malloc(total_len + 2); if (provis_dir_name) { strcpy(provis_dir_name, prefix_extracting_name); strcpy(provis_dir_name + len_prefix, filename_inzip); transform_fileName_separator(provis_dir_name + len_prefix, transform_path_separator); if (quiet == 0) u_printf("creating directory: %s\n", provis_dir_name); mkDirPortable(provis_dir_name); free(provis_dir_name); } } } } else { char* previousPathCreated = NULL; const char* write_filename; int skip=0; if ((*popt_extract_without_path)==0) write_filename = filename_inzip; else write_filename = filename_withoutpath; err = unzOpenCurrentFile(uf); if (err!=UNZ_OK) { error("error %d with zipfile in unzOpenCurrentFilePassword\n",err); } if ((skip==0) && (err==UNZ_OK)) { char* provis_concat_name = NULL; if (prefix_extracting_name == NULL) prefix_extracting_name = ""; if (prefix_extracting_name != NULL) { size_t len_prefix = strlen(prefix_extracting_name); size_t total_len = len_prefix + strlen(write_filename); provis_concat_name = (char*)malloc(total_len+2); if (provis_concat_name != NULL) { strcpy(provis_concat_name,prefix_extracting_name); strcat(provis_concat_name,write_filename); transform_fileName_separator(provis_concat_name + len_prefix, transform_path_separator); } } const char* useFileName = (provis_concat_name != NULL) ? provis_concat_name : write_filename; if ((*popt_extract_without_path)==0) { char* newPathOnlyPortion = (char*)malloc(strlen(useFileName)+1); if (newPathOnlyPortion != NULL) { strcpy(newPathOnlyPortion,useFileName); removeNoPathPortionInFileName(newPathOnlyPortion); int can_skip_creating = 0; if (previousPathCreated != NULL) if (strcmp(previousPathCreated,newPathOnlyPortion) == 0) can_skip_creating = 1; if (can_skip_creating == 0) { if (quiet == 0) u_printf("Creating directory: %s\n",newPathOnlyPortion); mkDirPortable(newPathOnlyPortion); } if (previousPathCreated != NULL) free(previousPathCreated); previousPathCreated = newPathOnlyPortion; } } fout=af_fopen(useFileName,"wb"); if (quiet == 0) u_printf("extracting %s to %s...",filename_inzip,useFileName); if (fout==NULL) { error("error opening %s\n",useFileName); } if (provis_concat_name != NULL) free(provis_concat_name); /* some zipfile don't contain directory alone before file */ if ((fout==NULL) && ((*popt_extract_without_path)==0) && (filename_withoutpath!=(char*)filename_inzip)) { char c=*(filename_withoutpath-1); *(filename_withoutpath-1)='\0'; mkDirPortable(write_filename); *(filename_withoutpath-1)=c; fout=af_fopen(write_filename,"wb"); } if (quiet == 0) u_printf(" done\n"); } if (fout!=NULL) { af_setsizereservation(fout, (long)file_info.uncompressed_size); do { err = unzReadCurrentFile(uf,buf,(unsigned)size_buf); if (err<0) { error("error %d with zipfile in unzReadCurrentFile\n",err); break; } if (err>0) if (af_fwrite(buf,err,1,fout)!=1) { error("error in writing extracted file\n"); err=UNZ_ERRNO; break; } } while (err>0); if (fout) af_fclose(fout); /* if (err==0) change_file_date(write_filename,file_info.dosDate, file_info.tmu_date); */ } if (err==UNZ_OK) { err = unzCloseCurrentFile (uf); if (err!=UNZ_OK) { error("error %d with zipfile in unzCloseCurrentFile\n",err); } } else unzCloseCurrentFile(uf); /* don't lose the error */ if (previousPathCreated != NULL) free(previousPathCreated); } free(buf); return err; }
/** * Returns 1 if the given file exists and can be read; 0 otherwise. */ int fexists(const char* name) { ABSTRACTFILE* f=af_fopen(name,"rb"); if (f==NULL) return 0; af_fclose(f); return 1; }
static struct ExecutionLogging* BuildAllocInitExecutionLoggingForIncrementedNumber(void* privateLoggerPtr) { struct ExecutionLogging* pEL = NULL; struct UniLoggerSpace * pULS=(struct UniLoggerSpace *)privateLoggerPtr; struct ActivityLoggerPrivateData* pALPD = (struct ActivityLoggerPrivateData*) pULS->privateUnloggerData; char szNumFileSuffix[256]; if (pULS -> auto_increment_logfilename == 0) { return NULL; } /* we take a mutex, to be sure two thread don't increment and use same number at same time */ SyncGetMutex(pALPD->pMutexLog); if (pULS->szNameLog == NULL) { unsigned int current_number = 0; const char* szNumFile = buildDupFileNameWithPrefixDir(pULS->szPathLog,"unitex_logging_parameters_count.txt"); /* here : we will need protect with a mutex */ ABSTRACTFILE *af_fin = af_fopen_unlogged(szNumFile,"rb"); if (af_fin!=NULL) { size_t size_num_file=0; if (af_fseek(af_fin, 0, SEEK_END) == 0) { size_num_file = af_ftell(af_fin); af_fseek(af_fin, 0, SEEK_SET); } char* buf_num_file=(char*)malloc(size_num_file+1); *(buf_num_file+size_num_file)=0; if (af_fread(buf_num_file,1,size_num_file,af_fin) == size_num_file) { sscanf(buf_num_file,"%u",¤t_number); } af_fclose(af_fin); free(buf_num_file); } current_number++; ABSTRACTFILE *af_fout = af_fopen_unlogged(szNumFile,"wb"); if (af_fout!=NULL) { char szNumOut[32]; sprintf(szNumOut,"%010u",current_number); af_fwrite(szNumOut,1,strlen(szNumOut),af_fout); af_fclose(af_fout); } free((void*)szNumFile); sprintf(szNumFileSuffix,"unitex_log_%08u.ulp",current_number); } else { sprintf(szNumFileSuffix,"%s",pULS->szNameLog); } SyncReleaseMutex(pALPD->pMutexLog); const char* szLogFileName = buildDupFileNameWithPrefixDir(pULS->szPathLog,szNumFileSuffix); pEL=BuildAllocInitExecutionLogging(privateLoggerPtr,szLogFileName); free((void*)szLogFileName); return pEL; }