Go to the documentation of this file.00001 #ifndef __NITRO_ZIP_UTILITIES_CPP__
00002 #define __NITRO_ZIP_UTILITIES_CPP__
00003
00004 #include <system/zip_abstraction.h>
00005 #include <utilities/exception.h>
00006 #include <utilities/file_utilities.h>
00007 #include <utilities/testing_utilities.h>
00008 #include <utilities/zip_utilities.h>
00009
00010 namespace nitro
00011 {
00012
00013 void ZIPUtilities::ExtractFiles( const std::string & ArchivePath , const std::string & DirectoryPath )
00014 {
00015 try
00016 {
00017 nitro::UnZIPAbstraction ZipFile( ArchivePath );
00018
00019 std::size_t FileCount( ZipFile.GetCountOfFiles() );
00020 for( std::size_t i( 0 ) ; i < FileCount ; i++ )
00021 {
00022 ZipFile.UnZIPFile( i , DirectoryPath , false );
00023 }
00024
00025 ZipFile.Close();
00026 }
00027 catch( nitro::exception e )
00028 {
00029 throw( nitro::exception( std::string( "ZIPUtilities::ExtractFiles( const std::string & ArchivePath , const std::string & DirectoryPath )::" ) + e.what() , e.code() ) );
00030 }
00031 catch( ... )
00032 {
00033 throw( nitro::exception( std::string( "ZIPUtilities::ExtractFiles( const std::string & ArchivePath , const std::string & DirectoryPath )::An error occured" ) , 1 ) );
00034 }
00035 }
00036
00037 void ZIPUtilities::ArchiveDirectory( const std::string & ArchivePath , const std::string & DirectoryPath )
00038 {
00039 try
00040 {
00041 nitro::ZIPAbstraction ZipFile( ArchivePath );
00042
00043 std::vector< std::string > Paths;
00044 nitro::CollectFilesFromDirectory( DirectoryPath , Paths );
00045
00046 for( std::size_t i( 0 ) ; i < Paths.size() ; i++ )
00047 {
00048 ZipFile.AddFile( Paths[ i ] );
00049 }
00050
00051 ZipFile.Close();
00052 }
00053 catch( nitro::exception e )
00054 {
00055 throw( nitro::exception( std::string( "ZIPUtilities::ArchiveDirectory( const std::string & ArchivePath , const std::string & DirectoryPath )::" ) + e.what() , e.code() ) );
00056 }
00057 catch( ... )
00058 {
00059 throw( nitro::exception( std::string( "ZIPUtilities::ArchiveDirectory( const std::string & ArchivePath , const std::string & DirectoryPath )::An error occured" ) , 1 ) );
00060 }
00061 }
00062
00063 BEGIN_TESTING_SECTION()
00064
00065 #ifdef ENABLE_AUTOTESTING
00066 NITRO_EXPORTING void tstExtractFiles( const char * ArchivePath , const char * DirectoryPath )
00067 {
00068 try
00069 {
00070 ZIPUtilities::ExtractFiles( ArchivePath , DirectoryPath );
00071 }
00072 catch( nitro::exception e )
00073 {
00074 std::cout<<e.what()<<std::endl;
00075 throw( nitro::exception( std::string( "tstExtractFiles( const char * ArchivePath , const char * DirectoryPath )::An error occured" ) , 1 ) );
00076 }
00077 catch( ... )
00078 {
00079 throw( nitro::exception( std::string( "tstExtractFiles( const char * ArchivePath , const char * DirectoryPath )::An error occured" ) , 1 ) );
00080 }
00081 }
00082
00083 NITRO_EXPORTING void tstArchiveDirectory( const char * ArchivePath , const char * DirectoryPath )
00084 {
00085 try
00086 {
00087 ZIPUtilities::ArchiveDirectory( ArchivePath , DirectoryPath );
00088 }
00089 catch( nitro::exception e )
00090 {
00091 std::cout<<e.what()<<std::endl;
00092 throw( nitro::exception( std::string( "tstArchiveDirectory( const char * ArchivePath , const char * DirectoryPath )::An error occured" ) , 1 ) );
00093 }
00094 catch( ... )
00095 {
00096 throw( nitro::exception( std::string( "tstArchiveDirectory( const char * ArchivePath , const char * DirectoryPath )::An error occured" ) , 1 ) );
00097 }
00098 }
00099 #endif
00100
00101 END_TESTING_SECTION()
00102 }
00103
00104 #endif