/* Unmass - unpacker for game archives. Copyright (C) 2002-2007 Mirex This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include "config.h" #ifdef _UNIX #include #include #include #include #endif #include "utools.h" UnmassTools::s_params UnmassTools::param_def[ UnmassTools::param_def_count ] = { { param_help, "-help", 0 }, { param_help, "--help", 0 }, { param_help, "/?", 0 }, { param_list_of_modules, "-modules", 0 }, { param_print_file_list, "-list", 1 }, { param_extract_files, "-e", -2 }, } ; char UnmassTools::version_string[ 20 ] = "0.9 console"; char UnmassTools::executable_name_string[ 20 ] = "unmass"; void UnmassTools::Log( int severity, const char* format, ... ) { va_list argptr; va_start( argptr, format ); vprintf( format, argptr ); va_end( argptr ); } int UnmassTools::Start( int argc, char* argv[] ) { int action = param_help; int i, c, required_params_number; bool or_more = false; UnmassTools::array_of_filenames names_array; if ( argc <= 1 ) { action = param_none; } else { for( i=0; i required_params_number ) && ( or_more == false )) { Log( 0, "Supplied more than enough parameters.\n" ); } if ( c < required_params_number ) { Log( 0, "Not enough parameters.\n" ); action = param_none; } break; } } switch( action ) { case param_none: PrintProgramInfo(); return 0; case param_help: PrintHelp(); return 0; case param_list_of_modules: PrintModules(); return 0; case param_print_file_list: return PrintMassFileList( argv[ 2 ] ); case param_extract_files: names_array.clear(); for( i=0; i\n" ); Log( 0, "Opens the archive and prints list of the files inside.\n" ); break; case param_extract_files: Log( 0, "Parameters: [...]\n" ); Log( 0, "Opens the archive and extract files.\n" ); Log( 0, " file name can be specified also with * wildcard in one of these forms:\n"); Log( 0, " 'name', 'prefix*', '*suffix' or 'prefix*suffix' \n"); Log( 0, " so 'level*.txt' should work well.\n"); Log( 0, " Enclose the filenames with wildcards into ' ' so unix system won't replace\n" ); Log( 0, " those names with currently existing files names.\n" ); break; } Log( 0, "\n" ); } Log( 0, "Example:\n" ); Log( 0, " %s -list battle.lgp\n", executable_name_string ); Log( 0, " Displays list of files contained inside archive 'battle.lgp'\n\n" ); Log( 0, " %s -e battle.lgp aabc.txt *dat\n", executable_name_string ); Log( 0, " Opens 'battle.lgp' and extracts file 'aabc.txt' and all files ending\n" ); Log( 0, " with 'dat' into current directory\n\n" ); Log( 0, "\n" ); return; } void UnmassTools::PrintModules( void ) { int i, c; CMassArchive* pArchive; Log( 0, "Plugins and their supported types:\n" ); for( i=0; iGetExtension(), pArchive->GetIdent() ); } } } int UnmassTools::PrintMassFileList( const char* mass_filename ) { if ( massfs.Open( mass_filename ) == 0 ) { Log( 1, "Error, could not open file (%s)\n", massfs.GetErrorStr() ); return 0; } int i, c; c = massfs.MassfInfo.files_count; massfs.ReadAllRecords(); for( i=0; i 1 ) break; // treat all characters before star as prefix if ( ccp != fname ) { c = ( ccp - fname ); if ( c >= name_len ) c = name_len - 1; memcpy( prefix, fname, c ); prefix[ c ] = 0; prefix_length = c; } } else { // if there was star already, and suffix is empty then create it if (( stars > 0 ) && ( suffix[ 0 ] == 0 )) { strncpy( suffix, ccp, name_len-1 ); suffix_length = strlen( suffix ); } } ccp++; } // too many stars ? invalid mask ! if ( stars > 1 ) { Reset(); valid = false; } else { strncpy( name, fname, name_len-1 ); valid = true; } } // Parse } filespec; for( i=0; i 0 ) && ( _strncasecmp( filespec.prefix, massfs.FileRec.name, filespec.prefix_length ) == 0 )) prefix_match = true; // check for suffix if (( extract == false ) && ( filespec.suffix_length > 0 ) && ( _strcasecmp( filespec.suffix, massfs.FileRec.name + strlen( massfs.FileRec.name ) - filespec.suffix_length ) == 0 )) suffix_match = true; // if there is both prefix and suffix defined, then extract only if both match if (( filespec.prefix_length > 0 ) && ( filespec.suffix_length > 0 )) { if (( prefix_match) && ( suffix_match )) extract = true; } else { if (( prefix_match ) || ( suffix_match )) extract = true; } if ( extract ) { extracted_files++; Log( 0, "Extracting file '%s'\n", massfs.FileRec.name ); massfs.Extract(); } } // if I extract all files its not needed to extract any more if ( filespec.all ) { break; } } Log( 0, "Extracted %i files.\n", extracted_files ); massfs.Close(); return 1; } void UnmassTools::_strlwr( char* string ) { #ifdef _UNIX char* cp = string; while( *cp != 0 ) { *cp = tolower( *cp ); cp++; } return; #else strlwr( string ); return; #endif } int UnmassTools::_strcasecmp( const char* s1, const char* s2 ) { #ifdef _UNIX return strcasecmp( s1, s2 ); #else return stricmp( s1, s2 ); #endif } int UnmassTools::_strncasecmp( const char* s1, const char* s2, int n ) { #ifdef _UNIX return strncasecmp( s1, s2, n ); #else error, don't know of suitable function return stricmp( s1, s2 ); #endif }