Panda3D
|
00001 // Filename: virtualFileSystem.I 00002 // Created by: drose (03Aug02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: VirtualFileSystem::exists 00018 // Access: Published 00019 // Description: Convenience function; returns true if the named file 00020 // exists. 00021 //////////////////////////////////////////////////////////////////// 00022 INLINE bool VirtualFileSystem:: 00023 exists(const Filename &filename) const { 00024 return get_file(filename, true) != (VirtualFile *)NULL; 00025 } 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Function: VirtualFileSystem::is_directory 00029 // Access: Published 00030 // Description: Convenience function; returns true if the named file 00031 // exists and is a directory. 00032 //////////////////////////////////////////////////////////////////// 00033 INLINE bool VirtualFileSystem:: 00034 is_directory(const Filename &filename) const { 00035 PT(VirtualFile) file = get_file(filename, true); 00036 return (file != (VirtualFile *)NULL && file->is_directory()); 00037 } 00038 00039 //////////////////////////////////////////////////////////////////// 00040 // Function: VirtualFileSystem::is_regular_file 00041 // Access: Published 00042 // Description: Convenience function; returns true if the named file 00043 // exists and is a regular file. 00044 //////////////////////////////////////////////////////////////////// 00045 INLINE bool VirtualFileSystem:: 00046 is_regular_file(const Filename &filename) const { 00047 PT(VirtualFile) file = get_file(filename, true); 00048 return (file != (VirtualFile *)NULL && file->is_regular_file()); 00049 } 00050 00051 //////////////////////////////////////////////////////////////////// 00052 // Function: VirtualFileSystem::scan_directory 00053 // Access: Published 00054 // Description: If the file represents a directory (that is, 00055 // is_directory() returns true), this returns the list 00056 // of files within the directory at the current time. 00057 // Returns NULL if the file is not a directory or if the 00058 // directory cannot be read. 00059 //////////////////////////////////////////////////////////////////// 00060 INLINE PT(VirtualFileList) VirtualFileSystem:: 00061 scan_directory(const Filename &filename) const { 00062 PT(VirtualFile) file = get_file(filename, true); 00063 if (file == (VirtualFile *)NULL) { 00064 return NULL; 00065 } 00066 00067 return file->scan_directory(); 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: VirtualFileSystem::ls 00072 // Access: Published 00073 // Description: Convenience function; lists the files within the 00074 // indicated directory. 00075 //////////////////////////////////////////////////////////////////// 00076 INLINE void VirtualFileSystem:: 00077 ls(const Filename &filename) const { 00078 PT(VirtualFile) file = get_file(filename, true); 00079 if (file == (VirtualFile *)NULL) { 00080 express_cat.info() 00081 << "Not found: " << filename << "\n"; 00082 } else { 00083 file->ls(); 00084 } 00085 } 00086 00087 //////////////////////////////////////////////////////////////////// 00088 // Function: VirtualFileSystem::ls_all 00089 // Access: Published 00090 // Description: Convenience function; lists the files within the 00091 // indicated directory, and all files below, 00092 // recursively. 00093 //////////////////////////////////////////////////////////////////// 00094 INLINE void VirtualFileSystem:: 00095 ls_all(const Filename &filename) const { 00096 PT(VirtualFile) file = get_file(filename, true); 00097 if (file == (VirtualFile *)NULL) { 00098 express_cat.info() 00099 << "Not found: " << filename << "\n"; 00100 } else { 00101 file->ls_all(); 00102 } 00103 } 00104 00105 //////////////////////////////////////////////////////////////////// 00106 // Function: VirtualFileSystem::read_file 00107 // Access: Published 00108 // Description: Convenience function; returns the entire contents of 00109 // the indicated file as a string. 00110 // 00111 // If auto_unwrap is true, an explicitly-named .pz file 00112 // is automatically decompressed and the decompressed 00113 // contents are returned. This is different than 00114 // vfs-implicit-pz, which will automatically decompress 00115 // a file if the extension .pz is *not* given. 00116 //////////////////////////////////////////////////////////////////// 00117 INLINE string VirtualFileSystem:: 00118 read_file(const Filename &filename, bool auto_unwrap) const { 00119 string result; 00120 bool okflag = read_file(filename, result, auto_unwrap); 00121 nassertr(okflag, string()); 00122 return result; 00123 } 00124 00125 //////////////////////////////////////////////////////////////////// 00126 // Function: VirtualFileSystem::read_file 00127 // Access: Public 00128 // Description: Convenience function; fills the string up with the 00129 // data from the indicated file, if it exists and can be 00130 // read. Returns true on success, false otherwise. 00131 // 00132 // If auto_unwrap is true, an explicitly-named .pz file 00133 // is automatically decompressed and the decompressed 00134 // contents are returned. This is different than 00135 // vfs-implicit-pz, which will automatically decompress 00136 // a file if the extension .pz is *not* given. 00137 //////////////////////////////////////////////////////////////////// 00138 INLINE bool VirtualFileSystem:: 00139 read_file(const Filename &filename, string &result, bool auto_unwrap) const { 00140 PT(VirtualFile) file = get_file(filename, false); 00141 return (file != (VirtualFile *)NULL && file->read_file(result, auto_unwrap)); 00142 } 00143 00144 //////////////////////////////////////////////////////////////////// 00145 // Function: VirtualFileSystem::read_file 00146 // Access: Public 00147 // Description: Convenience function; fills the pvector up with the 00148 // data from the indicated file, if it exists and can be 00149 // read. Returns true on success, false otherwise. 00150 // 00151 // If auto_unwrap is true, an explicitly-named .pz file 00152 // is automatically decompressed and the decompressed 00153 // contents are returned. This is different than 00154 // vfs-implicit-pz, which will automatically decompress 00155 // a file if the extension .pz is *not* given. 00156 //////////////////////////////////////////////////////////////////// 00157 INLINE bool VirtualFileSystem:: 00158 read_file(const Filename &filename, pvector<unsigned char> &result, bool auto_unwrap) const { 00159 PT(VirtualFile) file = get_file(filename, false); 00160 return (file != (VirtualFile *)NULL && file->read_file(result, auto_unwrap)); 00161 }