libzippp icon indicating copy to clipboard operation
libzippp copied to clipboard

Zip file fails to open for some users

Open BullyWiiPlaza opened this issue 2 years ago • 5 comments

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.

  1. Is there a way to get more details on why opening the file failed?
  2. 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 for std::wstring file paths or for std::filesystem::path objects. My project is compiled with the character set Use Unicode Character Set in Visual Studio. A previous call to std::filesystem::is_regular_file(zip_file_path) yields that the file exists though.

BullyWiiPlaza avatar Feb 17 '22 17:02 BullyWiiPlaza

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 avatar Mar 03 '22 22:03 ctabin

@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 avatar Mar 04 '22 16:03 BullyWiiPlaza

@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.

ctabin avatar May 22 '22 09:05 ctabin

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.

BullyWiiPlaza avatar May 22 '22 21:05 BullyWiiPlaza

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

flomnes avatar Jul 17 '22 20:07 flomnes

Implmented in #156.

ctabin avatar Oct 31 '22 12:10 ctabin