Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include <windows.h>
- #include <stdio.h>
- #include <iostream>
- #include "zlib123-dll/include/zlib.h"
- #include "blowfish.h"
- #pragma comment(lib, "./zlib123-dll/lib/zdll")
- #pragma warning( disable : 4099 )
- #include "acvarchive.h"
- using namespace std;
- const int MAYORVERSION = 1;
- const int MINORVERSION = 3;
- enum Acvmode { ACVLIST, ACVCOMPRESS1, ACVCOMPRESSALL,
- ACVDECOMPRESS1, ACVDECOMPRESSALL, ACVCOMPRESSINDEX,
- ACVCOMPRESSNEW } ;
- Acvmode acvmode = ACVLIST;
- char * acvfilename = 0;
- char * outputdirectory = 0;
- char * inputdirectory = 0;
- char * inputfilename = 0;
- int acvindex = 0;
- vector<string> pathlist;
- void usage();
- bool parseargs( int argc, char * argv[] );
- bool acvprintlist(AcvArchive& acv);
- bool acvcompress1(AcvArchive& acv);
- bool acvcompressall(AcvArchive& acv);
- bool acvdecompress1(AcvArchive& acv);
- bool acvdecompressall(AcvArchive& acv);
- bool acvcompressindex(AcvArchive& acv);
- bool acvcompressnew(AcvArchive& acv);
- extern unsigned char acvkeyheader[];
- int main(int argc, char * argv[] )
- {
- /*BlowFish::CBlowFish crypt( &acvkeyheader[0], 56);
- FILE * in = fopen("052.acv","rb");
- int filecount=0;
- unsigned short csize;
- unsigned char * bufin = new unsigned char[1024*1024];
- unsigned char * bufout = new unsigned char[1024*1024];
- fread( bufin, 4, 1, in);
- fread( &filecount, 4, 1, in );
- fread( &csize, 2, 1, in );
- fread( bufin, csize, csize, in );
- crypt.Decrypt( bufin, bufout, csize );
- uncompress(bufin, (uLongf *)&filecount, bufout, 1024*1024 );
- fclose(in);
- */
- //////////////////////////////
- int err;
- bool result;
- AcvArchive acv;
- if ( parseargs( argc, argv ) == false )
- {
- usage();
- return 1;
- }
- bool openmode = ( acvmode == ACVCOMPRESSALL || acvmode == ACVCOMPRESS1 || ACVCOMPRESSINDEX );
- result = acv.Open( acvfilename, openmode );
- pathlist = acv.Getpathlist();
- if ( result == false )
- {
- printf("Error opening file ...%s\n", acvfilename );
- return 1;
- }
- switch( acvmode )
- {
- case ACVLIST:
- err = acvprintlist( acv ) == true;
- break;
- case ACVCOMPRESS1:
- err = acvcompress1( acv ) == true;
- acv.Rebuild();
- break;
- case ACVCOMPRESSALL:
- err = acvcompressall( acv ) == true;
- acv.Rebuild();
- break;
- case ACVCOMPRESSINDEX:
- err = acvcompressindex( acv ) == true;
- acv.Rebuild();
- break;
- case ACVCOMPRESSNEW:
- err = acvcompressnew( acv ) == true;
- acv.Rebuild();
- break;
- case ACVDECOMPRESS1:
- err = acvdecompress1( acv ) == true;
- break;
- case ACVDECOMPRESSALL:
- err = acvdecompressall( acv ) == true;
- break;
- default:
- printf("Should not get here \"switch(acvmode)\"....\n");
- }
- return !(err==1);
- }
- bool acvprintlist(AcvArchive& acv)
- {
- Acvfilelist& acvlist = acv.Getfilelist();
- Acvfilelist::iterator it;
- it = acvlist.begin();
- while( it != acvlist.end() )
- {
- printf( "[%03i] %s\n", it->index, it->fullname.c_str() );
- it++;
- }
- printf("Total files = %i\n", acv.Getfilecount() );
- int i=1;
- vector<string>::iterator sit;
- sit = pathlist.begin();
- while( sit != pathlist.end() )
- {
- printf( "<<< %02i >>> %s\n", i, sit->c_str() );
- sit++;
- i++;
- }
- return true;
- }
- bool acvcompressindex(AcvArchive& acv)
- {
- Acvfilelist& acvlist = acv.Getfilelist();
- Acvfilelist::iterator it;
- string argsinput;
- int matchindex=-1;
- argsinput = inputfilename;
- it = acvlist.begin();
- while( it != acvlist.end() )
- {
- if ( it->index == acvindex )
- matchindex = it->index;
- it++;
- }
- if ( matchindex == -1 )
- {
- printf( "File not found : %s\n", inputfilename );
- return false;
- }
- if ( acv.Insert( acvlist[matchindex], argsinput ) == false )
- {
- printf( "Insert failed...\n" );
- return false;
- }
- return true;
- }
- bool acvcompressnew(AcvArchive& acv)
- {
- int size = pathlist.size();
- if ( acvindex > size )
- {
- printf( "Directory not found\n");
- return false;
- }
- vector<string>& pathlist = acv.Getpathlist();
- string argsinput = inputfilename;
- if ( acv.InsertNew( pathlist[acvindex-1], argsinput ) == false )
- {
- printf( "Insert failed...\n" );
- return false;
- }
- return true;
- }
- bool acvcompress1(AcvArchive& acv)
- {
- Acvfilelist& acvlist = acv.Getfilelist();
- Acvfilelist::iterator it;
- string argsinput;
- int matchindex=-1;
- argsinput = inputfilename;
- it = acvlist.begin();
- while( it != acvlist.end() )
- {
- if ( it->name == argsinput )
- matchindex = it->index;
- it++;
- }
- if ( matchindex == -1 )
- {
- printf( "File not found : %s\n", inputfilename );
- return false;
- }
- if ( acv.Insert( acvlist[matchindex], argsinput ) == false )
- {
- printf( "Insert failed...\n" );
- return false;
- }
- return true;
- }
- bool acvcompressall(AcvArchive& acv)
- {
- // NOT IMPLEMENTED
- return true;
- }
- bool acvdecompress1(AcvArchive& acv)
- {
- Acvfilelist& acvlist = acv.Getfilelist();
- Acvfilelist::iterator it;
- if ( !(acvindex && acvindex <= acv.Getfilecount()) )
- {
- printf("Index out of range, valid range are 0 to %03i\n", acv.Getfilecount() );
- return false;
- }
- printf("Extract...%s\n", acvlist[acvindex].name.c_str() );
- return acv.Extract( acvlist[acvindex], acvlist[acvindex].name );
- }
- bool acvdecompressall(AcvArchive& acv)
- {
- Acvfilelist& acvlist = acv.Getfilelist();
- Acvfilelist::iterator it;
- vector<string>::iterator sit;
- vector<string>& pathlist = acv.Getpathlist();
- CreateDirectory( outputdirectory, 0 );
- sit = pathlist.begin();
- while( sit != pathlist.end() )
- {
- string path = outputdirectory;
- path += "\\";
- path += *sit;
- CreateDirectory( path.c_str(), 0 );
- sit++;
- }
- it = acvlist.begin();
- int i=0;
- while ( it != acvlist.end() )
- {
- i++;
- if ( i==0xb2 )
- i=i;
- string path = outputdirectory;
- path += "\\";
- path += it->fullname;
- printf(" writing : %s\n", path.c_str() );
- acv.Extract( *it, path );
- it++;
- }
- return true;
- }
- void usage()
- {
- printf( "ACV Archive Tool v%i.%i\n", MAYORVERSION, MINORVERSION );
- printf( " Copyright (C) 2009 mnemonix\n\n" );
- printf( "Usage : acv <switch> <acvfile> <filename>\n\n");
- printf( "Examples :\n");
- printf( " acv -l <acvfile> list archive contents\n" );
- printf( " acv -da <acvfile> <outdir> decompress all files to directory <outdir>\n" );
- printf( " acv -d <acvfile> <index> decompress 1 file specified by <index>\n" );
- printf( " use -l switch to get the index\n" );
- // NOT IMPLEMENTED
- //printf( " acv -ca <acvfile> <inputdir> compress <inputdir> directory into\n");
- //printf( " a single <acvfile>\n" );
- printf( " acv -c <acvfile> <input> compress <input> to <acvfile>\n" );
- printf( " acv -c1 <acvfile> <input> <index> compress <input> to <index> into <acvfile>\n" );
- printf( " acv -cn <acvfile> <input> <dindex> compress <input> to directory <index>\n");
- printf( "Have a nice mod....\n\n" );
- }
- bool parseargs( int argc, char * argv[] )
- {
- if ( argc < 3 ) return false;
- char * sw = argv[1];
- if ( sw[0] != '-' ) return false;
- bool bret = false;
- switch ( sw[1] )
- {
- case 'l' :
- acvmode = ACVLIST;
- acvfilename = argv[2];
- bret = true;
- break;
- case 'd' :
- if ( sw[2] == 'a' && argc == 4)
- {
- acvfilename = argv[2];
- outputdirectory = argv[3];
- acvmode = ACVDECOMPRESSALL;
- bret = true;
- }
- else if ( sw[2] == 0 && argc != 4 )
- {
- acvfilename = argv[2];
- acvmode = ACVDECOMPRESS1;
- if ( sscanf(argv[3], "%i", &acvindex ) == 0 )
- {
- bret = true;
- }
- }
- break;
- case 'c' :
- if ( sw[2] == 'a' && argc == 4 )
- {
- acvfilename = argv[2];
- inputdirectory = argv[3];
- acvmode = ACVCOMPRESSALL;
- bret = true;
- }
- else if ( sw[2] == 0 && argc == 4)
- {
- acvfilename = argv[2];
- inputfilename = argv[3];
- acvmode = ACVCOMPRESS1;
- //if ( sscanf(argv[4], "%i", &acvindex ) == 1 )
- //{
- bret = true;
- //}
- }
- else if ( sw[2] == '1' && argc == 5 )
- {
- acvfilename = argv[2];
- inputfilename = argv[3];
- acvmode = ACVCOMPRESSINDEX;
- if ( sscanf(argv[4], "%i", &acvindex ) == 1 )
- {
- bret = true;
- }
- }
- else if ( sw[2] == 'n' && argc == 5 )
- {
- acvfilename = argv[2];
- inputfilename = argv[3];
- acvmode = ACVCOMPRESSNEW;
- if ( sscanf( argv[4], "%i", &acvindex ) == 1 )
- {
- bret = true;
- }
- }
- break;
- }
- return bret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement