libzippp
libzippp copied to clipboard
Zip file fails to open for some users
I'm using libzippp
via vcpkg in my software to open a zip file and to access a certain file inside the zip. This seems to work fine for most users but for some users my code fails to open the zip file:
libzippp::ZipArchive zip_archive(zip_file_path.string());
const auto file_opened_successfully = zip_archive.open(libzippp::ZipArchive::ReadOnly);
if (!file_opened_successfully)
{
throw std::runtime_error("Failed to open the archive file");
}
Here, the exception is thrown. I confirmed that the file referenced by zip_file_path
is exactly the same one as expected so no tampering or corruption has occurred with the zip file.
- Is there a way to get more details on why opening the file failed?
- What are possible causes for an
open()
failure despite it working on my development machine (and my other 2 test machines)? Can it be an encoding problem of the file path, e.g. if the user comes from Asian countries and uses non-ASCII symbols in the file path? There is no constructor forstd::wstring
file paths or forstd::filesystem::path
objects. My project is compiled with the character setUse Unicode Character Set
in Visual Studio. A previous call tostd::filesystem::is_regular_file(zip_file_path)
yields that the file exists though.
Hi @BullyWiiPlaza,
Without a test case, it will be pretty hard to help you. By default, it is true that libzippp doesn't provide any details when an open fails. However, you can uncomment this piece of code so you may get some details in the console.
@ctabin Thanks for the suggestion. However, an exception with the error message text would be more helpful. I cannot simply look at the console when a user runs my GUI software. Maybe you can consider extending your library with something like this so it can be treated/displayed more easily.
@BullyWiiPlaza I made a slight improvement so you can set a custom handling for errors in this case so you might have more information.
Let me know if this is helpful.
Thanks, I might try it later at some point. Also a hint for you, since it's a C++ library, using macros is discouraged. You can offer a std::function
global variable instead or better, some member variable of the libzippp
class so it's not a global change to the code's behavior when getting the error message etc.
I completely agree with @BullyWiiPlaza, you could provide an error-handler in the form of
- A callback function
- A virtual class interface, overridable by the user
Implmented in #156.