00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef FILESYSTEM_HPP_INCLUDED
00019 #define FILESYSTEM_HPP_INCLUDED
00020
00021 #include <time.h>
00022
00023 #include <iosfwd>
00024 #include <string>
00025 #include <vector>
00026
00027
00028 struct io_exception : public std::exception {
00029 io_exception() : message("") {}
00030 io_exception(const std::string& msg) : message(msg) {}
00031 virtual ~io_exception() throw() {}
00032
00033 virtual const char* what() const throw() { return message.c_str(); }
00034 private:
00035 std::string message;
00036 };
00037
00038 enum FILE_NAME_MODE { ENTIRE_FILE_PATH, FILE_NAME_ONLY };
00039 enum FILE_FILTER { NO_FILTER, SKIP_MEDIA_DIR};
00040 enum FILE_REORDER_OPTION { DONT_REORDER, DO_REORDER };
00041
00042
00043
00044
00045
00046
00047 void get_files_in_dir(const std::string dir,
00048 std::vector<std::string>* files,
00049 std::vector<std::string>* dirs=NULL,
00050 FILE_NAME_MODE mode=FILE_NAME_ONLY,
00051 FILE_FILTER = NO_FILTER,
00052 FILE_REORDER_OPTION reorder=DONT_REORDER);
00053
00054 std::string get_dir(const std::string &dir);
00055
00056
00057 std::string get_prefs_file();
00058 std::string get_save_index_file();
00059 std::string get_saves_dir();
00060 std::string get_cache_dir();
00061 std::string get_intl_dir();
00062 std::string get_screenshot_dir();
00063
00064
00065
00066 std::string get_next_filename(const std::string& name, const std::string& extension);
00067 std::string get_upload_dir();
00068 std::string get_user_data_dir();
00069
00070 std::string get_cwd();
00071
00072 bool make_directory(const std::string& dirname);
00073 bool delete_directory(const std::string& dirname);
00074
00075
00076
00077
00078 std::string read_file(const std::string& fname);
00079 std::istream *istream_file(std::string const &fname);
00080 std::ostream *ostream_file(std::string const &fname);
00081
00082 void write_file(const std::string& fname, const std::string& data);
00083
00084 std::string read_map(const std::string& name);
00085
00086
00087 bool is_directory(const std::string& fname);
00088
00089
00090 bool file_exists(const std::string& name);
00091
00092
00093 time_t file_create_time(const std::string& fname);
00094
00095
00096 std::string next_filename(const std::string &dirname, unsigned int max = 0);
00097
00098
00099 bool is_gzip_file(const std::string& filename);
00100
00101 struct file_tree_checksum
00102 {
00103 file_tree_checksum();
00104 explicit file_tree_checksum(const class config& cfg);
00105 void write(class config& cfg) const;
00106 void reset() {nfiles = 0;modified = 0;sum_size=0;};
00107
00108 size_t nfiles, sum_size;
00109 time_t modified;
00110 };
00111
00112 bool operator==(const file_tree_checksum& lhs, const file_tree_checksum& rhs);
00113 bool operator!=(const file_tree_checksum& lhs, const file_tree_checksum& rhs);
00114
00115
00116
00117 const file_tree_checksum& data_tree_checksum(bool reset = false);
00118
00119
00120 int file_size(const std::string& fname);
00121
00122 bool ends_with(const std::string& str, const std::string& suffix);
00123
00124
00125
00126 std::string file_name(const std::string& file);
00127
00128
00129
00130 std::string directory_name(const std::string& file);
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 struct binary_paths_manager
00144 {
00145 binary_paths_manager();
00146 binary_paths_manager(const class config& cfg);
00147 ~binary_paths_manager();
00148
00149 void set_paths(const class config& cfg);
00150
00151 private:
00152 binary_paths_manager(const binary_paths_manager& o);
00153 binary_paths_manager& operator=(const binary_paths_manager& o);
00154
00155 void cleanup();
00156
00157 std::vector<std::string> paths_;
00158 };
00159
00160 void clear_binary_paths_cache();
00161
00162
00163
00164 const std::vector<std::string>& get_binary_paths(const std::string& type);
00165
00166
00167
00168 std::string get_binary_file_location(const std::string& type, const std::string& filename);
00169
00170 class scoped_istream {
00171 std::istream *stream;
00172 public:
00173 scoped_istream(std::istream *s): stream(s) {}
00174 scoped_istream& operator=(std::istream *);
00175 std::istream &operator*() { return *stream; }
00176 std::istream *operator->() { return stream; }
00177 ~scoped_istream();
00178 };
00179
00180 class scoped_ostream {
00181 std::ostream *stream;
00182 public:
00183 scoped_ostream(std::ostream *s): stream(s) {}
00184 scoped_ostream& operator=(std::ostream *);
00185 std::ostream &operator*() { return *stream; }
00186 std::ostream *operator->() { return stream; }
00187 ~scoped_ostream();
00188 };
00189
00190 #endif