User Tools

Site Tools


proton:filemanager

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
proton:filemanager [2010/10/28 05:30]
seth created
proton:filemanager [2012/03/09 01:05] (current)
seth
Line 49: Line 49:
  
 ====How to stream a file in==== ====How to stream a file in====
-To insure a hassle free Android compile you should use FileManager::​GetStreaming. ​ It returns a **StreamingInstance** that operates sort of like a FileInstance but actually smartly loads the file as you go, which may even be from a .zip file.+To insure a hassle free Android compile you should use FileManager::​GetStreaming ​instead of raw fopen/fread type stuff.  It returns a **StreamingInstance** that operates sort of like a FileInstance but actually smartly loads the file as you go, which may even be from a .zip file.
  
 Why would you want to do this and not just load it all in one chunk? Why would you want to do this and not just load it all in one chunk?
Line 75: Line 75:
   * We used **StreamingInstance::​ReadLineOfText** but we could have used **StreamingInstance::​Read** instead for pure data. (It's a lot like fread)   * We used **StreamingInstance::​ReadLineOfText** but we could have used **StreamingInstance::​Read** instead for pure data. (It's a lot like fread)
   * It internally cached the file for speed, for instance, if it's actually in a compressed zip and you are asking for one byte at a time it will really be decoding in 4 KB chunks behind the scenes   * It internally cached the file for speed, for instance, if it's actually in a compressed zip and you are asking for one byte at a time it will really be decoding in 4 KB chunks behind the scenes
 +
 +====Mounting a .zip as a filesystem====
 +This happens automatically when you are doing an Android target, so you can load resources by filename and not worry about where they actually are. (Android wants to keep them in your .apk you used to install)
 +
 +But you may want to mount your own zips for some reason. ​ Let's examine how it's done:
 +
 +<code cpp>
 +FileSystemZip *pFileSystem = new FileSystemZip();​
 +pFileSystem->​Init("​somezip.file"​)); ​ //I'm not doing error handling in these examples, but it would return false on error
 +
 +//to print out the entire contents of the zip:
 +
 +vector<​string>​ contents = pFileSystem->​GetContents();​
 +for (int i=0; i < contents.size();​ i++)
 +{
 +   ​LogMsg("​%s",​ contents[i].c_str());​
 +}
 +
 +//before mounting, we can optionally mount only a subdir of the zip by doing this:
 +pFileSystem->​SetRootDirectory("​assets"​);​ //mount the assets directory only, the user won't have to have "​assets"​ in  the filename to find things in it
 +
 +//to actually mount it
 +GetFileManager()->​MountFileSystem(pFileSystem);​
 +
 +//test that it worked:
 +
 +FileInstance myFile("​textFileInsideAssetsDirOfTheZip.txt"​);​
 +
 +if (myFile.IsLoaded()) LogMsg("​Marty,​ it worked!"​);​
 +</​code>​
  
 ====What about writing user data files?==== ====What about writing user data files?====
 I just use fwrite and fread and haven'​t have any trouble with porting so far.  As long as you use GetSavePath() you're ok as far as file permissions go. I just use fwrite and fread and haven'​t have any trouble with porting so far.  As long as you use GetSavePath() you're ok as far as file permissions go.
 +
proton/filemanager.1288243810.txt.gz ยท Last modified: 2010/10/28 05:30 by seth