📄 arj_user.c
字号:
} if(cmd==ARJ_CMD_DELETE&&total_chapters!=0&¤t_chapter!=RESERVED_CHAPTER&&total_chapters>max_chapter) final_header(FP_CHAPTER); if(cmd==ARJ_CMD_DELETE&&!first_vol_passed&&!continued_nextvolume&&ftell(aostream)==first_file_offset) { msg_cprintf(H_HL|H_NFMT, M_DELETING_EMPTY_ARCH, archive_name); file_close(aistream); aistream=NULL; if(!no_file_activity) { if(file_unlink(archive_name)) error(M_CANT_DELETE, archive_name); tmp_archive_cleanup(); } } /* ASR fix: the original didn't check for ARJ_CMD_COMMENT */ else if(total_files!=0||(cmd==ARJ_CMD_COMMENT&&comment_entries!=0)||create_sfx!=0) { fput_word(HEADER_ID, aostream); fput_word(0, aostream); last_hdr_offset=0L; if(!no_file_activity) { eof_pos=ftell(aostream); if(continued_nextvolume&&add_command&&!volume_flag_set&&!force_volume_flag) { final_header(FP_VOLUME); continued_nextvolume=0; } if(!encryption_applied&&encryption_id!=ENCID_NONE) final_header(FP_GARBLE); if(sign_with_arjsec) { msg_cprintf(0, M_WORKING); cur_pos=ftell(aostream); secured_size=cur_pos-main_hdr_offset; arjsec_offset=(unsigned long)is_registered*cur_pos; final_header(FP_SECURITY); if(create_envelope(aostream, arjsec_offset, ARJSEC_ITER)) { arj_delay(5); error(M_NO_ARJSEC_KEY); } } if(test_archive_crc) { archive_cleanup(); cmd_verb=cmd; } protected=0; if(arjprot_tail) { if(prot_blocks==0) prot_blocks=arjprot_tail; fseek(aostream, 0L, SEEK_END); arjsec_offset=ftell(aostream); if(!sign_with_arjsec) final_header(FP_PROT); protected=1; create_protfile(aostream, prot_blocks, 0); } if(multivolume_option) { fseek(aostream, 0L, SEEK_END); if(debug_enabled&&strchr(debug_opt, 'a')!=NULL&&create_index) { if(msg_fprintf(idxstream, M_ARCH_SIZE, ftell(aostream), archive_name)<0) error(M_DISK_FULL); } if(ftell(aostream)>volume_limit&&create_index) { if(msg_fprintf(idxstream, M_VOLUME_BUG, archive_name)<0) error(M_DISK_FULL); } } if(ferror(aostream)||fclose(aostream)==EOF) error(M_DISK_FULL); aostream=NULL; if(test_archive_crc&&protected) { protected=1; if(debug_enabled&&strchr(debug_opt, 'a')!=NULL) protected=2; msg_strcpy(tmp_tmp_filename, M_ARJFIXED_NAME); if(recover_file(tmp_archive_name, nullstr, tmp_tmp_filename, protected, eof_pos)) { msg_cprintf(H_HL, M_CANT_FIND_DAMAGE, archive_name); printf(lf); } else { if(create_index) { if(msg_fprintf(idxstream, M_AUTOPROT_DAMAGE, archive_name)<0) error(M_DISK_FULL); } } tmp_tmp_filename[0]='\0'; } } aostream=NULL; if(create_sfx&&!first_vol_passed) { entry=split_name(archive_name, NULL, NULL); if((ext_ptr=strchr(archive_name+entry, '.'))==NULL) msg_strcat(archive_name, M_EXE_EXT); #ifndef NULL_EXE_EXTENSION else msg_strcpy(ext_ptr, M_EXE_EXT); #endif } if(aistream!=NULL) { file_close(aistream); aistream=NULL; if(!no_file_activity) { if(keep_bak&&file_exists(archive_name)) { bak_name=(char *)malloc_msg(far_strlen(M_BAK_EXT)+strlen(archive_name)+1); strcpy(bak_name, archive_name); entry=split_name(bak_name, NULL, NULL); if((ext_ptr=strchr(bak_name+entry, '.'))==NULL) msg_strcat(bak_name, M_BAK_EXT); else msg_strcpy(ext_ptr, M_BAK_EXT); file_unlink(bak_name); rename_with_check(archive_name, bak_name); free(bak_name); } else { if(create_sfx) { if(file_exists(archive_name)) if(file_unlink(archive_name)) error(M_CANT_DELETE, archive_name); } else { if(file_unlink(archive_name)) error(M_CANT_DELETE, archive_name); } } } } if(!no_file_activity) { if(assign_work_directory) { msg_cprintf(H_HL|H_NFMT, M_COPYING_TEMP, tmp_archive_name, archive_name); tmp_archive_used=1; if(file_copy(archive_name, tmp_archive_name, test_archive_crc)) error(M_CANT_COPY_TEMP, tmp_archive_name, archive_name); tmp_archive_used=0; if(file_unlink(tmp_archive_name)) error(M_CANT_DELETE, archive_name); } else rename_with_check(tmp_archive_name, archive_name); if(create_sfx&&!first_vol_passed) msg_cprintf(0, M_SFX_CREATED); } tmp_archive_name[0]='\0'; } else { fput_word(HEADER_ID, aostream); fput_word(0, aostream); last_hdr_offset=0L; if(!no_file_activity&&delete_processed&&add_command&&test_archive_crc) { for(cur_file=0; cur_file<flist_main.files; cur_file++) if(cfa_get(cur_file)==FLFLAG_PROCESSED) break; if(cur_file<flist_main.files) { archive_cleanup(); cmd_verb=cmd; } } file_close(aistream); aistream=NULL; tmp_archive_cleanup(); if(continued_nextvolume&&!volume_flag_set&&no_inarch) continued_nextvolume=0; } } if(create_index&&(cmd==ARJ_CMD_ADD||cmd==ARJ_CMD_UPDATE)) { filename[0]='\0'; vol_code=2; if(continued_nextvolume&&volume_flag_set) { vol_code=continued_prevvolume; far_strcpy((char FAR *)filename, tmp_filename); } if(msg_fprintf(idxstream, M_NEXT_VOLUME_STATS, volume_number, vol_code, resume_position, filename)<0) error(M_DISK_FULL); } if(cmd==ARJ_CMD_ADD||cmd==ARJ_CMD_FRESHEN||cmd==ARJ_CMD_UPDATE||cmd==ARJ_CMD_JOIN) { if(filter_fa_arch==FAA_BACKUP_CLEAR||filter_fa_arch==FAA_CLEAR) group_clear_arch(&flist_main); if(delete_processed) delete_processed_files(&flist_main); } total_processed+=total_files+comment_entries; av_compressed+=total_compressed; av_uncompressed+=total_uncompressed; av_total_files+=total_files; av_total_longnames+=total_longnames; if(quiet_mode==ARJ_QUIET2) new_stdout=stdout; /* Now produce statistics for each command individually */ if(cmd==ARJ_CMD_LIST) { if(!std_list_cmd||verbose_display!=VERBOSE_ENH) { if(total_files==0||(std_list_cmd&&verbose_display==VERBOSE_STD)) { if(total_longnames==0) msg_cprintf(H_HL|H_NFMT, M_N_FILES, total_files); else msg_cprintf(H_HL|H_NFMT, M_N_FILES_LFN, total_files, total_longnames); if(total_chapters!=0) { msg_cprintf(0, M_CHAPTERS_ON); msg_cprintf(0, (FMSG *)lf); } } else { msg_cprintf(0, M_BRIEF_LIST_SEPARATOR); if(total_chapters!=0) { msg_strcpy(strcpy_buf, M_CHAPTERS_ON); msg_ptr=strcpy_buf; } else msg_ptr=nullstr; ratio=calc_percentage(total_compressed, total_uncompressed); if(total_longnames==0) msg_cprintf(H_HL|H_NFMT, M_TOTAL_STATS, total_files, total_uncompressed, total_compressed, ratio/1000, ratio%1000, msg_ptr); else msg_cprintf(H_HL|H_NFMT, M_TOTAL_STATS_LFN, total_files, total_uncompressed, total_compressed, ratio/1000, ratio%1000, msg_ptr, total_longnames); if(av_total_files>total_files) { ratio=calc_percentage(av_compressed, av_uncompressed); if(total_longnames==0) msg_cprintf(H_HL|H_NFMT, M_TOTAL_STATS, av_total_files, av_uncompressed, av_compressed, ratio/1000, ratio%1000, nullstr); else msg_cprintf(H_HL|H_NFMT, M_TOTAL_STATS_LFN, av_total_files, av_uncompressed, av_compressed, ratio/1000, ratio%1000, nullstr, av_total_longnames); } } } if(chk_free_space) { free_space=file_getfree(target_dir); if(disk_space_used+minfree>free_space) { msg_cprintf(H_ALERT, M_NOT_ENOUGH_SPACE_X, disk_space_used+minfree-free_space); errors++; } } } else if(cmd==ARJ_CMD_PRINT) { if(!help_issued) msg_cprintf(H_HL|H_NFMT, M_N_FILES, total_files); } else if(cmd==ARJ_CMD_COMMENT) msg_cprintf(H_HL|H_NFMT, M_N_COMMENTS, comment_entries); else if(cmd==ARJ_CMD_ADD||cmd==ARJ_CMD_FRESHEN||cmd==ARJ_CMD_UPDATE) { if(total_files==0) { if(total_longnames==0) msg_cprintf(H_HL|H_NFMT, M_N_FILES, total_files); else msg_cprintf(H_HL|H_NFMT, M_N_FILES_LFN, total_files, total_longnames); } else { if(verbose_display==VERBOSE_STD) { msg_cprintf(0, M_FINAL_FOOTER); ratio=calc_percentage(total_compressed, total_uncompressed); msg_cprintf(H_HL|H_NFMT, M_VERBOSE_FOOTER, total_files, total_uncompressed, total_compressed, ratio/10, ratio%10); if(total_files<av_total_files) { ratio=calc_percentage(av_compressed, av_uncompressed); msg_cprintf(H_HL|H_NFMT, M_VERBOSE_FOOTER, av_total_files, av_uncompressed, av_compressed, ratio/10, ratio%10); } } else { if(total_longnames==0) msg_cprintf(H_HL|H_NFMT, M_N_FILES, total_files); else msg_cprintf(H_HL|H_NFMT, M_N_FILES_LFN, total_files, total_longnames); } } if(comment_entries!=0) msg_cprintf(H_HL|H_NFMT, M_N_COMMENTS, comment_entries); } else if(cmd==ARJ_CMD_TEST&&total_files!=0&&errors==0&&(protfile_option||arjprot_tail||security_state==ARJSEC_SIGNED)) { eof_pos=ftell(aistream); fseek(aistream, 0L, SEEK_END); arjsec_offset=ftell(aistream); is_prot=(security_state==ARJSEC_SIGNED&&chk_prot_sig(aistream, eof_pos))?1:0; file_close(aistream); aistream=NULL; if(arjprot_tail||is_prot) { protected=1; if(debug_enabled&&strchr(debug_opt, 'a')!=NULL) protected=2; if(recover_file(archive_name, nullstr, nullstr, protected, eof_pos)) { msg_cprintf(H_HL, M_CANT_FIND_DAMAGE, archive_name); printf(lf); } else { if(create_index) { if(msg_fprintf(idxstream, M_AUTOPROT_DAMAGE, archive_name)<0) error(M_DISK_FULL); } } } if(protfile_option&&protected) { arjprot_tail=protfile_option; if(prot_blocks==0) prot_blocks=protfile_option; if((aostream=file_open(archive_name, m_rbp))==NULL) error(M_CANTOPEN, archive_name); if(security_state==ARJSEC_NONE) final_header(FP_PROT); create_protfile(aostream, prot_blocks, 0); file_close(aostream); aostream=NULL; } } else { if(cmd==ARJ_CMD_COPY&&chapter_mode) { if(chapter_mode==CHAP_USE) msg_cprintf(0, M_CHAPTERS_ON); else if(chapter_mode==CHAP_REMOVE) msg_cprintf(0, M_CHAPTERS_OFF); msg_cprintf(0, strform, lf); } if(cmd==ARJ_CMD_COPY&&protfile_option&&!arjprot_tail) msg_cprintf(0, M_ARJPROT_DISABLED); msg_cprintf(H_HL|H_NFMT, M_N_FILES, total_files); if(comment_entries>0) msg_cprintf(H_HL|H_NFMT, M_N_COMMENTS, comment_entries); } if(security_state==ARJSEC_SIGNED&&arjsec_opt!=ARJSECP_SKIP) { msg_cprintf(H_HL|H_NFMT, M_VALID_ARJSEC, arjsec_signature); msg_strcpy(strcpy_buf, M_SDN_1); if(strstr(arjsec_signature, strcpy_buf)!=NULL) { msg_cprintf(0, M_SDN_ADD_DESC); msg_cprintf(0, M_SDN_SECURITY_TEST); } msg_strcpy(strcpy_buf, M_SDN_2); if(strstr(arjsec_signature, strcpy_buf)!=NULL) { msg_cprintf(0, M_SDN_DIST_DESC); msg_cprintf(0, M_SDN_SECURITY_TEST); } } file_close(aistream); aistream=NULL; if(arjprot_tail) msg_cprintf(0, M_ARJPROT_ENABLED, prot_blocks); if(arjsec_signature!=NULL) { free(arjsec_signature); arjsec_signature=NULL; } if(((modify_command&×tamp_override==ATO_SAVE_ARCHIVE)|| timestamp_override==ATO_NEWEST)&&ts_valid(ftime_max)) file_setftime(archive_name, ts_native(&ftime_max, OS)); else if((timestamp_override==ATO_SAVE_ORIGINAL||timestamp_override==ATO_SAVE_BOTH)&&saved_timestamp!=0L) file_setftime(archive_name, saved_timestamp); if(modify_command&&file_is_removable(archive_name)) reset_drive(archive_name); if(!modify_command&&total_processed==0&&!continued_nextvolume) { if(errorlevel==ARJ_ERL_SUCCESS) errorlevel=ARJ_ERL_WARNING; errors++; } total_processed-=split_files; av_total_files-=split_files; av_total_longnames-=split_longnames;}#endif/* Changes SFX executable name (for -ve) */#if SFX_LEVEL>=ARJSFXVstatic char *iterate_sfxname(){ char *rc, *p; int l; char *tmp_str; for(l=strlen(archive_name); l>0; l--) { if(archive_name[l]=='.') break; } if(l<4) { p=(l>0)?(archive_name+l):nullstr; l=0; rc=archive_name; } else { p=archive_name+l; l-=3; rc=archive_name+l; } if(volume_number>0) { tmp_str=malloc_str(archive_name); tmp_str[l]='\0'; sprintf(archive_name, stub_fmt, tmp_str, volume_number, p); free(tmp_str); } return(rc);}#endif/* Mangles the filename so it can be transformed to an aesthetic SFX name. ASR fix 26/08/2001 for UNIX. */#if SFX_LEVEL>=ARJSFXVstatic void fix_sfx_name(){ #ifdef NULL_EXE_EXTENSION char *digit_pos; static char exe_append[]=".exe"; if(!first_vol_passed) return; digit_pos=strrchr(archive_name, PATHSEP_DEFAULT); if(digit_pos==NULL) digit_pos=archive_name; digit_pos=strchr(digit_pos, '.'); if(digit_pos==NULL) /* "test" -> "test.exe" */ strcat(archive_name, exe_append); else if(strlen(digit_pos)<3) /* ".xx" -> ".01" */ strcpy(digit_pos, exe_append); #endif}#endif/* Extended archive processing routine. A non-zero return value indicates that processing of further volumes must be omitted. */#if SFX_LEVEL>=ARJstatic int process_archive_proc(int cmd){ struct timestamp tmp_time; static unsigned int t_buf, v_buf; char *tmp_ptr; int vol_num_digits; int encryption_version; char *vol_name_fmt; int filename_length; unsigned long avail_space; char timetext[22]; char *sfx_name; int entry; int query_result;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -