[Plugin] ZipUtility (7zip)

Simple C++:

Let’s say you have a class called UMyClass. You then add the IZipUtilityInterface to it via multiple inheritance e.g.



class UMyClass : public UObject, public IZipUtilityInterface
{
   GENERATED_BODY()
    ...
};

Because the events are BlueprintNativeEvent you add the C++ implementation of the events like so



class UMyClass : public UObject, public IZipUtilityInterface
{
    GENERATED_BODY()
    ...

    //event overrides
    virtual void OnProgress_Implementation(const FString& archive, float percentage, int32 bytes) override;
    virtual void OnDone_Implementation(const FString& archive, EZipUtilityCompletionState CompletionState) override;
    virtual void OnStartProcess_Implementation(const FString& archive, int32 bytes) override;
    virtual void OnFileDone_Implementation(const FString& archive, const FString& file) override;
    virtual void OnFileFound_Implementation(const FString& archive, const FString& file, int32 size) override;
};

and in your c++ file you add the implementation



void UMyClass::OnProgress_Implementation(const FString& archive, float percentage, int32 bytes)
{
    //your code here
}


To call a ziputility function you first get a valid pointer to your class (I leave that up to you) e.g.



UMyClass* MyZipClass = NewObject<UMyClass>(); //or you may already have a valid pointer from allocating elsewhere


then you pass the pointer to your class with the IZipUtilityInterface as your second parameter (and if you use them, any other optional parameters such as compression format)



UZipFileFunctionLibrary::Unzip(FString("C:/path/to/your/zip.7z"), MyZipClass);


and then you should receive your callbacks!

Optional Method using Lambda Expressions:
There is a lambda method I’ve added a while back https://github.com/getnamo/ZipUtility-ue4/blob/master/Source/ZipUtility/Private/ZULambdaDelegate.h used here: https://github.com/getnamo/ZipUtility-ue4/blob/6c30762622e6cbc708da85ee35c75c167c7ea093/Source/ZipUtility/Private/ZipFileFunctionLibrary.cpp#L457

The signature is


static bool UnzipWithLambda(	const FString& ArchivePath,
							TFunction<void()> OnDoneCallback,
							TFunction<void(float)> OnProgressCallback = nullptr,
							TEnumAsByte<ZipUtilityCompressionFormat> format = COMPRESSION_FORMAT_UNKNOWN);

example using this



UZipFileFunctionLibrary::UnzipWithLambda(FString("C:/path/to/your/zip.7z"),
    ]()
    {
         //Called when done
    },
    ](float Percent)
    {
         //called when progress updates with % done
    });


or



UZipFileFunctionLibrary::UnzipWithLambda(FString("C:/path/to/your/zip.7z"), nullptr, ](float Percent)
    {
         //called when progress updates with % done
    });


if you’re not interested in the done callback.

Let me know if that helps :slight_smile:

Edit:
I’ve added these instructions on the github readme: