1 /* Copyright (C) 2018 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 /* 24 * higher-level interface on top of sysdep/filesystem.h 25 */ 26 27 #ifndef INCLUDED_FILE_SYSTEM 28 #define INCLUDED_FILE_SYSTEM 29 30 #include "lib/os_path.h" 31 #include "lib/posix/posix_filesystem.h" // mode_t 32 33 34 LIB_API bool DirectoryExists(const OsPath& path); 35 LIB_API bool FileExists(const OsPath& pathname); 36 37 LIB_API u64 FileSize(const OsPath& pathname); 38 39 40 // (bundling size and mtime avoids a second expensive call to stat()) 41 class CFileInfo 42 { 43 public: CFileInfo()44 CFileInfo() 45 { 46 } 47 CFileInfo(const OsPath & name,off_t size,time_t mtime)48 CFileInfo(const OsPath& name, off_t size, time_t mtime) 49 : name(name), size(size), mtime(mtime) 50 { 51 } 52 Name()53 const OsPath& Name() const 54 { 55 return name; 56 } 57 Size()58 off_t Size() const 59 { 60 return size; 61 } 62 MTime()63 time_t MTime() const 64 { 65 return mtime; 66 } 67 68 private: 69 OsPath name; 70 off_t size; 71 time_t mtime; 72 }; 73 74 LIB_API Status GetFileInfo(const OsPath& pathname, CFileInfo* fileInfo); 75 76 typedef std::vector<CFileInfo> CFileInfos; 77 typedef std::vector<OsPath> DirectoryNames; 78 79 LIB_API Status GetDirectoryEntries(const OsPath& path, CFileInfos* files, DirectoryNames* subdirectoryNames); 80 81 // same as boost::filesystem::create_directories, except that mkdir is invoked with 82 // <mode> instead of 0755. 83 // If the breakpoint is enabled, debug_break will be called if the directory didn't exist and couldn't be created. 84 LIB_API Status CreateDirectories(const OsPath& path, mode_t mode, bool breakpoint = true); 85 86 LIB_API Status DeleteDirectory(const OsPath& dirPath); 87 88 LIB_API Status CopyFile(const OsPath& path, const OsPath& newPath, bool override_if_exists = false); 89 90 #endif // #ifndef INCLUDED_FILE_SYSTEM 91