The Battle for Wesnoth  1.19.7+dev
Classes | Namespaces | Typedefs | Enumerations | Functions | Variables
filesystem.hpp File Reference

Declarations for File-IO. More...

#include <ctime>
#include <cstdint>
#include <fstream>
#include <iosfwd>
#include <memory>
#include <string>
#include <vector>
#include "exceptions.hpp"
#include "game_version.hpp"
#include "global.hpp"
#include "utils/optional_fwd.hpp"
Include dependency graph for filesystem.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

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

Namespaces

 game_config
 Game configuration data as global variables.
 
 filesystem
 

Typedefs

using filesystem::scoped_istream = std::unique_ptr< std::istream >
 
using filesystem::scoped_ostream = std::unique_ptr< std::ostream >
 
using filesystem::rwops_ptr = std::unique_ptr< SDL_RWops, sdl_rwops_deleter >
 

Enumerations

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

Functions

rwops_ptr filesystem::make_read_RWops (const std::string &path)
 
rwops_ptr filesystem::make_write_RWops (const std::string &path)
 
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. More...
 
std::string filesystem::get_dir (const std::string &dir)
 
std::string filesystem::autodetect_game_data_dir (std::string exe_dir)
 Try to autodetect the location of the game data dir. More...
 
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 More...
 
std::string filesystem::get_unsynced_prefs_file ()
 location of preferences file containing preferences that aren't synced between computers More...
 
std::string filesystem::get_credentials_file ()
 
std::string filesystem::get_default_prefs_file ()
 
std::string filesystem::get_save_index_file ()
 
std::string filesystem::get_lua_history_file ()
 
std::string filesystem::get_sync_dir ()
 parent directory for everything that should be synced between systems. More...
 
std::string filesystem::get_saves_dir ()
 
std::string filesystem::get_wml_persist_dir ()
 
std::string filesystem::get_intl_dir ()
 
std::string filesystem::get_screenshot_dir ()
 
std::string filesystem::get_addons_data_dir ()
 
std::string filesystem::get_addons_dir ()
 
std::string filesystem::get_current_editor_dir (const std::string &addon_id)
 
const std::string filesystem::get_version_path_suffix (const version_info &version)
 
const std::string & filesystem::get_version_path_suffix ()
 
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. More...
 
bool filesystem::is_userdata_initialized ()
 
void filesystem::set_user_data_dir (std::string newprefdir)
 
void filesystem::set_cache_dir (const std::string &newcachedir)
 
std::string filesystem::get_user_data_dir ()
 
std::string filesystem::get_logs_dir ()
 
std::string filesystem::get_cache_dir ()
 
std::string filesystem::get_legacy_editor_dir ()
 
std::string filesystem::get_core_images_dir ()
 
bool filesystem::rename_dir (const std::string &old_dir, const std::string &new_dir)
 
std::vector< other_version_dir > filesystem::find_other_version_saves_dirs ()
 Searches for directories containing saves created by other versions of Wesnoth. More...
 
std::string filesystem::get_cwd ()
 
bool filesystem::set_cwd (const std::string &dir)
 
std::string filesystem::get_exe_path ()
 
std::string filesystem::get_exe_dir ()
 
std::string filesystem::get_wesnothd_name ()
 
bool filesystem::make_directory (const std::string &dirname)
 
bool filesystem::delete_directory (const std::string &dirname, const bool keep_pbl)
 
bool filesystem::delete_file (const std::string &filename)
 
bool filesystem::looks_like_pbl (const std::string &file)
 
std::string filesystem::read_file (const std::string &fname)
 Basic disk I/O - read file. More...
 
std::vector< uint8_t > filesystem::read_file_binary (const std::string &fname)
 
std::string filesystem::read_file_as_data_uri (const std::string &fname)
 
filesystem::scoped_istream filesystem::istream_file (const std::string &fname, bool treat_failure_as_error)
 
filesystem::scoped_ostream filesystem::ostream_file (const std::string &fname, std::ios_base::openmode mode, bool create_directory)
 
void filesystem::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 filesystem::copy_file (const std::string &src, const std::string &dest)
 Read a file and then writes it back out. More...
 
std::string filesystem::read_map (const std::string &name)
 
std::string filesystem::read_scenario (const std::string &name)
 
bool filesystem::create_directory_if_missing (const std::string &dirname)
 Creates a directory if it does not exist already. More...
 
bool filesystem::create_directory_if_missing_recursive (const std::string &dirname)
 Creates a recursive directory tree if it does not exist already. More...
 
bool filesystem::is_directory (const std::string &fname)
 Returns true if the given file is a directory. More...
 
bool filesystem::file_exists (const std::string &name)
 Returns true if a file or directory with such name already exists. More...
 
std::time_t filesystem::file_modified_time (const std::string &fname)
 Get the modification time of a file. More...
 
bool filesystem::is_map (const std::string &filename)
 Returns true if the file ends with the mapfile extension. More...
 
bool filesystem::is_cfg (const std::string &filename)
 Returns true if the file ends with the wmlfile extension. More...
 
bool filesystem::is_mask (const std::string &filename)
 Returns true if the file ends with the maskfile extension. More...
 
bool filesystem::is_gzip_file (const std::string &filename)
 Returns true if the file ends with '.gz'. More...
 
bool filesystem::is_bzip2_file (const std::string &filename)
 Returns true if the file ends with '.bz2'. More...
 
bool filesystem::is_compressed_file (const std::string &filename)
 
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. More...
 
const file_tree_checksum & filesystem::data_tree_checksum (bool reset=false)
 Get the time at which the data/ tree was last modified at. More...
 
int filesystem::file_size (const std::string &fname)
 Returns the size of a file, or -1 if the file doesn't exist. More...
 
int filesystem::dir_size (const std::string &path)
 Returns the sum of the sizes of the files contained in a directory. More...
 
std::string filesystem::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 filesystem::directory_name (const std::string &file)
 Returns the directory name of a file, with filename stripped. More...
 
std::string filesystem::nearest_extant_parent (const std::string &file)
 Finds the nearest parent in existence for a file or directory. More...
 
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. More...
 
bool filesystem::to_asset_path (std::string &abs_path, const std::string &addon_id, const std::string &asset_type)
 Helper function to convert absolute path to wesnoth relative path. More...
 
std::string filesystem::sanitize_path (const std::string &path)
 Sanitizes a path to remove references to the user's name. More...
 
bool filesystem::is_root (const std::string &path)
 Returns whether the path is the root of the file hierarchy. More...
 
std::string filesystem::root_name (const std::string &path)
 Returns the name of the root device if included in the given path. More...
 
bool filesystem::is_relative (const std::string &path)
 Returns whether the path seems to be relative. More...
 
bool filesystem::is_path_sep (char c)
 Returns whether c is a path separator. More...
 
char filesystem::path_separator ()
 Returns the standard path separator for the current platform. More...
 
void filesystem::clear_binary_paths_cache ()
 
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. More...
 
utils::optional< std::string > filesystem::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 > 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. More...
 
utils::optional< std::string > filesystem::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 filesystem::get_short_wml_path (const std::string &filename)
 Returns a short path to filename, skipping the (user) data directory. More...
 
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. More...
 
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. More...
 
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. More...
 
utils::optional< std::string > filesystem::get_addon_id_from_path (const std::string &location)
 Returns the add-on ID from a path. More...
 

Variables

const std::string filesystem::map_extension = ".map"
 
const std::string filesystem::mask_extension = ".mask"
 
const std::string filesystem::wml_extension = ".cfg"
 

Detailed Description

Declarations for File-IO.

Definition in file filesystem.hpp.