The Battle for Wesnoth  1.19.4+dev
Classes | Typedefs | Enumerations | Functions | Variables
filesystem Namespace Reference

Classes

struct  sdl_rwops_deleter
 
struct  io_exception
 An exception object used when an IO error occurs. More...
 
class  blacklist_pattern_list
 
struct  other_version_dir
 
struct  file_tree_checksum
 
struct  binary_paths_manager
 The paths manager is responsible for recording the various paths that binary files may be located at. More...
 
class  atomic_commit
 Wrapper class that guarantees that file commit atomicity. More...
 

Typedefs

using scoped_istream = std::unique_ptr< std::istream >
 
using scoped_ostream = std::unique_ptr< std::ostream >
 
using rwops_ptr = std::unique_ptr< SDL_RWops, sdl_rwops_deleter >
 
typedef std::pair< int64_t, std::ios_base::seekdir > offset_dir
 

Enumerations

enum class  name_mode { ENTIRE_FILE_PATH , FILE_NAME_ONLY }
 
enum class  filter_mode { NO_FILTER , SKIP_MEDIA_DIR , SKIP_PBL_FILES }
 
enum class  reorder_mode { DONT_REORDER , DO_REORDER }
 

Functions

static void push_if_exists (std::vector< std::string > *vec, const bfs::path &file, bool full)
 
static bool error_except_not_found (const error_code &ec)
 
static bool is_directory_internal (const bfs::path &fpath)
 
static bool file_exists (const bfs::path &fpath)
 
static bfs::path get_dir (const bfs::path &dirpath)
 
static bool create_directory_if_missing (const bfs::path &dirpath)
 
static bool create_directory_if_missing_recursive (const bfs::path &dirpath)
 
static bool check_prefix (bfs::path::iterator &fi, const bfs::path::iterator &fe, const bfs::path &prefix)
 
static bool is_prefix (const bfs::path &full, const bfs::path &prefix_path)
 
static bfs::path subtract_path (const bfs::path &full, const bfs::path &prefix_path)
 
void get_files_in_dir (const std::string &dir, std::vector< std::string > *files, std::vector< std::string > *dirs=nullptr, name_mode mode=name_mode::FILE_NAME_ONLY, filter_mode filter=filter_mode::NO_FILTER, reorder_mode reorder=reorder_mode::DONT_REORDER, file_tree_checksum *checksum=nullptr)
 Get a list of all files and/or directories in a given directory. More...
 
std::string get_dir (const std::string &dir)
 
std::string get_next_filename (const std::string &name, const std::string &extension)
 Get the next free filename using "name + number (3 digits) + extension" maximum 1000 files then start always giving 999. More...
 
bool is_userdata_initialized ()
 
const std::string get_version_path_suffix (const version_info &version)
 
const std::string & get_version_path_suffix ()
 
static void setup_user_data_dir ()
 
void set_user_data_dir (std::string newprefdir)
 
bool rename_dir (const std::string &old_dir, const std::string &new_dir)
 
static void set_cache_path (bfs::path newcache)
 
void set_cache_dir (const std::string &newcachedir)
 
static const bfs::path & get_user_data_path ()
 
std::string get_user_data_dir ()
 
std::string get_logs_dir ()
 
std::string get_cache_dir ()
 
std::vector< other_version_dirfind_other_version_saves_dirs ()
 Searches for directories containing saves created by other versions of Wesnoth. More...
 
std::string get_cwd ()
 
bool set_cwd (const std::string &dir)
 
std::string get_exe_path ()
 
std::string get_exe_dir ()
 
std::string get_wesnothd_name ()
 
bool make_directory (const std::string &dirname)
 
bool delete_directory (const std::string &dirname, const bool keep_pbl)
 
bool delete_file (const std::string &filename)
 
std::vector< uint8_t > read_file_binary (const std::string &fname)
 
std::string read_file_as_data_uri (const std::string &fname)
 
std::string read_file (const std::string &fname)
 Basic disk I/O - read file. More...
 
filesystem::scoped_istream istream_file (const std::string &fname, bool treat_failure_as_error)
 
filesystem::scoped_ostream ostream_file (const std::string &fname, std::ios_base::openmode mode, bool create_directory)
 
void write_file (const std::string &fname, const std::string &data, std::ios_base::openmode mode=std::ios_base::binary)
 Throws io_exception if an error occurs. More...
 
void copy_file (const std::string &src, const std::string &dest)
 Read a file and then writes it back out. More...
 
bool create_directory_if_missing (const std::string &dirname)
 Creates a directory if it does not exist already. More...
 
bool create_directory_if_missing_recursive (const std::string &dirname)
 Creates a recursive directory tree if it does not exist already. More...
 
bool is_directory (const std::string &fname)
 Returns true if the given file is a directory. More...
 
bool file_exists (const std::string &name)
 Returns true if a file or directory with such name already exists. More...
 
std::time_t file_modified_time (const std::string &fname)
 Get the modification time of a file. More...
 
bool is_map (const std::string &filename)
 Returns true if the file ends with the mapfile extension. More...
 
bool is_cfg (const std::string &filename)
 Returns true if the file ends with the wmlfile extension. More...
 
bool is_mask (const std::string &filename)
 Returns true if the file ends with the maskfile extension. More...
 
bool is_gzip_file (const std::string &filename)
 Returns true if the file ends with '.gz'. More...
 
bool is_bzip2_file (const std::string &filename)
 Returns true if the file ends with '.bz2'. More...
 
int file_size (const std::string &fname)
 Returns the size of a file, or -1 if the file doesn't exist. More...
 
