Declarations for File-IO. More...
#include <time.h>#include <iosfwd>#include <string>#include <vector>#include "exceptions.hpp"

Go to the source code of this file.
Classes | |
| struct | io_exception |
| An exception object used when an IO error occurs. More... | |
| 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 | scoped_istream |
| class | scoped_ostream |
Enumerations | |
| enum | file_name_option { ENTIRE_FILE_PATH, FILE_NAME_ONLY } |
| enum | file_filter_option { NO_FILTER, SKIP_MEDIA_DIR, SKIP_PBL_FILES } |
| enum | file_reorder_option { DONT_REORDER, DO_REORDER } |
Functions | |
| void | get_files_in_dir (const std::string &dir, std::vector< std::string > *files, std::vector< std::string > *dirs=NULL, file_name_option mode=FILE_NAME_ONLY, file_filter_option filter=NO_FILTER, file_reorder_option reorder=DONT_REORDER, file_tree_checksum *checksum=NULL) |
| Populates 'files' with all the files and 'dirs' with all the directories in dir. | |
| std::string | get_dir (const std::string &dir) |
| std::string | get_prefs_file () |
| std::string | get_default_prefs_file () |
| std::string | get_save_index_file () |
| std::string | get_saves_dir () |
| std::string | get_intl_dir () |
| std::string | get_screenshot_dir () |
| std::string | get_addon_campaigns_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. | |
| void | set_preferences_dir (std::string path) |
| const std::string & | get_user_config_dir () |
| const std::string & | get_user_data_dir () |
| const std::string & | get_cache_dir () |
| std::string | get_cwd () |
| std::string | get_exe_dir () |
| bool | make_directory (const std::string &dirname) |
| bool | delete_directory (const std::string &dirname, const bool keep_pbl=false) |
| bool | looks_like_pbl (const std::string &file) |
| std::string | read_file (const std::string &fname) |
| Basic disk I/O - read file. | |
| std::istream * | istream_file (const std::string &fname) |
| std::ostream * | ostream_file (std::string const &fname) |
| void | write_file (const std::string &fname, const std::string &data) |
| Throws io_exception if an error occurs. | |
| std::string | read_map (const std::string &name) |
| bool | create_directory_if_missing (const std::string &dirname) |
| Creates a directory if it does not exist already. | |
| bool | create_directory_if_missing_recursive (const std::string &dirname) |
| Creates a recursive directory tree if it does not exist already. | |
| bool | is_directory (const std::string &fname) |
| Returns true if the given file is a directory. | |
| bool | file_exists (const std::string &name) |
| Returns true if a file or directory with such name already exists. | |
| time_t | file_create_time (const std::string &fname) |
| Get the creation time of a file. | |
| bool | is_gzip_file (const std::string &filename) |
| Returns true if the file ends with '.gz'. | |
| const file_tree_checksum & | data_tree_checksum (bool reset=false) |
| Get the time at which the data/ tree was last modified at. | |
| int | file_size (const std::string &fname) |
| Returns the size of a file, or -1 if the file doesn't exist. | |
| bool | ends_with (const std::string &str, const std::string &suffix) |
| std::string | file_name (const std::string &file) |
| Returns the base filename of a file, with directory name stripped. | |
| std::string | directory_name (const std::string &file) |
| Returns the directory name of a file, with filename stripped. | |
| std::string | normalize_path (const std::string &path) |
| Returns the absolute path of a file. | |
| void | clear_binary_paths_cache () |
| 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. | |
| 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 present. | |
| 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 or an empty string if the directory isn't present. | |
| std::string | get_wml_location (const std::string &filename, const std::string ¤t_dir=std::string()) |
| Returns a complete path to the actual WML file or directory or an empty string if the file isn't present. | |
| std::string | get_short_wml_path (const std::string &filename) |
| Returns a short path to filename, skipping the (user) data directory. | |
| std::string | get_independent_image_path (const std::string &filename) |
| Returns an image path to filename for binary path-independent use in saved games. | |
| 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. | |
Declarations for File-IO.
Definition in file filesystem.hpp.
| enum file_filter_option |
Definition at line 41 of file filesystem.hpp.
| enum file_name_option |
Definition at line 40 of file filesystem.hpp.
| enum file_reorder_option |
Definition at line 42 of file filesystem.hpp.
| void clear_binary_paths_cache | ( | ) |
Referenced by game_controller::play_multiplayer(), and game_controller::reload_changed_game_config().

| bool create_directory_if_missing | ( | const std::string & | dirname | ) |
Creates a directory if it does not exist already.
| dirname | Path to directory. All parents should exist. |
Definition at line 467 of file filesystem.cpp.
References DBG_FS, ERR_FS, file_exists(), is_directory(), and make_directory().
Referenced by create_directory_if_missing_recursive(), persist_file_context::load(), set_preferences_dir(), and setup_user_data_dir().


| bool create_directory_if_missing_recursive | ( | const std::string & | dirname | ) |
Creates a recursive directory tree if it does not exist already.
| dirname | Full path of target directory. Non existing parents will be created |
Definition at line 479 of file filesystem.cpp.
References create_directory_if_missing(), create_directory_if_missing_recursive(), DBG_FS, is_directory(), and pos.
Referenced by create_directory_if_missing_recursive(), get_cache_dir(), get_user_config_dir(), preprocess_resource(), and set_preferences_dir().


| const file_tree_checksum& data_tree_checksum | ( | bool | reset = false |
) |
Get the time at which the data/ tree was last modified at.
Referenced by game_controller::load_game_cfg(), game_config::config_cache::read_cache(), and game_config::config_cache::recheck_filetree_checksum().

| bool delete_directory | ( | const std::string & | dirname, | |
| const bool | keep_pbl = false | |||
| ) |
Definition at line 395 of file filesystem.cpp.
References delete_directory(), ENTIRE_FILE_PATH, get_files_in_dir(), is_directory(), LOG_FS, NO_FILTER, schema_validation::remove, and SKIP_PBL_FILES.
Referenced by delete_directory(), delete_random_sendfile(), remove_local_addon(), persist_file_context::save_context(), and game_config::config_cache::write_file().


| std::string directory_name | ( | const std::string & | file | ) |
Returns the directory name of a file, with filename stripped.
Equivalent to a portable dirname()
Referenced by do_gameloop(), preprocessor_data::get_chunk(), image::get_localized_path(), editor::context_manager::load_map_dialog(), editor::map_context::map_context(), preprocess_resource(), and preprocessor_file::preprocessor_file().

| bool ends_with | ( | const std::string & | str, | |
| const std::string & | suffix | |||
| ) |
Definition at line 90 of file filesystem.cpp.
Referenced by get_files_in_dir(), and preprocess_resource().

| time_t file_create_time | ( | const std::string & | fname | ) |
Get the creation time of a file.
Referenced by savegame::create_save_info::operator()(), and savegame::save_index_class::rebuild().

| bool file_exists | ( | const std::string & | name | ) |
Returns true if a file or directory with such name already exists.
Referenced by adjust_profile(), archive_addon(), available_addons(), create_directory_if_missing(), gui::file_menu::file_menu(), get_next_filename(), have_addon_in_vcs_tree(), have_addon_pbl_info(), installed_addons(), is_addon_installed(), persist_file_context::load(), game_controller::load_game_cfg(), main(), editor::map_context::map_context(), open_font(), process_command_args(), game_config::config_cache::read_cache(), read_ignore_patterns(), wesnothd::room_manager::read_rooms(), refresh_addon_version_info_cache(), remove_local_addon(), events::menu_handler::save_map(), editor::context_manager::save_map_as_dialog(), font::set_font_list(), game_controller::start_wesnothd(), and game_config::config_cache::write_file().

| std::string file_name | ( | const std::string & | file | ) |
Returns the base filename of a file, with directory name stripped.
Equivalent to a portable basename() function.
Referenced by cutter::find_configuration(), game_controller::game_controller(), image::get_localized_path(), main(), and preprocess_resource().

| int file_size | ( | const std::string & | fname | ) |
Returns the size of a file, or -1 if the file doesn't exist.
Referenced by WESNOTH_PARAMETERIZED_TEST_CASE().

| std::string get_addon_campaigns_dir | ( | ) |
Definition at line 311 of file filesystem.cpp.
References get_dir(), and get_user_data_dir().
Referenced by archive_addon(), available_addons(), have_addon_in_vcs_tree(), have_addon_pbl_info(), installed_addons(), is_addon_installed(), game_controller::load_game_cfg(), read_ignore_patterns(), remove_local_addon(), and unarchive_addon().


| 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 or an empty string if the directory isn't present.
Referenced by init_textdomains().

| 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 present.
Referenced by image::locator::file_exists(), sound::load_chunk(), image::locator::load_image_file(), image::localized_file_uptodate(), and sound::music_track::resolve().

| 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.
'images', 'sounds', etc,
Referenced by font::manager::deinit(), and font::manager::init().

| const std::string& get_cache_dir | ( | ) |
Definition at line 715 of file filesystem.cpp.
References cache_dir, create_directory_if_missing_recursive(), get_dir(), and get_user_data_dir().
Referenced by game_config::config_cache::read_cache().


