Jump to content
  • Advertisement
Sign in to follow this  
Tsumuji

zlib and files in a directory?

This topic is 4853 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

OK, I have done with zlib. Is working in my project, but I noticed that zlib can't handle more than one file at once(like gzip), and can't handle directories. So if I plan to "zip" a directory with my game files, how can I do that? Something like unix tar? And than compress the tar file? Or have another way to handle this problem?

Share this post


Link to post
Share on other sites
Advertisement
hi

I have written a zip file read, if you would like to use it just pm me

maybe we could develop it further on together, I planned to release it for free somewhen

it have tested it a bit and it worked fine

however its just for reading no writing of zip files supported til now

Share this post


Link to post
Share on other sites
ok, I'm giving the physfs a try, but the things appear a little trick.
I'm writing this code, but I don't know if it's right. The function PHYSFS_read() takes a parameter buffer, but I must not allocate this first? With PHYSFS_setBuffer()? I'm confused :

if ( PHYSFS_init( argv[0] ) == 0 ){ //Para inicializar o arquivo PAK
std::cout << "Inicialização do arquivo PAK falhou." << PHYSFS_getLastError() << std::endl;
SDL_Quit( );
return -1;
}
//std::cout << PHYSFS_addToSearchPath(".",1) << std::endl;
PHYSFS_addToSearchPath(".",1);
if ( PHYSFS_exists("pak.zip") == 0 ){
std::cout << PHYSFS_getLastError() << std::endl;
SDL_Quit( );
return -1;
}
PHYSFS_File arquivo_virtual;
arquivo_virtual = *PHYSFS_openRead("pak.zip");
PHYSFS_uint32 pakSize;
pakSize = PHYSFS_fileLength( &arquivo_virtual );
//std::cout << << std::endl;
if ( PHYSFS_setBuffer( &arquivo_virtual, pakSize) == 0 ){
std::cout << PHYSFS_getLastError() << std::endl;
SDL_Quit( );
return -1;
}
char* buffer;
PHYSFS_read( &arquivo_virtual, buffer, pakSize, 1 );

...........

if ( PHYSFS_close( &arquivo_virtual ) == 0 ){
std::cout << PHYSFS_getLastError() << std::endl;
}
if ( PHYSFS_removeFromSearchPath(".") == 0 ){
std::cout << PHYSFS_getLastError() << std::endl;
}
if ( PHYSFS_deinit( ) == 0 ){
std::cout << "Finalização do arquivo PAK falhou." << PHYSFS_getLastError() << std::endl;
}

Share this post


Link to post
Share on other sites
Sorry, I could've helped you, have you decided to use my project, but as for PhysFS, I just pointed it out to you, I have no experience with it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
.zip files are NOT like .gz files
they can handle more than one file and directories
so you can pack your gamefiles in the .zip file, maybe best with apps like winrar, winzip, .. and unpack it with zlib in your program

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
don't know PhysFS,
but when you look at their site, there is a simple tutorial
http://icculus.org/physfs/physfstut.txt

Share this post


Link to post
Share on other sites
k, now the things are working. Look at this:

//The function that take the file I desire:
void *engine::abreArquivoCompactado( const char *arquivo ){

if ( PHYSFS_exists(arquivo) == 0 ){
std::cout << PHYSFS_getLastError() << std::endl;
}else{
PHYSFS_File arquivo_virtual;
arquivo_virtual = *PHYSFS_openRead(arquivo);
PHYSFS_uint32 pakSize;
pakSize = PHYSFS_fileLength( &arquivo_virtual );
if ( PHYSFS_setBuffer( &arquivo_virtual, pakSize) == 0 ){
std::cout << PHYSFS_getLastError() << std::endl;
}
char *buffer = new char[pakSize];
PHYSFS_read( &arquivo_virtual, buffer, pakSize, 1 );

if ( PHYSFS_close( &arquivo_virtual ) == 0 ){
std::cout << PHYSFS_getLastError() << std::endl;
}
return buffer;
}

return 0;
}

..................
//main:
if ( PHYSFS_init( argv[0] ) == 0 ){ //Para inicializar o arquivo PAK
std::cout << "Inicialização do arquivo PAK falhou." << PHYSFS_getLastError() << std::endl;
SDL_Quit( );
return -1;
}
PHYSFS_addToSearchPath("pak.zip",1);
............
layer1 = IMG_Load((char*)abreArquivoCompactado("pak/imagens/layout.png"));




So, since I want to load images with IMG_Load from SDL_Image, and the PHYSFS_read() throw the contents of the file in a buffer, how can I load the image with SDL_Image?
This is the last step to make things working! :)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
try the following:


int size;
char *buffer = abreArquivoCompactado("pak/imagens/layout.png", &size); // return also the size of the buffer !!!
SDL_RWops *rw = SDL_RWFromMem(buffer, size);
SDL_Surface *surface = IMG_Load_RW(rw, 0);
delete [] buffer;





as a note:

IMG_Load_RW can load all supported image formats, except TGA
so when you need .tga's,
use instead IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, char *type)
ie.
SDL_Surface *surface = IMG_LoadTyped_RW(rw, 0, "TGA");
or you can also use the seperate func's:
ie.
SDL_Surface *IMG_LoadJPG_RW(SDL_RWops *src)
SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
SDL_Surface *IMG_LoadTGA_RW(SDL_RWops *src)
....

Share this post


Link to post
Share on other sites
Great! I tryed this and works very well :)
But, cannot load TGA? What's the difference? (I really need TGA and a automatic loading thing)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!