23 #include <boost/algorithm/string.hpp>
26 #define LOG_FS LOG_STREAM(info, log_filesystem)
27 #define ERR_FS LOG_STREAM(err, log_filesystem)
43 if(name.empty() || name.back() ==
'.' || name.find(
"..") != std::string::npos || name.size() > 255) {
48 static const std::set<std::string> dos_device_names = {
50 "NUL",
"CON",
"AUX",
"PRN",
51 "COM1",
"COM2",
"COM3",
"COM4",
"COM5",
"COM6",
"COM7",
"COM8",
"COM9",
52 "LPT1",
"LPT2",
"LPT3",
"LPT4",
"LPT5",
"LPT6",
"LPT7",
"LPT8",
"LPT9",
66 const auto& first_name =
67 boost::algorithm::to_upper_copy(name.substr(0, name.find(
'.')), std::locale::classic());
69 if(dos_device_names.count(first_name)) {
73 const auto& name_ucs4 = unicode_cast<std::u32string>(name);
74 if(name != unicode_cast<std::string>(name_ucs4)){
78 return name_ucs4.end() == std::find_if(name_ucs4.begin(), name_ucs4.end(), [=](char32_t
c)
82 return !allow_whitespace;
97 (c >= 0x80 && c < 0xA0) ||
98 (c >= 0xD800 && c < 0xE000);
103 void blacklist_pattern_list::remove_blacklisted_files_and_dirs(std::vector<std::string>& files, std::vector<std::string>& directories)
const
106 std::remove_if(files.begin(), files.end(), [
this](
const std::string& name) { return match_file(name); }),
109 std::remove_if(directories.begin(), directories.end(), [
this](
const std::string& name) { return match_dir(name); }),
113 bool blacklist_pattern_list::match_file(
const std::string& name)
const
115 return std::any_of(file_patterns_.begin(), file_patterns_.end(),
119 bool blacklist_pattern_list::match_dir(
const std::string& name)
const
121 return std::any_of(directory_patterns_.begin(), directory_patterns_.end(),
127 std::string auto_dir;
132 auto_dir = std::move(exe_dir);
173 #ifdef HAS_RELATIVE_DEFPREF
215 const std::string dir_path =
get_sync_dir() +
"/persist";
221 const std::string dir_path =
get_sync_dir() +
"/editor";
227 if(addon_id ==
"mainline") {
245 #ifdef USE_INTERNAL_DATA
249 #if HAS_RELATIVE_LOCALEDIR
270 file_tree_checksum::file_tree_checksum()
271 : nfiles(0), sum_size(0), modified(0)
275 nfiles (cfg[
"nfiles"].to_size_t()),
276 sum_size(cfg[
"size"].to_size_t()),
277 modified(cfg[
"modified"].to_time_t())
335 std::vector<std::string> dirs;
338 for(std::vector<std::string>::const_iterator j = dirs.begin(); j != dirs.end(); ++j) {
348 if(checksum.
nfiles == 0) {
351 LOG_FS <<
"calculated data tree checksum: "
352 << 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(const std::string &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 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.