On VFS and Multifiles

Three questions:

  1. Looking in the manual at the example code:
vfs = VirtualFileSystem.getGlobalPtr()
vfs.mount(Filename('foo.mf'), '.', VirtualFileSystem.MFReadOnly)

I’m not quite clear what that ‘.’ does. Does it indicate the current directory, the one returned by the vfs.getCwd() method, implying that foo.mf will be mounted there?

  1. the reference manual hints to creating your own vfx objects. How can the root of the new object or the global vfs root be set? I.e. can I set the global root to the installation folder of my game? Or is that going to break something?

  2. Can python code (py/pyc) be imported directly from a multifile?

Thanks for your help!

Manu

  1. Yes, “.” means the current directory. Mounting foo.mf onto the current directory is convenient, because it means if you call loader.loadModel(‘model.egg’), it will search first in the current directory (assuming that “.” is first on your model-path), which now happens to be foo.mf!

You could alternatively mount it anywhere in particular, like “/foo”, instead of mounting it on “.”. This would mean that you’d need to either call loader.loadModel(’/foo/model.egg’), or you’d need to put “/foo” on your model-path.

  1. Not 100% sure of your question, but you can call vfs->chdir(’/my/new/directory’) to change the return value of vfs.getCwd(). It might also be a good idea to call ExecutionEnvrionment.chdir(’/my/new/directory’) too. This effectively changes the meaning of “.”. It shouldn’t break anything.

  2. Yes. As of the current version of Panda (1.5.3), you’ll need to write your own Python importer for this (Python provides a mechanism to do this, but you have to write the code). However, on the Panda CVS trunk right now we have just added the necessary code, and there you can call:

from direct.showbase import VFSImporter
VFSImporter.register()

which will automatically make future Python imports load from the vfs, and therefore from any mounted multifiles. This will be officially released with 1.6.0.

David

Hi David, thanks for your replies.

I guess I was looking for something to limit the VFS to the application’s folder structure rather than an entire hard drive, i.e. having a vfs.setRoot() method that prevents any other vfs method from climbing out of a given folder. I don’t know how much that would make sense though. There would be ways to easily go around it I guess. Never mind though, all your replies did help! Thank you!

Manu

Ah, I gotcha. If you remove the default mounting of “/”, with vfs.unmount() or vfs.unmountAll(), then only those directories which are explicitly mounted will be valid.

If your goal is to provide a secure environment in which to run untrusted code, though, that won’t do it. There are numerous ways for code to get around this limitation; not least of which is simply re-mounting “/” again.

David

from direct.showbase import VFSImporter
VFSImporter.register()

which will automatically make future Python imports load from the vfs, and therefore from any mounted multifiles. This will be officially released with 1.6.0.

OH wow thats great. I was working on some thing like this for myself and got some prof of concept going but because it became hard to debug import problems i dropped it. Right now i just extract all .pyc files into a zip from which i add to python path but removing that extra zip step would be great!

Thanks for the Info David! Much appreciated!

Manu

Quick question:
If you mount stuff using the Virtual File System, will the stuff then really be placed on the hard drive (e.g. if the user alt+tabs into his file manager will he be able to see it?) or, is the stuff mounted using the VFS only accessible from within the application?

The stuff mounted using the VFS is only accessible from within the application. Its like cab, dat, upk, big … files for other games.