Public Member Functions | Private Member Functions | Private Attributes

nitro::UnTARAbstraction Class Reference

Class for tar files manipulation. More...

#include <system/tar_abstraction.h>

Collaboration diagram for nitro::UnTARAbstraction:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 UnTARAbstraction (void)
 UnTARAbstraction (const std::string &FilePath)
void OpenFile (const std::string &FilePath)
std::size_t GetCountOfFiles (void)
void ExtractFile (const std::size_t &FileCursor, const std::string &Folder, bool IgnoreFilePath)
template<class type >
void ExtractFile (const std::size_t &FileCursor, type &Storage)
void CloseFile (void)
virtual ~UnTARAbstraction ()

Private Member Functions

void GotoFirstFile (void)
void ReadHeader (void)
void SetReadCursor (const std::size_t &ReadCursor)

Private Attributes

std::size_t Cursor
TARFileHeader Header
nitro::File LoadedFile

Detailed Description

Class for tar files manipulation.

Author:
Dodonov A.A.

Definition at line 122 of file tar_abstraction.h.


Constructor & Destructor Documentation

nitro::UnTARAbstraction::UnTARAbstraction ( void   ) 

Constructor.

Exceptions:
nitro::exception - An exception of that type is thrown. Contains error description.
Author:
Dodonov A.A.

Definition at line 54 of file tar_abstraction.cpp.

References nitro::exception::code(), and nitro::exception::what().

        {
                try
                {
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "UnTARAbstraction::UnTARAbstraction( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "UnTARAbstraction::UnTARAbstraction( void )::An error occured while opening file" ) , 1 ) );
                }
        }

Here is the call graph for this function:

nitro::UnTARAbstraction::UnTARAbstraction ( const std::string &  FilePath  ) 

Constructor.

Parameters:
FilePath - Path to the loading file.
Exceptions:
nitro::exception - An exception of that type is thrown. Contains error description.
Author:
Dodonov A.A.

Definition at line 69 of file tar_abstraction.cpp.

References nitro::exception::code(), OpenFile(), and nitro::exception::what().

        {
                try
                {
                        OpenFile( FilePath );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "UnTARAbstraction::UnTARAbstraction( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "UnTARAbstraction::UnTARAbstraction( void )::An error occured while opening file" ) , 1 ) );
                }
        }

Here is the call graph for this function:

nitro::UnTARAbstraction::~UnTARAbstraction (  )  [virtual]

Destructor.

Author:
Dodonov A.A.

Definition at line 188 of file tar_abstraction.cpp.

References CloseFile().

        {
                try
                {
                        CloseFile();
                }
                catch( nitro::exception e )
                {
                }
                catch( ... )
                {
                }
        }

Here is the call graph for this function:


Member Function Documentation

void nitro::UnTARAbstraction::CloseFile ( void   ) 

Finction closes TAR file.

Returns:
true if the file was closed successfully.
Exceptions:
nitro::exception - An exception of that type is thrown. Contains error description.
Author:
Dodonov A.A.

Definition at line 172 of file tar_abstraction.cpp.

References nitro::FileAbstraction::Close(), nitro::exception::code(), LoadedFile, and nitro::exception::what().

Referenced by ~UnTARAbstraction().

        {
                try
                {
                        LoadedFile.Close();
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "UnTARAbstraction::CloseFile( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "UnTARAbstraction::CloseFile( void )::An error occured while closing file" ) , 1 ) );
                }
        }

Here is the call graph for this function:

void nitro::UnTARAbstraction::ExtractFile ( const std::size_t &  FileCursor,
const std::string &  Folder,
bool  IgnoreFilePath 
)

Function extracts files.

Parameters:
FileCursor - Cursor fo the file.
Folder - Directory of the unzipping file.
IgnoreFilePath - Deprecated.
Exceptions:
nitro::exception - An exception of that type is thrown. Contains error description.
Author:
Dodonov A.A.

Definition at line 139 of file tar_abstraction.cpp.

References nitro::FSPath::AddEndSlash(), nitro::exception::code(), nitro::FSPath::ExtractFileName(), nitro::TARFileHeader::FileName, Header, nitro::TARFileHeader::LinkType, nitro::File::SaveBinDataToFile(), SetReadCursor(), and nitro::exception::what().

        {
                try
                {
                        SetReadCursor( FileCursor );

                        if( '0' == Header.LinkType )
                        {
                                std::string             FilePath( "" );
                                if( IgnoreFilePath )
                                {
                                        FilePath = nitro::FSPath::AddEndSlash( std::string( Folder ) ) + nitro::FSPath::ExtractFileName( std::string( Header.FileName ) );
                                }
                                else
                                {
                                        FilePath = nitro::FSPath::AddEndSlash( std::string( Folder ) ) + std::string( Header.FileName );
                                }

                                nitro::BinaryData                       Storage;
                                ExtractFile( FileCursor , Storage );
                                nitro::File::SaveBinDataToFile( Storage , FilePath );
                        }
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "UnTARAbstraction::ExtractFile( const std::size_t & FileCursor , const std::string & Folder , bool IgnoreFilePath /* = true */ )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "UnTARAbstraction::ExtractFile( const std::size_t & FileCursor , const std::string & Folder , bool IgnoreFilePath /* = true */ )::An error occured while extracting file" ) , 1 ) );
                }
        }

