xoreos  0.0.5
filepath.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef COMMON_FILEPATH_H
26 #define COMMON_FILEPATH_H
27 
28 #include <list>
29 
30 #include "src/common/types.h"
31 #include "src/common/ustring.h"
32 
33 namespace Common {
34 
35 static const size_t kFileInvalid = SIZE_MAX;
36 
38 class FilePath {
39 public:
45  static bool isRegularFile(const UString &p);
46 
52  static bool isDirectory(const UString &p);
53 
59  static size_t getFileSize(const UString &p);
60 
68  static UString getFile(const UString &p);
69 
77  static UString getStem(const UString &p);
78 
86  static UString getExtension(const UString &p);
87 
96  static UString changeExtension(const UString &p, const UString &ext = "");
97 
105  static UString getDirectory(const UString &p);
106 
112  static bool isAbsolute(const UString &p);
113 
125  static UString absolutize(const UString &p);
126 
134  static UString relativize(const UString &basePath, const UString &path);
135 
156  static UString normalize(const UString &p, bool resolveSymLinks = true);
157 
170  static UString canonicalize(const UString &p, bool resolveSymLinks = true);
171 
179  static UString findSubDirectory(const UString &directory, const UString &subDirectory,
180  bool caseInsensitive = false);
181 
192  static bool getSubDirectories(const UString &directory, std::list<UString> &subDirectories);
193 
202  static bool createDirectories(const UString &path);
203 
205  static UString escapeStringLiteral(const UString &str);
206 
208  static UString getHumanReadableSize(size_t size);
209 
214  static UString getHomeDirectory();
215 
226  static UString getConfigDirectory();
227 
236  static UString getUserDataDirectory();
237 
243  static UString getUserDataFile(UString file);
244 };
245 
246 } // End of namespace Common
247 
248 #endif // COMMON_FILEPATH_H
static UString getUserDataDirectory()
Return the OS-specific path of the user data directory.
Definition: filepath.cpp:379
static UString getHumanReadableSize(size_t size)
Format this file size into a human readable string.
Definition: filepath.cpp:357
Definition: 2dafile.h:39
A class holding an UTF-8 string.
Definition: ustring.h:48
static UString absolutize(const UString &p)
Return the absolute path.
Definition: filepath.cpp:125
static UString getExtension(const UString &p)
Return a file name&#39;s extension.
Definition: filepath.cpp:93
static bool getSubDirectories(const UString &directory, std::list< UString > &subDirectories)
Collect all direct subdirectories of a directory in a list.
Definition: filepath.cpp:234
static bool isDirectory(const UString &p)
Does specified path exist and is it a directory?
Definition: filepath.cpp:56
static UString getUserDataFile(UString file)
Return a path suitable for writing into.
Definition: filepath.cpp:383
static bool isRegularFile(const UString &p)
Does specified path exist and is it a regular file?
Definition: filepath.cpp:52
static UString escapeStringLiteral(const UString &str)
Escape a string literal for use in a regexp.
Definition: filepath.cpp:350
Utility class for manipulating file paths.
Definition: filepath.h:38
static UString canonicalize(const UString &p, bool resolveSymLinks=true)
Return the canonical, absolutized and normalized path.
Definition: filepath.cpp:230
Low-level type definitions to handle fixed width types portably.
static UString getDirectory(const UString &p)
Return a path&#39;s directory.
Definition: filepath.cpp:107
Unicode string handling.
static UString getConfigDirectory()
Return the OS-specific path of the config directory.
Definition: filepath.cpp:375
static UString getStem(const UString &p)
Return a file name&#39;s stem.
Definition: filepath.cpp:87
static bool createDirectories(const UString &path)
Create all directories in this path.
Definition: filepath.cpp:342
static bool isAbsolute(const UString &p)
Is the given string an absolute path?
Definition: filepath.cpp:113
static UString relativize(const UString &basePath, const UString &path)
Return the path relative to the base path.
Definition: filepath.cpp:142
static size_t getFileSize(const UString &p)
Return a file&#39;s size.
Definition: filepath.cpp:60
static UString normalize(const UString &p, bool resolveSymLinks=true)
Normalize a path.
Definition: filepath.cpp:154
static const size_t kFileInvalid
Definition: filepath.h:35
#define SIZE_MAX
Definition: types.h:172
static UString getHomeDirectory()
Return the OS-specific path of the user&#39;s home directory.
Definition: filepath.cpp:371
static UString getFile(const UString &p)
Return a file name without its path.
Definition: filepath.cpp:81
static UString changeExtension(const UString &p, const UString &ext="")
Change a file name&#39;s extension.
Definition: filepath.cpp:99
static UString findSubDirectory(const UString &directory, const UString &subDirectory, bool caseInsensitive=false)
Find a directory&#39;s subdirectory.
Definition: filepath.cpp:318