📄 aimage.cpp
字号:
if(lastchar(optarg)=='s'){ opt_skip_sectors = 1; } break; case 'S': opt_pagesize = scaled_atoi(optarg); break; case 'x': opt_compress = 0; opt_compression_level = AF_COMPRESSION_ALG_NONE; opt_compression_alg = AF_COMPRESSION_ALG_NONE; break; case 'A': opt_auto_compress = 1; opt_compress = 1; // opt_compression_alg = AF_COMPRESSION_ALG_ZLIB; opt_compression_level = 2; // why not? break; case 'v': printf("aimage %s\n\n",PACKAGE_VERSION); exit(0); case 'X': opt_compression_level = atoi(optarg); break; case 't': opt_retry_count = atoi(optarg); break; case 'm': opt_make_config = 1; break; case 'V': opt_reverse = 1; break; case 'Y': opt_batch = 1; break; case 'Z': opt_fast_quit = 1; break; case 'E': im->allow_regular=1; break; case 'T': opt_title = optarg; opt_blink = 0; break; case 'p': opt_preview = 1; break; case 'P': opt_preview = 0; break; case 'l': opt_logfile_fname=optarg; break; case 'L': opt_compression_alg = AF_COMPRESSION_ALG_LZMA; break; case 'G': im->opt_logAFF = true; break; case 'M': maxsize_set = 1; if(strcasecmp(optarg,"cd")==0){ opt_maxsize = 650000000; break; } if(strcasecmp(optarg,"bigcd")==0){ opt_maxsize = 700000000; break; } opt_maxsize = scaled_atoi(optarg); break; case 'y': opt_use_timers = 1;break; case 's': opt_setseg.push_back(optarg);break; case 'h': case '?': default: usage(); case 0: break; }}void beeps(int count){ if(opt_beeps && !opt_quiet && !opt_silent){ while(count-->0){ beep(); fflush(stdout); Sleep(300); } }}void process_config_file_options(){ FILE *f = fopen(config_filename,"r"); if(f){ while(!feof(f)){ char buf[1024]; memset(buf,0,sizeof(buf)); if(fgets(buf,sizeof(buf)-1,f)){ if(strncmp(buf,"set ",4)==0){ } } } }}int main(int argc,char **argv){ setupterm((char *)0,1,(int *)0); // set up termcap; it's needed for usage() /* If the AIMAGE_CONFIG variable is set, use it */ if(getenv(AIMAGE_CONFIG)){ config_filename = getenv(AIMAGE_CONFIG); } /* Figure out the command line that was used to run this program. * This information will be recorded in the AFF file. */ command_line = (char *)malloc(1); command_line[0] = 0; for(int i=0;i<argc;i++){ if(i>0) command_line = append(command_line," "); command_line = append(command_line,argv[i]); } /* Build the options string that will be used for getopt_long */ char optstring[256]; optstring[0] = 0; char *cc = optstring; for(int i=0;longopts[i].name;i++){ switch(longopts[i].has_arg){ case no_argument: *cc++ = longopts[i].val; break; case required_argument: case optional_argument: *cc++ = longopts[i].val; *cc++ =':'; break; default: printf("unknown value for longopts[%d].has_arg=%d\n", i,longopts[i].has_arg); exit(9); } } *cc++ = 0; /* Create the imager; we'll need this for option processing */ imagers = (imager **)malloc(0); num_imagers = 0; add_imager(); // create the first one /* Process the config file if it exists */ process_config_file_options(); /* Process the options */ int ch; while ((ch = getopt_long_only(argc, argv, optstring,longopts,NULL))!= -1) { process_option(imagers[0],ch,optarg); } argc -= optind; argv += optind; if(default_pagesize != opt_pagesize && !maxsize_set){ opt_maxsize = (1<<31) - opt_pagesize; // recalculate maxsize } if(opt_make_config) make_config(config_filename); /* Make the config file if necessary */ /* Open the logfile */ if(opt_logfile_fname) open_logfile(opt_logfile_fname); /* Make sure at least one input file was provided */ if(argc<1){ usage(); exit(0); } /* Now, for each argument, construct input and output files */ while(*argv){ imager *im = imagers[current_imager]; im->logfile = logfile; if(im->set_input(*argv)){ // opens dev and idents if necessary fprintf(stderr,"Cannot continue."); exit(1); } argv++; argc--; /* If there is an additional argument, it must be the output file * If an output file is set, that's bad. */ if(argc>0){ if(im->fname_aff[0] || im->fname_raw[0]){ err(1,"two outputs are provided for input file %s", im->infile); } process_option(im,'o',*argv); argv++; argc--; } /* If no output file has been set, indicate an error */ if(im->fname_aff[0]==0 && im->fname_raw[0]==0){ errx(1,"No output filename specified."); } /* If there are arguments left, create another imager... */ if(*argv){ add_imager(); } } total_time.start(); /* Now, image with each imager with curses... */ for(current_imager=0;current_imager<num_imagers;current_imager++){ imager *im = imagers[current_imager]; if(opt_zap){ if(im->fname_raw[0]) unlink(im->fname_raw); // if we are zapping if(im->fname_aff[0]) unlink(im->fname_aff); } /* If either file exists and we are not appending, give an error */ if(!opt_append){ if(access(im->fname_raw,F_OK)==0) errx(1,"%s: file exists",im->fname_raw); if(access(im->fname_aff,F_OK)==0) errx(1,"%s: file exists",im->fname_aff); /* If an AFM file is being created and the .000 file exists, * generate an error */ if(af_ext_is(im->fname_aff,"afm")){ char file000[MAXPATHLEN+1]; strlcpy(file000,im->fname_aff,sizeof(file000)); char *cc = rindex(file000,'.'); if(!cc) err(1,"Cannot file '.' in %s\n",file000); for(int i=0;i<2;i++){ char buf[16]; snprintf(buf,sizeof(buf),".%03d",i); *cc = '\000'; // truncate strlcat(file000,buf,sizeof(file000)); // and concatenate if(access(file000,F_OK)==0){ fprintf(stderr,"%s: file exists. Delete it before converting.\n", file000); fprintf(stderr,"NOTE: -z option will not delete %s\n", file000); return -1; } } } } if(im->fname_raw[0]){ im->fout = fopen(im->fname_raw,"wb"); if(!im->fout){ err(1,"fopen(%s)",im->fname_raw); } } if(im->fname_aff[0]){ char buf[256]; memset(buf,0,sizeof(buf)); int fstype = af_identify_file_type(im->fname_aff,1); if(fstype!=AF_IDENTIFY_AFF && fstype!=AF_IDENTIFY_AFD && fstype!=AF_IDENTIFY_AFM && fstype!=AF_IDENTIFY_NOEXIST){ fprintf(stderr,"%s exists and is not an AFF, AFD or AFM file.\n",im->fname_aff); fprintf(stderr,"Delete it or move it first.\n"); exit(-1); } im->af = af_open(im->fname_aff,O_CREAT|O_RDWR,0666); if(!im->af) err(1,"af_open %s: ",im->fname_aff); /* Set up the AFF */ af_enable_writing(im->af,1); // we will be writing this file af_enable_compression(im->af,opt_compression_alg,opt_compression_level); process_config_questions(im->af,im); // process the config file for questions for(vector<string>::iterator i = opt_setseg.begin(); i!= opt_setseg.end(); i++){ string::size_type eq = i->find('='); if(eq>0){ string name = i->substr(0,eq); string value = i->substr(eq+1); af_update_seg(im->af,name.c_str(),0,value.c_str(),value.length()); } } } beeps(1); // one beep to start gui_startup(); im->start_imaging(); // run aimage gui_shutdown(); /* Raw Cleanup */ if(im->fout){ if(fclose(im->fout)){ warnx("fclose(%s)",im->fname_raw); fprintf(stderr,"This shouldn't happen. '%s' may be corrupt.\n", im->fname_raw); } im->fout = 0; } /* AFF cleanup */ if(im->af){ if(opt_debug==2) fprintf(stderr,"af->bytes_memcpy=%qd\n",im->af->bytes_memcpy); if(af_close(im->af)){ warnx("af_close failed. This shouldn't happen.\n"); fprintf(stderr,"Run 'ainfo -v %s' to see if %s is corrupt.\n", im->fname_aff,im->fname_aff); } im->af = 0; } beeps(2); // two beeps when this is done } total_time.stop(); beeps(2); // two more beeps for everything done gotorc(tgetnum("li")-1,0); // go to the bottom of the screen tputs(clr_eos,0,putchar); endwin(); /* find out how much free space is left on the drive */ long long freebytes = imagers[0]->output_ident->freebytes(); /* Generate all of the final reports and detach any drives as necessary */ for(current_imager=0;current_imager<num_imagers;current_imager++){ imager *im = imagers[current_imager]; im->final_report(); if(im->cmd_detach[0]){ printf("Detaching drive...\n%s\n",im->cmd_detach); system(im->cmd_detach); } } /* say how much free space is left on the drive */ char buf[64]; printf("Free space remaining on capture drive: "); printf(" %s MB\n",af_commas(buf,freebytes/(1024*1024))); if(logfile) fclose(logfile); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -