Coder Social home page Coder Social logo

7zip-cpp's Introduction

7zip-cpp

Fork of SevenZip++ for VS2015, VS2017 (https://github.com/getnamo/7zip-cpp)

Implement compress file list paradigm

Uses latest lzma1801 SDK

From: http://bitbucket.org/cmcnab/sevenzip/wiki/Home

This is a C++ wrapper for accessing the 7-zip COM-like API in 7z.dll and 7za.dll. This code is heavily based off of the Client7z sample found in the LZMA SDK.

The project itself is a static library.

To use, first load the 7z DLL into memory:

#include <7zpp/7zpp.h>

SevenZip::SevenZipLibrary lib;
lib.Load();

If the appropriate 7z DLL is not in your path you may wish to specify it explicitly in the call to load. Note you may have the 64-bit version installed but are trying to load it from a 32-bit executable; keep that in mind if you encounter errors.

lib.Load(_T("path\\to\\7za.dll"));

Then create and use a compressor:

SevenZip::SevenZipCompressor compressor(lib, archiveName);
compressor.SetCompressionFormat(SevenZip::CompressionFormat::Zip);
compressor.UseAbsolutePaths(false);
compressor.AddFile(targetFile);
compressor.AddDirectory(targetDir);
compressor.DoCompress(callbackfunc);

Or an extractor:

SevenZip::SevenZipExtractor extractor(lib, archiveName);

// Try to detect compression type
if (!extractor.DetectCompressionFormat())
{
	extractor.SetCompressionFormat(SevenZip::CompressionFormat::Zip);
}

...

// Change this function to suit
SevenZip::ProgressCallBack *extractcallbackfunc = nullptr;

...

extractor.ExtractArchive(destination, extractcallbackfunc);

Or a lister:

class ListCallBackOutput : SevenZip::ListCallback
{
	virtual void OnFileFound(WCHAR* path, ULONGLONG size)
	{
		std::wcout
			<< path
			<< L" "
			<< size
			<< std::endl;
	}
};

...

SevenZip::SevenZipLister lister(lib, archiveName);

// Try to detect compression type
if (!lister.DetectCompressionFormat())
{
	lister.SetCompressionFormat(SevenZip::CompressionFormat::Zip);
}

ListCallBackOutput myListCallBack;


lister.ListArchive((SevenZip::ListCallback *)&myListCallBack);

Note: Most of the functions now return a boolean to indicate if it worked instead of throwing an exception.

Otherwise, don't forget to wrap the operations in a try/catch block to handle errors:

...
catch (SevenZip::SevenZipException& ex)
{
    std::cerr << ex.GetMessage() << std::endl;
}
...

Requirements

In order to compile the tests, the following requirements must be available:

  • Download and build Boost v1.66
  • Install binaries into $(SolutionDir)\..\boost-1_66\ from http://www.boost.org
  • Install GoogleTest into $(SolutionDir)\..\googletest\ from https://github.com/google/googletest.git
    • Go into the googletest directory
    • Make directory build
    • Change directory into build
    • Run cmake .. -G "Visual Studio 14 2015 Win64"
    • OR Run cmake .. -G "Visual Studio 15 2017 Win64"
    • Open the solution and compile GoogleTest solution.
  • Now you can compile 7zip-cpp

The solution assumes 7zip is installed in C:\Program Files\7-Zip\7z.dll.

Known Issues

There is a bug in the testing program. The issue has been logged on @keithjjones repository.

Contributing

Read Contributing.md

Branches

  • Devel branch is the bleeding edge, but it should still work.
  • Devel-XXX branches are current topics.
  • Master branch is the latest stable version.
  • More branch information is in Contributing.md.

7zip-cpp's People

Contributors

deams51 avatar error454 avatar getnamo avatar keithjjones avatar kocourkuba avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.