📄 arj_user.c
字号:
int no_input; FILE *cmtstream; int cmt_len; char *digit_pos; unsigned long arch_size; unsigned int desc_word, reg_id; /* SFX */ order_fcount=0; order_fcap=0; order_list=NULL; arjsec_signature=NULL; volume_flag_set=0; main_hdr_offset=last_hdr_offset=0L; tmp_archive_used=0; cf_num=0; total_files=total_longnames=0; comment_entries=0; security_state=ARJSEC_NONE; disk_space_used=0L; total_uncompressed=0L; total_compressed=0L; archive_size=0L; ts_store(&ftime_max, OS_SPECIAL, 0L); saved_timestamp=0L; ext_hdr_flags=0; encryption_applied=0; split_files=0; split_longnames=0; cmd_verb=cmd; if(!setjmp(main_proc)) { set_file_apis(use_ansi_cp); v_buf=add_command?VBUF_ADD:VBUF_EXTRACT; t_buf=TBUF_ARJ; if(coreleft()<TBUF_MINFREE) t_buf>>=1; if(coreleft()<VBUF_MINFREE) v_buf>>=1; if((tmp_ptr=strchr(debug_opt, 'b'))!=NULL) { tmp_ptr++; v_buf=(int)strtol(tmp_ptr, &tmp_ptr, 10); } if((tmp_ptr=strchr(debug_opt, 'p'))!=NULL) { tmp_ptr++; t_buf=(int)strtol(tmp_ptr, &tmp_ptr, 10); } if((tmp_ptr=strchr(debug_opt, 'v'))!=NULL) msg_cprintf(H_HL|H_NFMT, M_BRIEF_MEMSTATS, coreleft(), t_buf, v_buf); if(chk_free_space) alloc_unit_size=get_bytes_per_cluster(target_dir); ts_store(&ftime_stamp, OS_SPECIAL, 0L); first_hdr_size=FIRST_HDR_SIZE; if(multivolume_option) { if(use_sfxstub) digit_pos=iterate_sfxname(); else { vol_num_digits=2; tmp_ptr=volfmt_2digit; fix_sfx_name(); filename_length=strlen(archive_name)-vol_num_digits; if(volume_number>99||isdigit(archive_name[filename_length-1])) { vol_num_digits=3; tmp_ptr=volfmt_3digit; filename_length--; if(volume_number>999&&lfn_supported) { if(volume_number>1000) filename_length--; tmp_ptr=volfmt_4digit; } else if(volume_number>999) volume_number=1; } if(volume_number>0) { vol_name_fmt=malloc_str(archive_name); vol_name_fmt[filename_length]='\0'; sprintf(archive_name, tmp_ptr, vol_name_fmt, volume_number); free(vol_name_fmt); } digit_pos=archive_name+filename_length; } continued_nextvolume=1; if(modify_command) { do { avail_space=file_getfree(archive_name); arch_size=0L; if(assign_work_directory&&file_exists(archive_name)) { arch_size=file_getfsize(archive_name); if(file_getfree(work_directory)<(avail_space+arch_size)*2) arch_size=0L; avail_space+=arch_size; } if(multivolume_option==MV_AVAIL) volume_limit=avail_space; if(debug_enabled&&strchr(debug_opt, 'v')!=NULL) msg_cprintf(H_HL|H_NFMT, M_AVAIL_SPACE, avail_space); if(avail_space<MIN_VOLUME_SIZE) { msg_cprintf(H_HL|H_NFMT, M_FILENAME_FORM, archive_name); if(!yes_on_all_queries&&!skip_space_query) { msg_cprintf(H_ALERT, M_NOT_ENOUGH_SPACE_V); return(0); } else error(M_NOT_ENOUGH_SPACE_V); } if(volume_limit>avail_space) { if(!yes_on_all_queries&&!skip_space_query) { msg_cprintf(H_HL|H_NFMT, M_FILENAME_FORM, archive_name); msg_sprintf(misc_buf, M_LOW_SPACE_WARNING, avail_space); if(!query_action(REPLY_YES, QUERY_LOW_SPACE, (FMSG *)misc_buf)) return(0); } } } while((arch_size+avail_space)!=file_getfree(archive_name)); } } ctrlc_not_busy=0; aistream=NULL; if(file_exists(archive_name)) { if(modify_command) { saved_timestamp=file_getftime(archive_name); aistream=file_open_noarch(archive_name, m_rbp); } else aistream=file_open(archive_name, m_rb); } ctrlc_not_busy=1; if(aistream==NULL&&msg_strchr(M_UPDATE_COMMANDS, (char)cmd)==NULL) { if(multivolume_option&&!yes_on_all_queries&&!skip_next_vol_query) { error_report(); msg_cprintf(H_ERR, M_CANTOPEN, archive_name); nputlf(); return(0); } else error(M_CANTOPEN, archive_name); } if(create_index) { cur_time_stamp(&tmp_time); timestamp_to_str(timetext, &tmp_time); if(msg_fprintf(idxstream, M_IDX_VOLUME_HEADER, timetext, resume_position, archive_name)<0) error(M_DISK_FULL); } no_inarch=1; if(aistream!=NULL) { #ifndef NO_CACHING setvbuf(aistream, NULL, _IOFBF, v_buf); #endif no_inarch=0; } if(!modify_command) msg_cprintf(H_HL|H_NFMT, M_PROCESSING_ARCHIVE, archive_name); else { if(!tmp_archive_name) { tmp_archive_used=-1; tmp_archive_name=(char *)malloc_msg(FILENAME_MAX); tmp_archive_name[0]='\0'; tmp_archive_used=0; } if(create_sfx) { if(!first_vol_passed) { sfx_name=malloc_msg(filename_length=strlen(archive_name)+far_strlen(M_EXE_EXT)+1); strcpy(sfx_name, archive_name); entry=split_name(sfx_name, NULL, NULL); if((tmp_ptr=strchr(sfx_name+entry, '.'))==NULL) msg_strcat(sfx_name, M_EXE_EXT); #ifndef NULL_EXE_EXTENSION else msg_strcpy(tmp_ptr, M_EXE_EXT); #endif if(file_exists(sfx_name)) { query_result=yes_on_all_queries||overwrite_existing; if(!query_result) { msg_cprintf(H_HL|H_NFMT, M_EXISTS, sfx_name); msg_sprintf(misc_buf, M_QUERY_UPDATE, sfx_name); query_result=query_action(REPLY_YES, QUERY_OVERWRITE, (FMSG *)misc_buf); } if(!query_result||(stricmp(archive_name, sfx_name)&&file_unlink(sfx_name))) error(M_CANT_DELETE, sfx_name); } msg_cprintf(H_HL|H_NFMT, M_CREATING_SFX, sfx_name); free(sfx_name); } } else msg_cprintf(H_HL|H_NFMT, (aistream==NULL)?M_CREATING_ARCHIVE:M_UPDATING_ARCHIVE, archive_name); if(!no_file_activity) { if(aistream==NULL) { aostream=file_open_noarch(archive_name, m_wb); file_close(aostream); aostream=NULL; file_unlink(archive_name); } tmp_archive_used=-1; if(assign_work_directory) { strcpy(tmp_archive_name, work_directory); add_pathsep(tmp_archive_name); } else split_name(archive_name, tmp_archive_name, NULL); strcat(tmp_archive_name, arjtemp_spec); find_tmp_filename(tmp_archive_name); aostream=file_open_noarch(tmp_archive_name, m_wbp); tmp_archive_used=0; #ifndef NO_CACHING setvbuf(aostream, NULL, _IOFBF, t_buf); #endif avail_space=file_getfree(tmp_archive_name); if(volume_limit>avail_space) { if(!yes_on_all_queries&&!skip_space_query) { msg_cprintf(H_HL|H_NFMT, M_FILENAME_FORM, tmp_archive_name); msg_sprintf(misc_buf, M_LOW_SPACE_WARNING, avail_space); if(!query_action(REPLY_YES, QUERY_LOW_SPACE, (FMSG *)misc_buf)) { tmp_archive_cleanup(); return(0); } } } if(create_sfx==SFXCRT_SFX&&multivolume_option) { if(!first_vol_passed) fetch_sfxv(); else if(use_sfxstub) fetch_sfxstub(); } else if(create_sfx==SFXCRT_SFX) fetch_sfx(); else if(create_sfx==SFXCRT_SFXJR) fetch_sfxjr(); /* Adjust the privileges on UNIX platforms */ #if TARGET==UNIX if(create_sfx) { if(create_sfx==SFXCRT_SFX&&multivolume_option&&first_vol_passed&&!use_sfxstub) make_nonexecutable(aostream); else make_executable(aostream); } else make_nonexecutable(aostream); #endif } } no_input=0; if(aistream==NULL) { no_input=1; fill_archive_header(); if(win32_platform&&use_ansi_cp) msg_cprintf(0, M_ANSI_CP_ARCHIVE); } else { if((main_hdr_offset=find_header(0, aistream))<0L) { msg_cprintf(H_ALERT, M_NOT_ARJ_ARCHIVE, archive_name); msg_cprintf(0, (FMSG *)lf); file_close(aistream); aistream=NULL; if(errorlevel==ARJ_ERL_SUCCESS) errorlevel=ARJ_ERL_NOT_ARJ_ARCHIVE; errors++; tmp_archive_cleanup(); return(ARJ_ERL_NOT_ARJ_ARCHIVE); } if(main_hdr_offset==0L&&modify_command&&create_sfx) copy_bytes(main_hdr_offset); if(main_hdr_offset>EXESIZE_MINSFX) { fseek(aistream, main_hdr_offset, SEEK_SET); fseek(aistream, -8L, SEEK_CUR); desc_word=fget_word(aistream); reg_id=fget_word(aistream); sfx_desc_word=desc_word; /* Perform a simple integrity check */ if(reg_id!=REG_ID&®_id!=UNREG_ID) sfx_desc_word=SFXDESC_NONSFX; if(sfx_desc_word<SFXDESC_MIN||sfx_desc_word>SFXDESC_MAX) sfx_desc_word=SFXDESC_NONSFX; } fseek(aistream, main_hdr_offset, SEEK_SET); if(!read_header(1, aistream, archive_name)) error(M_INVALID_COMMENT_HDR); if(use_sfxstub) digit_pos=iterate_sfxname(); if(modify_command&&continued_nextvolume&&!multivolume_option) { msg_cprintf(0, M_MV_UPDATE_REQ_SW); file_close(aistream); aistream=NULL; errors++; tmp_archive_cleanup(); return(0); } if(modify_command&&(cmd==ARJ_CMD_GARBLE||garble_enabled)) { if(arj_nbr>=ARJ_NEWCRYPT_VERSION&&ext_hdr_flags==0&&!encryption_applied) { ext_hdr_flags=ENCRYPT_STD; if(gost_cipher==GOST256) ext_hdr_flags=ENCRYPT_UNK; else if(gost_cipher==GOST40) ext_hdr_flags=ENCRYPT_GOST40; } else { if((gost_cipher!=GOST256||ext_hdr_flags!=ENCRYPT_GOST256&&ext_hdr_flags!=ENCRYPT_GOST256L)&& (gost_cipher!=GOST40||ext_hdr_flags!=ENCRYPT_GOST40)&& gost_cipher!=GOST_NONE) error(M_WRONG_ENC_VERSION, 0); } } if(!win32_platform&&create_sfx&&!multivolume_option&&ext_hdr_flags>=ENCRYPT_STD) error(M_BAD_SYNTAX); if(cmd!=ARJ_CMD_COPY&&chapter_mode&&total_chapters==0) error(M_NOT_A_CHAPTER_ARCH); if(cmd==ARJ_CMD_DELETE&&delete_processed==DP_EXTRACT&&total_chapters!=0) error(M_BAD_SYNTAX); if(cmd==ARJ_CMD_DELETE&¤t_chapter==RESERVED_CHAPTER&&total_chapters==0) error(M_NOT_A_CHAPTER_ARCH); if(arjsec_opt==ARJSECP_SET_ERROR&&arj_flags&SECURED_FLAG) error(M_SKIPPING_SEC); if(protfile_option&&(multivolume_option||continued_nextvolume)&& !arjprot_tail&&is_removable) error(M_ARJPROT_REJECTED); timestamp_to_str(timetext, &ftime_stamp); msg_cprintf(H_HL|H_NFMT, M_ARCHIVE_CREATED, timetext); if(arj_nbr>=ARJ_M_VERSION) { ts_store(&tmp_time, host_os, compsize); timestamp_to_str(timetext, &tmp_time); msg_cprintf(H_HL|H_NFMT, M_MODIFIED, timetext); if(total_chapters!=0) msg_cprintf(H_HL, M_CHAPTER_NUMBER, total_chapters); } msg_cprintf(0, (FMSG *)lf); if((!modify_command||!use_comment)&&(cmd!=ARJ_CMD_COMMENT||supply_comment_file)) { if((cmd!=ARJ_CMD_LIST||!std_list_cmd||verbose_display!=VERBOSE_ENH)&&comment_display!=CMTD_NONE) display_comment(comment); } set_file_apis(ansi_codepage); if(ansi_codepage) { msg_cprintf(0, M_ANSI_CP_ARCHIVE);#if TARGET!=WIN32 if(cmd==ARJ_CMD_EXTR_NP&&!use_ansi_cp) error(M_REQUIRES_ARJ32);#endif } if(cmd==ARJ_CMD_LIST&&debug_enabled&&strchr(debug_opt, 'l')!=NULL) msg_cprintf(H_HL|H_NFMT, M_ENCRYPT_VALUE, ext_hdr_flags); } if(multivolume_option) volume_number=strtol(digit_pos, &digit_pos, 10)+1; if(modify_command) { main_hdr_offset=ftell(aostream); if(security_state) { msg_cprintf(0, M_CANT_UPDATE_SEC); msg_cprintf(0, (FMSG *)lf); file_close(aistream); aistream=NULL; errors++; errorlevel=ARJ_ERL_ARJSEC_ERROR; tmp_archive_cleanup(); return(0); } if(timestamp_override!=ATO_SAVE_BOTH) { cur_time_stamp(&tmp_time); compsize=ts_native(&tmp_time, host_os); } if(ts_valid(secondary_ftime)) compsize=ts_native(&secondary_ftime, host_os); /* Archive modification time */ if(garble_enabled) { encryption_version=garble_init(0); if(ext_hdr_flags==ENCRYPT_UNK) ext_hdr_flags=encryption_version; if(ext_hdr_flags!=0&&encryption_version!=ext_hdr_flags) error(M_WRONG_ENC_VERSION, ext_hdr_flags); } ext_flags=ext_hdr_flags; if(protfile_option) { arjprot_tail=protfile_option; if(prot_blocks==0) prot_blocks=arjprot_tail%256; /* v 2.75+ - %'ing is pointless! */ } if(sfx_desc_word!=SFXDESC_NONSFX) { if(chapter_mode) error(M_CHAPTER_SFX_CREATION); if(custom_method==5||method_specifier==4) error(M_INVALID_METHOD_SFX); if(sfx_desc_word<=SFXDESC_SFX&&multivolume_option) error(M_BAD_SYNTAX); /* Skip check for EAs - an existing archive may contain them but they are harmless! */ if(sfx_desc_word==SFXDESC_SFXJR&&(type_override||lfn_supported!=LFN_NOT_SUPPORTED)) error(M_TEXTMODE_LFN_SFXJR); if(sfx_desc_word==SFXDESC_SFXJR&&garble_enabled) error(M_NO_GARBLE_IN_SFXJR); if(sfx_desc_word==SFXDESC_SFX&&ext_hdr_flags>ENCRYPT_STD) error(M_WRONG_ENC_VERSION, ext_hdr_flags); } if(cmd==ARJ_CMD_COPY) { if(chapter_mode==CHAP_USE&&total_chapters!=0&&!multivolume_option) error(M_ALREADY_CHAPTER_ARCH); if(chapter_mode==CHAP_REMOVE&&total_chapters==0) error(M_NOT_A_CHAPTER_ARCH); if(chapter_mode==CHAP_USE&&total_chapters==0) { chapter_number=1; total_chapters=1; current_chapter=HIGHEST_CHAPTER; comment_entries++; } else if(chapter_mode==CHAP_REMOVE&&total_chapters!=0) { chapter_number=0; total_chapters=0; current_chapter=HIGHEST_CHAPTER; comment_entries++; } if(garble_enabled) { ext_flags=0; arj_flags&=~GARBLED_FLAG; if(!test_archive_crc) test_archive_crc=TC_ARCHIVE; } if(use_ansi_cp==ANSICP_SKIP) { if(arj_nbr==ARJ_ANSI_VERSION||arj_flags&ANSICP_FLAG) { msg_cprintf(H_ALERT, M_NOT_OEM_CP_ARCHIVE); file_close(aistream); aistream=NULL; errors++; errorlevel=ARJ_ERL_WARNING; tmp_archive_cleanup(); return(0); } arj_flags|=ANSICP_FLAG; comment_entries++; } if(protfile_option) { arjprot_tail=0; prot_blocks=0; arj_flags&=~PROT_FLAG;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -