コード例 #1
0
ファイル: gcf-rw.c プロジェクト: hinike/MyDocuments
int main(int argc, char *argv[]){
	char*gcf_name;
	archive_t gcf=NULL;
	RTinitPopt(&argc,&argv,options,1,-1,&gcf_name,NULL,"([-c] <gcf> (<dir>|<file>)*) | (-x <gcf> [<dir>|<pattern>])",
		"Tool for creating and extracting GCF archives\n\nOptions");
	compression_policy_compile(policy);
	if (operation==GCF_EXTRACT) {
		char *out_name=RTinitNextArg();
		archive_t dir;
		if(out_name){
			if(RTinitNextArg()){
				Fatal(1,error,"extraction uses gcf -x <gcf> [<dir>|<pattern>]");
			}
			if (strstr(out_name,"%s")) {
				dir=arch_fmt(out_name,file_input,file_output,blocksize);
			} else {
				dir=arch_dir_create(out_name,blocksize,force?DELETE_ALL:DELETE_NONE);
			}
		} else {
			dir=arch_dir_open(".",blocksize);
		}
		if (is_a_dir(gcf_name)){
			gcf=arch_dir_open(gcf_name,blocksize);
		} else {
			gcf=arch_gcf_read(raf_unistd(gcf_name));
		}
		archive_copy(gcf,"auto",dir,NULL,blocksize);
		arch_close(&dir);
		arch_close(&gcf);
	} else {
		if (operation==GCF_FILE){
			gcf=arch_gcf_create(raf_unistd(gcf_name),blocksize,blocksize*blockcount,0,1);
		} else {
			gcf=arch_dir_create(gcf_name,blocksize,force?DELETE_ALL:DELETE_NONE);
		}
		for(;;){
			char *input_name=RTinitNextArg();
			if (!input_name) break;
			if (is_a_dir(input_name)){
				Warning(info,"copying contents of %s",input_name);
				archive_t dir=arch_dir_open(input_name,blocksize);
				archive_copy(dir,NULL,gcf,get_compression,blocksize);
				arch_close(&dir);
			} else {
				Warning(info,"copying %s",input_name);
				stream_t is=file_input(input_name);
				stream_t os=arch_write(gcf,input_name,get_compression(input_name),1);
				char buf[blocksize];
				for(;;){
					int len=stream_read_max(is,buf,blocksize);
					if (len) stream_write(os,buf,len);
					if(len<blocksize) break;
				}
				stream_close(&is);
				stream_close(&os);	
			}
		}
		arch_close(&gcf);
	}
}
コード例 #2
0
ファイル: gcf-tool.c プロジェクト: Meijuh/ltsmin
static void gcf_compress(){
    char*source;
    char target[LTSMIN_PATHNAME_MAX];
    while((source=HREnextArg())){
        if (is_a_file(source)){
            sprintf(target,"%s.gzf",source);
            stream_t is=file_input(source);
            stream_t os=file_output(target);
            char *code=SSMcall(compression_policy,source);
            DSwriteS(os,code);
            os=stream_add_code(os,code);
            char buf[blocksize];
            for(;;){
                int len=stream_read_max(is,buf,blocksize);
                if (len) stream_write(os,buf,len);
                if(len<blocksize) break;
            }
            stream_close(&is);
            stream_close(&os);
            if (!keep) recursive_erase(source);
        } else if (is_a_dir(source)){
            sprintf(target,"%s.gcf",source);
            archive_t arch_in=arch_dir_open(source,blocksize);
            archive_t arch_out=arch_gcf_create(raf_unistd(target),blocksize,blocksize*blockcount,0,1);
            archive_copy(arch_in,arch_out,compression_policy,blocksize,NULL);
            arch_close(&arch_in);
            arch_close(&arch_out);
            if (!keep) recursive_erase(source);
        } else {
            Abort("source %s is neither a file nor a directory",source);
        }
    }
}
コード例 #3
0
ファイル: gcf-tool.c プロジェクト: Meijuh/ltsmin
static void zip_copy_gcf(){
    char* source=HREnextArg();
    if (source==NULL) {
        Abort("missing <source> argument");
    }
    char* target=HREnextArg();
    if (target==NULL) {
        Abort("missing <target> argument");
    }
    if (HREnextArg()){
        Abort("too many arguments");
    }
    archive_t arch_in=arch_zip_read(source,65536);
    archive_t arch_out=arch_gcf_create(raf_unistd(target),blocksize,blocksize*blockcount,0,1);
    archive_copy(arch_in,arch_out,compression_policy,blocksize,NULL);
    arch_close(&arch_in);
    arch_close(&arch_out);
}
コード例 #4
0
ファイル: gcf-tool.c プロジェクト: Meijuh/ltsmin
static void gcf_extract(){
    char *gcf_name=HREnextArg();
    if (gcf_name==NULL) {
        Abort("missing <gcf archive> argument");
    }
    archive_t arch=arch_gcf_read(raf_unistd(gcf_name));
    archive_t dir;
    if (outputdir) {
        dir=arch_dir_create(outputdir,blocksize,force?DELETE_ALL:DELETE_NONE);
    } else {
        dir=arch_dir_open(".",blocksize);
    }
    char*pattern=HREnextArg();
    do {
        archive_copy(arch,dir,NULL,blocksize,pattern);
    } while((pattern=HREnextArg()));
    arch_close(&dir);
    arch_close(&arch);
}
コード例 #5
0
ファイル: gcf-tool.c プロジェクト: Meijuh/ltsmin
static void gcf_decompress(){
    char*source;
    char target[LTSMIN_PATHNAME_MAX];
    while((source=HREnextArg())){
        if (has_extension(source,".gzf")){
            strncpy(target,source,strlen(source)-4);
            target[strlen(source)-4]=0;
            stream_t is=file_input(source);
            stream_t os=file_output(target);
            char *code=DSreadSA(is);
            is=stream_add_code(is,code);
            char buf[blocksize];
            for(;;){
                int len=stream_read_max(is,buf,blocksize);
                if (len) stream_write(os,buf,len);
                if(len<blocksize) break;
            }
            stream_close(&is);
            stream_close(&os);
            if (!keep) recursive_erase(source);
        } else if (has_extension(source,".gcf")||has_extension(source,".zip")){
            strncpy(target,source,strlen(source)-4);
            target[strlen(source)-4]=0;
            archive_t arch_in;
            if (has_extension(source,".gcf")){
                arch_in=arch_gcf_read(raf_unistd(source));
            } else {
                arch_in=arch_zip_read(source,blocksize);
            }
            archive_t arch_out=arch_dir_create(target,blocksize,force?DELETE_ALL:DELETE_NONE);
            archive_copy(arch_in,arch_out,NULL,blocksize,NULL);
            arch_close(&arch_in);
            arch_close(&arch_out);
            if (!keep) recursive_erase(source);
        } else {
            Abort("source %s does not have known extension",source);
        }
    }
}