int dir_size (const std::string &path)
 Returns the sum of the sizes of the files contained in a directory. More...
 
std::string base_name (const std::string &file, const bool remove_extension=false)
 Returns the base filename of a file, with directory name stripped. More...
 
std::string directory_name (const std::string &file)
 Returns the directory name of a file, with filename stripped. More...
 
std::string nearest_extant_parent (const std::string &file)
 Finds the nearest parent in existence for a file or directory. More...
 
bool is_path_sep (char c)
 Returns whether c is a path separator. More...
 
char path_separator ()
 Returns the standard path separator for the current platform. More...
 
bool is_root (const std::string &path)
 Returns whether the path is the root of the file hierarchy. More...
 
std::string root_name (const std::string &path)
 Returns the name of the root device if included in the given path. More...
 
bool is_relative (const std::string &path)
 Returns whether the path seems to be relative. More...
 
std::string normalize_path (const std::string &path, bool normalize_separators=false, bool resolve_dot_entries=false)
 Returns the absolute path of a file. More...
 
bool to_asset_path (std::string &abs_path, std::string addon_id, std::string asset_type)
 Helper function to convert absolute path to wesnoth relative path. More...
 
static void init_binary_paths ()
 
void clear_binary_paths_cache ()
 
static bool is_legal_file (const std::string &filename_str)
 
const std::vector< std::string > & get_binary_paths (const std::string &type)
 Returns a vector with all possible paths to a given type of binary, e.g. More...
 
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. More...
 
utils::optional< std::string > get_binary_dir_location (const std::string &type, const std::string &filename)
 Returns a complete path to the actual directory of a given type, if it exists. More...
 
utils::optional< std::string > get_wml_location (const std::string &path, const utils::optional< std::string > &current_dir=utils::nullopt)
 Returns a translated path to the actual file or directory, if it exists. More...
 
std::string get_short_wml_path (const std::string &filename)
 Returns a short path to filename, skipping the (user) data directory. More...
 
utils::optional< std::string > get_independent_binary_file_path (const std::string &type, const std::string &filename)
 Returns an asset path to filename for binary path-independent use in saved games. More...
 
std::string get_program_invocation (const std::string &program_name)
 Returns the appropriate invocation for a Wesnoth-related binary, assuming that it is located in the same directory as the running wesnoth binary. More...
 
std::string sanitize_path (const std::string &path)
 Sanitizes a path to remove references to the user's name. More...
 
utils::optional< std::string > get_localized_path (const std::string &file, const std::string &suff="")
 Returns the localized version of the given filename, if it exists. More...
 
utils::optional< std::string > get_addon_id_from_path (const std::string &location)
 Returns the add-on ID from a path. More...
 
rwops_ptr make_read_RWops (const std::string &path)
 
rwops_ptr make_write_RWops (const std::string &path)
 
std::string autodetect_game_data_dir (std::string exe_dir)
 Try to autodetect the location of the game data dir. More...
 
std::string get_synced_prefs_file ()
 location of preferences file containing preferences that are synced between computers note that wesnoth does not provide the syncing functionality itself More...
 
std::string get_unsynced_prefs_file ()
 location of preferences file containing preferences that aren't synced between computers More...
 
std::string get_credentials_file ()
 
std::string get_default_prefs_file ()
 
std::string get_save_index_file ()
 
std::string get_lua_history_file ()
 
std::string get_sync_dir ()
 parent directory for everything that should be synced between systems. More...
 
std::string get_saves_dir ()
 
std::string get_wml_persist_dir ()
 
std::string get_intl_dir ()
 
std::string get_screenshot_dir ()
 
std::string get_addons_data_dir ()
 
std::string get_addons_dir ()
 
std::string get_current_editor_dir (const std::string &addon_id)
 
std::string get_legacy_editor_dir ()
 
std::string get_core_images_dir ()
 
bool looks_like_pbl (const std::string &file)
 
std::string read_map (const std::string &name)
 
std::string read_scenario (const std::string &name)
 
bool is_compressed_file (const std::string &filename)
 
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. More...
 
const file_tree_checksumdata_tree_checksum (bool reset=false)
 Get the time at which the data/ tree was last modified at. More...
 
static void get_file_tree_checksum_internal (const std::string &path, file_tree_checksum &res)
 
static int64_t ifs_size (struct SDL_RWops *context)
 
static int64_t ofs_size (struct SDL_RWops *context)
 
static int64_t SDLCALL ifs_seek (struct SDL_RWops *context, int64_t offset, int whence)
 
static int64_t SDLCALL ofs_seek (struct SDL_RWops *context, int64_t offset, int whence)
 
static std::size_t SDLCALL ifs_read (struct SDL_RWops *context, void *ptr, std::size_t size, std::size_t maxnum)
 
static std::size_t SDLCALL ofs_read (struct SDL_RWops *context, void *ptr, std::size_t size, std::size_t maxnum)
 
static std::size_t SDLCALL ifs_write (struct SDL_RWops *context, const void *ptr, std::size_t size, std::size_t num)
 
static std::size_t SDLCALL ofs_write (struct SDL_RWops *context, const void *ptr, std::size_t size, std::size_t num)
 
static int SDLCALL ifs_close (struct SDL_RWops *context)
 
static int SDLCALL ofs_close (struct SDL_RWops *context)
 
static offset_dir translate_seekdir (int64_t offset, int whence)
 

Variables

const blacklist_pattern_list default_blacklist
 
static bfs::path user_data_dir
 
static bfs::path cache_dir
 
const std::string map_extension = ".map"
 
const std::string mask_extension = ".mask"
 
const std::string wml_extension = ".cfg"
 
static const uint32_t read_type = 7
 
static const uint32_t write_type = 8
 

Typedef Documentation

◆ offset_dir

typedef std::pair<int64_t, std::ios_base::seekdir> filesystem::offset_dir

Definition at line 119 of file filesystem_sdl.cpp.

◆ rwops_ptr

using filesystem::rwops_ptr = typedef std::unique_ptr<SDL_RWops, sdl_rwops_deleter>

Definition at line 61 of file filesystem.hpp.

◆ scoped_istream

using filesystem::scoped_istream = typedef std::unique_ptr<std::istream>

Definition at line 53 of file filesystem.hpp.

◆ scoped_ostream

using filesystem::scoped_ostream = typedef std::unique_ptr<std::ostream>

Definition at line 54 of file filesystem.hpp.

Enumeration Type Documentation

◆ filter_mode

Enumerator
NO_FILTER 
SKIP_MEDIA_DIR 
SKIP_PBL_FILES 

Definition at line 75 of file filesystem.hpp.

◆ name_mode

enum filesystem::name_mode
strong
Enumerator
ENTIRE_FILE_PATH 
FILE_NAME_ONLY 

Definition at line 74 of file filesystem.hpp.

◆ reorder_mode

Enumerator
DONT_REORDER 
DO_REORDER 

Definition at line 76 of file filesystem.hpp.

Function Documentation

◆ autodetect_game_data_dir()

std::string filesystem::autodetect_game_data_dir ( std::string  exe_dir)

Try to autodetect the location of the game data dir.

Note that the root of the source tree currently doubles as the data dir.

Definition at line 125 of file filesystem_common.cpp.

References file_exists(), get_cwd(), and normalize_path().

Referenced by process_command_args().

◆ base_name()

std::string filesystem::base_name ( const std::string &  file,
const bool  remove_extension = false 
)

◆ check_prefix()

static bool filesystem::check_prefix ( bfs::path::iterator &  fi,
const bfs::path::iterator &  fe,
const bfs::path &  prefix 
)
static

Definition at line 411 of file filesystem.cpp.

Referenced by is_prefix(), and subtract_path().

◆ clear_binary_paths_cache()

void filesystem::clear_binary_paths_cache ( )

Definition at line 1507 of file filesystem.cpp.

Referenced by game_config_manager::reload_changed_game_config().

◆ copy_file()

void filesystem::copy_file ( const std::string &  src,
const std::string &  dest 
)

Read a file and then writes it back out.

Parameters
srcThe source file.
destThe destination of the copied file.

Definition at line 1193 of file filesystem.cpp.

References read_file(), src, and write_file().

Referenced by gui2::dialogs::migrate_version_selection::migrate_credentials(), prefs::migrate_preferences(), gui2::dialogs::custom_tod::select_file(), gui2::dialogs::editor_edit_unit::select_file(), and setup_user_data_dir().

◆ create_directory_if_missing() [1/2]

static bool filesystem::create_directory_if_missing ( const bfs::path &  dirpath)
static

◆ create_directory_if_missing() [2/2]

bool filesystem::create_directory_if_missing ( const std::string &  dirname)

Creates a directory if it does not exist already.

Parameters
dirnamePath to directory. All parents should exist.
Returns
True if the directory exists or could be successfully created; false otherwise.

Definition at line 1198 of file filesystem.cpp.

References create_directory_if_missing(), and game_config::path.

◆ create_directory_if_missing_recursive() [1/2]

static bool filesystem::create_directory_if_missing_recursive ( const bfs::path &  dirpath)
static

◆ create_directory_if_missing_recursive() [2/2]

bool filesystem::create_directory_if_missing_recursive ( const std::string &  dirname)

Creates a recursive directory tree if it does not exist already.

Parameters
dirnameFull path of target directory. Non existing parents will be created
Returns
True if the directory exists or could be successfully created; false otherwise.

Definition at line 1203 of file filesystem.cpp.

References create_directory_if_missing_recursive(), and game_config::path.

◆ data_tree_checksum()

const file_tree_checksum & filesystem::data_tree_checksum ( bool  reset = false)

◆ delete_directory()

bool filesystem::delete_directory ( const std::string &  dirname,
const bool  keep_pbl 
)

◆ delete_file()

bool filesystem::delete_file ( const std::string &  filename)

◆ dir_size()

int filesystem::dir_size ( const std::string &  pname)

Returns the sum of the sizes of the files contained in a directory.

Definition at line 1268 of file filesystem.cpp.

References file_size(), i, LOG_FS, p, and game_config::path.

Referenced by purge_dir(), and gui2::dialogs::game_cache_options::update_cache_size_display().

◆ directory_name()

std::string filesystem::directory_name ( const std::string &  file)

◆ error_except_not_found()

static bool filesystem::error_except_not_found ( const error_code &  ec)
inlinestatic

◆ file_exists() [1/2]

static bool filesystem::file_exists ( const bfs::path &  fpath)
static

Definition at line 325 of file filesystem.cpp.

References ERR_FS, error_except_not_found(), and image::exists().

Referenced by ad_hoc_addon_fetch_session(), autodetect_game_data_dir(), BOOST_AUTO_TEST_CASE(), lg::check_log_dir_writable(), editor::map_context::convert_scenario(), savegame::save_index_class::data(), network::download(), file_exists(), get_binary_file_location(), get_files_in_dir(), get_localized_path(), hotkey::command_executor::get_menu_image(), get_next_filename(), get_wesnothd_name(), get_wml_location(), handle_preprocess_command(), have_addon_in_vcs_tree(), have_addon_install_info(), have_addon_pbl_info(), gui2::init(), editor::initialize_addon(), installed_addons_and_versions(), is_addon_installed(), persist_file_context::load(), game_config_manager::load_addons_cfg(), prefs::load_credentials(), game_config_manager::load_game_config(), gui::button::load_images(), editor::map_context::map_context(), gui2::dialogs::migrate_version_selection::migrate_credentials(), prefs::migrate_preferences(), gui2::dialogs::migrate_version_selection::migrate_version_selection(), desktop::os_version(), gui2::dialogs::editor_choose_addon::populate_list(), gui2::dialogs::migrate_version_selection::post_show(), gui2::dialogs::editor_edit_pbl::pre_show(), gui2::dialogs::game_version::pre_show(), process_command_args(), wesnothd::ban_manager::read(), achievements::read_achievements_file(), game_config::config_cache::read_cache(), read_ignore_patterns(), refresh_addon_version_info_cache(), gui2::dialogs::file_dialog::register_new_selection(), remove_local_addon(), prefs::save_credentials(), savegame::save_game_exists(), editor::map_context::save_schedule(), hotkey::command_executor_default::set_button_state(), gui2::dialogs::preferences_dialog::setup_hotkey_list(), setup_user_data_dir(), editor::start(), game_launcher::start_wesnothd(), gui2::dialogs::editor_edit_pbl::update_icon_preview(), game_config::config_cache::write_file(), and prefs::write_preferences().

◆ file_exists() [2/2]

bool filesystem::file_exists ( const std::string &  name)

Returns true if a file or directory with such name already exists.

Definition at line 1213 of file filesystem.cpp.

References file_exists(), and game_config::path.

◆ file_modified_time()

std::time_t filesystem::file_modified_time ( const std::string &  fname)

Get the modification time of a file.

Definition at line 1218 of file filesystem.cpp.

References LOG_FS, and game_config::path.

Referenced by prefs::migrate_preferences(), savegame::create_save_info::operator()(), and savegame::save_index_class::rebuild().

◆ file_size()

int filesystem::file_size ( const std::string &  fname)

◆ find_other_version_saves_dirs()

std::vector< other_version_dir > filesystem::find_other_version_saves_dirs ( )

Searches for directories containing saves created by other versions of Wesnoth.

The directories returned will exist, but might not contain any saves. Changes to the filesystem (by running other versions or by deleting old directories) may change the results returned by the function.

Definition at line 866 of file filesystem.cpp.

References image::exists(), get_user_data_path(), get_version_path_suffix(), game_config::min_savegame_version, game_config::path, version_info::set_major_version(), and game_config::wesnoth_version.

Referenced by gui2::dialogs::game_load::execute(), and gui2::dialogs::game_load::set_save_dir_list().

◆ get_addon_id_from_path()

utils::optional< std::string > filesystem::get_addon_id_from_path ( const std::string &  location)

Returns the add-on ID from a path.

aka the directory directly following the "add-ons" folder, or an empty string if none is found.

Definition at line 1802 of file filesystem.cpp.

References get_addons_dir(), normalize_path(), and game_config::path.

Referenced by editor::context_manager::load_map().

◆ get_addons_data_dir()

std::string filesystem::get_addons_data_dir ( )

Definition at line 201 of file filesystem_common.cpp.

References get_dir(), and get_user_data_dir().

Referenced by get_addons_dir(), and setup_user_data_dir().

◆ get_addons_dir()

std::string filesystem::get_addons_dir ( )

◆ get_binary_dir_location()

utils::optional< std::string > filesystem::get_binary_dir_location ( const std::string &  type,
const std::string &  filename 
)

Returns a complete path to the actual directory of a given type, if it exists.

Definition at line 1637 of file filesystem.cpp.

References DBG_FS, filename, get_binary_paths(), is_directory_internal(), is_legal_file(), and game_config::path.

Referenced by BOOST_AUTO_TEST_CASE(), and init_textdomains().

◆ get_binary_file_location()

utils::optional< std::string > filesystem::get_binary_file_location ( const std::string &  type,
const std::string &  filename 
)

◆ get_binary_paths()

NOT_DANGLING const std::vector< std::string > & filesystem::get_binary_paths ( const std::string &  type)

Returns a vector with all possible paths to a given type of binary, e.g.

'images', 'sounds', etc,

Definition at line 1552 of file filesystem.cpp.

References dummy, ERR_FS, get_user_data_dir(), init_binary_paths(), and game_config::path.

Referenced by get_binary_dir_location(), get_binary_file_location(), and image::precache_file_existence().

◆ get_cache_dir()

std::string filesystem::get_cache_dir ( )

◆ get_core_images_dir()

std::string filesystem::get_core_images_dir ( )

◆ get_credentials_file()

std::string filesystem::get_credentials_file ( )

◆ get_current_editor_dir()

std::string filesystem::get_current_editor_dir ( const std::string &  addon_id)

◆ get_cwd()

std::string filesystem::get_cwd ( )

◆ get_default_prefs_file()

std::string filesystem::get_default_prefs_file ( )

◆ get_dir() [1/2]

static bfs::path filesystem::get_dir ( const bfs::path &  dirpath)
static

◆ get_dir() [2/2]

std::string filesystem::get_dir ( const std::string &  dir)

Definition at line 580 of file filesystem.cpp.

References get_dir(), and game_config::path.

◆ get_exe_dir()

std::string filesystem::get_exe_dir ( )

◆ get_exe_path()

std::string filesystem::get_exe_path ( )

◆ get_file_tree_checksum_internal()

static void filesystem::get_file_tree_checksum_internal ( const std::string &  path,
file_tree_checksum res 
)
static

◆ get_files_in_dir()

void filesystem::get_files_in_dir ( const std::string &  dir,
std::vector< std::string > *  files,
std::vector< std::string > *  dirs = nullptr,
name_mode  mode = name_mode::FILE_NAME_ONLY,
filter_mode  filter = filter_mode::NO_FILTER,
reorder_mode  reorder = reorder_mode::DONT_REORDER,
file_tree_checksum checksum = nullptr 
)

Get a list of all files and/or directories in a given directory.

Parameters
dirThe directory to examine.
[out]filesThe files in dir. Won't be used if nullptr.
[out]dirsThe directories in dir. Won't be used if nullptr.
modeDetermines whether the entire path or just the filename is retrieved.
filterDetermines if we skip images and sounds directories.
reorderTriggers the special handling of _main.cfg and _final.cfg.
[out]checksumCan be used to store checksum info.

Definition at line 444 of file filesystem.cpp.

References DO_REORDER, ENTIRE_FILE_PATH, error_except_not_found(), file_exists(), file_size(), i, is_directory_internal(), is_relative(), LOG_FS, looks_like_pbl(), filesystem::file_tree_checksum::modified, filesystem::file_tree_checksum::nfiles, game_config::path, push_if_exists(), utf8::size(), SKIP_MEDIA_DIR, SKIP_PBL_FILES, and filesystem::file_tree_checksum::sum_size.

Referenced by archive_dir(), BOOST_AUTO_TEST_CASE(), game_config::config_cache::clean_cache(), savegame::save_index_class::clean_up_index(), ng::create_engine::create_engine(), delete_directory(), get_file_tree_checksum_internal(), savegame::save_index_class::get_saves_list(), gui2::init(), lua_fileops::intf_read_file(), game_config_manager::load_addons_cfg(), campaignd::server::load_config(), game_config_manager::load_game_config(), gui2::dialogs::editor_choose_addon::populate_list(), gui2::dialogs::migrate_version_selection::post_show(), gui2::dialogs::campaign_selection::pre_show(), gui2::dialogs::editor_edit_pbl::pre_show(), image::precache_file_existence_internal(), preprocess_resource(), preprocessor_file::preprocessor_file(), game_config::config_cache::purge_cache(), gui2::dialogs::file_dialog::refresh_fileview(), achievements::reload(), and lg::rotate_logs().

◆ get_independent_binary_file_path()

utils::optional< std::string > filesystem::get_independent_binary_file_path ( const std::string &  type,
const std::string &  filename 
)

Returns an asset path to filename for binary path-independent use in saved games.

Example: images, units/konrad-fighter.png -> data/campaigns/Heir_To_The_Throne/images/units/konrad-fighter.png

Definition at line 1714 of file filesystem.cpp.

References filename, get_binary_file_location(), get_user_data_path(), partial, game_config::path, and subtract_path().

Referenced by BOOST_AUTO_TEST_CASE(), gui2::dialogs::game_load::display_savegame_internal(), savegame::extract_summary_from_config(), and intf_resolve_asset().

◆ get_intl_dir()

std::string filesystem::get_intl_dir ( )

◆ get_legacy_editor_dir()

std::string filesystem::get_legacy_editor_dir ( )

◆ get_localized_path()

utils::optional< std::string > filesystem::get_localized_path ( const std::string &  file,
const std::string &  suff 
)

Returns the localized version of the given filename, if it exists.

Definition at line 1762 of file filesystem.cpp.

References _(), base_name(), directory_name(), file_exists(), and utils::split().

Referenced by sound::load_chunk(), image::load_image_file(), and sound::play_new_music().

◆ get_logs_dir()

std::string filesystem::get_logs_dir ( )

◆ get_lua_history_file()

std::string filesystem::get_lua_history_file ( )

Definition at line 185 of file filesystem_common.cpp.

References get_sync_dir().

◆ get_next_filename()

std::string filesystem::get_next_filename ( const std::string &  name,
const std::string &  extension 
)

Get the next free filename using "name + number (3 digits) + extension" maximum 1000 files then start always giving 999.

Definition at line 585 of file filesystem.cpp.

References file_exists(), and filename.

Referenced by editor::map_context::convert_scenario(), and gui2::dialogs::make_screenshot().

◆ get_program_invocation()

std::string filesystem::get_program_invocation ( const std::string &  program_name)

Returns the appropriate invocation for a Wesnoth-related binary, assuming that it is located in the same directory as the running wesnoth binary.

This is just a string-transformation based on argv[0], so the returned program is not guaranteed to actually exist. '-debug' variants are handled correctly.

Definition at line 1735 of file filesystem.cpp.

Referenced by get_exe_path(), and get_wesnothd_name().

◆ get_save_index_file()

std::string filesystem::get_save_index_file ( )

◆ get_saves_dir()

std::string filesystem::get_saves_dir ( )

◆ get_screenshot_dir()

std::string filesystem::get_screenshot_dir ( )

◆ get_short_wml_path()

std::string filesystem::get_short_wml_path ( const std::string &  filename)

Returns a short path to filename, skipping the (user) data directory.

Definition at line 1697 of file filesystem.cpp.

References filename, get_user_data_path(), partial, game_config::path, and subtract_path().