| std::string get_cwd | ( | ) |
Definition at line 436 of file filesystem.cpp.
Referenced by game_controller::game_controller(), get_exe_dir(), get_intl_dir(), main(), process_command_args(), set_preferences_dir(), and wesnoth_global_fixture::wesnoth_global_fixture().

| std::string get_default_prefs_file | ( | ) |
Definition at line 290 of file filesystem.cpp.
References game_config::default_preferences_path, and game_config::path.
Referenced by preferences::base_manager::base_manager().

| std::string get_dir | ( | const std::string & | dir | ) |
Definition at line 363 of file filesystem.cpp.
References closedir(), ERR_FS, mkdir, and opendir().
Referenced by editor::context_manager::context_manager(), get_addon_campaigns_dir(), get_cache_dir(), get_persist_cfg_name(), get_saves_dir(), get_screenshot_dir(), persist_file_context::load(), and events::menu_handler::save_map().


| std::string get_exe_dir | ( | ) |
Definition at line 453 of file filesystem.cpp.
References get_cwd().
Referenced by main().


| void get_files_in_dir | ( | const std::string & | dir, | |
| std::vector< std::string > * | files, | |||
| std::vector< std::string > * | dirs = NULL, |
|||
| file_name_option | mode = FILE_NAME_ONLY, |
|||
| file_filter_option | filter = NO_FILTER, |
|||
| file_reorder_option | reorder = DONT_REORDER, |
|||
| file_tree_checksum * | checksum = NULL | |||
| ) |
Populates 'files' with all the files and 'dirs' with all the directories in dir.
If files or dirs are NULL they will not be used.
mode: determines whether the entire path or just the filename is retrieved. filter: determines if we skip images and sounds directories reorder: triggers the special handling of _main.cfg and _final.cfg checksum: can be used to store checksum info
Definition at line 95 of file filesystem.cpp.
References closedir(), dirent::d_name, DO_REORDER, ends_with(), ENTIRE_FILE_PATH, get_files_in_dir(), is_directory(), LOG_FS, looks_like_pbl(), file_tree_checksum::modified, file_tree_checksum::nfiles, opendir(), game_config::path, readdir(), S_ISDIR, S_ISREG, SKIP_MEDIA_DIR, SKIP_PBL_FILES, sort(), and file_tree_checksum::sum_size.
Referenced by archive_dir(), available_addons(), mp::create::create(), font::manager::deinit(), delete_directory(), get_files_in_dir(), font::manager::init(), installed_addons(), game_controller::load_game_cfg(), main(), image::precache_file_existence_internal(), preprocess_resource(), preprocessor_file::preprocessor_file(), and gui::file_menu::update_file_lists().


| std::string get_independent_image_path | ( | const std::string & | filename | ) |
Returns an image path to filename for binary path-independent use in saved games.
Example: units/konrad-fighter.png -> data/campaigns/Heir_To_The_Throne/images/units/konrad-fighter.png
Referenced by extract_summary_from_config().

| std::string get_intl_dir | ( | ) |
Definition at line 317 of file filesystem.cpp.
References get_cwd(), and game_config::path.
Referenced by test_utils::game_config_manager::game_config_manager(), init_locale(), and init_textdomains().


| 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.
Definition at line 343 of file filesystem.cpp.
References file_exists(), and right.

| std::string get_prefs_file | ( | ) |
Definition at line 285 of file filesystem.cpp.
References get_user_config_dir().
Referenced by preferences::base_manager::base_manager().


| 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.
This is just a string-transformation based on argv[0], so the returned program is not guaranteed to actaully exist. '-debug' variants are handled correctly.
Referenced by game_controller::start_wesnothd().

| std::string get_save_index_file | ( | ) |
Definition at line 299 of file filesystem.cpp.
References get_user_data_dir().
Referenced by savegame::save_index_class::data(), and savegame::save_index_class::write_save_index().


| std::string get_saves_dir | ( | ) |
Definition at line 304 of file filesystem.cpp.
References get_dir(), and get_user_data_dir().
Referenced by savegame::savegame::open_save_game(), and savegame::save_index_class::rebuild().


| std::string get_screenshot_dir | ( | ) |
Definition at line 337 of file filesystem.cpp.
References get_dir(), and get_user_data_dir().

| std::string get_short_wml_path | ( | const std::string & | filename | ) |
Returns a short path to filename, skipping the (user) data directory.
Referenced by preprocessor_file::preprocessor_file().

| const std::string& get_user_config_dir | ( | ) |
Definition at line 691 of file filesystem.cpp.
References create_directory_if_missing_recursive(), get_user_data_dir(), and user_config_dir.
Referenced by get_prefs_file(), and game_controller::start_wesnothd().


