diff options
Diffstat (limited to '')
-rw-r--r-- | split.cc | 42 |
1 files changed, 18 insertions, 24 deletions
@@ -1,5 +1,5 @@ /* Lziprecover - Data recovery tool for the lzip format - Copyright (C) 2009-2017 Antonio Diaz Diaz. + Copyright (C) 2009-2018 Antonio Diaz Diaz. 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 @@ -86,7 +86,7 @@ int find_magic( const uint8_t * const buffer, const int pos, const int size ) int do_split_file( const std::string & input_filename, uint8_t * & base_buffer, const std::string & default_output_filename, - const int verbosity, const bool force ) + const bool force ) { const int hsize = File_header::size; const int tsize = File_trailer::size; @@ -98,7 +98,15 @@ int do_split_file( const std::string & input_filename, uint8_t * & base_buffer, struct stat in_stats; const int infd = open_instream( input_filename.c_str(), &in_stats, true, true ); if( infd < 0 ) return 1; - Pretty_print pp( input_filename, verbosity ); + Pretty_print pp( input_filename ); + + // don't move this after seek_read + const File_index file_index( infd, true, true, true ); +// if( file_index.retval() != 0 ) pp( file_index.error().c_str() ); + const long max_members = file_index.retval() ? 999999 : file_index.members(); + int max_digits = 1; + for( long i = max_members; i >= 10; i /= 10 ) ++max_digits; + int size = seek_read( infd, buffer, buffer_size + hsize, 0 ) - hsize; bool at_stream_end = ( size < buffer_size ); if( size != buffer_size && errno ) @@ -107,17 +115,12 @@ int do_split_file( const std::string & input_filename, uint8_t * & base_buffer, { pp( "Input file is too short." ); return 2; } if( !verify_header( *(File_header *)buffer, pp ) ) return 2; - const File_index file_index( infd, true, true ); - if( file_index.retval() != 0 ) pp( file_index.error().c_str() ); - const long max_members = file_index.retval() ? 999999 : file_index.members(); - int max_digits = 1; - for( long i = max_members; i >= 10; i /= 10 ) ++max_digits; - first_filename( input_filename, default_output_filename, max_digits ); if( !open_outstream( force, false, false, false ) ) { close( infd ); return 1; } unsigned long long partial_member_size = 0; + const bool ttyout = isatty( STDOUT_FILENO ); while( true ) { int pos = 0; @@ -135,7 +138,8 @@ int do_split_file( const std::string & input_filename, uint8_t * & base_buffer, if( close_outstream( &in_stats ) != 0 ) return 1; if( verbosity >= 1 ) { - std::printf( "Member '%s' done \r", output_filename.c_str() ); + std::printf( "Member '%s' done %c", output_filename.c_str(), + ttyout ? '\r' : '\n' ); std::fflush( stdout ); } if( !next_filename( max_digits ) ) @@ -184,29 +188,19 @@ int do_split_file( const std::string & input_filename, uint8_t * & base_buffer, bool verify_header( const File_header & header, const Pretty_print & pp ) { if( !header.verify_magic() ) - { - pp( "Bad magic number (file not in lzip format)." ); - return false; - } + { pp( bad_magic_msg ); return false; } if( !header.verify_version() ) - { - if( pp.verbosity() >= 0 ) - { pp(); - std::fprintf( stderr, "Version %d member format not supported.\n", - header.version() ); } - return false; - } + { pp( bad_version( header.version() ) ); return false; } return true; } int split_file( const std::string & input_filename, - const std::string & default_output_filename, - const int verbosity, const bool force ) + const std::string & default_output_filename, const bool force ) { uint8_t * base_buffer; const int retval = do_split_file( input_filename, base_buffer, - default_output_filename, verbosity, force ); + default_output_filename, force ); delete[] base_buffer; return retval; } |