00001 // Filename: virtualFileMountMultifile.cxx 00002 // Created by: drose (03Aug02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "virtualFileMountMultifile.h" 00020 #include "virtualFileSystem.h" 00021 00022 TypeHandle VirtualFileMountMultifile::_type_handle; 00023 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function: VirtualFileMountMultifile::Destructor 00027 // Access: Public, Virtual 00028 // Description: 00029 //////////////////////////////////////////////////////////////////// 00030 VirtualFileMountMultifile:: 00031 ~VirtualFileMountMultifile() { 00032 if ((_mount_flags & VirtualFileSystem::MF_owns_pointer) != 0) { 00033 // Delete the _multifile pointer if we own it. 00034 nassertv(_multifile != (Multifile *)NULL); 00035 delete _multifile; 00036 } 00037 } 00038 00039 00040 //////////////////////////////////////////////////////////////////// 00041 // Function: VirtualFileMountMultifile::has_file 00042 // Access: Public, Virtual 00043 // Description: Returns true if the indicated file exists within the 00044 // mount system. 00045 //////////////////////////////////////////////////////////////////// 00046 bool VirtualFileMountMultifile:: 00047 has_file(const Filename &file) const { 00048 return (file.empty() || 00049 _multifile->find_subfile(file) >= 0 || 00050 _multifile->has_directory(file)); 00051 } 00052 00053 //////////////////////////////////////////////////////////////////// 00054 // Function: VirtualFileMountMultifile::is_directory 00055 // Access: Public, Virtual 00056 // Description: Returns true if the indicated file exists within the 00057 // mount system and is a directory. 00058 //////////////////////////////////////////////////////////////////// 00059 bool VirtualFileMountMultifile:: 00060 is_directory(const Filename &file) const { 00061 return (file.empty() || _multifile->has_directory(file)); 00062 } 00063 00064 //////////////////////////////////////////////////////////////////// 00065 // Function: VirtualFileMountMultifile::is_regular_file 00066 // Access: Public, Virtual 00067 // Description: Returns true if the indicated file exists within the 00068 // mount system and is a regular file. 00069 //////////////////////////////////////////////////////////////////// 00070 bool VirtualFileMountMultifile:: 00071 is_regular_file(const Filename &file) const { 00072 return (_multifile->find_subfile(file) >= 0); 00073 } 00074 00075 //////////////////////////////////////////////////////////////////// 00076 // Function: VirtualFileMountMultifile::open_read_file 00077 // Access: Public, Virtual 00078 // Description: Opens the file for reading, if it exists. Returns a 00079 // newly allocated istream on success (which you should 00080 // eventually delete when you are done reading). 00081 // Returns NULL on failure. 00082 //////////////////////////////////////////////////////////////////// 00083 istream *VirtualFileMountMultifile:: 00084 open_read_file(const Filename &file) const { 00085 int subfile_index = _multifile->find_subfile(file); 00086 if (subfile_index < 0) { 00087 return NULL; 00088 } 00089 return _multifile->open_read_subfile(subfile_index); 00090 } 00091 00092 //////////////////////////////////////////////////////////////////// 00093 // Function: VirtualFileMountMultifile::scan_directory 00094 // Access: Public, Virtual 00095 // Description: Fills the given vector up with the list of filenames 00096 // that are local to this directory, if the filename is 00097 // a directory. Returns true if successful, or false if 00098 // the file is not a directory or cannot be read. 00099 //////////////////////////////////////////////////////////////////// 00100 bool VirtualFileMountMultifile:: 00101 scan_directory(vector_string &contents, const Filename &dir) const { 00102 return _multifile->scan_directory(contents, dir); 00103 } 00104