Public Member Functions | Private Member Functions | Private Attributes

nitro::ZIPAbstraction Class Reference

Class for zip files manipulation. More...

#include <system/zip_abstraction.h>

List of all members.

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

Detailed Description

Class for zip files manipulation.

Author:
Dodonov A.A.

Definition at line 49 of file zip_abstraction.h.


Constructor & Destructor Documentation

nitro::ZIPAbstraction::ZIPAbstraction ( void   ) 

Constructor.

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

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 ) );
                }
        }

Here is the call graph for this function:

nitro::ZIPAbstraction::ZIPAbstraction ( 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 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 ) );
                }
        }

Here is the call graph for this function:

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

Destructor.

Author:
Dodonov A.A.

Definition at line 194 of file zip_abstraction.cpp.

References Close().

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

Here is the call graph for this function:

nitro::ZIPAbstraction::ZIPAbstraction ( const ZIPAbstraction  )  [inline, private]

Private copy constructor.

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

Definition at line 221 of file zip_abstraction.h.

{}


Member Function Documentation

void nitro::ZIPAbstraction::AddFile ( const std::string &  FilePath,
const nitro::BinaryData LoadedFile,
const std::string &  RelFolderPath = "" 
)

Additing file to ZIP.

Parameters:
FilePath - Path to the file.
LoadedFile - Path to the loaded file.
RelFolderPath - file will be added with this relative path.
Exceptions:
nitro::exception - An exception of that type is thrown. Contains error description.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

void nitro::ZIPAbstraction::AddFile ( const std::string &  FilePath,
const std::string &  RelFolderPath = "" 
)

Additing file to ZIP.

Parameters:
FilePath - Path to the file.
RelFolderPath - file will be added with this relative path.
Exceptions:
nitro::exception - An exception of that type is thrown. Contains error description.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

void nitro::ZIPAbstraction::Close ( void   ) 

Finction closes ZIP 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 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 ) );
                }
        }

Here is the call graph for this function:

void nitro::ZIPAbstraction::Open ( const std::string &  FilePath  ) 

Function opens ZIP 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 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 ) );
                }
        }

Here is the call graph for this function:

ZIPAbstraction nitro::ZIPAbstraction::operator= ( const ZIPAbstraction  )  [inline, private]

Private assign operator.

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

Definition at line 241 of file zip_abstraction.h.

{return( *this );}


Member Data Documentation

void* nitro::ZIPAbstraction::File [private]

Loaded file.

Author:
Dodonov A.A.

Definition at line 205 of file zip_abstraction.h.


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

Generated by  doxygen 1.6.1