Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef FILESYSTEM_HPP_INCLUDED
00022 #define FILESYSTEM_HPP_INCLUDED
00023
00024 #include <time.h>
00025
00026 #include <iosfwd>
00027 #include <string>
00028 #include <vector>
00029
00030 #include "exceptions.hpp"
00031
00032
00033 struct io_exception : public game::error {
00034 io_exception() : game::error("") {}
00035 io_exception(const std::string& msg) : game::error(msg) {}
00036 };
00037
00038 struct file_tree_checksum;
00039
00040 enum file_name_option { ENTIRE_FILE_PATH, FILE_NAME_ONLY };
00041 enum file_filter_option { NO_FILTER, SKIP_MEDIA_DIR, SKIP_PBL_FILES };
00042 enum file_reorder_option { DONT_REORDER, DO_REORDER };
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 void get_files_in_dir(const std::string &dir,
00055 std::vector<std::string>* files,
00056 std::vector<std::string>* dirs=NULL,
00057 file_name_option mode = FILE_NAME_ONLY,
00058 file_filter_option filter = NO_FILTER,
00059 file_reorder_option reorder = DONT_REORDER,
00060 file_tree_checksum* checksum = NULL);
00061
00062 std::string get_dir(const std::string &dir);
00063
00064
00065 std::string get_prefs_file();
00066 std::string get_default_prefs_file();
00067 std::string get_save_index_file();
00068 std::string get_saves_dir();
00069 std::string get_intl_dir();
00070 std::string get_screenshot_dir();
00071 std::string get_addon_campaigns_dir();
00072
00073
00074
00075
00076
00077 std::string get_next_filename(const std::string& name, const std::string& extension);
00078 void set_preferences_dir(std::string path);
00079
00080 const std::string &get_user_config_dir();
00081 const std::string &get_user_data_dir();
00082 const std::string &get_cache_dir();
00083
00084 std::string get_cwd();
00085 std::string get_exe_dir();
00086
00087 bool make_directory(const std::string& dirname);
00088 bool delete_directory(const std::string& dirname, const bool keep_pbl = false);
00089
00090 bool looks_like_pbl(const std::string& file);
00091
00092
00093
00094
00095
00096
00097
00098 std::string read_file(const std::string &fname);
00099 std::istream *istream_file(const std::string &fname);
00100 std::ostream *ostream_file(std::string const &fname);
00101
00102 void write_file(const std::string& fname, const std::string& data);
00103
00104 std::string read_map(const std::string& name);
00105
00106
00107
00108
00109
00110
00111
00112
00113 bool create_directory_if_missing(const std::string& dirname);
00114
00115
00116
00117
00118
00119
00120
00121 bool create_directory_if_missing_recursive(const std::string& dirname);
00122
00123
00124 bool is_directory(const std::string& fname);
00125
00126
00127 bool file_exists(const std::string& name);
00128
00129
00130 time_t file_create_time(const std::string& fname);
00131
00132
00133 bool is_gzip_file(const std::string& filename);
00134
00135 struct file_tree_checksum
00136 {
00137 file_tree_checksum();
00138 explicit file_tree_checksum(const class config& cfg);
00139 void write(class config& cfg) const;
00140 void reset() {nfiles = 0;modified = 0;sum_size=0;};
00141
00142 size_t nfiles, sum_size;
00143 time_t modified;
00144 bool operator==(const file_tree_checksum &rhs) const;
00145 bool operator!=(const file_tree_checksum &rhs) const
00146 { return !operator==(rhs); }
00147 };
00148
00149
00150 const file_tree_checksum& data_tree_checksum(bool reset = false);
00151
00152
00153 int file_size(const std::string& fname);
00154
00155 bool ends_with(const std::string& str, const std::string& suffix);
00156
00157
00158
00159
00160
00161 std::string file_name(const std::string& file);
00162
00163
00164
00165
00166
00167 std::string directory_name(const std::string& file);
00168
00169
00170
00171
00172 std::string normalize_path(const std::string &path);
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 struct binary_paths_manager
00187 {
00188 binary_paths_manager();
00189 binary_paths_manager(const class config& cfg);
00190 ~binary_paths_manager();
00191
00192 void set_paths(const class config& cfg);
00193
00194 private:
00195 binary_paths_manager(const binary_paths_manager& o);
00196 binary_paths_manager& operator=(const binary_paths_manager& o);
00197
00198 void cleanup();
00199
00200 std::vector<std::string> paths_;
00201 };
00202
00203 void clear_binary_paths_cache();
00204
00205
00206
00207
00208
00209 const std::vector<std::string>& get_binary_paths(const std::string& type);
00210
00211
00212
00213
00214
00215 std::string get_binary_file_location(const std::string& type, const std::string& filename);
00216
00217
00218
00219
00220
00221 std::string get_binary_dir_location(const std::string &type, const std::string &filename);
00222
00223
00224
00225
00226
00227 std::string get_wml_location(const std::string &filename,
00228 const std::string ¤t_dir = std::string());
00229
00230
00231
00232
00233 std::string get_short_wml_path(const std::string &filename);
00234
00235
00236
00237
00238
00239
00240
00241
00242 std::string get_independent_image_path(const std::string &filename);
00243
00244
00245
00246
00247
00248
00249
00250
00251 std::string get_program_invocation(const std::string &program_name);
00252
00253 class scoped_istream {
00254 std::istream *stream;
00255 public:
00256 scoped_istream(std::istream *s): stream(s) {}
00257 scoped_istream& operator=(std::istream *);
00258 std::istream &operator*() { return *stream; }
00259 std::istream *operator->() { return stream; }
00260 ~scoped_istream();
00261 };
00262
00263 class scoped_ostream {
00264 std::ostream *stream;
00265 public:
00266 scoped_ostream(std::ostream *s): stream(s) {}
00267 scoped_ostream& operator=(std::ostream *);
00268 std::ostream &operator*() { return *stream; }
00269 std::ostream *operator->() { return stream; }
00270 ~scoped_ostream();
00271 };
00272
00273 #endif