Referenced by gui2::init(), preprocessor_file::init(), game_config_manager::load_addons_cfg(), and editor::map_context::map_context().

◆ get_sync_dir()

std::string filesystem::get_sync_dir ( )

parent directory for everything that should be synced between systems.

implemented due to limitations of Steam's AutoCloud (non-SDK) syncing, but will also simplify things if it's ever added for any other platforms.

Definition at line 190 of file filesystem_common.cpp.

References get_user_data_dir().

Referenced by get_legacy_editor_dir(), get_lua_history_file(), get_saves_dir(), get_synced_prefs_file(), get_wml_persist_dir(), and setup_user_data_dir().

◆ get_synced_prefs_file()

std::string filesystem::get_synced_prefs_file ( )

location of preferences file containing preferences that are synced between computers note that wesnoth does not provide the syncing functionality itself

Definition at line 156 of file filesystem_common.cpp.

References get_sync_dir().

Referenced by prefs::load_preferences(), prefs::migrate_preferences(), gui2::dialogs::migrate_version_selection::post_show(), setup_user_data_dir(), and prefs::write_preferences().

◆ get_unsynced_prefs_file()

std::string filesystem::get_unsynced_prefs_file ( )

location of preferences file containing preferences that aren't synced between computers

Definition at line 161 of file filesystem_common.cpp.

References get_user_data_dir().

Referenced by prefs::load_preferences(), gui2::dialogs::migrate_version_selection::post_show(), setup_user_data_dir(), and prefs::write_preferences().

◆ get_user_data_dir()

std::string filesystem::get_user_data_dir ( )

◆ get_user_data_path()

static const bfs::path& filesystem::get_user_data_path ( )
static

◆ get_version_path_suffix() [1/2]

const std::string & filesystem::get_version_path_suffix ( )

Definition at line 620 of file filesystem.cpp.

References get_version_path_suffix(), and game_config::wesnoth_version.

◆ get_version_path_suffix() [2/2]

const std::string filesystem::get_version_path_suffix ( const version_info version)

◆ get_wesnothd_name()

std::string filesystem::get_wesnothd_name ( )

◆ get_wml_location()

utils::optional< std::string > filesystem::get_wml_location ( const std::string &  path,
const utils::optional< std::string > &  current_dir = utils::nullopt 
)

◆ get_wml_persist_dir()

std::string filesystem::get_wml_persist_dir ( )

Definition at line 213 of file filesystem_common.cpp.

References get_dir(), and get_sync_dir().

Referenced by setup_user_data_dir().

◆ ifs_close()

static int SDLCALL filesystem::ifs_close ( struct SDL_RWops *  context)
static

Definition at line 203 of file filesystem_sdl.cpp.

Referenced by make_read_RWops().

◆ ifs_read()

static std::size_t SDLCALL filesystem::ifs_read ( struct SDL_RWops *  context,
void *  ptr,
std::size_t  size,
std::size_t  maxnum 
)
static

Definition at line 169 of file filesystem_sdl.cpp.

References utf8::size().

Referenced by make_read_RWops().

◆ ifs_seek()

static int64_t SDLCALL filesystem::ifs_seek ( struct SDL_RWops *  context,
int64_t  offset,
int  whence 
)
static

Definition at line 134 of file filesystem_sdl.cpp.

References translate_seekdir().

Referenced by make_read_RWops().

◆ ifs_size()

static int64_t filesystem::ifs_size ( struct SDL_RWops *  context)
static

Definition at line 94 of file filesystem_sdl.cpp.

Referenced by make_read_RWops().

◆ ifs_write()

static std::size_t SDLCALL filesystem::ifs_write ( struct SDL_RWops *  context,
const void *  ptr,
std::size_t  size,
std::size_t  num 
)
static

Definition at line 187 of file filesystem_sdl.cpp.

Referenced by make_read_RWops().

◆ init_binary_paths()

static void filesystem::init_binary_paths ( )
static

◆ is_bzip2_file()

bool filesystem::is_bzip2_file ( const std::string &  filename)

Returns true if the file ends with '.bz2'.

Definition at line 1249 of file filesystem.cpp.

References filename, and game_config::path.

Referenced by BOOST_AUTO_TEST_CASE(), is_compressed_file(), and savegame::read_save_file().

◆ is_cfg()

bool filesystem::is_cfg ( const std::string &  filename)

◆ is_compressed_file()

bool filesystem::is_compressed_file ( const std::string &  filename)
inline

◆ is_directory()

bool filesystem::is_directory ( const std::string &  fname)

◆ is_directory_internal()

static bool filesystem::is_directory_internal ( const bfs::path &  fpath)
static

◆ is_gzip_file()

bool filesystem::is_gzip_file ( const std::string &  filename)

Returns true if the file ends with '.gz'.

Definition at line 1244 of file filesystem.cpp.

References filename, and game_config::path.

Referenced by BOOST_AUTO_TEST_CASE(), is_compressed_file(), and savegame::read_save_file().

◆ is_legal_file()

static bool filesystem::is_legal_file ( const std::string &  filename_str)
static

◆ is_legal_user_file_name()

bool filesystem::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.

This is meant to be used for any files created by Wesnoth where user input is required, including save files and add-on files for uploading to the add-ons server.

Parameters
nameFile name to verify.
allow_whitespaceWhether whitespace should be allowed.

Definition at line 32 of file filesystem_common.cpp.

References c.

Referenced by addon_filename_legal(), and savegame::savegame::check_filename().

◆ is_map()

bool filesystem::is_map ( const std::string &  filename)

