I'm triying the simple solution of compressing the data adding a password. I'm using minizip library provided in the zlib homepage.
Now i can read info from zips but the problem comes when adding a password. There aren't tutorials on the internet. Minizip library is well documented but there aren''t examples. They provide unzOpenCurrentFilePassword function that is the same as unzOpenCurrentFile but adding a second parameter for password. I don't understand why the password function fails.
This code works.
unzFile unz_file = unzOpen("tilesets/tileset_01.zip");
if (unz_file == nullptr) std::cout << "Unz_file is nullptr" << std::endl;
unz_file_info info;
unzGetCurrentFileInfo(unz_file, &info, NULL, 0, NULL, 0, NULL, 0);
char *file = (char*)malloc(info.uncompressed_size);
//std::string password = "lapislazuli";
//if(unzOpenCurrentFilePassword(unz_file, password.c_str()) == UNZ_OK) std::cout << "OPENED" << std::endl;
if (unzOpenCurrentFile(unz_file) == UNZ_OK) std::cout << "OPENED" << std::endl;
unzReadCurrentFile(unz_file, file, info.uncompressed_size);
sf::Image image;
image.loadFromMemory(&file[0], info.uncompressed_size);
tileset_texture.loadFromImage(image);
free(file);
Anyone knows how to do it with this library or with a differentr one?
There is no error compiling.
if(unzOpenCurrentFilePassword(unz_file, password) == UNZ_OK) std::cout << "OPENED" << std::endl;
The unzipping fails because the return of the function it's not UNZ_OK.
There is no error compiling.
if(unzOpenCurrentFilePassword(unz_file, password) == UNZ_OK) std::cout << "OPENED" << std::endl;
The unzipping fails because the return of the function it's not UNZ_OK.
I know, but what is it then? Check what values can return unzOpenCurrentFilePassword and what it actually returns.
There is no error compiling.
if(unzOpenCurrentFilePassword(unz_file, password) == UNZ_OK) std::cout << "OPENED" << std::endl;
The unzipping fails because the return of the function it's not UNZ_OK.
I know, but what is it then? Check what values can return unzOpenCurrentFilePassword and what it actually returns.
Solved.
The problem was in the encrytion method. In winzip you have to choose "inherit Zip 2.0".
There is only one valid return value wich is UNZ_OK. This is from the library.
extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
const char* password));
/*
Open for reading data the current file in the zipfile.
password is a crypting password
If there is no error, the return value is UNZ_OK.
*/