1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef FILE_SYSTEM_H
#define FILE_SYSTEM_H
#include "FileSystemAbstraction.h"
#include <string>
// Win-API redifines these, which breaks things
#if defined(CreateDirectory)
#undef CreateDirectory
#endif
#if defined(DeleteFile)
#undef DeleteFile
#endif
/**
* @brief filesystem interface
*
* Abstracts locating of content on different platforms.
* Use this from the rest of the spring code, not FileSystemHandler!
*/
class FileSystem : public FileSystemAbstraction
{
public:
/**
* @brief remove a file
*
* Operates on the current working directory.
*/
static bool Remove(std::string file);
/// @name meta-data
///@{
/// Returns true if the file exists, and is not a directory
static bool FileExists(std::string path);
/**
* @brief get filesize
*
* @return the filesize or 0 if the file doesn't exist.
*/
static size_t GetFileSize(std::string path);
///@}
/// @name directory
///@{
/**
* @brief creates a directory recursively
*
* Works like mkdir -p, ie. attempts to create parent directories too.
* Operates on the current working directory.
* @return true if the postcondition of this function is that dir exists
* in the write directory.
*/
static bool CreateDirectory(std::string dir);
///@}
/// @name convenience
///@{
/**
* @brief Returns the directory part of a path
* "/home/user/.spring/test.txt" -> "/home/user/.spring/"
* "test.txt" -> ""
*/
static std::string GetDirectory(const std::string& path);
/**
* @brief Returns the filename part of a path
* "/home/user/.spring/test.txt" -> "test.txt"
*/
static std::string GetFilename(const std::string& path);
/**
* @brief Returns the basename part of a path
* This is equvalent to the filename without extension.
* "/home/user/.spring/test.txt" -> "test"
*/
static std::string GetBasename(const std::string& path);
/**
* @brief Returns the extension of the filename part of the path
* "/home/user/.spring/test.txt" -> "txt"
* "/home/user/.spring/test.txt..." -> "txt"
* "/home/user/.spring/test.txt. . ." -> "txt"
*/
static std::string GetExtension(const std::string& path);
/**
* Converts the given path into a canonicalized one.
* CAUTION: be careful where using this, as it easily allows to link to
* outside a certain parent dir, for example a data-dir.
* @param path could be something like
* "./symLinkToHome/foo/bar///./../test.log"
* @return with the example given in path, it could be
* "./symLinkToHome/foo/test.log"
*/
static std::string GetNormalizedPath(const std::string& path);
/**
* @brief Converts a glob expression to a regex
* @param glob string containing glob
* @return string containing regex
*/
static std::string ConvertGlobToRegex(const std::string& glob);
/**
* Converts all slashes and backslashes in path to the
* native_path_separator.
*/
static std::string& FixSlashes(std::string& path);
/**
* @brief converts backslashes in path to forward slashes
*/
static std::string& ForwardSlashes(std::string& path);
///@}
/**
* @brief does a little checking of a filename
*/
static bool CheckFile(const std::string& file);
// static bool CheckDir(const std::string& dir) const;
};
#endif // !FILE_SYSTEM_H
|