Panda3D
 All Classes Functions Variables Enumerations
virtualFileSystem.I
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::write_file
00127 //       Access: Published
00128 //  Description: Convenience function; writes the entire contents of
00129 //               the indicated file as a string.
00130 //
00131 //               If auto_wrap is true, an explicitly-named .pz file
00132 //               is automatically compressed while writing.
00133 ////////////////////////////////////////////////////////////////////
00134 INLINE bool VirtualFileSystem::
00135 write_file(const Filename &filename, const string &data, bool auto_wrap) {
00136   return write_file(filename, (const unsigned char *)data.data(), data.size(), auto_wrap);
00137 }
00138 
00139 ////////////////////////////////////////////////////////////////////
00140 //     Function: VirtualFileSystem::read_file
00141 //       Access: Public
00142 //  Description: Convenience function; fills the string up with the
00143 //               data from the indicated file, if it exists and can be
00144 //               read.  Returns true on success, false otherwise.
00145 //
00146 //               If auto_unwrap is true, an explicitly-named .pz file
00147 //               is automatically decompressed and the decompressed
00148 //               contents are returned.  This is different than
00149 //               vfs-implicit-pz, which will automatically decompress
00150 //               a file if the extension .pz is *not* given.
00151 ////////////////////////////////////////////////////////////////////
00152 INLINE bool VirtualFileSystem::
00153 read_file(const Filename &filename, string &result, bool auto_unwrap) const {
00154   PT(VirtualFile) file = get_file(filename, false);
00155   return (file != (VirtualFile *)NULL && file->read_file(result, auto_unwrap));
00156 }
00157 
00158 ////////////////////////////////////////////////////////////////////
00159 //     Function: VirtualFileSystem::read_file
00160 //       Access: Public
00161 //  Description: Convenience function; fills the pvector up with the
00162 //               data from the indicated file, if it exists and can be
00163 //               read.  Returns true on success, false otherwise.
00164 //
00165 //               If auto_unwrap is true, an explicitly-named .pz file
00166 //               is automatically decompressed and the decompressed
00167 //               contents are returned.  This is different than
00168 //               vfs-implicit-pz, which will automatically decompress
00169 //               a file if the extension .pz is *not* given.
00170 ////////////////////////////////////////////////////////////////////
00171 INLINE bool VirtualFileSystem::
00172 read_file(const Filename &filename, pvector<unsigned char> &result, bool auto_unwrap) const {
00173   PT(VirtualFile) file = get_file(filename, false);
00174   return (file != (VirtualFile *)NULL && file->read_file(result, auto_unwrap));
00175 }
00176 
00177 ////////////////////////////////////////////////////////////////////
00178 //     Function: VirtualFileSystem::write_file
00179 //       Access: Public
00180 //  Description: Convenience function; writes the entire contents of
00181 //               the indicated file as a block of data.
00182 //
00183 //               If auto_wrap is true, an explicitly-named .pz file
00184 //               is automatically compressed while writing.
00185 ////////////////////////////////////////////////////////////////////
00186 INLINE bool VirtualFileSystem::
00187 write_file(const Filename &filename, const unsigned char *data, size_t data_size, bool auto_wrap) {
00188   PT(VirtualFile) file = create_file(filename);
00189   return (file != (VirtualFile *)NULL && file->write_file(data, data_size, auto_wrap));
00190 }
 All Classes Functions Variables Enumerations