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