Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setProgressCallback does not work when compressing the directory #20

Closed
5 of 20 tasks
huynguyenvu1996 opened this issue Jul 16, 2019 · 2 comments
Closed
5 of 20 tasks

Comments

@huynguyenvu1996
Copy link

huynguyenvu1996 commented Jul 16, 2019

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):

  • bit7z version:

    • v2.0
    • v2.1
    • v3.0
  • 7-zip version:

    • v16.02
    • v16.03
    • v16.04
    • v18.01
    • v18.03
    • v18.05
    • v19.00
  • MSVC version:

    • 2012
    • 2013
    • 2015
    • 2017
  • Windows version:

    • Windows Vista
    • Windows 8
    • Windows 8.1
    • Windows 10
  • Architecture:

    • x86
    • x86_64
@rikyoz
Copy link
Owner

rikyoz commented Jul 18, 2019

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:

  • Check if global_total_size is non zero in the progress callback: it seems strange to me, but maybe the total callback is not called and hence a division by zero occurs (which may freeze the program under some conditions, crash it on others);
  • Check, if possible, the code of ExportProgressCallback and verify if there are some errors there.

Thank you!

@huynguyenvu1996
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants