Class for zip files manipulation. More...
#include <system/zip_abstraction.h>
Public Member Functions | |
| 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) |
Public Attributes | |
| void * | File |
| std::size_t | CurrentCursorPosition |
Class for zip files manipulation.
Definition at line 256 of file zip_abstraction.h.
| nitro::UnZIPAbstraction::UnZIPAbstraction | ( | void | ) |
Constructor.
| nitro::exception | - An exception of that type is thrown. Contains error description. |
Definition at line 208 of file zip_abstraction.cpp.
References nitro::exception::code(), CurrentCursorPosition, and 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 | ) |
Constructor.
| FilePath | - Path to the loading file. |
| nitro::exception | - An exception of that type is thrown. Contains error description. |
Definition at line 225 of file zip_abstraction.cpp.
References Close(), nitro::exception::code(), Open(), and 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] |
Destructor.
Definition at line 512 of file zip_abstraction.cpp.
References Close().
{
try
{
Close();
}
catch( nitro::exception e )
{
}
catch( ... )
{
}
}

| nitro::UnZIPAbstraction::UnZIPAbstraction | ( | const UnZIPAbstraction & | ) | [inline] |
Private copy constructor.
| nitro::exception | - An exception of that type is thrown. Contains error description. |
Definition at line 436 of file zip_abstraction.h.
{}
| void nitro::UnZIPAbstraction::Close | ( | void | ) |
Finction closes ZIP file.
| nitro::exception | - An exception of that type is thrown. Contains error description. |
Definition at line 491 of file zip_abstraction.cpp.
References nitro::exception::code(), and nitro::exception::what().
Referenced by nitro::ZIPUtilities::ExtractFiles(), Open(), UnZIPAbstraction(), and ~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 |
Function returns count of zipped files.
| nitro::exception | - An exception of that type is thrown. Contains error description. |
Definition at line 375 of file zip_abstraction.cpp.
References nitro::exception::code(), and nitro::exception::what().
Referenced by nitro::ZIPUtilities::ExtractFiles(), and 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 | ) |
Function shift file cursor.
| FileCursor | - file cursor. |
| nitro::exception | - An exception of that type is thrown. Contains error description. |
Definition at line 278 of file zip_abstraction.cpp.
References nitro::exception::code(), CurrentCursorPosition, GetCountOfFiles(), GotoFirstFile(), GotoNextFile(), and nitro::exception::what().
Referenced by 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 | ) |
Function shifts cursor to the firt file.
| nitro::exception | - An exception of that type is thrown. Contains error description. |
Definition at line 323 of file zip_abstraction.cpp.
References nitro::exception::code(), CurrentCursorPosition, and nitro::exception::what().
Referenced by 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 | ) |
Function shifts cursor to the next file.
| nitro::exception | - An exception of that type is thrown. Contains error description. |
Definition at line 349 of file zip_abstraction.cpp.
References nitro::exception::code(), CurrentCursorPosition, and nitro::exception::what().
Referenced by 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 | ) |
Function opens zip file.
| FilePath | - Path to the opening file. |
| nitro::exception | - An exception of that type is thrown. Contains error description. |
Definition at line 243 of file zip_abstraction.cpp.
References Close(), nitro::exception::code(), CurrentCursorPosition, nitro::File::FileExists(), and nitro::exception::what().
Referenced by 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] |
Private assign operator.
| nitro::exception | - An exception of that type is thrown. Contains error description. |
Definition at line 456 of file zip_abstraction.h.
{return( *this );}
| void nitro::UnZIPAbstraction::UnZIPFile | ( | const std::size_t | FileCursor, | |
| const std::string & | Folder, | |||
| bool | IgnoreFilePath = true | |||
| ) |
Function unzips files.
| FileCursor | - Cursor fo the file. | |
| Folder | - directory of the unzipping file. | |
| IgnoreFilePath | - deprecated. |
| nitro::exception | - An exception of that type is thrown. Contains error description. |
Definition at line 403 of file zip_abstraction.cpp.
References nitro::exception::code(), GotoFile(), and nitro::exception::what().
Referenced by 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 | |||
| ) |
Function unzips file.
| Folder | - Destination folder. | |
| IgnoreFilePath | - deprecated. |
| nitro::exception | - An exception of that type is thrown. Contains error description. |
Definition at line 426 of file zip_abstraction.cpp.
References 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(), and 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 |
Current cursor position.
Definition at line 420 of file zip_abstraction.h.
Referenced by GotoFile(), GotoFirstFile(), GotoNextFile(), Open(), and UnZIPAbstraction().
Loaded file.
Definition at line 408 of file zip_abstraction.h.
1.6.1