Here is the call graph for this function:

template<class type >
void nitro::UnTARAbstraction::ExtractFile ( const std::size_t &  FileCursor,
type &  Storage 
)

Function extracts files.

Parameters:
FileCursor - Cursor fo the file.
Storage - Memory storage to accept data.
Exceptions:
nitro::exception - An exception of that type is thrown. Contains error description.
Author:
Dodonov A.A.

Definition at line 375 of file tar_abstraction.h.

References nitro::Converters::atoi(), nitro::exception::code(), nitro::TARFileHeader::FileSize, Header, nitro::TARFileHeader::LinkType, LoadedFile, nitro::OCTAL, nitro::FileAbstraction::Read(), SetReadCursor(), and nitro::exception::what().

        {
                try
                {
                        SetReadCursor( FileCursor );

                        if( Header.LinkType == '0' )
                        {
                                char                    Buffer[ 512 ];
                                int                             FileSize( nitro::Converters::atoi( Header.FileSize , nitro::OCTAL ) );
                                int                             ReadBytes( 0 ) , TotalReadBytes( 0 );

                                do
                                {
                                        LoadedFile.Read( Buffer , 512 );
                                        ReadBytes = TotalReadBytes + 512 < FileSize ? 512 : FileSize % 512;
                                        if( ReadBytes > 0 )
                                        {
                                                Storage.AppendData( Buffer , ReadBytes );
                                        }
                                        TotalReadBytes += ReadBytes;
                                }
                                while( ReadBytes == 512 );
                        }
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "UnTARAbstraction::ExtractFile( const std::size_t & FileCursor , type & Storage )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "UnTARAbstraction::ExtractFile( const std::size_t & FileCursor , type & Storage )::An error occured while extracting file" ) , 1 ) );
                }
        }

Here is the call graph for this function:

std::size_t nitro::UnTARAbstraction::GetCountOfFiles ( void   ) 

Function returns count of files.

Returns:
Count of files.
Exceptions:
nitro::exception - An exception of that type is thrown. Contains error description.
Author:
Dodonov A.A.

Definition at line 103 of file tar_abstraction.cpp.

References nitro::Converters::atoi(), nitro::exception::code(), Cursor, nitro::FA_FILE_BEGIN, nitro::FA_FILE_CURRENT, nitro::TARFileHeader::FileName, nitro::TARFileHeader::FileSize, GotoFirstFile(), Header, LoadedFile, nitro::OCTAL, ReadHeader(), nitro::FileAbstraction::Seek(), nitro::FileAbstraction::Tell(), and nitro::exception::what().

        {
                try
                {
                        std::size_t             CurrentCursor( Cursor );
                        std::size_t             CurrentFilePosition( LoadedFile.Tell() );
                        TARFileHeader   CurrentHeader( Header );

                        GotoFirstFile();
                        std::size_t     Counter( 0 );
                        for( ; std::string( "" ) != Header.FileName ; Counter++ )
                        {
                                int                             FileSize( nitro::Converters::atoi( Header.FileSize , nitro::OCTAL ) );
                                if( FileSize )
                                {
                                        int                             Offset( FileSize / 512 * 512 + ( FileSize % 512 ? 512 : 0 ) );
                                        LoadedFile.Seek( Offset , nitro::FA_FILE_CURRENT );
                                }
                                ReadHeader();
                        }

                        Cursor = CurrentCursor;
                        Header = CurrentHeader;
                        LoadedFile.Seek( CurrentFilePosition , nitro::FA_FILE_BEGIN );
                        return( Counter );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "UnTARAbstraction::GetCountOfFiles( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "UnTARAbstraction::GetCountOfFiles( void )::An error occured while getting count of files" ) , 1 ) );
                }
        }

Here is the call graph for this function:

void nitro::UnTARAbstraction::GotoFirstFile ( void   )  [private]

Finction moves cursor to the beginning.

Exceptions:
nitro::exception - An exception of that type is thrown. Contains error description.
Author:
Dodonov A.A.

Definition at line 202 of file tar_abstraction.cpp.

References nitro::exception::code(), Cursor, nitro::FA_FILE_BEGIN, LoadedFile, ReadHeader(), nitro::FileAbstraction::Seek(), and nitro::exception::what().

