if(argc>2) { fname = argv[2]; if((argv[1][0]=='-')&&(strlen(argv[1])==2)) { switch(argv[1][1]) { case 'l': mode = LIST; break; case 'x': mode = EXTRACT; break; case 'c': mode = CAT; break; case 'a': mode = ADD; break; default: mode = NONE; break; } } }  switch(mode) { case LIST: { if(argc!=3) break; U7FileManager fm; U7file *f = fm.get_file_object(fname); int count = f->number_of_objects(0); cout << "Archive: " << fname << endl; cout << "Type: " << f->get_archive_type() << endl; cout << "Size: " << count << endl; cout << "-------------------------" << endl; for(int i=0; i<count; i++) { char *buf; size_t len;  f->retrieve(i, &buf, &len); cout << i << "\t" << len << endl; delete [] buf; } } break; case EXTRACT: { if(argc==4) { U7object f(fname,atoi(argv[3])); char outfile[32]; sprintf(outfile,"%d.u7o",atoi(argv[3])); if(!f.retrieve(outfile)) cout << "Failed to get object" << endl; } else { U7FileManager fm; U7file *f = fm.get_file_object(fname); int count = f->number_of_objects(0); for(index=0; index<count; index++) { U7object o(fname,index); char outfile[32]; sprintf(outfile,"%d.u7o",index); o.retrieve(outfile);
switch(mode) { case LIST: { if(argc!=3) break; U7FileManager fm; U7file *f = fm.get_file_object(fname); int count = f->number_of_objects(0); cout << "Archive: " << fname << endl; cout << "Type: " << f->get_archive_type() << endl; cout << "Size: " << count << endl; cout << "-------------------------" << endl; for(int i=0; i<count; i++) { char *buf; size_t len;  f->retrieve(i, &buf, &len); cout << i << "\t" << len << endl; delete [] buf; } } break; case EXTRACT: { if(argc==4) { U7object f(fname,atoi(argv[3])); char outfile[32]; sprintf(outfile,"%d.%s",atoi(argv[3]),ext); if(!f.retrieve(outfile)) cerr << "Failed to get object" << endl; } else { U7FileManager fm; U7file *f = fm.get_file_object(fname); int count = f->number_of_objects(0); for(index=0; index<count; index++) { U7object o(fname,index); char outfile[32]; sprintf(outfile,"%d.%s",index,ext); o.retrieve(outfile); } delete f; } } break; case CREATE: { if(argc<4) { cerr << "No files specified" << endl; exit(1); }  ofstream flex; U7open(flex, fname); StreamDataSource fs(&flex);  int count = argc-3; int *sizes = new int[count]; for(int i=0; i<count; i++) sizes[i] = get_file_size(argv[i+3]);   char title[0x50]; sprintf(title,"Exult Archive"); fs.write(title, 0x50);  fs.write4(0xFFFF1A00);  fs.write4(count);  fs.write4(0xCC);  for(int i=0; i<9; i++) fs.write4(0x0);  int data_start = 128+8*count; for(int i=0; i<count; i++) { if(sizes[i]) { fs.write4(data_start); fs.write4(sizes[i]); data_start += sizes[i]; } else { fs.write4(0x0); fs.write4(0x0); } }  for(int i=0; i<count; i++) { if(sizes[i]) { ifstream infile; U7open(infile, argv[i+3]); StreamDataSource ifs(&infile); char *buf = new char[sizes[i]]; ifs.read(buf, sizes[i]); fs.write(buf, sizes[i]); delete [] buf; infile.close(); } } flex.close();  } break; default: cout << "Usage:\n " << argv[0] << " -[l|x|c] file [index]" << endl; break;
int main(int argc, char **argv){  enum Arch_mode { NONE, LIST, EXTRACT, CAT, ADD } mode;  char *fname;  int index;    mode = NONE;  fname = 0;    if(argc>2) {    fname = argv[2];    if((argv[1][0]=='-')&&(strlen(argv[1])==2)) {      switch(argv[1][1]) {      case 'l':	mode = LIST;	break;      case 'x':	mode = EXTRACT;	break;      case 'c':	mode = CAT;	break;      case 'a':	mode = ADD;	break;      default:	mode = NONE;	break;      }    }  }    switch(mode) {  case LIST:    {      if(argc!=3)	break;      U7FileManager fm;      U7file *f = fm.get_file_object(fname);      int count = f->number_of_objects(0);      cout << "Archive: " << fname << endl;      cout << "Type: " << f->get_archive_type() << endl;      cout << "Size: " << count << endl;      cout << "-------------------------" << endl;      for(int i=0; i<count; i++) {	char *buf;	size_t len;		f->retrieve(i, &buf, &len);	cout << i << "\t" << len << endl;	delete [] buf;      }    }    break;  case EXTRACT:    {      if(argc==4) {	U7object f(fname,atoi(argv[3]));	char outfile[32];	sprintf(outfile,"%d.u7o",atoi(argv[3]));	if(!f.retrieve(outfile))	  cout << "Failed to get object" << endl;      } else {	U7FileManager fm;	U7file *f = fm.get_file_object(fname);	int count = f->number_of_objects(0);	for(index=0; index<count; index++) {	  U7object o(fname,index);	  char outfile[32];	  sprintf(outfile,"%d.u7o",index);	  o.retrieve(outfile);	}	delete f;      }    }    break;  default:    cout << "Usage:\n " << argv[0] << " -[l|x|c] file [index]" << endl;    break;  }  return 0;}