Classes | Enumerations | Functions

filesystem.hpp File Reference

Declarations for File-IO. More...

#include <time.h>
#include <iosfwd>
#include <string>
#include <vector>
#include "exceptions.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  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_checksumdata_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 &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.
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.

Detailed Description

Declarations for File-IO.

Definition in file filesystem.hpp.


Enumeration Type Documentation

Enumerator:
NO_FILTER 
SKIP_MEDIA_DIR 
SKIP_PBL_FILES 

Definition at line 41 of file filesystem.hpp.

Enumerator:
ENTIRE_FILE_PATH 
FILE_NAME_ONLY 

Definition at line 40 of file filesystem.hpp.

Enumerator:
DONT_REORDER 
DO_REORDER 

Definition at line 42 of file filesystem.hpp.


Function Documentation

void clear_binary_paths_cache (  ) 

Referenced by game_controller::play_multiplayer(), and game_controller::reload_changed_game_config().

Here is the caller graph for this function:

bool create_directory_if_missing ( const std::string &  dirname  ) 

Creates a directory if it does not exist already.

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

bool create_directory_if_missing_recursive ( const std::string &  dirname  ) 

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

Parameters:
dirname Full 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 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().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the caller graph for this function:

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

Here is the caller graph for this function:

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

Here is the caller graph for this function:

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

Here is the caller graph for this function:

bool file_exists ( const std::string &  name  ) 
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().

Here is the caller graph for this function:

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

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the caller graph for this function:

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

Here is the caller graph for this function:

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

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

std::string get_cwd (  ) 
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().

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

std::string get_exe_dir (  ) 

Definition at line 453 of file filesystem.cpp.

References get_cwd().

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Here is the call graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

std::string get_screenshot_dir (  ) 

Definition at line 337 of file filesystem.cpp.

References get_dir(), and get_user_data_dir().

Here is the call graph for this function:

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

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

const std::string& get_user_data_dir (  ) 
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().

Here is the caller graph for this function:

bool is_directory ( const std::string &  fname  ) 
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().

Here is the caller graph for this function:

std::istream* istream_file ( const std::string &  fname  ) 
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().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the caller graph for this function:

std::string normalize_path ( const std::string &  path  ) 

Returns the absolute path of a file.

Referenced by game_controller::goto_editor(), and main().

Here is the caller graph for this function:

std::ostream* ostream_file ( std::string const &  fname  ) 
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().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

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