Panda3D
|
A hierarchy of directories and files that appears to be one continuous file system, even though the files may originate from several different sources that may not be related to the actual OS's file system. More...
Public Types | |
enum | MountFlags { MFReadOnly = 2 } |
Public Member Functions | |
VirtualFileSystem () | |
bool | chdir (Filename const new_directory) |
Changes the current directory. | |
bool | exists (Filename const filename) |
Convenience function; returns true if the named file exists. | |
int | findAllFiles (Filename const filename, DSearchPath const searchpath, Results results) |
Searches all the directories in the search list for the indicated file, in order. | |
VirtualFile | findFile (Filename const filename, DSearchPath const searchpath, bool status_only) |
Uses the indicated search path to find the file within the file system. | |
VirtualFile | findFile (Filename const filename, DSearchPath const searchpath) |
Uses the indicated search path to find the file within the file system. | |
Filename | getCwd () |
Returns the current directory name. | |
VirtualFile | getFile (Filename const filename, bool status_only) |
Looks up the file by the indicated name in the file system. | |
VirtualFile | getFile (Filename const filename) |
Looks up the file by the indicated name in the file system. | |
VirtualFileMount | getMount (int n) |
Returns the nth mount in the system. | |
list | getMounts () |
int | getNumMounts () |
Returns the number of individual mounts in the system. | |
bool | isDirectory (Filename const filename) |
Convenience function; returns true if the named file exists and is a directory. | |
bool | isRegularFile (Filename const filename) |
Convenience function; returns true if the named file exists and is a regular file. | |
ls (Filename const filename) | |
Convenience function; lists the files within the indicated directory. | |
lsAll (Filename const filename) | |
Convenience function; lists the files within the indicated directory, and all files below, recursively. | |
bool | mount (Filename const physical_filename, Filename const mount_point, int flags) |
Mounts the indicated system file or directory at the given mount point. | |
bool | mount (Filename const physical_filename, Filename const mount_point, int flags, string password) |
Mounts the indicated system file or directory at the given mount point. | |
bool | mount (VirtualFileMount mount, Filename const mount_point, int flags) |
Adds the given VirtualFileMount object to the mount list. | |
bool | mount (Multifile multifile, Filename const mount_point, int flags) |
Mounts the indicated Multifile at the given mount point. | |
bool | mountLoop (Filename const virtual_filename, Filename const mount_point, int flags) |
This is similar to mount(), but it receives the name of a Multifile that already appears within the virtual file system. | |
bool | mountLoop (Filename const virtual_filename, Filename const mount_point, int flags, string password) |
This is similar to mount(), but it receives the name of a Multifile that already appears within the virtual file system. | |
istream | openReadFile (Filename const filename, bool auto_unwrap) |
Convenience function; returns a newly allocated istream if the file exists and can be read, or NULL otherwise. | |
PyObject | pyReadFile (Filename const filename, bool auto_unwrap) |
Convenience function; returns the entire contents of the indicated file as a string. | |
string | readFile (Filename const filename, bool auto_unwrap) |
Convenience function; returns the entire contents of the indicated file as a string. | |
bool | resolveFilename (Filename filename, DSearchPath const searchpath) |
Searches the given search path for the filename. | |
bool | resolveFilename (Filename filename, DSearchPath const searchpath, string default_extension) |
Searches the given search path for the filename. | |
VirtualFileList | scanDirectory (Filename const filename) |
If the file represents a directory (that is, is_directory() returns true), this returns the list of files within the directory at the current time. | |
int | unmount (VirtualFileMount mount) |
Unmounts the indicated VirtualFileMount object from the file system. | |
int | unmount (Multifile multifile) |
Unmounts all appearances of the indicated Multifile from the file system. | |
int | unmount (Filename const physical_filename) |
Unmounts all appearances of the indicated directory name or multifile name from the file system. | |
int | unmountAll () |
Unmounts all files from the file system. | |
int | unmountPoint (Filename const mount_point) |
Unmounts all systems attached to the given mount point from the file system. | |
write (ostream out) | |
Print debugging information. | |
Static Public Member Functions | |
static | closeReadFile (istream stream) |
Closes a file opened by a previous call to open_read_file(). | |
static VirtualFileSystem | getGlobalPtr () |
Returns the default global VirtualFileSystem. |
A hierarchy of directories and files that appears to be one continuous file system, even though the files may originate from several different sources that may not be related to the actual OS's file system.
For instance, a VirtualFileSystem can transparently mount one or more Multifiles as their own subdirectory hierarchies.
enum MountFlags |
bool chdir | ( | Filename const | new_directory | ) |
Changes the current directory.
This is used to resolve relative pathnames in get_file() and/or find_file(). Returns true if successful, false otherwise.
static closeReadFile | ( | istream | stream | ) | [static] |
Closes a file opened by a previous call to open_read_file().
This really just deletes the istream pointer, but it is recommended to use this interface instead of deleting it explicitly, to help work around compiler issues.
bool exists | ( | Filename const | filename | ) |
Convenience function; returns true if the named file exists.
int findAllFiles | ( | Filename const | filename, |
DSearchPath const | searchpath, | ||
Results | results | ||
) |
Searches all the directories in the search list for the indicated file, in order.
Fills up the results list with *all* of the matching filenames found, if any. Returns the number of matches found.
It is the responsibility of the the caller to clear the results list first; otherwise, the newly-found files will be appended to the list.
VirtualFile findFile | ( | Filename const | filename, |
DSearchPath const | searchpath | ||
) |
Uses the indicated search path to find the file within the file system.
Returns the first occurrence of the file found, or NULL if the file cannot be found.
VirtualFile findFile | ( | Filename const | filename, |
DSearchPath const | searchpath, | ||
bool | status_only | ||
) |
Uses the indicated search path to find the file within the file system.
Returns the first occurrence of the file found, or NULL if the file cannot be found.
VirtualFile getFile | ( | Filename const | filename, |
bool | status_only | ||
) |
Looks up the file by the indicated name in the file system.
Returns a VirtualFile pointer representing the file if it is found, or NULL if it is not.
If status_only is true, the file will be checked for existence and length and so on, but the returned file's contents cannot be read. This is an optimization which is especially important for certain mount types, for instance HTTP, for which opening a file to determine its status is substantially less expensive than opening it to read its contents.
VirtualFile getFile | ( | Filename const | filename | ) |
Looks up the file by the indicated name in the file system.
Returns a VirtualFile pointer representing the file if it is found, or NULL if it is not.
If status_only is true, the file will be checked for existence and length and so on, but the returned file's contents cannot be read. This is an optimization which is especially important for certain mount types, for instance HTTP, for which opening a file to determine its status is substantially less expensive than opening it to read its contents.
static VirtualFileSystem getGlobalPtr | ( | ) | [static] |
Returns the default global VirtualFileSystem.
You may create your own personal VirtualFileSystem objects and use them for whatever you like, but Panda will attempt to load models and stuff from this default object.
Initially, the global VirtualFileSystem is set up to mount the OS filesystem to root; i.e. it is equivalent to the OS filesystem. This may be subsequently adjusted by the user.
VirtualFileMount getMount | ( | int | n | ) |
Returns the nth mount in the system.
list getMounts | ( | ) |
int getNumMounts | ( | ) |
Returns the number of individual mounts in the system.
bool isDirectory | ( | Filename const | filename | ) |
Convenience function; returns true if the named file exists and is a directory.
bool isRegularFile | ( | Filename const | filename | ) |
Convenience function; returns true if the named file exists and is a regular file.
ls | ( | Filename const | filename | ) |
Convenience function; lists the files within the indicated directory.
lsAll | ( | Filename const | filename | ) |
Convenience function; lists the files within the indicated directory, and all files below, recursively.
bool mount | ( | Filename const | physical_filename, |
Filename const | mount_point, | ||
int | flags, | ||
string | password | ||
) |
Mounts the indicated system file or directory at the given mount point.
If the named file is a directory, mounts the directory. If the named file is a Multifile, mounts it as a Multifile. Returns true on success, false on failure.
A given system directory may be mounted to multiple different mount point, and the same mount point may share multiple system directories. In the case of ambiguities (that is, two different files with exactly the same full pathname), the most-recently mounted system wins.
The filename specified as the first parameter must refer to a real, physical filename on disk; it cannot be a virtual file already appearing within the vfs filespace. However, it is possible to mount such a file; see mount_loop() for this. Note that a mounted VirtualFileSystem directory is fully case-sensitive, unlike the native Windows file system, so you must refer to files within the virtual file system with exactly the right case.
Mounts the indicated system file or directory at the given mount point.
If the named file is a directory, mounts the directory. If the named file is a Multifile, mounts it as a Multifile. Returns true on success, false on failure.
A given system directory may be mounted to multiple different mount point, and the same mount point may share multiple system directories. In the case of ambiguities (that is, two different files with exactly the same full pathname), the most-recently mounted system wins.
The filename specified as the first parameter must refer to a real, physical filename on disk; it cannot be a virtual file already appearing within the vfs filespace. However, it is possible to mount such a file; see mount_loop() for this. Note that a mounted VirtualFileSystem directory is fully case-sensitive, unlike the native Windows file system, so you must refer to files within the virtual file system with exactly the right case.
bool mount | ( | VirtualFileMount | mount, |
Filename const | mount_point, | ||
int | flags | ||
) |
Adds the given VirtualFileMount object to the mount list.
This is a lower-level function that the other flavors of mount(); it requires you to create a VirtualFileMount object specifically.
Mounts the indicated Multifile at the given mount point.
bool mountLoop | ( | Filename const | virtual_filename, |
Filename const | mount_point, | ||
int | flags, | ||
string | password | ||
) |
This is similar to mount(), but it receives the name of a Multifile that already appears within the virtual file system.
It can be used to mount a Multifile that is itself hosted within a virtually-mounted Multifile.
This interface can also be used to mount physical files (that appear within the virtual filespace), but it cannot be used to mount directories. Use mount() if you need to mount a directory.
Note that there is additional overhead, in the form of additional buffer copies of the data, for recursively mounting a multifile like this.
This is similar to mount(), but it receives the name of a Multifile that already appears within the virtual file system.
It can be used to mount a Multifile that is itself hosted within a virtually-mounted Multifile.
This interface can also be used to mount physical files (that appear within the virtual filespace), but it cannot be used to mount directories. Use mount() if you need to mount a directory.
Note that there is additional overhead, in the form of additional buffer copies of the data, for recursively mounting a multifile like this.
Convenience function; returns a newly allocated istream if the file exists and can be read, or NULL otherwise.
Does not return an invalid istream.
If auto_unwrap is true, an explicitly-named .pz file is automatically decompressed and the decompressed contents are returned. This is different than vfs-implicit-pz, which will automatically decompress a file if the extension .pz is *not* given.
PyObject pyReadFile | ( | Filename const | filename, |
bool | auto_unwrap | ||
) |
Convenience function; returns the entire contents of the indicated file as a string.
This variant on read_file() is implemented directly for Python, as a small optimization, to avoid the double-construction of a string object that would be otherwise required for the return value.
string readFile | ( | Filename const | filename, |
bool | auto_unwrap | ||
) |
Convenience function; returns the entire contents of the indicated file as a string.
If auto_unwrap is true, an explicitly-named .pz file is automatically decompressed and the decompressed contents are returned. This is different than vfs-implicit-pz, which will automatically decompress a file if the extension .pz is *not* given.
bool resolveFilename | ( | Filename | filename, |
DSearchPath const | searchpath, | ||
string | default_extension | ||
) |
Searches the given search path for the filename.
If it is found, updates the filename to the full pathname found and returns true; otherwise, returns false.
bool resolveFilename | ( | Filename | filename, |
DSearchPath const | searchpath | ||
) |
Searches the given search path for the filename.
If it is found, updates the filename to the full pathname found and returns true; otherwise, returns false.
VirtualFileList scanDirectory | ( | Filename const | filename | ) |
If the file represents a directory (that is, is_directory() returns true), this returns the list of files within the directory at the current time.
Returns NULL if the file is not a directory or if the directory cannot be read.
Unmounts all appearances of the indicated Multifile from the file system.
Returns the number of appearances unmounted.
int unmount | ( | VirtualFileMount | mount | ) |
Unmounts the indicated VirtualFileMount object from the file system.
Returns the number of appearances unmounted.
Unmounts all appearances of the indicated directory name or multifile name from the file system.
Returns the number of appearances unmounted.
int unmountAll | ( | ) |
Unmounts all files from the file system.
Returns the number of systems unmounted.
Unmounts all systems attached to the given mount point from the file system.
Returns the number of appearances unmounted.
write | ( | ostream | out | ) |
Print debugging information.
(e.g. from Python or gdb prompt).