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

Zip file fails to open for some users #126

Closed
BullyWiiPlaza opened this issue Feb 17, 2022 · 6 comments
Closed

Zip file fails to open for some users #126

BullyWiiPlaza opened this issue Feb 17, 2022 · 6 comments

Comments

@BullyWiiPlaza
Copy link

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.
@ctabin
Copy link
Owner

ctabin commented Mar 3, 2022

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.

@BullyWiiPlaza
Copy link
Author

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

@ctabin
Copy link
Owner

ctabin commented May 22, 2022

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

@BullyWiiPlaza
Copy link
Author

BullyWiiPlaza commented May 22, 2022

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.

@flomnes
Copy link
Contributor

flomnes commented Jul 17, 2022

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

@ctabin
Copy link
Owner

ctabin commented Oct 31, 2022

Implmented in #156.

@ctabin ctabin closed this as completed Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants