X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Ffilesys.h;h=233e56bba4cb2823f63bcc11d829652ec3197ee9;hb=2d5b7b5fb48d182fbab8e4ad69e9a552a3c07c6e;hp=c22e89b3eff728445ada718339bb8f1fd3441e5f;hpb=0df736173e60df06a7a7162c285b9c5731a07c20;p=dragonfireclient.git diff --git a/src/filesys.h b/src/filesys.h index c22e89b3e..233e56bba 100644 --- a/src/filesys.h +++ b/src/filesys.h @@ -17,21 +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 #include #include #include "exceptions.h" -#ifdef _WIN32 // WINDOWS +#ifdef _WIN32 #define DIR_DELIM "\\" -#define FILESYS_CASE_INSENSITIVE 1 -#else // POSIX +#define DIR_DELIM_CHAR '\\' +#define FILESYS_CASE_INSENSITIVE true +#define PATH_DELIM ";" +#else #define DIR_DELIM "/" -#define FILESYS_CASE_INSENSITIVE 0 +#define DIR_DELIM_CHAR '/' +#define FILESYS_CASE_INSENSITIVE false +#define PATH_DELIM ":" #endif +namespace irr { namespace io { +class IFileSystem; +}} + namespace fs { @@ -63,13 +71,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(); + +/* Returns a list of subdirectories, including the path itself, but excluding + hidden directories (whose names start with . or _) +*/ +void GetRecursiveDirs(std::vector &dirs, const std::string &dir); +std::vector GetRecursiveDirs(const std::string &dir); -// The path itself not included -void GetRecursiveSubPaths(const std::string &path, std::vector &dst); +/* Multiplatform */ -// Tries to delete all, returns false if any failed -bool DeletePaths(const std::vector &paths); +/* 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 &dst, + bool list_files, + const std::set &ignore = {}); // Only pass full paths to this one. True on success. bool RecursiveDeleteContent(const std::string &path); @@ -101,9 +123,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); + +// Returns the filename from a path or the entire path if no directory +// delimiter is found. +const char *GetFilenameFromPath(const char *path); -}//fs +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