virtualFileMountMultifile.cxx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Filename: virtualFileMountMultifile.cxx
  2. // Created by: drose (03Aug02)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #include "virtualFileMountMultifile.h"
  19. #include "virtualFileSystem.h"
  20. TypeHandle VirtualFileMountMultifile::_type_handle;
  21. ////////////////////////////////////////////////////////////////////
  22. // Function: VirtualFileMountMultifile::Destructor
  23. // Access: Public, Virtual
  24. // Description:
  25. ////////////////////////////////////////////////////////////////////
  26. VirtualFileMountMultifile::
  27. ~VirtualFileMountMultifile() {
  28. if ((_mount_flags & VirtualFileSystem::MF_owns_pointer) != 0) {
  29. // Delete the _multifile pointer if we own it.
  30. nassertv(_multifile != (Multifile *)NULL);
  31. delete _multifile;
  32. }
  33. }
  34. ////////////////////////////////////////////////////////////////////
  35. // Function: VirtualFileMountMultifile::has_file
  36. // Access: Public, Virtual
  37. // Description: Returns true if the indicated file exists within the
  38. // mount system.
  39. ////////////////////////////////////////////////////////////////////
  40. bool VirtualFileMountMultifile::
  41. has_file(const Filename &file) const {
  42. return (file.empty() ||
  43. _multifile->find_subfile(file) >= 0 ||
  44. _multifile->has_directory(file));
  45. }
  46. ////////////////////////////////////////////////////////////////////
  47. // Function: VirtualFileMountMultifile::is_directory
  48. // Access: Public, Virtual
  49. // Description: Returns true if the indicated file exists within the
  50. // mount system and is a directory.
  51. ////////////////////////////////////////////////////////////////////
  52. bool VirtualFileMountMultifile::
  53. is_directory(const Filename &file) const {
  54. return (file.empty() || _multifile->has_directory(file));
  55. }
  56. ////////////////////////////////////////////////////////////////////
  57. // Function: VirtualFileMountMultifile::is_regular_file
  58. // Access: Public, Virtual
  59. // Description: Returns true if the indicated file exists within the
  60. // mount system and is a regular file.
  61. ////////////////////////////////////////////////////////////////////
  62. bool VirtualFileMountMultifile::
  63. is_regular_file(const Filename &file) const {
  64. return (_multifile->find_subfile(file) >= 0);
  65. }
  66. ////////////////////////////////////////////////////////////////////
  67. // Function: VirtualFileMountMultifile::open_read_file
  68. // Access: Public, Virtual
  69. // Description: Opens the file for reading, if it exists. Returns a
  70. // newly allocated istream on success (which you should
  71. // eventually delete when you are done reading).
  72. // Returns NULL on failure.
  73. ////////////////////////////////////////////////////////////////////
  74. istream *VirtualFileMountMultifile::
  75. open_read_file(const Filename &file) const {
  76. int subfile_index = _multifile->find_subfile(file);
  77. if (subfile_index < 0) {
  78. return NULL;
  79. }
  80. return _multifile->open_read_subfile(subfile_index);
  81. }
  82. ////////////////////////////////////////////////////////////////////
  83. // Function: VirtualFileMountMultifile::scan_directory
  84. // Access: Public, Virtual
  85. // Description: Fills the given vector up with the list of filenames
  86. // that are local to this directory, if the filename is
  87. // a directory. Returns true if successful, or false if
  88. // the file is not a directory or cannot be read.
  89. ////////////////////////////////////////////////////////////////////
  90. bool VirtualFileMountMultifile::
  91. scan_directory(vector_string &contents, const Filename &dir) const {
  92. return _multifile->scan_directory(contents, dir);
  93. }