Exemplo n.º 1
0
Arquivo: file.c Projeto: prophile/dim3
bool game_file_compress_save(char *path,char *err_str)
{
	unsigned long   compress_sz;
	ptr				compress_data;
	FILE			*file;
	
		// compress it

	compress_data=zip_compress(game_file_data,game_file_sz,&compress_sz,err_str);
	if (compress_data==NULL) return(FALSE);
	
		// save file
		
	file=fopen(path,"wb");
	if (file==NULL) {
		strcpy(err_str,"Could not create file");
		free(compress_data);
		return(FALSE);
	}
		
	fwrite(&game_file_sz,1,sizeof(unsigned long),file);
	fwrite(&compress_sz,1,sizeof(unsigned long),file);
	fwrite(compress_data,1,compress_sz,file);
	fclose(file);
	
#ifndef D3_OS_WINDOWS
	truncate(path,((sizeof(unsigned long)*2)+compress_sz));
#endif

	free(compress_data);
	
	return(TRUE);
}
Exemplo n.º 2
0
/*Each thread will called this function*/
void *worker_compress(void *arg)
{
    int ret, jdx;
    uint32_t count = 0;
    uint32_t point = 0;
    char header[128] =
    { 0 };
    ctx_t ctx1;
    margs_t *args = (margs_t *) arg;
    ctx_t *ctx = &(args->nums);
    file_container_t *fnames = args->fnames;
    int idx = args->idx;
    int bitsToLoss = args->bitsToLoss;
    sprintf(header, "thread %d", idx);
    init_context(&ctx1);
    point = fnames->size / 10 + 1;

    if (point < 10)
    {
        point = 10;
    }

    while (get_next_file(fnames, &jdx) > -1)
    {
        reset_context(&ctx1);
        ret = zip_compress(&ctx1, fnames->srcs[jdx], fnames->dsts[jdx], bitsToLoss);

        if (ret != 0)
        {
            continue;
        }

        print_context_info(&ctx1, "Context Info in Worker Compress");
        update_context(ctx, &ctx1);
        count += 1;

        if (count % point == 0)
        {
            //print the speeds for all the files
            //ctx_print_more(ctx, header);
            print_context_info(ctx, header);
        }
    }

    return 0;
}