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);
105 void blacklist_pattern_list::remove_blacklisted_files_and_dirs(std::vector<std::string>& files, std::vector<std::string>& directories)
const
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); }),
115 bool blacklist_pattern_list::match_file(
const std::string& name)
const
117 return std::any_of(file_patterns_.begin(), file_patterns_.end(),
121 bool blacklist_pattern_list::match_dir(
const std::string& name)
const
123 return std::any_of(directory_patterns_.begin(), directory_patterns_.end(),
139 #ifdef HAS_RELATIVE_DEFPREF
183 if(addon_id ==
"mainline") {
201 #ifdef USE_INTERNAL_DATA
205 #if HAS_RELATIVE_LOCALEDIR
226 file_tree_checksum::file_tree_checksum()
227 : nfiles(0), sum_size(0), modified(0)
231 nfiles (cfg[
"nfiles"].to_size_t()),
232 sum_size(cfg[
"size"].to_size_t()),
233 modified(cfg[
"modified"].to_time_t())
250 bool ends_with(
const std::string& str,
const std::string& suffix)
252 return str.size() >= suffix.size() && std::equal(suffix.begin(),suffix.end(),str.end()-suffix.size());
278 if(file_location.empty()) {
282 if(!file_location.empty()) {
296 std::vector<std::string> dirs;
299 for(std::vector<std::string>::const_iterator j = dirs.begin(); j != dirs.end(); ++j) {
309 if(checksum.
nfiles == 0) {
312 LOG_FS <<
"calculated data tree checksum: "
313 << checksum.
nfiles <<
" files; "
A config object defines a single node in a WML file, with access to child nodes.
Declarations for File-IO.
static lg::log_domain log_filesystem("filesystem")
Standard logging facilities (interface).
std::string get_legacy_editor_dir()
std::string get_user_config_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()
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_saves_dir()
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...
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.
bool ends_with(const std::string &str, const std::string &suffix)
std::string get_save_index_file()
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_prefs_file()
std::string read_scenario(const std::string &name)
std::string get_screenshot_dir()
std::string get_credentials_file()
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 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.