Класс для работы с tar архивами. Подробнее...
#include <system/tar_abstraction.h>
Открытые члены | |
| 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 () |
Закрытые члены | |
| void | GotoFirstFile (void) |
| void | ReadHeader (void) |
| void | SetReadCursor (const std::size_t &ReadCursor) |
Закрытые данные | |
| std::size_t | Cursor |
| TARFileHeader | Header |
| nitro::File | LoadedFile |
Класс для работы с tar архивами.
См. определение в файле tar_abstraction.h строка 122
| nitro::UnTARAbstraction::UnTARAbstraction | ( | void | ) |
Конструктор.
| nitro::exception | - Кидается исключение этого типа с описанием ошибки. |
См. определение в файле tar_abstraction.cpp строка 54
Перекрестные ссылки nitro::exception::code() и 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 ) );
}
}

| nitro::UnTARAbstraction::UnTARAbstraction | ( | const std::string & | FilePath | ) |
Конструктор.
| FilePath | - Путь к загружаемому файлу. |
| nitro::exception | - Кидается исключение этого типа с описанием ошибки. |
См. определение в файле tar_abstraction.cpp строка 69
Перекрестные ссылки nitro::exception::code(), OpenFile() и 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 ) );
}
}

| nitro::UnTARAbstraction::~UnTARAbstraction | ( | ) | [virtual] |
Деструктор.
См. определение в файле tar_abstraction.cpp строка 188
Перекрестные ссылки CloseFile().
{
try
{
CloseFile();
}
catch( nitro::exception e )
{
}
catch( ... )
{
}
}

| void nitro::UnTARAbstraction::CloseFile | ( | void | ) |
Закрытие TAR-файла.
| nitro::exception | - Кидается исключение этого типа с описанием ошибки. |
См. определение в файле tar_abstraction.cpp строка 172
Перекрестные ссылки nitro::FileAbstraction::Close(), nitro::exception::code(), LoadedFile и nitro::exception::what().
Используется в ~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 ) );
}
}

| void nitro::UnTARAbstraction::ExtractFile | ( | const std::size_t & | FileCursor, | |
| const std::string & | Folder, | |||
| bool | IgnoreFilePath | |||
| ) |
Разархивирование файла.
| FileCursor | - Курсор разархивируемого файла. | |
| Folder | - Директория куда будут распаковываться файлы. | |
| IgnoreFilePath | - Deprecated. |
| Кидает | исключение типа std::string с описанием ошибки. |
См. определение в файле tar_abstraction.cpp строка 139
Перекрестные ссылки nitro::FSPath::AddEndSlash(), nitro::exception::code(), nitro::FSPath::ExtractFileName(), nitro::TARFileHeader::FileName, Header, nitro::TARFileHeader::LinkType, nitro::File::SaveBinDataToFile(), SetReadCursor() и 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 ) );
}
}

| void nitro::UnTARAbstraction::ExtractFile | ( | const std::size_t & | FileCursor, | |
| type & | Storage | |||
| ) |
Разархивирование файла.
| FileCursor | - Курсор разархивируемого файла. | |
| Storage | - Блок в памяти куда будет принят распакованный файл. |
| Кидает | исключение типа std::string с описанием ошибки. |
См. определение в файле tar_abstraction.h строка 375
Перекрестные ссылки nitro::Converters::atoi(), nitro::exception::code(), nitro::TARFileHeader::FileSize, Header, nitro::TARFileHeader::LinkType, LoadedFile, nitro::OCTAL, nitro::FileAbstraction::Read(), SetReadCursor() и 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 ) );
}
}

| std::size_t nitro::UnTARAbstraction::GetCountOfFiles | ( | void | ) |
Получение количества файлов.
| nitro::exception | - Кидается исключение этого типа с описанием ошибки. |
См. определение в файле tar_abstraction.cpp строка 103
Перекрестные ссылки 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() и 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 ) );
}
}

| void nitro::UnTARAbstraction::GotoFirstFile | ( | void | ) | [private] |
Функция перемещения курсора в начало.
| nitro::exception | - Кидается исключение этого типа с описанием ошибки. |
См. определение в файле tar_abstraction.cpp строка 202
Перекрестные ссылки nitro::exception::code(), Cursor, nitro::FA_FILE_BEGIN, LoadedFile, ReadHeader(), nitro::FileAbstraction::Seek() и nitro::exception::what().
Используется в GetCountOfFiles(), OpenFile() и 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 ) );
}
}

| void nitro::UnTARAbstraction::OpenFile | ( | const std::string & | FilePath | ) |
Открытие TAR-файла.
| FilePath | - Путь к открываемому TAR-файлу. |
| nitro::exception | - Кидается исключение этого типа с описанием ошибки. |
См. определение в файле tar_abstraction.cpp строка 85
Перекрестные ссылки nitro::exception::code(), nitro::FA_FILE_BINARY, nitro::FA_FILE_READ, nitro::FA_FILE_WRITE, GotoFirstFile(), LoadedFile, nitro::FileAbstraction::Open() и nitro::exception::what().
Используется в 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 ) );
}
}

| void nitro::UnTARAbstraction::ReadHeader | ( | void | ) | [private] |
Функция чтения заголовка файла.
| nitro::exception | - Кидается исключение этого типа с описанием ошибки. |
См. определение в файле tar_abstraction.cpp строка 222
Перекрестные ссылки nitro::exception::code(), Header, LoadedFile, nitro::FileAbstraction::Read() и nitro::exception::what().
Используется в GetCountOfFiles(), GotoFirstFile() и 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 ) );
}
}

| void nitro::UnTARAbstraction::SetReadCursor | ( | const std::size_t & | ReadCursor | ) | [private] |
Установка курсора на чтение.
| ReadCursor | - Курсор элемента в архиве. |
| nitro::exception | - Кидается исключение этого типа с описанием ошибки. |
См. определение в файле tar_abstraction.cpp строка 238
Перекрестные ссылки nitro::Converters::atoi(), nitro::exception::code(), Cursor, nitro::FA_FILE_CURRENT, nitro::TARFileHeader::FileSize, GotoFirstFile(), Header, LoadedFile, nitro::OCTAL, ReadHeader(), nitro::FileAbstraction::Seek() и nitro::exception::what().
Используется в 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 ) );
}
}

std::size_t nitro::UnTARAbstraction::Cursor [private] |
Текущий курсор на чтение.
См. определение в файле tar_abstraction.h строка 296
Используется в GetCountOfFiles(), GotoFirstFile() и SetReadCursor().
TARFileHeader nitro::UnTARAbstraction::Header [private] |
Заголовок файла.
См. определение в файле tar_abstraction.h строка 308
Используется в ExtractFile(), GetCountOfFiles(), ReadHeader() и SetReadCursor().
Загруженный файл.
См. определение в файле tar_abstraction.h строка 372
Используется в CloseFile(), ExtractFile(), GetCountOfFiles(), GotoFirstFile(), OpenFile(), ReadHeader() и SetReadCursor().
1.6.1