Класс для работы с zip архивами. Подробнее...
#include <system/zip_abstraction.h>
Открытые члены | |
| UnZIPAbstraction (void) | |
| UnZIPAbstraction (const std::string &FilePath) | |
| void | Open (const std::string &FilePath) |
| void | Close (void) |
| std::size_t | GetCountOfFiles (void) const |
| void | UnZIPFile (const std::size_t FileCursor, const std::string &Folder, bool IgnoreFilePath=true) |
| virtual | ~UnZIPAbstraction () |
| UnZIPAbstraction (const UnZIPAbstraction &) | |
| UnZIPAbstraction | operator= (const UnZIPAbstraction &) |
| void | GotoFile (const std::size_t FileCursor) |
| void | GotoFirstFile (void) |
| void | GotoNextFile (void) |
| void | UnZIPFile (const std::string &Folder, bool IgnoreFilePath) |
Открытые атрибуты | |
| void * | File |
| std::size_t | CurrentCursorPosition |
Класс для работы с zip архивами.
См. определение в файле zip_abstraction.h строка 256
| nitro::UnZIPAbstraction::UnZIPAbstraction | ( | void | ) |
Конструктор.
| Кидает | исключение типа std::string с описанием ошибки. |
См. определение в файле zip_abstraction.cpp строка 208
Перекрестные ссылки nitro::exception::code(), CurrentCursorPosition и nitro::exception::what().
: File( 0 ) { try { CurrentCursorPosition = std::numeric_limits< std::size_t >::max(); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "UnZIPAbstraction::CloseZIP( void )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "UnZIPAbstraction::CloseZIP( void )::An error occured while unzipping file" ) , 1 ) ); } }

| nitro::UnZIPAbstraction::UnZIPAbstraction | ( | const std::string & | FilePath | ) |
Конструктор.
| FilePath | - Путь к загружаемому файлу. |
| Кидает | исключение типа std::string с описанием ошибки. |
См. определение в файле zip_abstraction.cpp строка 225
Перекрестные ссылки Close(), nitro::exception::code(), Open() и nitro::exception::what().
: File( 0 ) { try { Close(); Open( FilePath ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "UnZIPAbstraction::UnZIPAbstraction( const std::string & FilePath )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "UnZIPAbstraction::UnZIPAbstraction( const std::string & FilePath )::An error occured while unzipping file" ) , 1 ) ); } }

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

| nitro::UnZIPAbstraction::UnZIPAbstraction | ( | const UnZIPAbstraction & | ) | [inline] |
Закрытый конструктор копирования.
| nitro::exception | - Кидается исключение этого типа с описанием ошибки. |
См. определение в файле zip_abstraction.h строка 436
{}
| void nitro::UnZIPAbstraction::Close | ( | void | ) |
Закрытие ZIP-файла.
| Кидает | исключение типа std::string с описанием ошибки. |
См. определение в файле zip_abstraction.cpp строка 491
Перекрестные ссылки nitro::exception::code() и nitro::exception::what().
Используется в nitro::ZIPUtilities::ExtractFiles(), Open(), UnZIPAbstraction() и ~UnZIPAbstraction().
{
try
{
if( File ? unzClose( File ) : ZIP_OK != ZIP_OK )
{
throw( nitro::exception( std::string( "An error occured while closing zip file" ) , 1 ) );
}
File = NULL;
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "UnZIPAbstraction::Close( void )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "UnZIPAbstraction::Close( void )::An error occured while unzipping file" ) , 1 ) );
}
}

| std::size_t nitro::UnZIPAbstraction::GetCountOfFiles | ( | void | ) | const |
Получение количества заархивированных файлов.
| Кидает | исключение типа std::string с описанием ошибки. |
См. определение в файле zip_abstraction.cpp строка 375
Перекрестные ссылки nitro::exception::code() и nitro::exception::what().
Используется в nitro::ZIPUtilities::ExtractFiles() и GotoFile().
{
try
{
if( !File )
{
throw( nitro::exception( std::string( "Archive was not opened" ) , 1 ) );
}
unz_global_info info;
if( unzGetGlobalInfo( File , & info ) != UNZ_OK )
{
throw( nitro::exception( std::string( "An error occured while getting global info" ) , 1 ) );
}
return( ( int )info.number_entry );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "UnZIPAbstraction::GetCountOfFiles( void )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "UnZIPAbstraction::GetCountOfFiles( void )::An error occured while unzipping file" ) , 1 ) );
}
}

| void nitro::UnZIPAbstraction::GotoFile | ( | const std::size_t | FileCursor | ) |
Переход к файлу.
| FileCursor | - курсор файла. |
| nitro::exception | - Кидается исключение этого типа с описанием ошибки. |
См. определение в файле zip_abstraction.cpp строка 278
Перекрестные ссылки nitro::exception::code(), CurrentCursorPosition, GetCountOfFiles(), GotoFirstFile(), GotoNextFile() и nitro::exception::what().
Используется в UnZIPFile().
{
try
{
if( !File )
{
throw( nitro::exception( std::string( "Archive was not opened" ) , 1 ) );
}
if( FileCursor >= GetCountOfFiles() )
{
throw( nitro::exception( std::string( "Illegal file cursor" ) , 1 ) );
}
if( FileCursor < CurrentCursorPosition )
{
GotoFirstFile();
std::size_t TmpFileCursor( FileCursor );
while( TmpFileCursor-- )
{
GotoNextFile();
}
}
else
{
for( ; FileCursor - CurrentCursorPosition ; )
{
GotoNextFile();
}
}
CurrentCursorPosition = FileCursor;
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "UnZIPAbstraction::GotoFile( const std::size_t FileCursor )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "UnZIPAbstraction::GotoFile( const std::size_t FileCursor )::An error occured while unzipping file" ) , 1 ) );
}
}

| void nitro::UnZIPAbstraction::GotoFirstFile | ( | void | ) |
Переход к первому файлу в архиве.
| Кидает | исключение типа std::string с описанием ошибки. |
См. определение в файле zip_abstraction.cpp строка 323
Перекрестные ссылки nitro::exception::code(), CurrentCursorPosition и nitro::exception::what().
Используется в GotoFile().
{
try
{
if( !File )
{
throw( nitro::exception( std::string ( "Archive was not opened" ) , 1 ) );
}
if( unzGoToFirstFile( File ) != UNZ_OK )
{
throw( nitro::exception( std::string( "An error occured while moving cursor to the first file" ) , 1 ) );
}
CurrentCursorPosition = std::numeric_limits< std::size_t >::max();
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "UnZIPAbstraction::GotoFirstFile( void )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "UnZIPAbstraction::GotoFirstFile( void )::An error occured while unzipping file" ) , 1 ) );
}
}

| void nitro::UnZIPAbstraction::GotoNextFile | ( | void | ) |
Переход к следующему файлу.
| Кидает | исключение типа std::string с описанием ошибки. |
См. определение в файле zip_abstraction.cpp строка 349
Перекрестные ссылки nitro::exception::code(), CurrentCursorPosition и nitro::exception::what().
Используется в GotoFile().
{
try
{
if( !File )
{
throw( nitro::exception( std::string( "Archive was not opened" ) , 1 ) );
}
if( unzGoToNextFile( File ) != UNZ_OK )
{
throw( nitro::exception( std::string( "An error occured while moving cursor to the first file" ) , 1 ) );
}
CurrentCursorPosition++;
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "UnZIPAbstraction::GotoNextFile( void )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "UnZIPAbstraction::GotoNextFile( void )::An error occured while unzipping file" ) , 1 ) );
}
}

| void nitro::UnZIPAbstraction::Open | ( | const std::string & | FilePath | ) |
Открытие ZIP-файла.
| FilePath | - Путь к открываемому ZIP-файлу. |
| Кидает | исключение типа std::string с описанием ошибки. |
См. определение в файле zip_abstraction.cpp строка 243
Перекрестные ссылки Close(), nitro::exception::code(), CurrentCursorPosition, nitro::File::FileExists() и nitro::exception::what().
Используется в UnZIPAbstraction().
{
try
{
Close();
if( FilePath == "" || FilePath.size() == 0 )
{
throw( nitro::exception( std::string( "Invalid file path" ) , 1 ) );
}
if( nitro::File::FileExists( FilePath ) != false )
{
if( ( File = unzOpen( FilePath.c_str() ) ) == NULL )
{
throw( nitro::exception( std::string( "File " ) + FilePath + " was not opened" , 1 ) );
}
}
else
{
throw( nitro::exception( std::string( "File " ) + FilePath + " was not found" , 1 ) );
}
CurrentCursorPosition = std::numeric_limits< std::size_t >::max();
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "UnZIPAbstraction::Open( const std::string & FilePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "UnZIPAbstraction::Open( const std::string & FilePath )::An error occured while unzipping file" ) , 1 ) );
}
}

| UnZIPAbstraction nitro::UnZIPAbstraction::operator= | ( | const UnZIPAbstraction & | ) | [inline] |
Закрытый оператор присваивания.
| nitro::exception | - Кидается исключение этого типа с описанием ошибки. |
См. определение в файле zip_abstraction.h строка 456
{return( *this );}
| void nitro::UnZIPAbstraction::UnZIPFile | ( | const std::size_t | FileCursor, | |
| const std::string & | Folder, | |||
| bool | IgnoreFilePath = true | |||
| ) |
Разархивирование файла.
| FileCursor | - Курсор разархивируемого файла. | |
| Folder | - директория куда будут распаковываться файлы. | |
| IgnoreFilePath | - deprecated. |
| Кидает | исключение типа std::string с описанием ошибки. |
См. определение в файле zip_abstraction.cpp строка 403
Перекрестные ссылки nitro::exception::code(), GotoFile() и nitro::exception::what().
Используется в nitro::ZIPUtilities::ExtractFiles().
{
try
{
if( !File )
{
throw( nitro::exception( std::string( "Archive was not opened" ) , 1 ) );
}
GotoFile( FileCursor );
UnZIPFile( Folder , IgnoreFilePath );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "UnZIPAbstraction::UnZIPFile( const std::size_t FileCursor , const std::string & Folder, bool IgnoreFilePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "UnZIPAbstraction::UnZIPFile( const std::size_t FileCursor , const std::string & Folder, bool IgnoreFilePath )::An error occured while unzipping file" ) , 1 ) );
}
}

| void nitro::UnZIPAbstraction::UnZIPFile | ( | const std::string & | Folder, | |
| bool | IgnoreFilePath | |||
| ) |
Разархивирование файла.
| Folder | - директория куда будут распаковываться файлы. | |
| IgnoreFilePath | - deprecated. |
| Кидает | исключение типа std::string с описанием ошибки. |
См. определение в файле zip_abstraction.cpp строка 426
Перекрестные ссылки nitro::FSPath::AddEndSlash(), nitro::exception::code(), nitro::FSPath::ExtractFileName(), nitro::FA_FILE_BINARY, nitro::FA_FILE_TRUNCATE, nitro::FA_FILE_WRITE, nitro::Directory::ForceCreateDirectory(), nitro::File::ForceCreateFile(), nitro::FileAbstraction::Open(), nitro::exception::what() и nitro::File::Write().
{
try
{
if( !File )
{
throw( nitro::exception( std::string( "Archive was not opened" ) , 1 ) );
}
nitro::Directory::ForceCreateDirectory( Folder );
int Ret = UNZ_OK;
char Buffer[ 1024 ];
char FileName[ 1024 ];
nitro::File UncomressedFile;
if( unzGetCurrentFileInfo( File , NULL , FileName , 1024 , NULL , 0 , NULL , 0 ) != UNZ_OK )
{
throw( nitro::exception( std::string( "An error occured while reading info about the extracting file" ) , 1 ) );
}
std::string FilePath( "" );
if( IgnoreFilePath )
{
FilePath = nitro::FSPath::AddEndSlash( std::string( Folder ) ) + nitro::FSPath::ExtractFileName( std::string( FileName ) );
}
else
{
FilePath = nitro::FSPath::AddEndSlash( std::string( Folder ) ) + std::string( FileName );
}
File::ForceCreateFile( FilePath );
UncomressedFile.Open( FilePath , nitro::FA_FILE_BINARY | nitro::FA_FILE_WRITE | nitro::FA_FILE_TRUNCATE );
if( unzOpenCurrentFile( File ) != UNZ_OK )
{
throw( nitro::exception( std::string( "An error occured while opening zip file handle" ) , 1 ) );
}
do
{
Ret = unzReadCurrentFile( File , Buffer , 1024 );
if( Ret > 0 )
{
UncomressedFile.Write( Buffer , 1024 );
}
}
while( Ret > 0 );
if( unzCloseCurrentFile( File ) != UNZ_OK )
{
throw( nitro::exception( std::string( "An error occured while closing zip file handle" ) , 1 ) );
}
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "UnZIPAbstraction::UnZIPFile( const std::string & Folder , bool IgnoreFilePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "UnZIPAbstraction::UnZIPFile( const std::string & Folder , bool IgnoreFilePath )::An error occured while unzipping file" ) , 1 ) );
}
}

| std::size_t nitro::UnZIPAbstraction::CurrentCursorPosition |
Текущая позиция курсора.
См. определение в файле zip_abstraction.h строка 420
Используется в GotoFile(), GotoFirstFile(), GotoNextFile(), Open() и UnZIPAbstraction().
Загруженный файл.
См. определение в файле zip_abstraction.h строка 408
1.6.1