filesystem.cpp File Reference

File-IO. More...

#include "global.hpp"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <cstdlib>
#include <cerrno>
#include <string>
#include <cstring>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <set>
#include "wesconfig.h"
#include "config.hpp"
#include "filesystem.hpp"
#include "game_config.hpp"
#include "log.hpp"
#include "scoped_resource.hpp"
#include "util.hpp"
#include "loadscreen.hpp"

Include dependency graph for filesystem.cpp:

Go to the source code of this file.

Defines

#define DBG_FS   LOG_STREAM(debug, filesystem)
#define LOG_FS   LOG_STREAM(info, filesystem)
#define ERR_FS   LOG_STREAM(err, filesystem)
#define MAINCFG   "_main.cfg"
#define FINALCFG   "_final.cfg"
#define PREFERENCES_DIR   ".wesnoth"

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_MODE mode, FILE_FILTER filter, FILE_REORDER_OPTION reorder)
 Populates 'files' with all the files and 'dirs' with all the directories in 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_dir (const std::string &dir_path)
bool make_directory (const std::string &path)
bool delete_directory (const std::string &path)
std::string get_cwd ()
std::string get_user_data_dir ()
static std::string read_stream (std::istream &s)
std::istream * istream_file (std::string const &fname)
std::string read_file (std::string const &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

const mode_t AccessMode = 00770


Detailed Description

File-IO.

Definition in file filesystem.cpp.


Define Documentation

#define DBG_FS   LOG_STREAM(debug, filesystem)

Definition at line 64 of file filesystem.cpp.

#define ERR_FS   LOG_STREAM(err, filesystem)

Definition at line 66 of file filesystem.cpp.

Referenced by get_dir(), and get_user_data_dir().

#define FINALCFG   "_final.cfg"

Definition at line 85 of file filesystem.cpp.

Referenced by get_files_in_dir().

#define LOG_FS   LOG_STREAM(info, filesystem)

Definition at line 65 of file filesystem.cpp.

Referenced by delete_directory(), get_files_in_dir(), istream_file(), and ostream_file().

#define MAINCFG   "_main.cfg"

Definition at line 84 of file filesystem.cpp.

Referenced by get_files_in_dir().

#define PREFERENCES_DIR   ".wesnoth"

Referenced by get_user_data_dir().


Function Documentation

bool delete_directory ( const std::string &  path  ) 

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

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

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_path  ) 

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

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

Definition at line 556 of file filesystem.cpp.

References lg::info, and S_ISDIR.

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

bool make_directory ( const std::string &  path  ) 

Definition at line 326 of file filesystem.cpp.

References AccessMode, and mkdir.

Referenced by setup_dirs(), and unarchive_dir().

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

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

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

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

Definition at line 479 of file filesystem.cpp.

Referenced by read_file().

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


Variable Documentation

const mode_t AccessMode = 00770 [static]

Definition at line 69 of file filesystem.cpp.

Referenced by get_dir(), get_user_data_dir(), and make_directory().


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