0 votes
by (120 points)

Hi there,

I´m using/trying out Rebex Zip version 7.0.8657.0 (Rebex ZIP for .NET Framework 4.6-4.8) and found an issue when extracting files.
That´s what I do:

_archive = new ZipArchive(zipFileFullName, ArchiveOpenMode.Open, ArchiveAccessMode.ReadWrite);
FileSet dataToExtract = new FileSet(RootPath, "*");
ArchiveOperationResult result = await _archive.ExtractAsync(dataToExtract, extractPath, TransferMethod.Copy, ActionOnExistingFiles.OverwriteAll);

When a file already exists on the destination the event ProblemDetected fires with ProblemType = FileExists

What is wrong with that. Do I miss something?

Best regards

Applies to: Rebex ZIP

1 Answer

0 votes
by (70.3k points)

Please note that the ActionOnExistingFiles argument determines the default behavior for situations where a target file already exists. Please note the name of the argument: defaultActionOnExistingFiles.

The ProblemDetected is raised always (if registered), but the e.Action is set to the appropriate value (in your case ArchiveProblemActions.Overwrite). If you would not specify the defaultActionOnExistingFiles argument the e.Action would be set to ArchiveProblemActions.ThrowException.

This behavior is documented on the ActionOnExistingFiles enum itself:

Specifies the default action to perform when a target file already exists. However, the default action can still be changed using the ProblemDetected event.

If you specified the defaultActionOnExistingFiles argument, you can simply ignore (exit) the event if e.ProblemType == ArchiveProblemType.FileExists.

by (120 points)
Thank you for your answer.
But, I already set the  defaultActionOnExistingFiles to ActionOnExistingFiles.OverwriteAll.
As I wrote in my first post. And then I would expect the ProblemDetected event to be not fired. But it still get´s fired, even with
defaultActionOnExistingFiles = ActionOnExistingFiles.OverwriteAll
by (70.3k points)
I understand what you are doing. I tried to explain that the API works in a way you are not expecting: Even you specify defaultActionOnExistingFiles = ActionOnExistingFiles.OverwriteAll, the event is still fired.

We chose this behavior because it gives the API most capabilities. You can specify default action for whole operation, but it allows you to still overwrite the default behavior for specific files if needed.

As I suggested, you can simply ignore the ArchiveProblemType.FileExists case in the event handler (appropriate e.Action is set based on your defaultActionOnExistingFiles value).
by (120 points)
Ok, thank you.