Has anyone been able to load files within a .zip folder into an SDL Surface*? I looked at the tutorial here: http://www.kekkai.org/roger/sdl/rwops/rwops.html (Part 3), but I was receiving errors when opening the file. It uses ZZipLib and ZLib (I downloaded the pre-built binaries and header files). I'm using the following code to open the file inside a .zip folder:
char *filename = "data/credits.bmp";//path to the a zipped image
SDL_RWops *rw; //a SDL Read/Write Operations Ptr
ZZIP_FILE *file; // ZZIP_FILE is the zzip equivalent of the stdio FILE.
file = zzip_open(filename, 0);//almost like fopen() except the 2 parameter is unused
// !!! THIS IF STATEMENT RETURNS TRUE, MEANING zzip_open() returned NULL
if(file == NULL)
{
printf("FILE ptr is NULL\n");
throw;
}
int filesize = 0;//this will store the file's actual size
//create a buffer of size bytes
const int bytes = 800*600*4;
//Uint8
char *buffer = new char[bytes];
//now decompress the file, and record the filesize
filesize = zzip_read( file, buffer, bytes );
rw = SDL_RWFromMem(buffer, filesize);
if( rw == NULL )
{
puts("RW is Null");
throw;
}
SDL_Surface *temp1;
temp1 = IMG_Load_RW(rw, 0);
The problem is that zzip_open keeps on returning NULL even though there is a folder in my current directory called data.zip with a file named credits.bmp in it. Has anyone used the zzip_lib for reading in files in a zip folder? Also, if you wondering why the path isn't specified to data.zip/credits.bmp, the documentation for ZZipLib says that:
Quote: It has some magic functionality builtin - it will first try to open the given filename as a normal file. If it does not exist, the given path to the filename (if any) is split into its directory-part and the file-part. A ".zip" extension is then added to the directory-part to create the name of a zip-archive. That zip-archive (if it exists) is being searched for the file-part, and if found a zzip-handle is returned. |
which I interpreted as: "If a real folder with the name you specify exists, then that folder will try to be opened, Else the folder the the name+".zip" will try to be opened." I have already tried adding the .zip extension, but I get the same error. Also, when I leave the "data" folder unzipped, all the images load in successfully. Note: (If a Mod is reading this) I wasn't sure if I should post this in Game Programming or Here, as it does use SDL_RWops but that really isn't my problem.