Referenced by GetCountOfFiles(), OpenFile(), and SetReadCursor().

        {
                try
                {
                        LoadedFile.Seek( 0 , nitro::FA_FILE_BEGIN );

                        Cursor = 0;

                        ReadHeader();
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "UnTARAbstraction::GotoFirstFile( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "UnTARAbstraction::GotoFirstFile( void )::An error occured while moving cursor to the begin" ) , 1 ) );
                }
        }

Here is the call graph for this function:

void nitro::UnTARAbstraction::OpenFile ( const std::string &  FilePath  ) 

Function opens TAR file.

Parameters:
FilePath - Path to the opening file.
Exceptions:
nitro::exception - An exception of that type is thrown. Contains error description.
Author:
Dodonov A.A.

Definition at line 85 of file tar_abstraction.cpp.

References nitro::exception::code(), nitro::FA_FILE_BINARY, nitro::FA_FILE_READ, nitro::FA_FILE_WRITE, GotoFirstFile(), LoadedFile, nitro::FileAbstraction::Open(), and nitro::exception::what().

Referenced by UnTARAbstraction().

        {
                try
                {
                        LoadedFile.Open( FilePath , nitro::FA_FILE_BINARY | nitro::FA_FILE_READ | nitro::FA_FILE_WRITE );

                        GotoFirstFile();
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "UnTARAbstraction::OpenFile( const std::string & FilePath )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "UnTARAbstraction::OpenFile( const std::string & FilePath )::An error occured while opening file" ) , 1 ) );
                }
        }

Here is the call graph for this function:

void nitro::UnTARAbstraction::ReadHeader ( void   )  [private]

Finction reads file's header.

Exceptions:
nitro::exception - An exception of that type is thrown. Contains error description.
Author:
Dodonov A.A.

Definition at line 222 of file tar_abstraction.cpp.

References nitro::exception::code(), Header, LoadedFile, nitro::FileAbstraction::Read(), and nitro::exception::what().

Referenced by GetCountOfFiles(), GotoFirstFile(), and SetReadCursor().

        {
                try
                {
                        LoadedFile.Read( ( char * ) & Header , sizeof( Header ) );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "UnTARAbstraction::ReadHeader( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "UnTARAbstraction::ReadHeader( void )::An error occured while reading header" ) , 1 ) );
                }
        }

Here is the call graph for this function:

void nitro::UnTARAbstraction::SetReadCursor ( const std::size_t &  ReadCursor  )  [private]

Finction sets read cursor in the file.

Parameters:
ReadCursor - Element's cursor in the archive.
Exceptions:
nitro::exception - An exception of that type is thrown. Contains error description.
Author:
Dodonov A.A.

Definition at line 238 of file tar_abstraction.cpp.

References nitro::Converters::atoi(), nitro::exception::code(), Cursor, nitro::FA_FILE_CURRENT, nitro::TARFileHeader::FileSize, GotoFirstFile(), Header, LoadedFile, nitro::OCTAL, ReadHeader(), nitro::FileAbstraction::Seek(), and nitro::exception::what().

Referenced by ExtractFile().

        {
                try
                {
                        /* special case */
                        if( Cursor > ReadCursor )
                        {
                                GotoFirstFile();
                        }

                        /* moving cursor */
                        if( Cursor != ReadCursor )
                        {
                                for( std::size_t i( 0 ) ; i < ReadCursor - Cursor ; i++ )
                                {
                                        int                             FileSize( nitro::Converters::atoi( Header.FileSize , nitro::OCTAL ) );
                                        int                             Offset( FileSize / 512 * 512 + ( FileSize % 512 ? 512 : 0 ) );
                                        if( Offset )
                                        {
                                                LoadedFile.Seek( Offset , nitro::FA_FILE_CURRENT );
                                        }
                                        ReadHeader();
                                }
                                Cursor = ReadCursor;
                        }
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "UnTARAbstraction::SetReadCursor( const std::size_t & ReadCursor )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "UnTARAbstraction::SetReadCursor( const std::size_t & ReadCursor )::An error occured while setting cursor" ) , 1 ) );
                }
        }

Here is the call graph for this function:


Member Data Documentation

std::size_t nitro::UnTARAbstraction::Cursor [private]

Current read cursor.

Author:
Dodonov A.A.

Definition at line 296 of file tar_abstraction.h.

Referenced by GetCountOfFiles(), GotoFirstFile(), and SetReadCursor().

File's header.

Author:
Dodonov A.A.

Definition at line 308 of file tar_abstraction.h.

Referenced by ExtractFile(), GetCountOfFiles(), ReadHeader(), and SetReadCursor().

Loaded file.

Author:
Dodonov A.A.

Definition at line 372 of file tar_abstraction.h.

Referenced by CloseFile(), ExtractFile(), GetCountOfFiles(), GotoFirstFile(), OpenFile(), ReadHeader(), and SetReadCursor().


The documentation for this class was generated from the following files:

Generated by  doxygen 1.6.1