01-12-2011 11:44 PM
Here is an overview of application sandbox files system layout for the latest release 0.9.2
(disclaimer: can change in final version but unlikely)
Applications will be run in the directory we call "sandbox". Name of this directory is irrelevant and cannot be relied on.
Application should not attempt to access any files outside of this directory. Sandbox is the default "working directory".
The structure is
All except shared are app's private directories, only the app can read/write files there.
The "app" directory is the link to where application files are installed (what was packaged in the bar file), these files are read only. For air application files will be in subdirectory "air" (i.e. app/air/your_file).
The private data directory is "data". Application has full access to this directory (read/write). The $HOME env var is set to this directory. To initiate the sandbox app may copy files from "app" to "data" (for example user modifiable config files) on the first run.
The "tmp" directory can be used to create temporary files, application should take care of cleaning these files, but system may remove them at any time app is not running - so it cannot be used to persist data, only "data" directory should be used for this.
The "logs" is used for development, application stdin and stdout is redirected to logs/log file, as well as "core" files will be created there if app crashes.
The "shared" is link to common location where all apps share files. It has the following structure:
If you know how all of it maps to air File class fields please post here too
01-13-2011 03:14 AM
Haven't figured out 100% what to do with this info. So, in one of my apps I export an image. Currently I export it to File.userDirectory. Should I change this to the shared folder? And how?
01-13-2011 03:20 AM - edited 01-13-2011 03:22 AM
File.userDirectory is the convention for saving app settings on Android, can we still rely on that?
It would be nice to not have to write Playbook specific code here, can we just make userDirectory point to /data?
01-13-2011 11:19 AM - edited 01-13-2011 11:20 AM
Hi,
The directory tree maps (as elena listed) start at File.applicationStorageDirectory.nativePath
which is currently /accounts/1000/appdata/<actual_dname>
There are a couple folders there that weren't listed.
I can see the .../shared/ tree, but haven't managed to write anything down that path successfully yet.
Harry
01-13-2011 12:13 PM
Here's the mapping:
| Alias | Path |
|---|---|
| File.applicationDirectory | (appname)/app/air |
| File.applicationStorageDirectory | (appname)/data |
| File.desktopDirectory | (appname)/ |
| File.documentsDirectory | (appname)/shared/documents |
| File.userDirectory | (appname)/shared/documents |
In each case, in the above, (appname) is really "/accounts/1000/appdata/FooBar.RmlsASDFadfdsldskdC
So it looks like we don't even have to try to choose between user or documents directory, as they point (for now) to the same place. I'd ignore "desktop" and quite possibly it's read-only anyway.
01-13-2011 12:50 PM
Hi,
Thanks Peter. I wrote a bunch of pictures into the documentsDirectory and can see them using browse() from my already submitted app.
Harry
01-13-2011 12:58 PM
And what if my app generates an image for the enduser so he can use it? For example as an attachment in a mail, post on twitter, transfer to pc... Where should I save it then?
01-13-2011 01:01 PM
zezke wrote:
And what if my app generates an image for the enduser so he can use it? For example as an attachment in a mail, post on twitter, transfer to pc... Where should I save it then?
File.documentsDirectory will work as it is shared between apps. I used one app to write the pictures into it, and my game app to view/select/add them as backdrops.
01-13-2011 01:02 PM
Thank you for that clarification.
01-13-2011 01:07 PM
@zezke, if you didn't mind some PB-specific code, you could write to "photos/" under the documentsDirectory.
That was the only folder Elena missed in her list above.
It looks like our options are pretty simple at the moment actually: