00001 // Filename: virtualFileMountSystem.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 "virtualFileMountSystem.h" 00020 00021 TypeHandle VirtualFileMountSystem::_type_handle; 00022 00023 00024 //////////////////////////////////////////////////////////////////// 00025 // Function: VirtualFileMountSystem::has_file 00026 // Access: Public, Virtual 00027 // Description: Returns true if the indicated file exists within the 00028 // mount system. 00029 //////////////////////////////////////////////////////////////////// 00030 bool VirtualFileMountSystem:: 00031 has_file(const Filename &file) const { 00032 Filename pathname(_physical_filename, file); 00033 return pathname.exists(); 00034 } 00035 00036 //////////////////////////////////////////////////////////////////// 00037 // Function: VirtualFileMountSystem::is_directory 00038 // Access: Public, Virtual 00039 // Description: Returns true if the indicated file exists within the 00040 // mount system and is a directory. 00041 //////////////////////////////////////////////////////////////////// 00042 bool VirtualFileMountSystem:: 00043 is_directory(const Filename &file) const { 00044 Filename pathname(_physical_filename, file); 00045 return pathname.is_directory(); 00046 } 00047 00048 //////////////////////////////////////////////////////////////////// 00049 // Function: VirtualFileMountSystem::is_regular_file 00050 // Access: Public, Virtual 00051 // Description: Returns true if the indicated file exists within the 00052 // mount system and is a regular file. 00053 //////////////////////////////////////////////////////////////////// 00054 bool VirtualFileMountSystem:: 00055 is_regular_file(const Filename &file) const { 00056 Filename pathname(_physical_filename, file); 00057 return pathname.is_regular_file(); 00058 } 00059 00060 //////////////////////////////////////////////////////////////////// 00061 // Function: VirtualFileMountSystem::open_read_file 00062 // Access: Public, Virtual 00063 // Description: Opens the file for reading, if it exists. Returns a 00064 // newly allocated istream on success (which you should 00065 // eventually delete when you are done reading). 00066 // Returns NULL on failure. 00067 //////////////////////////////////////////////////////////////////// 00068 istream *VirtualFileMountSystem:: 00069 open_read_file(const Filename &file) const { 00070 Filename pathname(_physical_filename, file); 00071 pathname.set_binary(); 00072 ifstream *stream = new ifstream; 00073 if (!pathname.open_read(*stream)) { 00074 // Couldn't open the file for some reason. 00075 delete stream; 00076 return NULL; 00077 } 00078 00079 return stream; 00080 } 00081 00082 //////////////////////////////////////////////////////////////////// 00083 // Function: VirtualFileMountSystem::scan_directory 00084 // Access: Public, Virtual 00085 // Description: Fills the given vector up with the list of filenames 00086 // that are local to this directory, if the filename is 00087 // a directory. Returns true if successful, or false if 00088 // the file is not a directory or cannot be read. 00089 //////////////////////////////////////////////////////////////////// 00090 bool VirtualFileMountSystem:: 00091 scan_directory(vector_string &contents, const Filename &dir) const { 00092 Filename pathname(_physical_filename, dir); 00093 return pathname.scan_directory(contents); 00094 } 00095