Wednesday, January 16, 2008

File bundling




One highly elegant thing apple does is create bundles. Bundles are simply self contained folders which contain all the data relevant to that item, and are differentiated from normal folders via an folder extension (similar to a file extension, except is a folder)

So, an example game for instance in linux is currently

/opt/local/bin/portal
/opt/local/lib/portal.lib
/opt/local/etc/bleh/lib
/opt/local/share/portal/gfx/001.png
/opt/local/share/portal/gfx/002.png

etc.

So a user needs to navigate to either the application menu, or /opt/local/bin/portal to start the game. Also, note that there is no elegant way to move the application onto another computer. The data is not self contained and you cannot simply copy /opt/local, because there could be thousands of applications in there. There are probably a few other libs in the directories

Apples solution is to rearrange everything into something similar to
./portal.app/bin/portal
./portal.app/lib/portal.lib
./portal.app/etc/bleh/lib
./portal.app/gfx/001.png
./portal.app/gfx/002.png
./portal.app/contents.plist (contains what files the application opens, the type of bundle it is (which is obvious anyway), and the position of the application binary relative to the root of the bundle (so "./bin/portal" for instance))
./portal.app/sources.apt (holds the mirror the updates are stored on)

The game is now a portable directory and can be shifted around, if you want it in your home directory, you can just move it there. Executing the file acts as follows:
1) User selects top level of bundle, and double clicks, the directory has the icon of the file or/and type of file the bundle holds
2) Loader reads description.plist, and identifies where the binary is located (at ./portal.app/bin/portal)
3) Loader executes binary.
4) Program reads libraries from external library bundles (which cannot be moved around)
5) Program reads internal files using ./portal.app/*, NOT hardcoded /Apps/portal.app/*.

The main difference is that the user can now just double click the portal.app directory, and the game is automatically opened. So there are less levels of directories they need to go through and mess around with.

This is definately doable on linux as Gobolinux does something similar. If we could standardise the extension names being used for bundles, there wont be any issues.

You could self contain libssl now as:
/libraries/libssl.library/* (bin, libs, man, etc)

or even stored webpages as something like:
google.webpage/Index.htm
google.webpage/me.jpg

Its all clean and self contained, and you just need to implement an option in the context menu to peer inside it. Some changes would need to be made to console to allow paths to work though (unless you maintain symlinks to all the core libs in a central location for instance.

No comments: