/////////////////////////////////////////////////////////////////////////////////////////////////// // Project: agstools // Program: archive_tool // Purpose: Data archive unpacking, packing and info tool for Animation Game System engine DAT files. #include #include #include /////////////////////////////////////////////////////////////////////////////////////////////////// // Function: archive_info // Purpose: Displays info about provided archive. void archive_info(std::string& input_path) //Unless refactored into class, could create duplicate code issues. { //Struct --NOTE: May move to global if other functions use it or create overall archive class struct file_node { std::string name; int size = 0; int location = 0; }; //Local Variables --Note: Okay! You got me compiler! I'll initialize them this time... std::ifstream input_file; char* p_buffer = NULL; file_node* p_files_array = NULL; short file_count = 0; //Assumes exists and opens --NOTE: Replace with check to check if exists, then what type. input_file.open(input_path); p_buffer = new char[6]; input_file.read(p_buffer, 6); //Reads magic and number count together into buffer if ((int)&p_buffer == 1801675120) //This is 4-byte int of 'pack'. Quick 'n dirty compare. { file_count = (short)&p_buffer[4]; } else { printf("\nError! Format error!\n"); delete[] p_buffer; //Prevent potential memory leak? return; } delete[] p_buffer; //Read full index p_buffer = new char[file_count * 24]; input_file.seekg(6); input_file.read(p_buffer, (file_count * 24)); //sub expression warning but ITS OKAY! I PROMISE! :D //Process index into file_node array p_files_array = new file_node[file_count]; for (int loop_a = 0; loop_a < file_count; loop_a++) { p_files_array[loop_a].name = p_buffer[(loop_a * 24)]; //Complicated... non-null terminated but fixed size. p_files_array[loop_a].size = p_buffer[(loop_a * 24) + 10]; p_files_array[loop_a].location = 0; } delete[] p_buffer; //Print data cause... info for (int loop_b = 0; loop_b < file_count; loop_b++) { //So... Hey... If there is a lot of files, this gonna make a lot of output, ya know? printf("[%i] %s (%i bytes) (loc %i\n", loop_b + 1, p_files_array[loop_b].name.c_str(), p_files_array[loop_b].size, p_files_array[loop_b].location); } return; } /////////////////////////////////////////////////////////////////////////////////////////////////// // Function: main // Purpose: Program entry point int main(int arg_count, char* p_arg_array[]) { //Initial argument debug #ifdef _DEBUG printf("\nDEBUG: Number of arguments: %i\n", arg_count); for (int a = 0; a < arg_count; a++) { printf("DEBUG: [%i] %s\n", a, p_arg_array[a]); } #endif //Local Variables std::string temp; std::string input_path; std::string output_path; //Start program if (arg_count > 1) { if (arg_count < 5) { temp = p_arg_array[1]; if (temp == "-info" || temp == "-i") { input_path = p_arg_array[2]; if (arg_count >= 3) { //Set output path } archive_info(input_path); return 0; //We good? } else { printf("\nError! Unknown argument!"); } } else { printf("\nError! Too many arguments!"); } } else { printf("\nError! Not enough arguments!"); } //Usage branding printf("\n\nUsage: