24 #include <boost/algorithm/string.hpp>
27 #define LOG_FS LOG_STREAM(info, log_filesystem)
28 #define ERR_FS LOG_STREAM(err, log_filesystem)
44 if(name.empty() || name.back() ==
'.' || name.find(
"..") != std::string::npos || name.size() > 255) {
49 static const std::set<std::string> dos_device_names = {
51 "NUL",
"CON",
"AUX",
"PRN",
52 "COM1",
"COM2",
"COM3",
"COM4",
"COM5",
"COM6",
"COM7",
"COM8",
"COM9",
53 "LPT1",
"LPT2",
"LPT3",
"LPT4",
"LPT5",
"LPT6",
"LPT7",
"LPT8",
"LPT9",
67 const auto& first_name =
68 boost::algorithm::to_upper_copy(name.substr(0, name.find(
'.')), std::locale::classic());
70 if(dos_device_names.count(first_name)) {
74 const auto& name_ucs4 = unicode_cast<std::u32string>(name);
75 if(name != unicode_cast<std::string>(name_ucs4)){
79 return name_ucs4.end() == std::find_if(name_ucs4.begin(), name_ucs4.end(), [=](char32_t
c)
83 return !allow_whitespace;
98 (c >= 0x80 && c < 0xA0) ||
99 (c >= 0xD800 && c < 0xE000);
104 void blacklist_pattern_list::remove_blacklisted_files_and_dirs(std::vector<std::string>& files, std::vector<std::string>& directories)
const
106 utils::erase_if(files, [
this](
const std::string& name) {
return match_file(name); });
107 utils::erase_if(directories, [
this](
const std::string& name) {
return match_dir(name); });
110 bool blacklist_pattern_list::match_file(
const std::string& name)
const
112 return std::any_of(file_patterns_.begin(), file_patterns_.end(),
116 bool blacklist_pattern_list::match_dir(
const std::string& name)
const
118 return std::any_of(directory_patterns_.begin(), directory_patterns_.end(),
124 std::string auto_dir;
129 auto_dir = std::move(exe_dir);
170 #ifdef HAS_RELATIVE_DEFPREF
212 const std::string dir_path =
get_sync_dir() +
"/persist";
218 const std::string dir_path =
get_sync_dir() +
"/editor";
224 if(addon_id ==
"mainline") {
242 #ifdef USE_INTERNAL_DATA
246 #if HAS_RELATIVE_LOCALEDIR
267 file_tree_checksum::file_tree_checksum()
268 : nfiles(0), sum_size(0), modified(0)
272 nfiles (cfg[
"nfiles"].to_size_t()),
273 sum_size(cfg[
"size"].to_size_t()),
274 modified(cfg[
"modified"].to_time_t())
332 std::vector<std::string> dirs;
335 for(std::vector<std::string>::const_iterator j = dirs.begin(); j != dirs.end(); ++j) {
345 if(checksum.
nfiles == 0) {
348 LOG_FS <<
"calculated data tree checksum: "
349 << checksum.
nfiles <<
" files; "
A config object defines a single node in a WML file, with access to child nodes.
Definitions for the interface to Wesnoth Markup Language (WML).
Declarations for File-IO.
static lg::log_domain log_filesystem("filesystem")
Standard logging facilities (interface).
std::string get_legacy_editor_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)
Get a list of all files and/or directories in a given directory.
static bfs::path get_dir(const bfs::path &dirpath)
std::string get_user_data_dir()
std::string get_wml_persist_dir()
static bool file_exists(const bfs::path &fpath)
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.
std::string get_synced_prefs_file()
location of preferences file containing preferences that are synced between computers note that wesno...
utils::optional< std::string > get_wml_location(const std::string &path, const utils::optional< std::string > ¤t_dir)
Returns a translated path to the actual file or directory, if it exists.
std::string get_saves_dir()
const file_tree_checksum & data_tree_checksum(bool reset=false)
Get the time at which the data/ tree was last modified at.
std::string read_file(const std::string &fname)
Basic disk I/O - read file.
std::string get_unsynced_prefs_file()
location of preferences file containing preferences that aren't synced between computers
std::string get_save_index_file()
utils::optional< 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, if it exists.
std::string get_lua_history_file()
std::string autodetect_game_data_dir(std::string exe_dir)
Try to autodetect the location of the game data dir.
std::string read_scenario(const std::string &name)
std::string get_screenshot_dir()
std::string get_credentials_file()
std::string get_sync_dir()
parent directory for everything that should be synced between systems.
bool looks_like_pbl(const std::string &file)
std::string get_addons_data_dir()
std::string get_default_prefs_file()
std::string get_addons_dir()
std::string get_intl_dir()
std::string get_core_images_dir()
static void get_file_tree_checksum_internal(const std::string &path, file_tree_checksum &res)
std::string get_current_editor_dir(const std::string &addon_id)
std::string read_map(const std::string &name)
std::string normalize_path(const std::string &fpath, bool normalize_separators, bool resolve_dot_entries)
Returns the absolute path of a file.
std::string default_preferences_path
std::string lowercase(std::string_view s)
Returns a lowercased version of the string.
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,...
void erase_if(Container &container, const Predicate &predicate)
Convenience wrapper for using std::remove_if on a container.
void write(config &cfg) const
bool operator==(const file_tree_checksum &rhs) const
Encapsulates the map of the game.
Some defines: VERSION, PACKAGE, MIN_SAVEGAME_VERSION.