| const std::string& get_user_data_dir | ( | ) |
Definition at line 674 of file filesystem.cpp.
References game_config::preferences_dir, set_preferences_dir(), setup_user_data_dir(), and user_data_dir.
Referenced by editor::context_manager::context_manager(), mp::create::create(), get_addon_campaigns_dir(), get_cache_dir(), get_persist_cfg_name(), get_save_index_file(), get_saves_dir(), get_screenshot_dir(), get_user_config_dir(), persist_file_context::load(), process_command_args(), read_map(), and events::menu_handler::save_map().


| std::string get_wml_location | ( | const std::string & | filename, | |
| const std::string & | current_dir = std::string() | |||
| ) |
Returns a complete path to the actual WML file or directory or an empty string if the file isn't present.
Referenced by preprocessor_data::get_chunk(), intf_dofile(), intf_require(), load_language_list(), editor::map_context::map_context(), read_map(), and game_controller::start_wesnothd().

| bool is_directory | ( | const std::string & | fname | ) |
Returns true if the given file is a directory.
Referenced by create_directory_if_missing(), create_directory_if_missing_recursive(), delete_directory(), get_files_in_dir(), persist_file_context::load(), main(), editor::map_context::map_context(), preprocess_resource(), preprocessor_file::preprocessor_file(), process_command_args(), editor::context_manager::save_all_maps(), and editor::context_manager::save_map().

| bool is_gzip_file | ( | const std::string & | filename | ) |
Returns true if the file ends with '.gz'.
Referenced by savegame::savegame::check_filename(), and process_command_args().

| std::istream* istream_file | ( | const std::string & | fname | ) |
Definition at line 746 of file filesystem.cpp.
References ERR_FS, and LOG_FS.
Referenced by preferences::base_manager::base_manager(), savegame::save_index_class::data(), get_addon_pbl_info(), persist_file_context::load(), preprocessor_file::preprocessor_file(), process_command_args(), read_file(), game_config::config_cache::read_file(), read_ignore_patterns(), wesnothd::room_manager::read_rooms(), and refresh_addon_version_info_cache().

| bool looks_like_pbl | ( | const std::string & | file | ) |
Definition at line 388 of file filesystem.cpp.
References utils::lowercase(), and utils::wildcard_string_match().
Referenced by archive_dir(), and get_files_in_dir().


| bool make_directory | ( | const std::string & | dirname | ) |
Definition at line 383 of file filesystem.cpp.
References mkdir.
Referenced by create_directory_if_missing(), main(), and unarchive_dir().

| std::string normalize_path | ( | const std::string & | path | ) |
Returns the absolute path of a file.
Referenced by game_controller::goto_editor(), and main().

| std::ostream* ostream_file | ( | std::string const & | fname | ) |
Definition at line 771 of file filesystem.cpp.
References LOG_FS.
Referenced by create_random_sendfile(), savegame::savegame::open_save_game(), preprocess_resource(), process_command_args(), persist_file_context::save_context(), wesnothd::game::save_replay(), set_addon_pbl_info(), game_config::config_cache::write_file(), wesnothd::room_manager::write_rooms(), and savegame::save_index_class::write_save_index().

| std::string read_file | ( | const std::string & | fname | ) |
Basic disk I/O - read file.
The bool relative_from_game_path determines whether relative paths should be treated as relative to the game path (true) or to the current directory from which Wesnoth was run (false).
Definition at line 765 of file filesystem.cpp.
References istream_file(), and read_stream().
Referenced by archive_file(), server::load_config(), image::localized_file_uptodate(), editor::map_context::map_context(), read_map(), editor::map_context::save(), and game_controller::start_wesnothd().


| std::string read_map | ( | const std::string & | name | ) |
Definition at line 800 of file filesystem.cpp.
References get_user_data_dir(), get_wml_location(), and read_file().
Referenced by game_info::game_info(), mp::create::process_event(), and mp::gamebrowser::set_game_items().


| void set_preferences_dir | ( | std::string | path | ) |
Definition at line 533 of file filesystem.cpp.
References create_directory_if_missing(), create_directory_if_missing_recursive(), get_cwd(), get_version_path_suffix(), LOG_FS, game_config::preferences_dir, setup_user_data_dir(), user_data_dir, and WRN_FS.
Referenced by get_user_data_dir(), and process_command_args().


| void write_file | ( | const std::string & | fname, | |
| const std::string & | data | |||
| ) |
Throws io_exception if an error occurs.
Definition at line 778 of file filesystem.cpp.
References util::scoped_resource< T, ReleasePolicy >::get().
Referenced by preprocess_resource(), editor::map_context::save(), events::menu_handler::save_map(), game_controller::start_wesnothd(), and unarchive_file().


| Generated by doxygen 1.7.1 on Thu May 24 2012 01:04:13 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |