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
627 stars 114 forks source link

setProgressCallback does not work when compressing the directory #20

Closed huynguyenvu1996 closed 5 years ago

huynguyenvu1996 commented 5 years ago

I have been looking for a lot of solutions for archiving in Inno Setup, so luckily I found this project on github, it helped me solved my problem, but there is a small bug, I hope you can be fixed it. Thank you very much.

Describe the bug I am writing the archive help functions with Win32 DLL, which will be used for InnoSetup in compressing and extracting files and folders. I'm having trouble exporting information about the process of compressing the folder out of the screen, which causes the program to freeze. Conversely, the information of the extraction process displayed on the screen works very well.

To Reproduce Steps to reproduce the behavior:

typedef void(__stdcall *ExportProgressCallback)(int progress);
typedef void(__stdcall *ExportFileCallback)(const char* filename);

ExportProgressCallback progress_callback;
ExportFileCallback file_callback;
uint64_t global_total_size = 0;

void Bit7zTotalCallback(uint64_t total_size) {
    global_total_size = total_size;
}
void Bit7zProgressCallback(uint64_t progress_size) {
    progress_callback(int(progress_size * 100 / global_total_size));
}
void Bit7zFileCallback(wstring filename) {
    file_callback(ConvertFromWString(filename.c_str()));
}

EXPORT int __stdcall CompressDirectory(int format, LPCWSTR input, LPCWSTR ouput, LPCWSTR dll, ExportProgressCallback export_progress_callback, ExportFileCallback export_file_callback, char* exception, size_t exception_length) {
    try {
        Bit7zLibrary lib(wstring(dll).c_str());
        BitCompressor compressor(lib, GetBitInOutFormat(format)); //Format is zip in this case
        progress_callback = export_progress_callback;
        file_callback = export_file_callback;
        compressor.setTotalCallback(Bit7zTotalCallback);
        compressor.setProgressCallback(Bit7zProgressCallback); // Not working
        compressor.setFileCallback(Bit7zFileCallback);
        compressor.compressDirectory(input, ouput);
    }
    catch (const std::exception& ex) {
        strncpy(exception, ex.what(), exception_length);
        exception[exception_length - 1] = 0;
        return COMPRESS_FAILED;
    };
    return COMPRESS_SUCCESSFUL;
}

Expected behavior When using "setProgressCallback", the program will freeze, the folder will not be compressed. If I don't use "setProgressCallback" but only use "setTotalCallback" and "setFileCallback", the program works well

Environment details (put an x in all the boxes that apply):

rikyoz commented 5 years ago

Hi! First of all, thank you for using bit7z and for having reported the issue! Unfortunately, I still didn't manage to reproduce the bug and in my case the progress callback works without problems! However, I didn't test in the exact same conditions you've reported: in particular, I've used MSVC 2017 (I don't think it is a compiler problem, anyway I'll test also the 2015 version) and I didn't test it by creating a dll (I will try if everything else will fail, maybe depends on that but I doubt it). Just to be clear, the program freezes when compressDirectory is called and previously a progress callback was set, is that right? Anyway, if you could try the following tests it would be really useful:

Thank you!

huynguyenvu1996 commented 5 years ago

Thank you very much for your feedback! I have some personal work so now I can respond to you about this issue, so sorry about this. I will try the recommended methods and check the cases that I do without dll, I will temporarily close this issue if any problems arise please look forward to your help. Thank you for creating a very useful project!