Class for zip files manipulation. More...
#include <system/zip_abstraction.h>
Public Member Functions | |
| ZIPAbstraction (void) | |
| ZIPAbstraction (const std::string &FilePath) | |
| void | Open (const std::string &FilePath) |
| void | AddFile (const std::string &FilePath, const nitro::BinaryData &LoadedFile, const std::string &RelFolderPath="") |
| void | AddFile (const std::string &FilePath, const std::string &RelFolderPath="") |
| void | Close (void) |
| virtual | ~ZIPAbstraction () |
Private Member Functions | |
| ZIPAbstraction (const ZIPAbstraction &) | |
| ZIPAbstraction | operator= (const ZIPAbstraction &) |
Private Attributes | |
| void * | File |
Class for zip files manipulation.
Definition at line 49 of file zip_abstraction.h.
| nitro::ZIPAbstraction::ZIPAbstraction | ( | void | ) |
Constructor.
| nitro::exception | - An exception of that type is thrown. Contains error description. |
Definition at line 27 of file zip_abstraction.cpp.
References nitro::exception::code(), and nitro::exception::what().
: File( 0 ) { try { } catch( nitro::exception e ) { throw( nitro::exception( std::string( "ZIPAbstraction::CloseZIP( void )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "ZIPAbstraction::CloseZIP( void )::An error occured while unzipping file" ) , 1 ) ); } }

| nitro::ZIPAbstraction::ZIPAbstraction | ( | 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 43 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( "ZIPAbstraction::ZIPAbstraction( const std::string & FilePath /* = NULL */ )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "ZIPAbstraction::ZIPAbstraction( const std::string & FilePath /* = NULL */ )::An error occured while unzipping file" ) , 1 ) ); } }

| nitro::ZIPAbstraction::~ZIPAbstraction | ( | ) | [virtual] |
Destructor.
Definition at line 194 of file zip_abstraction.cpp.
References Close().
{
try
{
Close();
}
catch( nitro::exception e )
{
}
catch( ... )
{
}
}

| nitro::ZIPAbstraction::ZIPAbstraction | ( | const ZIPAbstraction & | ) | [inline, private] |
Private copy constructor.
| nitro::exception | - An exception of that type is thrown. Contains error description. |
Definition at line 221 of file zip_abstraction.h.
{}
| void nitro::ZIPAbstraction::AddFile | ( | const std::string & | FilePath, | |
| const nitro::BinaryData & | LoadedFile, | |||
| const std::string & | RelFolderPath = "" | |||
| ) |
Additing file to ZIP.
| FilePath | - Path to the file. | |
| LoadedFile | - Path to the loaded file. | |
| RelFolderPath | - file will be added with this relative path. |
| nitro::exception | - An exception of that type is thrown. Contains error description. |
Definition at line 97 of file zip_abstraction.cpp.
References nitro::FSPath::AddEndSlash(), nitro::exception::code(), nitro::FSPath::ExtractFileName(), nitro::BinaryData::GetBuffer(), nitro::BinaryData::GetBufferLength(), nitro::File::GetLastModified(), and nitro::exception::what().
Referenced by AddFile(), and nitro::ZIPUtilities::ArchiveDirectory().
{
try
{
// сохраняем аттрибуты и время
zip_fileinfo zfi;
zfi.internal_fa = 0;
zfi.external_fa = 0;
tm LastModifiedDate = nitro::File::GetLastModified( FilePath );
zfi.dosDate = 0;
zfi.tmz_date.tm_year = LastModifiedDate.tm_year + 1900;
zfi.tmz_date.tm_mon = LastModifiedDate.tm_mon;
zfi.tmz_date.tm_mday = LastModifiedDate.tm_mday;
zfi.tmz_date.tm_hour = LastModifiedDate.tm_hour;
zfi.tmz_date.tm_min = LastModifiedDate.tm_min;
zfi.tmz_date.tm_sec = LastModifiedDate.tm_sec;
// загружаем зипуемый файл
std::string FileName;
if( RelFolderPath == "" )
{
FileName = nitro::FSPath::ExtractFileName( std::string( FilePath ) );
}
else
{
FileName = nitro::FSPath::AddEndSlash( std::string( RelFolderPath ) ) + nitro::FSPath::ExtractFileName( std::string( FilePath ) );
}
// открываем архив
if( zipOpenNewFileInZip( File , FileName.c_str() , & zfi ,
NULL , 0 , NULL , 0 ,
NULL , Z_DEFLATED , Z_DEFAULT_COMPRESSION ) != ZIP_OK )
{
throw( nitro::exception( std::string( "An error occured while opening zip file " ) + FileName , 1 ) );
}
if( zipWriteInFileInZip( File , LoadedFile.GetBuffer() , ( unsigned int )LoadedFile.GetBufferLength() ) != ZIP_OK )
{
throw( nitro::exception( std::string( "An error occured while saving data " ) + FilePath + " to zip file" , 1 ) );
}
zipCloseFileInZip( File );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "ZIPAbstraction::AddFile( const std::string & FilePath , const nitro::BinaryData & LoadedFile , const std::string & RelFolderPath /* = "" */ )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "ZIPAbstraction::AddFile( const std::string & FilePath , const nitro::BinaryData & LoadedFile , const std::string & RelFolderPath /* = "" */ )::An error occured while unzipping file" ) , 1 ) );
}
}

| void nitro::ZIPAbstraction::AddFile | ( | const std::string & | FilePath, | |
| const std::string & | RelFolderPath = "" | |||
| ) |
Additing file to ZIP.
| FilePath | - Path to the file. | |
| RelFolderPath | - file will be added with this relative path. |
| nitro::exception | - An exception of that type is thrown. Contains error description. |
Definition at line 153 of file zip_abstraction.cpp.
References AddFile(), nitro::exception::code(), nitro::File::LoadBinDataFromFile(), and nitro::exception::what().
{
try
{
nitro::BinaryData LoadedFile;
nitro::File::LoadBinDataFromFile( LoadedFile , FilePath );
AddFile( FilePath , LoadedFile , RelFolderPath );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "ZIPAbstraction::AddFile( const std::string & FilePath , const std::string & RelFolderPath /* = NULL */ )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "ZIPAbstraction::AddFile( const std::string & FilePath , const std::string & RelFolderPath /* = NULL */ )::An error occured while unzipping file" ) , 1 ) );
}
}

| void nitro::ZIPAbstraction::Close | ( | void | ) |
Finction closes ZIP file.
| nitro::exception | - An exception of that type is thrown. Contains error description. |
Definition at line 173 of file zip_abstraction.cpp.
References nitro::exception::code(), and nitro::exception::what().
Referenced by nitro::ZIPUtilities::ArchiveDirectory(), Open(), ZIPAbstraction(), and ~ZIPAbstraction().
{
try
{
if( File ? zipClose( File , NULL ) : 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( "ZIPAbstraction::Close( void )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "ZIPAbstraction::Close( void )::An error occured while unzipping file" ) , 1 ) );
}
}

| void nitro::ZIPAbstraction::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 61 of file zip_abstraction.cpp.
References Close(), nitro::exception::code(), nitro::File::FileExists(), and nitro::exception::what().
Referenced by ZIPAbstraction().
{
try
{
Close();
if( FilePath == "" || FilePath.size() == 0 )
{
throw( nitro::exception( std::string( "Invalid file path" ) , 1 ) );
}
if( nitro::File::FileExists( FilePath ) == false )
{
if( ( File = zipOpen( FilePath.c_str() , 0 ) ) == NULL )
{
throw( nitro::exception( std::string( "File " ) + FilePath + " was not opened" , 1 ) );
}
}
else
{
if( ( File = zipOpen( FilePath.c_str() , 1 ) ) == NULL )
{
throw( nitro::exception( std::string( "File " ) + FilePath + " was not opened" , 1 ) );
}
}
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "ZIPAbstraction::Open( const std::string & FilePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "ZIPAbstraction::Open( const std::string & FilePath )::An error occured while unzipping file" ) , 1 ) );
}
}

| ZIPAbstraction nitro::ZIPAbstraction::operator= | ( | const ZIPAbstraction & | ) | [inline, private] |
Private assign operator.
| nitro::exception | - An exception of that type is thrown. Contains error description. |
Definition at line 241 of file zip_abstraction.h.
{return( *this );}
void* nitro::ZIPAbstraction::File [private] |
Loaded file.
Definition at line 205 of file zip_abstraction.h.
1.6.1