Returns true if the file ends with the mapfile extension.

Definition at line 1229 of file filesystem.cpp.

References filename, map_extension, and game_config::path.

Referenced by wfl::builtins::DEFINE_WFL_FUNCTION(), editor::editor_controller::do_execute_command(), editor::map_context::map_context(), and wfl::parse_expression().

◆ is_mask()

bool filesystem::is_mask ( const std::string &  filename)

Returns true if the file ends with the maskfile extension.

Definition at line 1239 of file filesystem.cpp.

References filename, mask_extension, and game_config::path.

Referenced by editor::map_context::map_context().

◆ is_path_sep()

bool filesystem::is_path_sep ( char  c)

Returns whether c is a path separator.

Note
/ is always a path separator. Additionally, on Windows \ is a path separator as well.

Definition at line 1323 of file filesystem.cpp.

References c, game_config::path, and s.

◆ is_prefix()

static bool filesystem::is_prefix ( const bfs::path &  full,
const bfs::path &  prefix_path 
)
static

Definition at line 422 of file filesystem.cpp.

References check_prefix().

Referenced by get_wml_location().

◆ is_relative()

bool filesystem::is_relative ( const std::string &  path)

Returns whether the path seems to be relative.

Definition at line 1373 of file filesystem.cpp.

References game_config::path.

Referenced by BOOST_AUTO_TEST_CASE(), get_files_in_dir(), and gui2::dialogs::file_dialog::register_new_selection().

◆ is_root()

bool filesystem::is_root ( const std::string &  path)

Returns whether the path is the root of the file hierarchy.

Note
This function is unreliable for paths that do not exist – it will always return false for those.

Definition at line 1335 of file filesystem.cpp.

References p, and game_config::path.

Referenced by BOOST_AUTO_TEST_CASE(), gui2::dialogs::file_dialog::get_filelist_selection(), nearest_extant_parent(), gui2::dialogs::file_dialog::refresh_fileview(), and gui2::dialogs::file_dialog::register_new_selection().

◆ is_userdata_initialized()

bool filesystem::is_userdata_initialized ( )

Definition at line 608 of file filesystem.cpp.

References user_data_dir.

Referenced by process_command_args().

◆ istream_file()

filesystem::scoped_istream filesystem::istream_file ( const std::string &  fname,
bool  treat_failure_as_error 
)

◆ looks_like_pbl()

bool filesystem::looks_like_pbl ( const std::string &  file)

◆ make_directory()

bool filesystem::make_directory ( const std::string &  dirname)

◆ make_read_RWops()

rwops_ptr filesystem::make_read_RWops ( const std::string &  path)

◆ make_write_RWops()

rwops_ptr filesystem::make_write_RWops ( const std::string &  path)

◆ nearest_extant_parent()

std::string filesystem::nearest_extant_parent ( const std::string &  file)

Finds the nearest parent in existence for a file or directory.

Note
The file's own existence is not checked.
Returns
An absolute path to the closest parent of the given path, or an empty string if none could be found. While on POSIX platforms this cannot happen (unless the original path was already empty), on Windows it might be the case that the original path refers to a drive letter or network share that does not exist.

Definition at line 1303 of file filesystem.cpp.

References is_root(), p, and game_config::path.

Referenced by BOOST_AUTO_TEST_CASE(), and gui2::dialogs::file_dialog::set_path().

◆ normalize_path()

std::string filesystem::normalize_path ( const std::string &  path,
bool  normalize_separators = false,
bool  resolve_dot_entries = false 
)

Returns the absolute path of a file.

Parameters
pathOriginal path.
normalize_separatorsWhether to substitute path separators with the platform's preferred format.
resolve_dot_entriesWhether to resolve . and .. directory entries. This requires path to refer to a valid existing object.
Returns
An absolute path – that is, a path that is independent of the current working directory for the process. If resolve_dot_entries is set to true, the returned path has . and .. components resolved; however, if resolution fails because a component does not exist, an empty string is returned instead.

Definition at line 1378 of file filesystem.cpp.

References p, and game_config::path.

Referenced by autodetect_game_data_dir(), get_addon_id_from_path(), game_launcher::goto_editor(), campaignd::server::load_config(), gui2::dialogs::file_dialog::path(), gui2::dialogs::game_version::pre_show(), process_command_args(), gui2::dialogs::file_dialog::register_new_selection(), run_campaignd(), sanitize_path(), gui2::dialogs::file_dialog::set_path(), set_user_data_dir(), gui2::dialogs::file_dialog::sync_bookmarks_bar(), and campaignd::server::write_config().

◆ ofs_close()

static int SDLCALL filesystem::ofs_close ( struct SDL_RWops *  context)
static

Definition at line 211 of file filesystem_sdl.cpp.

Referenced by make_write_RWops().

◆ ofs_read()

static std::size_t SDLCALL filesystem::ofs_read ( struct SDL_RWops *  context,
void *  ptr,
std::size_t  size,
std::size_t  maxnum 
)
static

Definition at line 182 of file filesystem_sdl.cpp.

Referenced by make_write_RWops().

◆ ofs_seek()

static int64_t SDLCALL filesystem::ofs_seek ( struct SDL_RWops *  context,
int64_t  offset,
int  whence 
)
static

Definition at line 151 of file filesystem_sdl.cpp.

References translate_seekdir().

Referenced by make_write_RWops().

◆ ofs_size()

static int64_t filesystem::ofs_size ( struct SDL_RWops *  context)
static

Definition at line 106 of file filesystem_sdl.cpp.

Referenced by make_write_RWops().

◆ ofs_write()

static std::size_t SDLCALL filesystem::ofs_write ( struct SDL_RWops *  context,
const void *  ptr,
std::size_t  size,
std::size_t  num 
)
static

Definition at line 191 of file filesystem_sdl.cpp.

References utf8::size().

Referenced by make_write_RWops().

◆ ostream_file()

filesystem::scoped_ostream filesystem::ostream_file ( const std::string &  fname,
std::ios_base::openmode  mode,
bool  create_directory 
)

◆ path_separator()

char filesystem::path_separator ( )

Returns the standard path separator for the current platform.

Definition at line 1330 of file filesystem.cpp.

◆ push_if_exists()

static void filesystem::push_if_exists ( std::vector< std::string > *  vec,
const bfs::path &  file,
bool  full 
)
static

Definition at line 298 of file filesystem.cpp.

Referenced by get_files_in_dir().

◆ read_file()

std::string filesystem::read_file ( const std::string &  fname)

◆ read_file_as_data_uri()

std::string filesystem::read_file_as_data_uri ( const std::string &  fname)

◆ read_file_binary()

std::vector< uint8_t > filesystem::read_file_binary ( const std::string &  fname)

Definition at line 1083 of file filesystem.cpp.

References file_size().

Referenced by read_file_as_data_uri().

◆ read_map()

std::string filesystem::read_map ( const std::string &  name)

◆ read_scenario()

std::string filesystem::read_scenario ( const std::string &  name)

◆ rename_dir()

bool filesystem::rename_dir ( const std::string &  old_dir,
const std::string &  new_dir 
)

Definition at line 796 of file filesystem.cpp.

References ERR_FS.

Referenced by editor::context_manager::change_addon_id().

◆ root_name()

std::string filesystem::root_name ( const std::string &  path)

Returns the name of the root device if included in the given path.

This only properly makes sense on Windows with paths containing a drive letter or UNC at the start – otherwise, it will return the empty string. To ensure that a suitable root name can be found you might want to use normalize_path() first with resolve_dot_entries set to true.

Definition at line 1368 of file filesystem.cpp.

References game_config::path.

Referenced by gui2::dialogs::file_dialog::register_new_selection().

◆ sanitize_path()

std::string filesystem::sanitize_path ( const std::string &  path)

Sanitizes a path to remove references to the user's name.

Definition at line 1744 of file filesystem.cpp.

References normalize_path(), and game_config::path.

Referenced by game_config::full_build_report(), and get_addon_pbl_info().

◆ set_cache_dir()

void filesystem::set_cache_dir ( const std::string &  newcachedir)

Definition at line 816 of file filesystem.cpp.

References set_cache_path().

Referenced by process_command_args().

◆ set_cache_path()

static void filesystem::set_cache_path ( bfs::path  newcache)
static

Definition at line 808 of file filesystem.cpp.

References cache_dir, create_directory_if_missing_recursive(), and ERR_FS.

Referenced by set_cache_dir().

◆ set_cwd()

bool filesystem::set_cwd ( const std::string &  dir)

Definition at line 932 of file filesystem.cpp.

References ERR_FS, LOG_FS, and game_config::path.

Referenced by run_campaignd().

◆ set_user_data_dir()

void filesystem::set_user_data_dir ( std::string  newprefdir)

◆ setup_user_data_dir()

static void filesystem::setup_user_data_dir ( )
static

◆ subtract_path()

static bfs::path filesystem::subtract_path ( const bfs::path &  full,
const bfs::path &  prefix_path 
)
static

Definition at line 428 of file filesystem.cpp.

References check_prefix(), and game_config::path.

Referenced by get_independent_binary_file_path(), and get_short_wml_path().

◆ to_asset_path()

bool filesystem::to_asset_path ( std::string &  path,
std::string  addon_id,
std::string  asset_type 
)

Helper function to convert absolute path to wesnoth relative path.

Definition at line 1398 of file filesystem.cpp.

References filename, get_current_editor_dir(), get_dir(), and game_config::path.

Referenced by gui2::dialogs::custom_tod::select_file(), and gui2::dialogs::editor_edit_unit::select_file().

◆ translate_seekdir()

static offset_dir filesystem::translate_seekdir ( int64_t  offset,
int  whence 
)
static

Definition at line 121 of file filesystem_sdl.cpp.

Referenced by ifs_seek(), and ofs_seek().

◆ write_file()

void filesystem::write_file ( const std::string &  fname,
const std::string &  data,
std::ios_base::openmode  mode 
)

Variable Documentation

◆ cache_dir

bfs::path filesystem::cache_dir
static

Definition at line 606 of file filesystem.cpp.

Referenced by get_cache_dir(), and set_cache_path().

◆ default_blacklist

const blacklist_pattern_list filesystem::default_blacklist

◆ map_extension

const std::string filesystem::map_extension = ".map"

◆ mask_extension

const std::string filesystem::mask_extension = ".mask"

Definition at line 80 of file filesystem.hpp.

Referenced by is_mask(), and editor::context_manager::save_map_as_dialog().

◆ read_type

const uint32_t filesystem::read_type = 7
static

Definition at line 29 of file filesystem_sdl.cpp.

Referenced by make_read_RWops().

◆ user_data_dir

bfs::path filesystem::user_data_dir
static

◆ wml_extension

const std::string filesystem::wml_extension = ".cfg"

◆ write_type

const uint32_t filesystem::write_type = 8
static

Definition at line 30 of file filesystem_sdl.cpp.

Referenced by make_write_RWops().