2
0

virtualMountSystem.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _CORE_VMS_H_
  23. #define _CORE_VMS_H_
  24. #include "core/volume.h"
  25. #include "core/util/tDictionary.h"
  26. namespace Torque
  27. {
  28. namespace FS
  29. {
  30. /// The VirtualMountSystem extend the mount system by allowing you to mount and access multiple filesystems
  31. /// on a single root. This allows you to mount multiple volume files on a single root without needing to
  32. /// change source paths that reference those volumes to use new roots. For instance, you could mount
  33. /// "missions1.zip" and "missions2.zip", on the same root "", and you could access files from either one.
  34. ///
  35. /// If you need to mount a writeable filesystem on a VMS, you should mount it as the first filesystem on a root.
  36. /// File writes are handled as follows:
  37. /// 1) If you try to open a file for write, and it exists on one of the virtual mounts,
  38. /// that is the mount that will be used for writing. But if the filesystem is read-only then the writes
  39. /// will fail (and you will get appropriate error codes from your FileStream or whatever).
  40. /// 2) If you try to open a file for write that doesn't exist, the VMS falls back to the default MountSystem
  41. /// behavior, which is to use the first filesystem mounted on the root. If this filesystem happens to be
  42. /// writable, then you will be able to write to the file.
  43. /// 3) Nothing special is done for the WriteAppend case; that is, it follows the same logic as if you were
  44. /// just trying to Write the file.
  45. ///
  46. /// Because of rule 1) above, you should take care that any files you need to write (such as prefs.tscript), are not
  47. /// included in read-only zip archive files.
  48. class VirtualMountSystem : public MountSystem
  49. {
  50. typedef MountSystem Parent;
  51. public:
  52. VirtualMountSystem() : mUseParentFind(false) {}
  53. virtual ~VirtualMountSystem() { }
  54. virtual bool mount(String root, FileSystemRef fs);
  55. virtual bool mount(String root, const Path &path);
  56. virtual FileSystemRef unmount(String root);
  57. virtual bool unmount(FileSystemRef fs);
  58. virtual S32 findByPattern( const Path &inBasePath, const String &inFilePattern, bool inRecursive, Vector<String> &outList, bool includeDirs=false, bool multiMatch = true );
  59. virtual bool createPath(const Path& path);
  60. protected:
  61. virtual void _log(const String& msg);
  62. virtual FileSystemRef _removeMountFromList(String root);
  63. virtual FileSystemRef _getFileSystemFromList(const Path& path) const ;
  64. // Vector of file system refs
  65. typedef Vector<FileSystemRef> RootToFSVec;
  66. // map of path to list of file systems containing path
  67. typedef Map<String, Vector<FileSystemRef> > PathFSMap;
  68. // map of root to PathFSMap for that root
  69. //typedef Map<String, PathFSMap*> RootToPathFSMap;
  70. //RootToPathFSMap mMountMap;
  71. PathFSMap mRootMap;
  72. bool mUseParentFind; // this is needed because findByParent calls itself recursively and in some cases we don't want it to re-enter our version
  73. };
  74. }
  75. }
  76. #endif