rikyoz / bit7z

A C++ static library offering a clean and simple interface to the 7-zip shared libraries.
https://rikyoz.github.io/bit7z
Mozilla Public License 2.0
611 stars 112 forks source link

[Bug]: Why can't compress an empty directory? #114

Closed kak13amaplus closed 1 year ago

kak13amaplus commented 1 year ago

bit7z version

4.0.x beta

7-zip version

v21.07

7-zip DLL used

7z.dll

MSVC version

2019

Architecture

x86_64

Which version of Windows are you using?

Windows 10

Bug description

Why can't compress an empty directory?

Steps to reproduce

No response

Expected behavior

No response

Relevant compilation output

No response

Code of Conduct

rikyoz commented 1 year ago

Hi! Which BitFileCompressor's function are you using? Could you provide any piece of the code? Thank you!

kak13amaplus commented 1 year ago

include "bitcompressor.hpp"

using namespace bit7z;

try { Bit7zLibrary lib{ L"7z.dll" }; BitCompressor compressor{ lib, BitFormat::Zip };

//The first parameter is dir compressor.compressFiles( Dir, L"protected_archive.zip" );

} catch ( const BitException& ex ) {
//do something with ex.what()...

}

kak13amaplus commented 1 year ago

If an empty folder in Dir, the empty folder will not be compressed

kak13amaplus commented 1 year ago

I modified part of the code, compressFiles‘s param filter L" . " -> L"" FSIndexer::listDirectoryItems if ( item_matches ) -> if ( item_matches || current_item.isDir )

so that the empty folder can be compressed

rikyoz commented 1 year ago

include "bitcompressor.hpp"

using namespace bit7z;

try { Bit7zLibrary lib{ L"7z.dll" }; BitCompressor compressor{ lib, BitFormat::Zip };

//The first parameter is dir compressor.compressFiles( Dir, L"protected_archive.zip" );

} catch ( const BitException& ex ) {
//do something with ex.what()...

}

If an empty folder in Dir, the empty folder will not be compressed

This is the expected default behavior of compressFiles. This function is meant to be used when you want to compress only the files inside the Dir path; hence, empty folders will be ignored by default.

I modified part of the code, compressFiles‘s param filter L" . " -> L"" FSIndexer::listDirectoryItems if ( item_matches ) -> if ( item_matches || current_item.isDir )

so that the empty folder can be compressed

I think that the changes to FSIndexer::listDirectoryItems are unnecessary.

Calling compressFiles with L"*" as the filter parameter should suffice, e.g., compressor.compressFiles( Dir, L"protected_archive.zip", true, L"*" ).