File-IO. More...
#include "global.hpp"#include <sys/stat.h>#include <unistd.h>#include <dirent.h>#include <libgen.h>#include <cerrno>#include <fstream>#include <iomanip>#include <set>#include <boost/algorithm/string.hpp>#include <cstring>#include "config.hpp"#include "filesystem.hpp"#include "foreach.hpp"#include "game_config.hpp"#include "game_preferences.hpp"#include "log.hpp"#include "loadscreen.hpp"#include "scoped_resource.hpp"#include "serialization/string_utils.hpp"#include "version.hpp"
Go to the source code of this file.
Defines | |
| #define | DBG_FS LOG_STREAM(debug, log_filesystem) |
| #define | LOG_FS LOG_STREAM(info, log_filesystem) |
| #define | WRN_FS LOG_STREAM(warn, log_filesystem) |
| #define | ERR_FS LOG_STREAM(err, log_filesystem) |
Functions | |
| bool | ends_with (const std::string &str, const std::string &suffix) |
| void | get_files_in_dir (const std::string &directory, std::vector< std::string > *files, std::vector< std::string > *dirs, file_name_option mode, file_filter_option filter, file_reorder_option reorder, file_tree_checksum *checksum) |
| Populates 'files' with all the files and 'dirs' with all the directories in 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_addon_campaigns_dir () |
| std::string | get_intl_dir () |
| std::string | get_screenshot_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. | |
| std::string | get_dir (const std::string &dir_path) |
| bool | make_directory (const std::string &path) |
| bool | looks_like_pbl (const std::string &file) |
| bool | delete_directory (const std::string &path, const bool keep_pbl) |
| std::string | get_cwd () |
| std::string | get_exe_dir () |
| 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. | |
| static void | setup_user_data_dir () |
| static const std::string & | get_version_path_suffix () |
| void | set_preferences_dir (std::string path) |
| const std::string & | get_user_data_dir () |
| const std::string & | get_user_config_dir () |
| const std::string & | get_cache_dir () |
| static std::string | read_stream (std::istream &s) |
| std::istream * | istream_file (const std::string &fname) |
| std::string | read_file (const std::string &fname) |
| Basic disk I/O - read file. | |
| 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) |
| static bool | is_directory_internal (const std::string &fname) |
Variables | |
| static lg::log_domain | log_filesystem ("filesystem") |
| static std::string | user_data_dir |
| static std::string | user_config_dir |
| static std::string | cache_dir |
File-IO.
Definition in file filesystem.cpp.
| #define DBG_FS LOG_STREAM(debug, log_filesystem) |
Definition at line 69 of file filesystem.cpp.
Referenced by create_directory_if_missing(), and create_directory_if_missing_recursive().
| #define ERR_FS LOG_STREAM(err, log_filesystem) |
Definition at line 72 of file filesystem.cpp.
Referenced by create_directory_if_missing(), get_dir(), istream_file(), and setup_user_data_dir().
| #define LOG_FS LOG_STREAM(info, log_filesystem) |
Definition at line 70 of file filesystem.cpp.
Referenced by delete_directory(), get_files_in_dir(), istream_file(), ostream_file(), and set_preferences_dir().
| #define WRN_FS LOG_STREAM(warn, log_filesystem) |
Definition at line 71 of file filesystem.cpp.
Referenced by set_preferences_dir().
| 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().


| bool delete_directory | ( | const std::string & | path, | |
| const bool | keep_pbl | |||
| ) |
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().


| 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().

| 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().


| 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_path | ) |
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_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_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().

| 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().


| static const std::string& get_version_path_suffix | ( | ) | [static] |
Definition at line 515 of file filesystem.cpp.
References version_info::major_version(), version_info::minor_version(), and game_config::wesnoth_version.
Referenced by set_preferences_dir().


| static bool is_directory_internal | ( | const std::string & | fname | ) | [static] |
Returns true if the file ends with '.gz'.
| filename | The name to test. |
Definition at line 815 of file filesystem.cpp.
| 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 & | path | ) |
Definition at line 383 of file filesystem.cpp.
References mkdir.
Referenced by create_directory_if_missing(), main(), and unarchive_dir().

| 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().


| static std::string read_stream | ( | std::istream & | s | ) | [static] |
Definition at line 739 of file filesystem.cpp.
Referenced by read_file().

| 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().


| static void setup_user_data_dir | ( | ) | [static] |
Definition at line 628 of file filesystem.cpp.
References closedir(), create_directory_if_missing(), ERR_FS, opendir(), and user_data_dir.
Referenced by get_user_data_dir(), and set_preferences_dir().


| 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().


std::string cache_dir [static] |
Definition at line 510 of file filesystem.cpp.
Referenced by get_cache_dir().
lg::log_domain log_filesystem("filesystem") [static] |
std::string user_config_dir [static] |
Definition at line 510 of file filesystem.cpp.
Referenced by get_user_config_dir().
std::string user_data_dir [static] |
Definition at line 510 of file filesystem.cpp.
Referenced by get_user_data_dir(), set_preferences_dir(), and setup_user_data_dir().
| Generated by doxygen 1.7.1 on Thu May 24 2012 01:04:02 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |