From 99f3d9a07cdf25066f559afbfe8ea01734e46b23 Mon Sep 17 00:00:00 2001 From: Orin Date: Wed, 28 Dec 2022 20:12:24 -0600 Subject: [PATCH] Roughed out archive info function. Functional but lacks validation and checks. --- arctool/arctool_cli.cpp | 52 ++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/arctool/arctool_cli.cpp b/arctool/arctool_cli.cpp index c14255d..85f032d 100644 --- a/arctool/arctool_cli.cpp +++ b/arctool/arctool_cli.cpp @@ -1,7 +1,7 @@ /////////////////////////////////////////////////////////////////////////////////////////////////// // Project: agstools // Program: archive_tool -// Purpose: +// Purpose: Data archive unpacking, packing and info tool for Animation Game System engine DAT files. #include #include @@ -10,7 +10,7 @@ /////////////////////////////////////////////////////////////////////////////////////////////////// // Function: archive_info // Purpose: Displays info about provided archive. -void archive_info(std::string& input_path) +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 @@ -20,31 +20,55 @@ void archive_info(std::string& input_path) int location = 0; }; - //Local Variables + //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 --NOTE: Replace with check to check if exists, then what type. + //Assumes exists and opens --NOTE: Replace with check to check if exists, then what type. input_file.open(input_path); - p_buffer = new char[8]; - - input_file.read(p_buffer, 8); + p_buffer = new char[6]; + input_file.read(p_buffer, 6); //Reads magic and number count together into buffer - /* - if (p_buffer == MAGIC) + if ((int)&p_buffer == 1801675120) //This is 4-byte int of 'pack'. Quick 'n dirty compare. { - + file_count = (short)&p_buffer[4]; } else { - //Not correct format! + 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; } ///////////////////////////////////////////////////////////////////////////////////////////////////