Results 1 to 8 of 8

Thread: Problem loading zip files on Android

  1. #1

    Default Problem loading zip files on Android

    I try loading zip archives on iPhone and Android using code:
    Code:
    int DataMgr::addZipPack(std::string pakfile_name)
    {
    	FileSystemZip *pFileSystem = new FileSystemZip();
    	if (!pFileSystem->Init(GetBaseAppPath()+ pakfile_name))
    	{
    		LogMsg("Error finding APK file to load resources");
    		return false;
    	}
    	pFileSystem->SetRootDirectory("");
    	GetFileManager()->MountFileSystem(pFileSystem);
    }
    On iPhone all work good, but on android emulator I got "file not found error" on zip files. All zip files located in assets directory in pkg file. rttex and font files load normal. Main menu is displayed.

    Ps. Also I found some bug in your code. If zip archive have only root directory it is impossible to load any file from this archive because engine add "/" for file name when search.
    Last edited by mmortall; 07-15-2011 at 07:42 PM.

  2. #2
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,343

    Default

    On iPhone all work good, but on android emulator I got "file not found error" on zip files. All zip files located in assets directory in pkg file.
    Hmm - the .pkg file actually IS a zip itself, so I think the problem may be it can't mount a zip file from a zip file.

    I'd either pre-unzip it in /assets, so it's only zipped once in the package, or, you could copy the entire file out of the zip, then open it as a zip.

    If you want to do the copy thing, use shared/FileSystem/FileCopier.cpp, I wrote it to do exactly that.

    Ps. Also I found some bug in your code. If zip archive have only root directory it is impossible to load any file from this archive because engine add "/" for file name when search.
    Oops, thanks, will fix.
    Seth A. Robinson
    Robinson Technologies

  3. #3

    Default

    I need to use zip archives for protect game data. I add LZMA support in Irrlicht for this. This issue works perfect on window but on iPhone I got crash.

    Do you know why Irrlicht zip methods crashes on iPhone and Android?. You use Irrlicht methods too but your methods do not crash.

    Do you know another simple methods to protect game data in .pkg or .app?

    Maybe I renounce the use of zip archive at all.
    Last edited by mmortall; 07-16-2011 at 01:57 PM.

  4. #4
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,343

    Default

    Irrlicht's zip loader does have something wrong with it.. for instance, it wouldn't load android archives correctly. Proton's version can, (I wrote the zip loading/caching part from scratch) so I actually use that instead of Irrlicht's stuff by setting up Proton's FileManager as a file source for Irrlicht.

    But back to the general question of "how do I protect my data" - one option is just to encrypt the file, before zipping.

    Simple example to get the idea:

    Add 1 to every byte in the file.


    In your app, load the file into memory (from zip or normal file, doesn't matter) then run your decrypt function on it, which removes 1 from every byte. Now use it.

    To get fancy, instead of just adding 1, you could add 1 + offset in the file or any number of things like XOR etc.
    Seth A. Robinson
    Robinson Technologies

  5. #5

    Default

    Sorry for late answer. Thanks for reply.

    I did this kind of protection by defining my own functions read/write for zip. There I make decoding (for example ZOR).
    It is useful to do with zip archives, but android not support zip archives.
    So for android I need to redefine read/write operation for all files in engine?
    There are a lot off different files. Some is text, not binary.

    It is possible to fix loading zip archives on android?

  6. #6
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,343

    Default

    It is possible to fix loading zip archives on android?
    All Android resources ARE loaded from a zip (.apk is a .zip), this is a requirement of Android. I'm not sure exactly what you mean by custom decrypting using a zip, but you can access a zipped zip like this:

    StreamingInstance *pFile = GetFileManager()->GetStreaming("myzip_file.zip");

    This would let you get at the zip from Android and process it yourself.

    If you need random access to the zip inside the zip, this would be possible by making sure it isn't compressed by the containing zip that zips your zip. (what did I just say? ) (.wav files are also set to not compress for instance, check the build.xml file to see where I set "<nocompress extension="wav" /> " .. you can add your own filetypes)

    As long as it's not compressed, StreamingInstance::SeekFromStart() can be used to move around it and do your own custom zip handling on it, without loading the whole thing, even from Android.
    Seth A. Robinson
    Robinson Technologies

  7. #7

    Default

    Quote Originally Posted by Seth View Post
    All Android resources ARE loaded from a zip (.apk is a .zip), this is a requirement of Android. I'm not sure exactly what you mean by custom decrypting using a zip, but you can access a zipped zip like this:

    StreamingInstance *pFile = GetFileManager()->GetStreaming("myzip_file.zip");

    This would let you get at the zip from Android and process it yourself.

    As long as it's not compressed, StreamingInstance::SeekFromStart() can be used to move around it and do your own custom zip handling on it, without loading the whole thing, even from Android.
    O. Is is good staff but it can only read binary and text data. I need use zip with Irrlicht functions like getMesh() or getTexture()


    Quote Originally Posted by Seth View Post
    If you need random access to the zip inside the zip, this would be possible by making sure it isn't compressed by the containing zip that zips your zip. (what did I just say? ) (.wav files are also set to not compress for instance, check the build.xml file to see where I set "<nocompress extension="wav" /> " .. you can add your own filetypes)
    So if I add my extension (.zip for example)
    FileSystemZip *pFileSystem = new FileSystemZip();
    will work on android?

  8. #8
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,343

    Default

    So if I add my extension (.zip for example)
    FileSystemZip *pFileSystem = new FileSystemZip();
    will work on android?
    Yes - well.. no - I mean, it can't mount a .zip from within another .zip. But it could mount from a normal file, so you could copy a .zip out of the zip (into a temp dir on the android phone) and mount that as I've mentioned.

    But if that works, why not just merge your original zip(s) with the android apk?

    If you look at AndroidUtils.cpp, you will see where it is mounting the apk as a zip already:

    Code:
    FileSystemZip *pFileSystem = new FileSystemZip();
    		if (!pFileSystem->Init(GetAPKFile()))
    		{
    			LogMsg("Error finding APK file to load resources (%s", GetAPKFile().c_str());
    		}
    
    		pFileSystem->SetRootDirectory("assets");
    		GetFileManager()->MountFileSystem(pFileSystem);
    So before you pack your game, just unzip your stuff into android/assets, and they will be zipped along in the .apk.

    Sorry but I don't think I can help more as I don't really know the specifics of what you are processing the zip for decryption. I don't think unzipping a zip from a parent zip will be needed for most people so I won't be adding this functionality, but anybody else is welcome to give it a shot.
    Last edited by Seth; 08-01-2011 at 06:44 AM. Reason: clarification
    Seth A. Robinson
    Robinson Technologies

Similar Threads

  1. android build problem
    By stubtemple in forum Proton SDK
    Replies: 7
    Last Post: 06-15-2011, 09:16 PM
  2. Yet another Android problem
    By kalango in forum Proton SDK
    Replies: 7
    Last Post: 06-08-2011, 02:48 AM
  3. Replies: 2
    Last Post: 04-14-2011, 05:15 PM
  4. Problem loading this jpeg image in svn 2.3
    By huntercool in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 02-01-2011, 03:38 PM
  5. Loading files using custom resource types
    By Hypercube in forum Official ClanLib SDK Forums
    Replies: 3
    Last Post: 12-12-2008, 04:53 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •