]> git.lizzy.rs Git - minetest.git/blobdiff - src/filesys.h
Add chat HUD flag (#13189)
[minetest.git] / src / filesys.h
index bfb340d85a20a468322d36f21ce4b75f4c511030..fa9ddcaa8914d62e2b2882afe911f42e19a1703d 100644 (file)
@@ -17,23 +17,29 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
-#ifndef FILESYS_HEADER
-#define FILESYS_HEADER
+#pragma once
 
+#include <set>
 #include <string>
 #include <vector>
 #include "exceptions.h"
 
-#ifdef _WIN32 // WINDOWS
+#ifdef _WIN32
 #define DIR_DELIM "\\"
 #define DIR_DELIM_CHAR '\\'
-#define FILESYS_CASE_INSENSITIVE 1
-#else // POSIX
+#define FILESYS_CASE_INSENSITIVE true
+#define PATH_DELIM ";"
+#else
 #define DIR_DELIM "/"
 #define DIR_DELIM_CHAR '/'
-#define FILESYS_CASE_INSENSITIVE 0
+#define FILESYS_CASE_INSENSITIVE false
+#define PATH_DELIM ":"
 #endif
 
+namespace irr { namespace io {
+class IFileSystem;
+}}
+
 namespace fs
 {
 
@@ -54,6 +60,13 @@ bool IsPathAbsolute(const std::string &path);
 
 bool IsDir(const std::string &path);
 
+bool IsExecutable(const std::string &path);
+
+inline bool IsFile(const std::string &path)
+{
+       return PathExists(path) && !IsDir(path);
+}
+
 bool IsDirDelimiter(char c);
 
 // Only pass full paths to this one. True on success.
@@ -65,13 +78,27 @@ bool DeleteSingleFileOrEmptyDirectory(const std::string &path);
 // Returns path to temp directory, can return "" on error
 std::string TempPath();
 
-/* Multiplatform */
+// Returns path to securely-created temporary file (will already exist when this function returns)
+// can return "" on error
+std::string CreateTempFile();
 
-// The path itself not included
-void GetRecursiveSubPaths(const std::string &path, std::vector<std::string> &dst);
+/* Returns a list of subdirectories, including the path itself, but excluding
+       hidden directories (whose names start with . or _)
+*/
+void GetRecursiveDirs(std::vector<std::string> &dirs, const std::string &dir);
+std::vector<std::string> GetRecursiveDirs(const std::string &dir);
 
-// Tries to delete all, returns false if any failed
-bool DeletePaths(const std::vector<std::string> &paths);
+/* Multiplatform */
+
+/* The path itself not included, returns a list of all subpaths.
+   dst - vector that contains all the subpaths.
+   list files - include files in the list of subpaths.
+   ignore - paths that start with these charcters will not be listed.
+*/
+void GetRecursiveSubPaths(const std::string &path,
+                 std::vector<std::string> &dst,
+                 bool list_files,
+                 const std::set<char> &ignore = {});
 
 // Only pass full paths to this one. True on success.
 bool RecursiveDeleteContent(const std::string &path);
@@ -86,6 +113,10 @@ bool CopyFileContents(const std::string &source, const std::string &target);
 // Omits files and subdirectories that start with a period
 bool CopyDir(const std::string &source, const std::string &target);
 
+// Move directory and all subdirectories
+// Behavior with files/subdirs that start with a period is undefined
+bool MoveDir(const std::string &source, const std::string &target);
+
 // Check if one path is prefix of another
 // For example, "/tmp" is a prefix of "/tmp" and "/tmp/file" but not "/tmp2"
 // Ignores case differences and '/' vs. '\\' on Windows
@@ -103,9 +134,22 @@ std::string RemoveLastPathComponent(const std::string &path,
 // this does not resolve symlinks and check for existence of directories.
 std::string RemoveRelativePathComponents(std::string path);
 
-bool safeWriteToFile(const std::string &path, const std::string &content);
+// Returns the absolute path for the passed path, with "." and ".." path
+// components and symlinks removed.  Returns "" on error.
+std::string AbsolutePath(const std::string &path);
 
-}//fs
+// Returns the filename from a path or the entire path if no directory
+// delimiter is found.
+const char *GetFilenameFromPath(const char *path);
 
+bool safeWriteToFile(const std::string &path, const std::string &content);
+
+#ifndef SERVER
+bool extractZipFile(irr::io::IFileSystem *fs, const char *filename, const std::string &destination);
 #endif
 
+bool ReadFile(const std::string &path, std::string &out);
+
+bool Rename(const std::string &from, const std::string &to);
+
+} // namespace fs