25 #include <boost/algorithm/string.hpp> 28 #define LOG_FS LOG_STREAM(info, log_filesystem) 29 #define ERR_FS LOG_STREAM(err, log_filesystem) 45 if(name.empty() || name.back() ==
'.' || name.find(
"..") != std::string::npos || name.size() > 255) {
50 static const std::set<std::string> dos_device_names = {
52 "NUL",
"CON",
"AUX",
"PRN",
53 "COM1",
"COM2",
"COM3",
"COM4",
"COM5",
"COM6",
"COM7",
"COM8",
"COM9",
54 "LPT1",
"LPT2",
"LPT3",
"LPT4",
"LPT5",
"LPT6",
"LPT7",
"LPT8",
"LPT9",
68 const auto& first_name =
69 boost::algorithm::to_upper_copy(name.substr(0, name.find(
'.')), std::locale::classic());
71 if(dos_device_names.count(first_name)) {
75 const auto& name_ucs4 =
unicode_cast<std::u32string>(name);
76 if(name != unicode_cast<std::string>(name_ucs4)){
80 return name_ucs4.end() == std::find_if(name_ucs4.begin(), name_ucs4.end(), [=](char32_t
c)
84 return !allow_whitespace;
99 (
c >= 0x80 &&
c < 0xA0) ||
100 (
c >= 0xD800 &&
c < 0xE000);
108 std::remove_if(files.begin(), files.end(), [
this](
const std::string& name) {
return match_file(name); }),
111 std::remove_if(directories.begin(), directories.end(), [
this](
const std::string& name) {
return match_dir(name); }),
139 #ifdef HAS_RELATIVE_DEFPREF 169 #ifdef USE_INTERNAL_DATA 173 #if HAS_RELATIVE_LOCALEDIR 195 : nfiles(0), sum_size(0), modified(0)
199 nfiles (cfg[
"nfiles"].to_size_t()),
201 modified(cfg[
"modified"].to_time_t())
218 bool ends_with(
const std::string& str,
const std::string& suffix)
220 return str.size() >= suffix.size() && std::equal(suffix.begin(),suffix.end(),str.end()-suffix.size());
227 if(map_location.empty()) {
232 if(!map_location.empty()) {
246 std::vector<std::string> dirs;
249 for(std::vector<std::string>::const_iterator j = dirs.begin(); j != dirs.end(); ++j) {
259 if(checksum.
nfiles == 0) {
262 LOG_FS <<
"calculated data tree checksum: " 263 << checksum.
nfiles <<
" files; " 264 << checksum.
sum_size <<
" bytes" << std::endl;
bool is_legal_user_file_name(const std::string &name, bool allow_whitespace=true)
Returns whether the given filename is a legal name for a user-created file.
static void get_file_tree_checksum_internal(const std::string &path, file_tree_checksum &res)
bool looks_like_pbl(const std::string &file)
bool ends_with(const std::string &str, const std::string &suffix)
ucs4_convert_impl::enableif< TD, typename TS::value_type >::type unicode_cast(const TS &source)
bool wildcard_string_match(const std::string &str, const std::string &match)
Match using '*' as any number of characters (including none), '+' as one or more characters, and '?' as any one character.
std::string get_screenshot_dir()
std::string get_binary_file_location(const std::string &type, const std::string &filename)
Returns a complete path to the actual file of a given type or an empty string if the file isn't prese...
std::string get_saves_dir()
Definitions for the interface to Wesnoth Markup Language (WML).
void remove_blacklisted_files_and_dirs(std::vector< std::string > &files, std::vector< std::string > &directories) const
static bfs::path get_dir(const bfs::path &dirpath)
bool match_file(const std::string &name) const
std::string get_user_data_dir()
std::vector< std::string > directory_patterns_
std::string get_intl_dir()
void get_files_in_dir(const std::string &dir, std::vector< std::string > *files, std::vector< std::string > *dirs, name_mode mode, filter_mode filter, reorder_mode reorder, file_tree_checksum *checksum)
Populates 'files' with all the files and 'dirs' with all the directories in dir.
std::vector< std::string > file_patterns_
void write(config &cfg) const
bool operator==(const file_tree_checksum &rhs) const
std::string get_default_prefs_file()
std::string read_file(const std::string &fname)
Basic disk I/O - read file.
std::string read_map(const std::string &name)
Encapsulates the map of the game.
Some defines: VERSION, PACKAGE, MIN_SAVEGAME_VERSION.
std::string get_wml_location(const std::string &filename, const std::string ¤t_dir)
Returns a complete path to the actual WML file or directory or an empty string if the file isn't pres...
Declarations for File-IO.
std::string lowercase(const std::string &s)
Returns a lowercased version of the string.
const file_tree_checksum & data_tree_checksum(bool reset=false)
Get the time at which the data/ tree was last modified at.
std::string get_user_config_dir()
std::string get_addons_dir()
std::string get_credentials_file()
Standard logging facilities (interface).
static lg::log_domain log_filesystem("filesystem")
std::string get_prefs_file()
bool match_dir(const std::string &name) const
A config object defines a single node in a WML file, with access to child nodes.
std::string get_save_index_file()
std::string default_preferences_path