2025-02-21 11:21:25 +01:00
|
|
|
/* Lziprecover - Data recovery tool for the lzip format
|
2025-02-21 11:23:37 +01:00
|
|
|
Copyright (C) 2009-2015 Antonio Diaz Diaz.
|
2025-02-21 11:11:34 +01:00
|
|
|
|
|
|
|
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
|
2025-02-21 11:20:57 +01:00
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
2025-02-21 11:11:34 +01:00
|
|
|
(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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class File_index
|
|
|
|
{
|
|
|
|
struct Member
|
|
|
|
{
|
|
|
|
Block dblock, mblock; // data block, member block
|
2025-02-21 11:25:59 +01:00
|
|
|
unsigned dictionary_size;
|
2025-02-21 11:11:34 +01:00
|
|
|
|
|
|
|
Member( const long long dp, const long long ds,
|
2025-02-21 11:25:59 +01:00
|
|
|
const long long mp, const long long ms, const unsigned dict_size )
|
|
|
|
: dblock( dp, ds ), mblock( mp, ms ), dictionary_size( dict_size ) {}
|
2025-02-21 11:16:43 +01:00
|
|
|
|
|
|
|
bool operator==( const Member & m ) const { return ( mblock == m.mblock ); }
|
|
|
|
bool operator!=( const Member & m ) const { return ( mblock != m.mblock ); }
|
2025-02-21 11:11:34 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
std::vector< Member > member_vector;
|
|
|
|
std::string error_;
|
2025-02-21 11:16:43 +01:00
|
|
|
long long isize;
|
2025-02-21 11:11:34 +01:00
|
|
|
int retval_;
|
|
|
|
|
2025-02-21 11:19:58 +01:00
|
|
|
void set_errno_error( const char * const msg );
|
|
|
|
void set_num_error( const char * const msg1, unsigned long long num,
|
2025-02-21 11:25:59 +01:00
|
|
|
const char * const msg2 = "" );
|
2025-02-21 11:19:58 +01:00
|
|
|
|
2025-02-21 11:11:34 +01:00
|
|
|
public:
|
2025-02-21 11:25:59 +01:00
|
|
|
File_index() : error_( "No index" ), isize( 0 ), retval_( 2 ) {}
|
2025-02-21 11:16:43 +01:00
|
|
|
explicit File_index( const int infd );
|
|
|
|
File_index( const std::vector< int > & infd_vector, const long long fsize );
|
2025-02-21 11:11:34 +01:00
|
|
|
|
2025-02-21 11:20:27 +01:00
|
|
|
long members() const { return member_vector.size(); }
|
2025-02-21 11:11:34 +01:00
|
|
|
const std::string & error() const { return error_; }
|
|
|
|
int retval() const { return retval_; }
|
|
|
|
|
2025-02-21 11:16:43 +01:00
|
|
|
bool operator==( const File_index & fi ) const
|
|
|
|
{
|
|
|
|
if( retval_ || fi.retval_ || isize != fi.isize ||
|
|
|
|
member_vector.size() != fi.member_vector.size() ) return false;
|
2025-02-21 11:20:27 +01:00
|
|
|
for( unsigned long i = 0; i < member_vector.size(); ++i )
|
2025-02-21 11:16:43 +01:00
|
|
|
if( member_vector[i] != fi.member_vector[i] ) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool operator!=( const File_index & fi ) const { return !( *this == fi ); }
|
|
|
|
|
2025-02-21 11:11:34 +01:00
|
|
|
long long data_end() const
|
|
|
|
{ if( member_vector.size() ) return member_vector.back().dblock.end();
|
|
|
|
else return 0; }
|
|
|
|
|
|
|
|
long long file_end() const
|
|
|
|
{ if( member_vector.size() ) return member_vector.back().mblock.end();
|
|
|
|
else return 0; }
|
|
|
|
|
2025-02-21 11:25:59 +01:00
|
|
|
// total size including trailing data (if any)
|
2025-02-21 11:16:43 +01:00
|
|
|
long long file_size() const
|
|
|
|
{ if( isize >= 0 ) return isize; else return 0; }
|
|
|
|
|
2025-02-21 11:20:27 +01:00
|
|
|
const Block & dblock( const long i ) const
|
2025-02-21 11:11:34 +01:00
|
|
|
{ return member_vector[i].dblock; }
|
2025-02-21 11:20:27 +01:00
|
|
|
const Block & mblock( const long i ) const
|
2025-02-21 11:11:34 +01:00
|
|
|
{ return member_vector[i].mblock; }
|
2025-02-21 11:25:59 +01:00
|
|
|
unsigned dictionary_size( const long i ) const
|
|
|
|
{ return member_vector[i].dictionary_size; }
|
2025-02-21 11:11:34 +01:00
|
|
|
};
|