Skip to content

Commit

Permalink
Merge branch 'release/v1.0.0-rc'
Browse files Browse the repository at this point in the history
  • Loading branch information
rikyoz committed Dec 26, 2014
2 parents e395e04 + 86ec4e4 commit 4171456
Show file tree
Hide file tree
Showing 21 changed files with 187 additions and 180 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ test/
roadmap.txt
doc/
Doxyfile
gh-pages/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ bit7z

**bit7z** is a C++ static library aiming to offer a clean, simple and object-oriented interface to the dlls supplied by the 7zip SDK. It allows to compress to and extract from many archive file formats from C++ code.

![](http://img.shields.io/badge/version-v1.0.0--beta.2-blue.svg?style=flat) ![](http://img.shields.io/badge/license-GPL%20v2-red.svg?style=flat) ![](http://img.shields.io/badge/platform-windows-green.svg?style=flat) ![](http://img.shields.io/badge/compiler-MSVC-lightgrey.svg?style=flat)
![](http://img.shields.io/badge/version-v1.0.0--rc-blue.svg?style=flat) ![](http://img.shields.io/badge/license-GPL%20v2-red.svg?style=flat) ![](http://img.shields.io/badge/platform-windows-green.svg?style=flat) ![](http://img.shields.io/badge/compiler-MSVC-lightgrey.svg?style=flat)

## Features ##
bit7z supports the following features:
Expand Down Expand Up @@ -69,7 +69,7 @@ try {
~~~~~~~~~~~~~

## Usage Requirements ##
+ **OS:** Windows
+ **Target OS:** Windows (supported both x86 and x64 architectures)
+ **Compiler:** MSVC (tested with version 2013)

Note: in order to use this library you should link your program with both **bit7z** and *oleaut32* (e.g. `-lbit7z -loleaut32`)
Expand Down
9 changes: 5 additions & 4 deletions bit7z.pro
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ HEADERS += include/bitcompressor.hpp \
include/bitformat.hpp \
include/bitcompressionlevel.hpp

contains(QMAKE_HOST.arch, x86_64) {
QMAKE_LFLAGS += /MACHINE:X64
PLATFORM = x64
} else {
contains(QT_ARCH, i386) {
QMAKE_LFLAGS += /MACHINE:X86
PLATFORM = x86
} else {
QMAKE_LFLAGS += /MACHINE:X64
PLATFORM = x64
}


CONFIG(debug, debug|release) {
BUILD = debug
} else {
Expand Down
8 changes: 2 additions & 6 deletions include/bit7zlibrary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,9 @@ namespace bit7z {
virtual ~Bit7zLibrary();

private:
typedef UINT32 ( WINAPI* CreateObjectFunc )( const GUID* clsID,
const GUID* interfaceID,
void** outObject );
typedef UINT32 ( WINAPI* CreateObjectFunc )( const GUID* clsID, const GUID* interfaceID, void** outObject );

void createArchiveObject( const GUID* format_ID,
const GUID* interface_ID,
void** out_object ) const;
void createArchiveObject( const GUID* format_ID, const GUID* interface_ID, void** out_object ) const;

HMODULE mLibrary;
CreateObjectFunc mCreateObjectFunc;
Expand Down
26 changes: 15 additions & 11 deletions include/bitcompressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ namespace bit7z {
*/
BitCompressor( const Bit7zLibrary& lib, BitOutFormat format );

/**
* @return the archive format used by the compressor
*/
BitOutFormat compressionFormat();

/**
* @brief Sets up a password for the output archive
*
Expand Down Expand Up @@ -109,25 +114,24 @@ namespace bit7z {
/**
* @brief Compresses the files contained in a directory
*
* @param in_dir the path (relative or absolute) to the input directory.
* @param out_archive the path (relative or absolute) to the output archive file.
* @param filter the filter to use when searching files inside in_dir.
* @param search_subdirs if true, it searches files inside the sub-folders of in_dir.
* @param in_dir the path (relative or absolute) to the input directory.
* @param out_archive the path (relative or absolute) to the output archive file.
* @param filter the filter to use when searching files inside in_dir.
* @param recursive if true, it searches files inside the sub-folders of in_dir.
*/
void compressFiles( const wstring& in_dir, const wstring& out_archive,
const wstring& filter = L"*", bool search_subdirs = true ) const;
void compressFiles( const wstring& in_dir, const wstring& out_archive, const wstring& filter = L"*",
bool recursive = true ) const;

/**
* @brief Compresses an entire directory
*
* @note This method is equivalent to compressFiles with filter set to L"*"
*
* @param in_dir the path (relative or absolute) to the input directory.
* @param out_archive the path (relative or absolute) to the output archive file.
* @param search_subdirs if true, it searches files inside the sub-folders of in_dir.
* @param in_dir the path (relative or absolute) to the input directory.
* @param out_archive the path (relative or absolute) to the output archive file.
* @param recursive if true, it searches files inside the sub-folders of in_dir.
*/
void compressDirectory( const wstring& in_dir, const wstring& out_archive,
bool search_subdirs = true ) const;
void compressDirectory( const wstring& in_dir, const wstring& out_archive, bool recursive = true ) const;

private:
const Bit7zLibrary& mLibrary;
Expand Down
7 changes: 6 additions & 1 deletion include/bitextractor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ namespace bit7z {
*/
BitExtractor( const Bit7zLibrary&, BitInFormat format );

/**
* @return the archive format used by the extractor
*/
BitInFormat extractionFormat();

/**
* @brief Extracts the given archive into the choosen directory
Expand All @@ -37,7 +42,7 @@ namespace bit7z {

private:
const Bit7zLibrary& mLibrary;
const BitInFormat& mFormat;
const BitInFormat mFormat;
};

}
Expand Down
33 changes: 14 additions & 19 deletions include/bitformat.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef BITFORMAT
#define BITFORMAT

#include <string>

#include "../include/bitguids.hpp"

using namespace std;
Expand All @@ -14,19 +12,17 @@ namespace bit7z {
*/
class BitOutFormat {
public:
enum { Zip, BZip2, SevenZip, Xz, Wim, Tar, GZip };
enum Format { Zip = 0, BZip2, SevenZip, Xz, Wim, Tar, GZip };

BitOutFormat( int value );
bool operator==( BitOutFormat const& other ) const;
bool operator!=( BitOutFormat const& other ) const;
bool operator==( int const& other ) const;
bool operator!=( int const& other ) const;
BitOutFormat( unsigned int value );
bool operator==( Format const& other ) const;
bool operator!=( Format const& other ) const;
operator unsigned int() const;
int value() const;
virtual const GUID guid() const;
unsigned int value() const;
virtual const GUID* guid() const;

protected:
int mValue;
unsigned int mValue;
};

/**
Expand All @@ -36,14 +32,13 @@ namespace bit7z {
*/
class BitInFormat : public BitOutFormat {
public:
enum { Rar = BitOutFormat::GZip + 1, Arj, Z, Lzh, Cab, Nsis, Lzma, Lzma86, Ppmd,
TE, UEFIc, UEFIs, SquashFS, CramFS, APM, Mslz, Flv, Swf, Swfc, Ntfs, Fat,
Mbr, Vhd, Pe, Elf, Macho, Udf, Xar, Mub, Hfs, Dmg, Compound, Iso,
Chm, Split, Rpm, Deb, Cpio
};

BitInFormat( int value );
const GUID guid() const;
enum Format { Rar = BitOutFormat::GZip + 1, Arj, Z, Lzh, Cab, Nsis, Lzma, Lzma86, Ppmd, TE, UEFIc, UEFIs,
SquashFS, CramFS, APM, Mslz, Flv, Swf, Swfc, Ntfs, Fat, Mbr, Vhd, Pe, Elf, Macho, Udf, Xar,
Mub, Hfs, Dmg, Compound, Iso, Chm, Split, Rpm, Deb, Cpio
};

BitInFormat( unsigned int value );
const GUID* guid() const;
};

}
Expand Down
3 changes: 1 addition & 2 deletions include/extractcallback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ using namespace std;

namespace bit7z {

class ExtractCallback : public IArchiveExtractCallback, ICryptoGetTextPassword, CMyUnknownImp,
public Callback {
class ExtractCallback : public IArchiveExtractCallback, ICryptoGetTextPassword, CMyUnknownImp, public Callback {
public:
ExtractCallback( IInArchive* archiveHandler, const wstring& directoryPath );
virtual ~ExtractCallback();
Expand Down
2 changes: 1 addition & 1 deletion include/fsitem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace bit7z {

class FSItem {
public:
FSItem( const wstring& path , const wstring& relative_dir = L"" );
FSItem( const wstring& path, const wstring& relative_dir = L"" );
FSItem( const wstring& dir, const wstring& relative_dir, FSItemInfo data );

bool exists() const;
Expand Down
3 changes: 1 addition & 2 deletions include/opencallback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ using namespace std;

namespace bit7z {

class OpenCallback : public IArchiveOpenCallback, ICryptoGetTextPassword, CMyUnknownImp,
public Callback {
class OpenCallback : public IArchiveOpenCallback, ICryptoGetTextPassword, CMyUnknownImp, public Callback {
public:
OpenCallback();
virtual ~OpenCallback();
Expand Down
6 changes: 2 additions & 4 deletions include/updatecallback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ using namespace bit7z::filesystem;

namespace bit7z {

class UpdateCallback : public IArchiveUpdateCallback2, ICryptoGetTextPassword2, CMyUnknownImp,
public Callback {
class UpdateCallback : public IArchiveUpdateCallback2, ICryptoGetTextPassword2, CMyUnknownImp, public Callback {
public:
MY_UNKNOWN_IMP2( IArchiveUpdateCallback2, ICryptoGetTextPassword2 )

Expand All @@ -23,8 +22,7 @@ namespace bit7z {

// IArchiveUpdateCallback2
STDMETHOD( EnumProperties )( IEnumSTATPROPSTG** enumerator );
STDMETHOD( GetUpdateItemInfo )( UInt32 index, Int32* newData, Int32* newProperties,
UInt32* indexInArchive );
STDMETHOD( GetUpdateItemInfo )( UInt32 index, Int32* newData, Int32* newProperties, UInt32* indexInArchive );
STDMETHOD( GetProperty )( UInt32 index, PROPID propID, PROPVARIANT* value );
STDMETHOD( GetStream )( UInt32 index, ISequentialInStream** inStream );
STDMETHOD( SetOperationResult )( Int32 operationResult );
Expand Down
7 changes: 2 additions & 5 deletions src/bit7zlibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

using namespace bit7z;

Bit7zLibrary::Bit7zLibrary( const std::wstring& dll_path ) : mLibrary( LoadLibrary(
dll_path.c_str() ) ) {
Bit7zLibrary::Bit7zLibrary( const std::wstring& dll_path ) : mLibrary( LoadLibrary( dll_path.c_str() ) ) {
if ( !mLibrary )
throw BitException( "Cannot load 7-zip library" );

Expand All @@ -21,9 +20,7 @@ Bit7zLibrary::~Bit7zLibrary() {
FreeLibrary( mLibrary );
}

void Bit7zLibrary::createArchiveObject( const GUID* format_ID,
const GUID* interface_ID,
void** out_object ) const {
void Bit7zLibrary::createArchiveObject( const GUID* format_ID, const GUID* interface_ID, void** out_object ) const {
if ( mCreateObjectFunc( format_ID, interface_ID, out_object ) != S_OK )
throw BitException( "Cannot get class object" );
}
65 changes: 36 additions & 29 deletions src/bitcompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
using namespace bit7z;
using namespace NWindows;

BitCompressor::BitCompressor( const Bit7zLibrary& lib, BitOutFormat format ) : mLibrary( lib ),
mFormat( format ), mCompressionLevel( BitCompressionLevel::Normal ), mPassword( L"" ),
mCryptHeaders( false ), mSolidMode( false ) {}
BitCompressor::BitCompressor( const Bit7zLibrary& lib, BitOutFormat format ) : mLibrary( lib ), mFormat( format ),
mCompressionLevel( BitCompressionLevel::Normal ), mPassword( L"" ), mCryptHeaders( false ), mSolidMode( false ) {}

BitOutFormat BitCompressor::compressionFormat() {
return mFormat;
}

void BitCompressor::setPassword( const wstring& password, bool crypt_headers ) {
mPassword = password;
Expand All @@ -30,6 +33,9 @@ void BitCompressor::setSolidMode( bool solid_mode ) {
}

void BitCompressor::compress( const vector<wstring>& in_paths, const wstring& out_archive ) const {
if ( in_paths.size() > 1 && ( mFormat == BitOutFormat::BZip2 || mFormat == BitOutFormat::GZip
|| mFormat == BitOutFormat::Xz ) )
throw BitException( "Unsupported operation!" );
vector<FSItem> dirItems;
for ( wstring filePath : in_paths ) {
FSItem item( filePath );
Expand All @@ -49,8 +55,10 @@ void BitCompressor::compressFile( const wstring& in_file, const wstring& out_arc
compressFiles( vfiles, out_archive );
}

void BitCompressor::compressFiles( const vector<wstring>& in_files,
const wstring& out_archive ) const {
void BitCompressor::compressFiles( const vector<wstring>& in_files, const wstring& out_archive ) const {
if ( in_files.size() > 1 && ( mFormat == BitOutFormat::BZip2 || mFormat == BitOutFormat::GZip
|| mFormat == BitOutFormat::Xz ) )
throw BitException( "Unsupported operation!" );
vector<FSItem> dirItems;
for ( wstring filePath : in_files ) {
FSItem item( filePath );
Expand All @@ -60,67 +68,66 @@ void BitCompressor::compressFiles( const vector<wstring>& in_files,
compressFS( dirItems, out_archive );
}

void BitCompressor::compressFiles( const wstring& in_dir, const wstring& out_archive,
const wstring& filter, bool search_subdirs ) const {
void BitCompressor::compressFiles( const wstring& in_dir, const wstring& out_archive, const wstring& filter,
bool recursive ) const {
if ( mFormat == BitOutFormat::BZip2 || mFormat == BitOutFormat::GZip || mFormat == BitOutFormat::Xz )
throw BitException( "Unsupported operation!" );
vector<FSItem> dirItems;
FSIndexer indexer( in_dir, filter );
indexer.listFilesInDirectory( dirItems, search_subdirs );
indexer.listFilesInDirectory( dirItems, recursive );
compressFS( dirItems, out_archive );
}

void BitCompressor::compressDirectory( const wstring& in_dir, const wstring& out_archive,
bool search_subdirs ) const {
/*vector<FSItem> dirItems;
FSIndexer indexer( in_dir );
indexer.listFilesInDirectory( dirItems, search_subdirs );
compressFS( dirItems, out_archive );*/
compressFiles( in_dir, out_archive, L"*", search_subdirs );
void BitCompressor::compressDirectory( const wstring& in_dir, const wstring& out_archive, bool recursive ) const {
compressFiles( in_dir, out_archive, L"*", recursive );
}

/* Most of this code, though heavily modified, is taken from the main() of Client7z.cpp in the 7z SDK
* Main changes made:
* + Generalized the code to work with any type of format (original works only with 7z format)
* + Use of exceptions instead of error codes */
void BitCompressor::compressFS( const vector<FSItem>& in_items, const wstring& out_archive ) const {
CMyComPtr<IOutArchive> outArchive;
mLibrary.createArchiveObject( &mFormat.guid(),
&IID_IOutArchive,
reinterpret_cast< void** >( &outArchive ) );
mLibrary.createArchiveObject( mFormat.guid(), &IID_IOutArchive, reinterpret_cast< void** >( &outArchive ) );

vector< const wchar_t* > names;
vector< NCOM::CPropVariant > values;
if ( mCryptHeaders && mFormat == BitOutFormat::SevenZip || mFormat == BitOutFormat::Xz ) {
if ( mCryptHeaders && ( mFormat == BitOutFormat::SevenZip || mFormat == BitOutFormat::Xz ) ) {
names.push_back( L"he" );
values.push_back( true );
}
if ( mFormat != BitOutFormat::Tar && mFormat != BitOutFormat::Wim ) {
names.push_back( L"x" );
values.push_back( static_cast< UInt32 >( mCompressionLevel ) );
}
if ( mFormat == BitOutFormat::SevenZip ) {
if ( mSolidMode && mFormat == BitOutFormat::SevenZip ) {
names.push_back( L"s" );
values.push_back( mSolidMode );
}

if ( names.size() > 0 ) {
CMyComPtr<ISetProperties> setProperties;
if ( outArchive->QueryInterface( IID_ISetProperties,
reinterpret_cast< void** >( &setProperties ) ) != S_OK )
if ( outArchive->QueryInterface( IID_ISetProperties, reinterpret_cast< void** >( &setProperties ) ) != S_OK )
throw BitException( "ISetProperties unsupported" );
if ( setProperties->SetProperties( &names[0], &values[0],
static_cast<UInt32>( names.size() ) ) != S_OK )
if ( setProperties->SetProperties( &names[0], &values[0], static_cast<UInt32>( names.size() ) ) != S_OK )
throw BitException( "Cannot set properties of the archive" );
}

COutFileStream* outFileStreamSpec = new COutFileStream;
COutFileStream* outFileStreamSpec = new COutFileStream();
/* note: if you remove the following line (and you use outFileStreamSpec with UpdateItems
* method), you will not have any problem... until you try to compress files with
* GZip format! In that case it will make crash your program!! */
CMyComPtr<IOutStream> outFileStream = outFileStreamSpec;
if ( !outFileStreamSpec->Create( out_archive.c_str(), false ) ) {
delete outFileStreamSpec;
throw BitException( "Can't create archive file" );
throw BitException( L"Can't create archive file '" + out_archive + L"'" );
}

UpdateCallback* updateCallbackSpec = new UpdateCallback( in_items );
updateCallbackSpec->setPassword( mPassword );

CMyComPtr<IArchiveUpdateCallback2> updateCallback( updateCallbackSpec );
HRESULT result = outArchive->UpdateItems( outFileStreamSpec,
static_cast< UInt32 >( in_items.size() ),
updateCallback );
HRESULT result = outArchive->UpdateItems( outFileStream, static_cast< UInt32 >( in_items.size() ), updateCallback );
updateCallbackSpec->Finilize();

if ( result != S_OK ) throw BitException( updateCallbackSpec->getErrorMessage() );
Expand Down
4 changes: 2 additions & 2 deletions src/bitexception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ using namespace bit7z;

BitException::BitException( const std::string& message ) : std::runtime_error( message ) {}

BitException::BitException( const std::wstring& message ) : std::runtime_error( std::string(
message.begin(), message.end() ) ) {}
BitException::BitException( const std::wstring& message ) : std::runtime_error( std::string( message.begin(),
message.end() ) ) {}
Loading

0 comments on commit 4171456

Please sign in to comment.