virtualFileSystem.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Filename: virtualFileSystem.h
  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. #ifndef VIRTUALFILESYSTEM_H
  19. #define VIRTUALFILESYSTEM_H
  20. #include "pandabase.h"
  21. #include "filename.h"
  22. #include "pmap.h"
  23. class Multifile;
  24. class VirtualFileMount;
  25. ////////////////////////////////////////////////////////////////////
  26. // Class : VirtualFileSystem
  27. // Description : A hierarchy of directories and files that appears to
  28. // be one continuous file system, even though the files
  29. // may originate from several different sources that may
  30. // not be related to the actual OS's file system.
  31. //
  32. // For instance, a VirtualFileSystem can transparently
  33. // mount one or more Multifiles as their own
  34. // subdirectory hierarchies.
  35. ////////////////////////////////////////////////////////////////////
  36. class EXPCL_PANDA VirtualFileSystem {
  37. PUBLISHED:
  38. VirtualFileSystem();
  39. ~VirtualFileSystem();
  40. enum MountFlags {
  41. MF_owns_pointer = 0x0001,
  42. MF_read_only = 0x0002,
  43. };
  44. bool mount(Multifile *multifile, const string &mount_point, int flags);
  45. bool mount(const Filename &physical_filename, const string &mount_point, int flags);
  46. int unmount(Multifile *multifile);
  47. int unmount(const Filename &physical_filename);
  48. int unmount_point(const string &mount_point);
  49. int unmount_all();
  50. bool chdir(const Filename &new_directory);
  51. const Filename &get_cwd() const;
  52. PT(VirtualFile) get_file(const Filename &file) const;
  53. PT(VirtualFile) find_file(const Filename &file,
  54. const DSearchPath &searchpath) const;
  55. void write(ostream &out) const;
  56. static VirtualFileSystem *get_global_ptr();
  57. public:
  58. void scan_mount_points(vector_string &names, const Filename &path) const;
  59. private:
  60. Filename normalize_mount_point(const string &mount_point) const;
  61. bool found_match(PT(VirtualFile) &found_file, VirtualFileComposite *&composite_file,
  62. VirtualFileMount *mount, const string &local_filename) const;
  63. typedef pvector<VirtualFileMount *> Mounts;
  64. Mounts _mounts;
  65. Filename _cwd;
  66. static VirtualFileSystem *_global_ptr;
  67. };
  68. #include "virtualFileSystem.I"
  69. #endif