filesystem.hpp (1705B)
1 /* ReaPack: Package manager for REAPER 2 * Copyright (C) 2015-2025 Christian Fillion 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef REAPACK_FILESYSTEM_HPP 19 #define REAPACK_FILESYSTEM_HPP 20 21 #include <algorithm> 22 #include <string> 23 24 class Path; 25 class TempPath; 26 27 namespace FS { 28 FILE *open(const Path &); 29 bool open(std::ifstream &, const Path &); 30 bool open(std::ofstream &, const Path &); 31 bool write(const Path &, const std::string &); 32 bool rename(const TempPath &); 33 bool rename(const Path &, const Path &); 34 bool remove(const Path &); 35 bool removeRecursive(const Path &); 36 bool mtime(const Path &, time_t *); 37 bool exists(const Path &, bool dir = false); 38 bool mkdir(const Path &); 39 Path canonical(const Path &); 40 41 const char *lastError(); 42 43 template<typename T, typename = 44 std::enable_if_t<std::is_convertible<typename T::value_type, Path>::value>> 45 bool allExists(const T &container, const bool dir = false) 46 { 47 return std::all_of(container.begin(), container.end(), 48 [&dir](const Path &path) { return exists(path, dir); }); 49 } 50 }; 51 52 #endif