Defines | Functions | Variables

filesystem.cpp File Reference

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"
Include dependency graph for filesystem.cpp:

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

Detailed Description

File-IO.

Definition in file filesystem.cpp.


Define Documentation

#define DBG_FS   LOG_STREAM(debug, log_filesystem)
#define ERR_FS   LOG_STREAM(err, log_filesystem)
#define LOG_FS   LOG_STREAM(info, log_filesystem)
#define WRN_FS   LOG_STREAM(warn, log_filesystem)

Definition at line 71 of file filesystem.cpp.

Referenced by set_preferences_dir().


Function Documentation

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:

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

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:

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

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_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_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:

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

Here is the call graph for this function:

Here is the caller graph for this function:

static bool is_directory_internal ( const std::string &  fname  )  [static]

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

Parameters:
filename The name to test.

Definition at line 815 of file filesystem.cpp.

References lg::info, and S_ISDIR.

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 &  path  ) 

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::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:

static std::string read_stream ( std::istream &  s  )  [static]

Definition at line 739 of file filesystem.cpp.

Referenced by read_file().

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:

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

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:


Variable Documentation

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

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

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