Line data Source code
1 : /* Copyright (C) 2026 Wildfire Games. 2 : * 3 : * Permission is hereby granted, free of charge, to any person obtaining 4 : * a copy of this software and associated documentation files (the 5 : * "Software"), to deal in the Software without restriction, including 6 : * without limitation the rights to use, copy, modify, merge, publish, 7 : * distribute, sublicense, and/or sell copies of the Software, and to 8 : * permit persons to whom the Software is furnished to do so, subject to 9 : * the following conditions: 10 : * 11 : * The above copyright notice and this permission notice shall be included 12 : * in all copies or substantial portions of the Software. 13 : * 14 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 : * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 : * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 : * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 : * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 : * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 : * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 : */ 22 : 23 : #ifndef INCLUDED_REAL_DIRECTORY 24 : #define INCLUDED_REAL_DIRECTORY 25 : 26 : #include "lib/code_annotation.h" 27 : #include "lib/file/common/file_loader.h" 28 : #include "lib/os_path.h" 29 : #include "lib/status.h" 30 : #include "lib/sysdep/dir_watch.h" 31 : 32 : #include <cstddef> 33 : #include <memory> 34 : #include <span> 35 : 36 1924 : class RealDirectory final : public IFileLoader 37 : { 38 : NONCOPYABLE(RealDirectory); 39 : public: 40 : RealDirectory(const OsPath& path, size_t priority, size_t flags); 41 : 42 27194 : size_t Priority() const 43 : { 44 27194 : return m_priority; 45 : } 46 : 47 2774 : size_t Flags() const 48 : { 49 2774 : return m_flags; 50 : } 51 : 52 : // IFileLoader 53 : size_t Precedence() const override; 54 : wchar_t LocationCode() const override; 55 12772 : const OsPath& Path() const override 56 : { 57 3913 : return m_path; 58 : } 59 : Status Load(const OsPath& name, const std::span<std::uint8_t> buffer) const override; 60 : 61 : Status Store(const OsPath& name, std::span<const std::uint8_t> fileContents); 62 : 63 : void Watch(); 64 : 65 : private: 66 : // note: paths are relative to the root directory, so storing the 67 : // entire path instead of just the portion relative to the mount point 68 : // is not all too wasteful. 69 : const OsPath m_path; 70 : 71 : const size_t m_priority; 72 : 73 : const size_t m_flags; 74 : 75 : // note: watches are needed in each directory because some APIs 76 : // (e.g. FAM) cannot watch entire trees with one call. 77 : PDirWatch m_watch; 78 : }; 79 : 80 : typedef std::shared_ptr<RealDirectory> PRealDirectory; 81 : 82 : extern PRealDirectory CreateRealSubdirectory(const PRealDirectory& realDirectory, const OsPath& subdirectoryName); 83 : 84 : #endif // #ifndef INCLUDED_REAL_DIRECTORY