filesystem.hpp File Reference

Declarations for File-IO. More...

#include <time.h>
#include <iosfwd>
#include <string>
#include <vector>

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
class  scoped_istream
class  scoped_ostream

Enumerations

enum  FILE_NAME_MODE { ENTIRE_FILE_PATH, FILE_NAME_ONLY }
enum  FILE_FILTER { NO_FILTER, SKIP_MEDIA_DIR }
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_MODE mode=FILE_NAME_ONLY, FILE_FILTER=NO_FILTER, FILE_REORDER_OPTION reorder=DONT_REORDER)
 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_save_index_file ()
std::string get_saves_dir ()
std::string get_cache_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_upload_dir ()
std::string get_user_data_dir ()
std::string get_cwd ()
bool make_directory (const std::string &dirname)
bool delete_directory (const std::string &dirname)
std::string read_file (const std::string &fname)
 Basic disk I/O - read file.
std::istream * istream_file (std::string const &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 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 file with name already exists.
time_t file_create_time (const std::string &fname)
 Get the creation time of a file.
std::string next_filename (const std::string &dirname, unsigned int max=0)
 Return the next ordered full filename within this directory.
bool is_gzip_file (const std::string &filename)
 Returns true if the file ends with '.gz'.
bool operator== (const file_tree_checksum &lhs, const file_tree_checksum &rhs)
bool operator!= (const file_tree_checksum &lhs, const file_tree_checksum &rhs)
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.
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 a type of binary, or an empty string if the file isn't present.


Detailed Description

Declarations for File-IO.

Definition in file filesystem.hpp.


Enumeration Type Documentation

Enumerator:
NO_FILTER 
SKIP_MEDIA_DIR 

Definition at line 39 of file filesystem.hpp.

Enumerator:
ENTIRE_FILE_PATH 
FILE_NAME_ONLY 

Definition at line 38 of file filesystem.hpp.

Enumerator:
DONT_REORDER 
DO_REORDER 

Definition at line 40 of file filesystem.hpp.


Function Documentation

void clear_binary_paths_cache (  ) 

const file_tree_checksum& data_tree_checksum ( bool  reset = false  ) 

Get the time at which the data/ tree was last modified at.

bool delete_directory ( const std::string &  dirname  ) 

Definition at line 333 of file filesystem.cpp.

References delete_directory(), ENTIRE_FILE_PATH, get_files_in_dir(), and LOG_FS.

Referenced by delete_directory(), and upload_logs().

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 map_editor::check_data(), preprocessor_data::get_chunk(), and preprocessor_file::preprocessor_file().

bool ends_with ( const std::string &  str,
const std::string &  suffix 
)

Definition at line 78 of file filesystem.cpp.

Referenced by get_files_in_dir().

time_t file_create_time ( const std::string &  fname  ) 

Get the creation time of a file.

Referenced by finish_save_game(), and get_saves_list().

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(), and upload_log::~upload_log().

int file_size ( const std::string &  fname  ) 

Returns the size of a file, or -1 if the file doesn't exist.

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 a type of binary, or an empty string if the file isn't present.

Referenced by image::exists(), init_textdomains(), sound::load_chunk(), image::locator::load_image_file(), loadscreen::loadscreen(), and sound::play_new_music().

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,

std::string get_cache_dir (  ) 

Definition at line 249 of file filesystem.cpp.

References get_dir(), and get_user_data_dir().

std::string get_cwd (  ) 

Definition at line 366 of file filesystem.cpp.

References buf.

Referenced by get_intl_dir(), and main().

std::string get_dir ( const std::string &  dir  ) 

void get_files_in_dir ( const std::string  dir,
std::vector< std::string > *  files,
std::vector< std::string > *  dirs = NULL,
FILE_NAME_MODE  mode = FILE_NAME_ONLY,
FILE_FILTER  = NO_FILTER,
FILE_REORDER_OPTION  reorder = DONT_REORDER 
)

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.

Definition at line 89 of file filesystem.cpp.

References closedir(), dirent::d_name, DO_REORDER, ends_with(), ENTIRE_FILE_PATH, FINALCFG, get_files_in_dir(), is_directory(), LOG_FS, MAINCFG, opendir(), game_config::path, readdir(), S_ISDIR, S_ISREG, and SKIP_MEDIA_DIR.

Referenced by archive_dir(), available_campaigns(), mp::create::create(), delete_directory(), get_files_in_dir(), get_saves_list(), installed_campaigns(), preprocessor_file::preprocessor_file(), gui::file_menu::update_file_lists(), and upload_logs().

std::string get_intl_dir (  ) 

Definition at line 255 of file filesystem.cpp.

References get_cwd(), LOCALEDIR, and game_config::path.

Referenced by init_textdomains(), main(), and play_game().

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 280 of file filesystem.cpp.

References file_exists(), and next_filename().

Referenced by hotkey::execute_command().

std::string get_prefs_file (  ) 

std::string get_save_index_file (  ) 

Definition at line 238 of file filesystem.cpp.

References get_user_data_dir().

Referenced by save_index(), and write_save_index().

std::string get_saves_dir (  ) 

std::string get_screenshot_dir (  ) 

Definition at line 274 of file filesystem.cpp.

References get_dir(), and get_user_data_dir().

Referenced by hotkey::execute_command().

std::string get_upload_dir (  ) 

std::string get_user_data_dir (  ) 

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 dialogs::get_save_name(), play_game(), and read_save_file().

std::istream* istream_file ( std::string const &  fname  ) 

bool make_directory ( const std::string &  dirname  ) 

Definition at line 326 of file filesystem.cpp.

References AccessMode, and mkdir.

Referenced by setup_dirs(), and unarchive_dir().

std::string next_filename ( const std::string &  dirname,
unsigned int  max = 0 
)

Return the next ordered full filename within this directory.

Referenced by get_next_filename(), upload_log::upload_log(), and upload_log::~upload_log().

bool operator!= ( const file_tree_checksum lhs,
const file_tree_checksum rhs 
)

bool operator== ( const file_tree_checksum lhs,
const file_tree_checksum rhs 
)

std::ostream* ostream_file ( std::string const &  fname  ) 

std::string read_file ( const std::string &  fname  ) 

std::string read_map ( const std::string &  name  ) 

void write_file ( const std::string &  fname,
const std::string &  data 
)

Throws io_exception if an error occurs.

Definition at line 520 of file filesystem.cpp.

References buf, file, and util::scoped_resource< T, ReleasePolicy >::get().

Referenced by events::menu_handler::save_map(), map_editor::save_map(), and unarchive_file().


Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs