Move everything in src/filesystem.hpp into its own namespace
This is a chearry pick by me (gfgtdf) of 66176b1738
. It differes a lot from the original becasue since there were so much merging conflics i decided to do it mostly from scratch.
Conflicts:
src/addon/manager.cpp
src/addon/manager_ui.cpp
src/campaign_server/campaign_server.cpp
src/config_cache.cpp
src/create_engine.cpp
src/editor/map/context_manager.cpp
src/editor/map/map_context.cpp
src/font.cpp
src/game_config_manager.cpp
src/gamestatus.cpp
src/gui/dialogs/editor/custom_tod.cpp
src/gui/dialogs/lobby/lobby_data.cpp
src/gui/dialogs/mp_create_game.cpp
src/gui/widgets/settings.cpp
src/hotkeys.cpp
src/image.cpp
src/multiplayer_lobby.cpp
src/network.cpp
src/playcampaign.cpp
src/preferences.cpp
src/savegame.cpp
src/serialization/preprocessor.cpp
src/tests/main.cpp
src/wesnoth.cpp
src/widgets/button.cpp
This commit is contained in:
parent
5cfef2eee5
commit
e5cb79b8e9
65 changed files with 360 additions and 352 deletions
|
@ -58,41 +58,41 @@ static lg::log_domain log_network("network");
|
|||
namespace {
|
||||
std::string get_pbl_file_path(const std::string& addon_name)
|
||||
{
|
||||
const std::string& parentd = get_addon_campaigns_dir();
|
||||
const std::string& parentd = filesystem::get_addons_dir();
|
||||
// Cope with old-style or new-style file organization
|
||||
const std::string exterior = parentd + "/" + addon_name + ".pbl";
|
||||
const std::string interior = parentd + "/" + addon_name + "/_server.pbl";
|
||||
return file_exists(exterior) ? exterior : interior;
|
||||
return filesystem::file_exists(exterior) ? exterior : interior;
|
||||
}
|
||||
|
||||
inline std::string get_info_file_path(const std::string& addon_name)
|
||||
{
|
||||
return get_addon_campaigns_dir() + "/" + addon_name + "/_info.cfg";
|
||||
return filesystem::get_addons_dir() + "/" + addon_name + "/_info.cfg";
|
||||
}
|
||||
}
|
||||
|
||||
bool have_addon_in_vcs_tree(const std::string& addon_name)
|
||||
{
|
||||
static const std::string parentd = get_addon_campaigns_dir();
|
||||
static const std::string parentd = filesystem::get_addons_dir();
|
||||
return
|
||||
file_exists(parentd+"/"+addon_name+"/.svn") ||
|
||||
file_exists(parentd+"/"+addon_name+"/.git") ||
|
||||
file_exists(parentd+"/"+addon_name+"/.hg");
|
||||
filesystem::file_exists(parentd+"/"+addon_name+"/.svn") ||
|
||||
filesystem::file_exists(parentd+"/"+addon_name+"/.git") ||
|
||||
filesystem::file_exists(parentd+"/"+addon_name+"/.hg");
|
||||
}
|
||||
|
||||
bool have_addon_pbl_info(const std::string& addon_name)
|
||||
{
|
||||
static const std::string parentd = get_addon_campaigns_dir();
|
||||
static const std::string parentd = filesystem::get_addons_dir();
|
||||
return
|
||||
file_exists(parentd+"/"+addon_name+".pbl") ||
|
||||
file_exists(parentd+"/"+addon_name+"/_server.pbl");
|
||||
filesystem::file_exists(parentd+"/"+addon_name+".pbl") ||
|
||||
filesystem::file_exists(parentd+"/"+addon_name+"/_server.pbl");
|
||||
}
|
||||
|
||||
void get_addon_pbl_info(const std::string& addon_name, config& cfg)
|
||||
{
|
||||
const std::string& pbl_path = get_pbl_file_path(addon_name);
|
||||
try {
|
||||
scoped_istream stream = istream_file(pbl_path);
|
||||
filesystem::scoped_istream stream = filesystem::istream_file(pbl_path);
|
||||
read(cfg, *stream);
|
||||
} catch(const config::error& e) {
|
||||
throw invalid_pbl_exception(pbl_path, e.message);
|
||||
|
@ -101,19 +101,19 @@ void get_addon_pbl_info(const std::string& addon_name, config& cfg)
|
|||
|
||||
void set_addon_pbl_info(const std::string& addon_name, const config& cfg)
|
||||
{
|
||||
scoped_ostream stream = ostream_file(get_pbl_file_path(addon_name));
|
||||
filesystem::scoped_ostream stream = filesystem::ostream_file(get_pbl_file_path(addon_name));
|
||||
write(*stream, cfg);
|
||||
}
|
||||
|
||||
bool have_addon_install_info(const std::string& addon_name)
|
||||
{
|
||||
return file_exists(get_info_file_path(addon_name));
|
||||
return filesystem::file_exists(get_info_file_path(addon_name));
|
||||
}
|
||||
|
||||
void get_addon_install_info(const std::string& addon_name, config& cfg)
|
||||
{
|
||||
const std::string& info_path = get_info_file_path(addon_name);
|
||||
scoped_istream stream = istream_file(info_path);
|
||||
filesystem::scoped_istream stream = filesystem::istream_file(info_path);
|
||||
try {
|
||||
read(cfg, *stream);
|
||||
} catch(const config::error& e) {
|
||||
|
@ -126,16 +126,16 @@ void get_addon_install_info(const std::string& addon_name, config& cfg)
|
|||
bool remove_local_addon(const std::string& addon)
|
||||
{
|
||||
bool ret = true;
|
||||
const std::string addon_dir = get_addon_campaigns_dir() + "/" + addon;
|
||||
const std::string addon_dir = filesystem::get_addons_dir() + "/" + addon;
|
||||
|
||||
LOG_CFG << "removing local add-on: " << addon << '\n';
|
||||
|
||||
if(file_exists(addon_dir) && !delete_directory(addon_dir, true)) {
|
||||
if(filesystem::file_exists(addon_dir) && !filesystem::delete_directory(addon_dir, true)) {
|
||||
ERR_CFG << "Failed to delete directory/file: " << addon_dir << '\n';
|
||||
ret = false;
|
||||
}
|
||||
|
||||
if(file_exists(addon_dir + ".cfg") && !delete_directory(addon_dir + ".cfg", true)) {
|
||||
if(filesystem::file_exists(addon_dir + ".cfg") && !filesystem::delete_directory(addon_dir + ".cfg", true)) {
|
||||
ERR_CFG << "Failed to delete directory/file: " << addon_dir << ".cfg" << std::endl;
|
||||
ret = false;
|
||||
}
|
||||
|
@ -151,16 +151,16 @@ std::vector<std::string> available_addons()
|
|||
{
|
||||
std::vector<std::string> res;
|
||||
std::vector<std::string> files, dirs;
|
||||
const std::string parentd = get_addon_campaigns_dir();
|
||||
get_files_in_dir(parentd,&files,&dirs);
|
||||
const std::string parentd = filesystem::get_addons_dir();
|
||||
filesystem::get_files_in_dir(parentd,&files,&dirs);
|
||||
|
||||
for(std::vector<std::string>::const_iterator i = dirs.begin(); i != dirs.end(); ++i) {
|
||||
const std::string external_cfg_file = *i + ".cfg";
|
||||
const std::string internal_cfg_file = *i + "/_main.cfg";
|
||||
const std::string external_pbl_file = *i + ".pbl";
|
||||
const std::string internal_pbl_file = *i + "/_server.pbl";
|
||||
if((std::find(files.begin(),files.end(),external_cfg_file) != files.end() || file_exists(parentd + "/" + internal_cfg_file)) &&
|
||||
(std::find(files.begin(),files.end(),external_pbl_file) != files.end() || (file_exists(parentd + "/" + internal_pbl_file)))) {
|
||||
if((std::find(files.begin(),files.end(),external_cfg_file) != files.end() || filesystem::file_exists(parentd + "/" + internal_cfg_file)) &&
|
||||
(std::find(files.begin(),files.end(),external_pbl_file) != files.end() || (filesystem::file_exists(parentd + "/" + internal_pbl_file)))) {
|
||||
res.push_back(*i);
|
||||
}
|
||||
}
|
||||
|
@ -181,14 +181,14 @@ std::vector<std::string> available_addons()
|
|||
std::vector<std::string> installed_addons()
|
||||
{
|
||||
std::vector<std::string> res;
|
||||
const std::string parentd = get_addon_campaigns_dir();
|
||||
const std::string parentd = filesystem::get_addons_dir();
|
||||
std::vector<std::string> files, dirs;
|
||||
get_files_in_dir(parentd,&files,&dirs);
|
||||
filesystem::get_files_in_dir(parentd,&files,&dirs);
|
||||
|
||||
for(std::vector<std::string>::const_iterator i = dirs.begin(); i != dirs.end(); ++i) {
|
||||
const std::string external_cfg_file = *i + ".cfg";
|
||||
const std::string internal_cfg_file = *i + "/_main.cfg";
|
||||
if(std::find(files.begin(),files.end(),external_cfg_file) != files.end() || file_exists(parentd + "/" + internal_cfg_file)) {
|
||||
if(std::find(files.begin(),files.end(),external_cfg_file) != files.end() || filesystem::file_exists(parentd + "/" + internal_cfg_file)) {
|
||||
res.push_back(*i);
|
||||
}
|
||||
}
|
||||
|
@ -198,9 +198,9 @@ std::vector<std::string> installed_addons()
|
|||
|
||||
bool is_addon_installed(const std::string& addon_name)
|
||||
{
|
||||
const std::string namestem = get_addon_campaigns_dir() + "/" + addon_name;
|
||||
const std::string namestem = filesystem::get_addons_dir() + "/" + addon_name;
|
||||
|
||||
return file_exists(namestem + ".cfg") || file_exists(namestem + "/_main.cfg");
|
||||
return filesystem::file_exists(namestem + ".cfg") || filesystem::file_exists(namestem + "/_main.cfg");
|
||||
}
|
||||
|
||||
static inline bool IsCR(const char& c)
|
||||
|
@ -256,16 +256,16 @@ namespace {
|
|||
|
||||
static std::pair<std::vector<std::string>, std::vector<std::string> > read_ignore_patterns(const std::string& addon_name)
|
||||
{
|
||||
const std::string parentd = get_addon_campaigns_dir();
|
||||
const std::string parentd = filesystem::get_addons_dir();
|
||||
const std::string exterior = parentd + "/" + addon_name + ".ign";
|
||||
const std::string interior = parentd + "/" + addon_name + "/_server.ign";
|
||||
|
||||
std::pair<std::vector<std::string>, std::vector<std::string> > patterns;
|
||||
std::string ign_file;
|
||||
LOG_CFG << "searching for .ign file for '" << addon_name << "'...\n";
|
||||
if (file_exists(interior)) {
|
||||
if (filesystem::file_exists(interior)) {
|
||||
ign_file = interior;
|
||||
} else if (file_exists(exterior)) {
|
||||
} else if (filesystem::file_exists(exterior)) {
|
||||
ign_file = exterior;
|
||||
} else {
|
||||
LOG_CFG << "no .ign file found for '" << addon_name << "'\n"
|
||||
|
@ -274,7 +274,7 @@ static std::pair<std::vector<std::string>, std::vector<std::string> > read_ignor
|
|||
return patterns; // just default patterns
|
||||
}
|
||||
LOG_CFG << "found .ign file: " << ign_file << '\n';
|
||||
std::istream *stream = istream_file(ign_file);
|
||||
std::istream *stream = filesystem::istream_file(ign_file);
|
||||
std::string line;
|
||||
while (std::getline(*stream, line)) {
|
||||
utils::strip(line);
|
||||
|
@ -292,7 +292,7 @@ static void archive_file(const std::string& path, const std::string& fname, conf
|
|||
{
|
||||
cfg["name"] = fname;
|
||||
const bool is_cfg = (fname.size() > 4 ? (fname.substr(fname.size() - 4) == ".cfg") : false);
|
||||
cfg["contents"] = encode_binary(strip_cr(read_file(path + '/' + fname),is_cfg));
|
||||
cfg["contents"] = encode_binary(strip_cr(filesystem::read_file(path + '/' + fname),is_cfg));
|
||||
}
|
||||
|
||||
static void archive_dir(const std::string& path, const std::string& dirname, config& cfg, std::pair<std::vector<std::string>, std::vector<std::string> >& ignore_patterns)
|
||||
|
@ -301,9 +301,9 @@ static void archive_dir(const std::string& path, const std::string& dirname, con
|
|||
const std::string dir = path + '/' + dirname;
|
||||
|
||||
std::vector<std::string> files, dirs;
|
||||
get_files_in_dir(dir,&files,&dirs);
|
||||
filesystem::get_files_in_dir(dir,&files,&dirs);
|
||||
for(std::vector<std::string>::const_iterator i = files.begin(); i != files.end(); ++i) {
|
||||
bool valid = !looks_like_pbl(*i);
|
||||
bool valid = !filesystem::looks_like_pbl(*i);
|
||||
for(std::vector<std::string>::const_iterator p = ignore_patterns.first.begin(); p != ignore_patterns.first.end(); ++p) {
|
||||
if (utils::wildcard_string_match(*i, *p)) {
|
||||
valid = false;
|
||||
|
@ -331,12 +331,12 @@ static void archive_dir(const std::string& path, const std::string& dirname, con
|
|||
|
||||
void archive_addon(const std::string& addon_name, config& cfg)
|
||||
{
|
||||
const std::string parentd = get_addon_campaigns_dir();
|
||||
const std::string parentd = filesystem::get_addons_dir();
|
||||
|
||||
std::pair<std::vector<std::string>, std::vector<std::string> > ignore_patterns;
|
||||
// External .cfg may not exist; newer campaigns have a _main.cfg
|
||||
const std::string external_cfg = addon_name + ".cfg";
|
||||
if (file_exists(parentd + "/" + external_cfg)) {
|
||||
if (filesystem::file_exists(parentd + "/" + external_cfg)) {
|
||||
archive_file(parentd, external_cfg, cfg.add_child("file"));
|
||||
}
|
||||
ignore_patterns = read_ignore_patterns(addon_name);
|
||||
|
@ -345,7 +345,7 @@ void archive_addon(const std::string& addon_name, config& cfg)
|
|||
|
||||
static void unarchive_file(const std::string& path, const config& cfg)
|
||||
{
|
||||
write_file(path + '/' + cfg["name"].str(), unencode_binary(cfg["contents"]));
|
||||
filesystem::write_file(path + '/' + cfg["name"].str(), unencode_binary(cfg["contents"]));
|
||||
}
|
||||
|
||||
static void unarchive_dir(const std::string& path, const config& cfg)
|
||||
|
@ -356,7 +356,7 @@ static void unarchive_dir(const std::string& path, const config& cfg)
|
|||
else
|
||||
dir = path + '/' + cfg["name"].str();
|
||||
|
||||
make_directory(dir);
|
||||
filesystem::make_directory(dir);
|
||||
|
||||
BOOST_FOREACH(const config &d, cfg.child_range("dir")) {
|
||||
unarchive_dir(dir, d);
|
||||
|
@ -369,7 +369,7 @@ static void unarchive_dir(const std::string& path, const config& cfg)
|
|||
|
||||
void unarchive_addon(const config& cfg)
|
||||
{
|
||||
const std::string parentd = get_addon_campaigns_dir();
|
||||
const std::string parentd = filesystem::get_addons_dir();
|
||||
unarchive_dir(parentd, cfg);
|
||||
}
|
||||
|
||||
|
@ -399,7 +399,7 @@ void refresh_addon_version_info_cache()
|
|||
const std::string& addon = addons[i];
|
||||
const std::string& info_file = addon_info_files[i];
|
||||
|
||||
if(file_exists(info_file)) {
|
||||
if(filesystem::file_exists(info_file)) {
|
||||
config cfg;
|
||||
get_addon_install_info(addon, cfg);
|
||||
|
||||
|
|
|
@ -992,8 +992,8 @@ bool addons_manager_ui(display& disp, const std::string& remote_address)
|
|||
} catch(const network_asio::error& e) {
|
||||
ERR_NET << "network_asio::error thrown during transaction with add-on server; \""<< e.what() << "\"" << std::endl;
|
||||
gui2::show_error_message(disp.video(), _("Remote host disconnected."));
|
||||
} catch(const io_exception& e) {
|
||||
ERR_FS << "io_exception thrown while installing an addon; \"" << e.what() << "\"" << std::endl;
|
||||
} catch(const filesystem::io_exception& e) {
|
||||
ERR_FS << "filesystem::io_exception thrown while installing an addon; \"" << e.what() << "\"" << std::endl;
|
||||
gui2::show_error_message(disp.video(), _("A problem occurred when trying to create the files necessary to install this add-on."));
|
||||
} catch(const invalid_pbl_exception& e) {
|
||||
ERR_CFG << "could not read .pbl file " << e.path << ": " << e.message << std::endl;
|
||||
|
|
|
@ -204,7 +204,7 @@ config configuration::default_config_ = config();
|
|||
|
||||
bool configuration::get_side_config_from_file(const std::string& file, config& cfg ){
|
||||
try {
|
||||
scoped_istream stream = preprocess_file(get_wml_location(file));
|
||||
filesystem::scoped_istream stream = preprocess_file(filesystem::get_wml_location(file));
|
||||
read(cfg, *stream);
|
||||
LOG_AI_CONFIGURATION << "Reading AI configuration from file '" << file << "'" << std::endl;
|
||||
} catch(config::error &) {
|
||||
|
|
|
@ -500,13 +500,13 @@ private:
|
|||
const std::string filename = var0.string_cast();
|
||||
|
||||
//NOTE: get_wml_location also filters file path to ensure it doesn't contain things like "../../top/secret"
|
||||
std::string path = get_wml_location(filename);
|
||||
std::string path = filesystem::get_wml_location(filename);
|
||||
if(path.empty()) {
|
||||
ERR_AI << "run_file : not found [" << filename <<"]"<< std::endl;
|
||||
return variant(); //no suitable file
|
||||
}
|
||||
|
||||
std::string formula_string = read_file(path);
|
||||
std::string formula_string = filesystem::read_file(path);
|
||||
//need to get function_table from somewhere or delegate to someone who has access to it
|
||||
formula_ptr parsed_formula = ai_.create_optional_formula(formula_string);
|
||||
if(parsed_formula == game_logic::formula_ptr()) {
|
||||
|
|
|
@ -124,7 +124,7 @@ void add_license(config& cfg)
|
|||
}
|
||||
|
||||
// Copy over COPYING.txt
|
||||
const std::string& contents = read_file("COPYING.txt");
|
||||
const std::string& contents = filesystem::read_file("COPYING.txt");
|
||||
if (contents.empty()) {
|
||||
LOG_CS << "Could not find COPYING.txt, path is \"" << game_config::path << "\"\n";
|
||||
return;
|
||||
|
|
|
@ -118,7 +118,7 @@ server::~server()
|
|||
|
||||
int server::load_config()
|
||||
{
|
||||
scoped_istream in = istream_file(cfg_file_);
|
||||
filesystem::scoped_istream in = filesystem::istream_file(cfg_file_);
|
||||
read(cfg_, *in);
|
||||
|
||||
read_only_ = cfg_["read_only"].to_bool(false);
|
||||
|
@ -171,7 +171,7 @@ void server::load_blacklist()
|
|||
}
|
||||
|
||||
try {
|
||||
scoped_istream in = istream_file(blacklist_file_);
|
||||
filesystem::scoped_istream in = filesystem::istream_file(blacklist_file_);
|
||||
config blcfg;
|
||||
|
||||
read(blcfg, *in);
|
||||
|
@ -185,7 +185,7 @@ void server::load_blacklist()
|
|||
|
||||
void server::write_config()
|
||||
{
|
||||
scoped_ostream out = ostream_file(cfg_file_);
|
||||
filesystem::scoped_ostream out = filesystem::ostream_file(cfg_file_);
|
||||
write(*out, cfg_);
|
||||
}
|
||||
|
||||
|
@ -444,7 +444,7 @@ void server::handle_request_campaign(const server::request& req)
|
|||
if(!campaign) {
|
||||
send_error("Add-on '" + req.cfg["name"].str() + "' not found.", req.sock);
|
||||
} else {
|
||||
const int size = file_size(campaign["filename"]);
|
||||
const int size = filesystem::file_size(campaign["filename"]);
|
||||
|
||||
if(size < 0) {
|
||||
std::cerr << " size: <unknown> KiB\n";
|
||||
|
@ -613,12 +613,12 @@ void server::handle_upload(const server::request& req)
|
|||
add_license(data);
|
||||
|
||||
{
|
||||
scoped_ostream campaign_file = ostream_file(filename);
|
||||
filesystem::scoped_ostream campaign_file = filesystem::ostream_file(filename);
|
||||
config_writer writer(*campaign_file, true, compress_level_);
|
||||
writer.write(data);
|
||||
}
|
||||
|
||||
(*campaign)["size"] = file_size(filename);
|
||||
(*campaign)["size"] = filesystem::file_size(filename);
|
||||
|
||||
write_config();
|
||||
|
||||
|
@ -656,7 +656,7 @@ void server::handle_delete(const server::request& req)
|
|||
}
|
||||
|
||||
// Erase the campaign.
|
||||
write_file(campaign["filename"], std::string());
|
||||
filesystem::write_file(campaign["filename"], std::string());
|
||||
if(remove(campaign["filename"].str().c_str()) != 0) {
|
||||
ERR_CS << "failed to delete archive for campaign '" << erase["name"]
|
||||
<< "' (" << campaign["filename"] << "): " << strerror(errno)
|
||||
|
@ -711,7 +711,7 @@ void server::handle_change_passphrase(const server::request& req)
|
|||
|
||||
int main(int argc, char**argv)
|
||||
{
|
||||
game_config::path = get_cwd();
|
||||
game_config::path = filesystem::get_cwd();
|
||||
|
||||
lg::set_log_domain_severity("campaignd", lg::info);
|
||||
lg::timestamps(true);
|
||||
|
@ -719,7 +719,7 @@ int main(int argc, char**argv)
|
|||
try {
|
||||
printf("argc %d argv[0] %s 1 %s\n",argc,argv[0],argv[1]);
|
||||
|
||||
const std::string& cfg_path = normalize_path("server.cfg");
|
||||
const std::string& cfg_path = filesystem::normalize_path("server.cfg");
|
||||
|
||||
if(argc >= 2 && atoi(argv[1])){
|
||||
campaignd::server(cfg_path, atoi(argv[1])).run();
|
||||
|
@ -729,7 +729,7 @@ int main(int argc, char**argv)
|
|||
} catch(config::error& /*e*/) {
|
||||
std::cerr << "Could not parse config file\n";
|
||||
return 1;
|
||||
} catch(io_exception& /*e*/) {
|
||||
} catch(filesystem::io_exception& /*e*/) {
|
||||
std::cerr << "File I/O error\n";
|
||||
return 2;
|
||||
} catch(network::error& e) {
|
||||
|
|
|
@ -97,7 +97,7 @@ namespace game_config {
|
|||
|
||||
void config_cache::write_file(std::string path, const config& cfg)
|
||||
{
|
||||
scoped_ostream stream = ostream_file(path);
|
||||
filesystem::scoped_ostream stream = filesystem::ostream_file(path);
|
||||
const bool gzip = true;
|
||||
config_writer writer(*stream, gzip, game_config::cache_compression_level);
|
||||
writer.write(cfg);
|
||||
|
@ -106,13 +106,13 @@ namespace game_config {
|
|||
{
|
||||
if (defines_map.empty())
|
||||
{
|
||||
if (file_exists(path))
|
||||
if (filesystem::file_exists(path))
|
||||
{
|
||||
delete_directory(path);
|
||||
filesystem::delete_directory(path);
|
||||
}
|
||||
return;
|
||||
}
|
||||
scoped_ostream stream = ostream_file(path);
|
||||
filesystem::scoped_ostream stream = filesystem::ostream_file(path);
|
||||
const bool gzip = true;
|
||||
config_writer writer(*stream, gzip, game_config::cache_compression_level);
|
||||
|
||||
|
@ -124,7 +124,7 @@ namespace game_config {
|
|||
|
||||
void config_cache::read_file(const std::string& path, config& cfg)
|
||||
{
|
||||
scoped_istream stream = istream_file(path);
|
||||
filesystem::scoped_istream stream = filesystem::istream_file(path);
|
||||
read_gz(cfg, *stream);
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,7 @@ namespace game_config {
|
|||
void config_cache::read_configs(const std::string& path, config& cfg, preproc_map& defines_map)
|
||||
{
|
||||
//read the file and then write to the cache
|
||||
scoped_istream stream = preprocess_file(path, &defines_map);
|
||||
filesystem::scoped_istream stream = preprocess_file(path, &defines_map);
|
||||
read(cfg, *stream);
|
||||
}
|
||||
|
||||
|
@ -181,26 +181,26 @@ namespace game_config {
|
|||
// Do cache check only if define map is valid and
|
||||
// caching is allowed
|
||||
if(is_valid) {
|
||||
const std::string& cache = get_cache_dir();
|
||||
const std::string& cache = filesystem::get_cache_dir();
|
||||
if(cache != "") {
|
||||
sha1_hash sha(defines_string.str()); // use a hash for a shorter display of the defines
|
||||
const std::string fname = cache + "/" +
|
||||
cache_file_prefix_ + sha.display();
|
||||
const std::string fname_checksum = fname + ".checksum" + extension;
|
||||
|
||||
file_tree_checksum dir_checksum;
|
||||
filesystem::file_tree_checksum dir_checksum;
|
||||
|
||||
if(!force_valid_cache_ && !fake_invalid_cache_) {
|
||||
try {
|
||||
if(file_exists(fname_checksum)) {
|
||||
if(filesystem::file_exists(fname_checksum)) {
|
||||
DBG_CACHE << "Reading checksum: " << fname_checksum << "\n";
|
||||
config checksum_cfg;
|
||||
read_file(fname_checksum, checksum_cfg);
|
||||
dir_checksum = file_tree_checksum(checksum_cfg);
|
||||
dir_checksum = filesystem::file_tree_checksum(checksum_cfg);
|
||||
}
|
||||
} catch(config::error&) {
|
||||
ERR_CACHE << "cache checksum is corrupt" << std::endl;
|
||||
} catch(io_exception&) {
|
||||
} catch(filesystem::io_exception&) {
|
||||
ERR_CACHE << "error reading cache checksum" << std::endl;
|
||||
}
|
||||
}
|
||||
|
@ -209,20 +209,20 @@ namespace game_config {
|
|||
LOG_CACHE << "skipping cache validation (forced)\n";
|
||||
}
|
||||
|
||||
if(file_exists(fname + extension) && (force_valid_cache_ || (dir_checksum == data_tree_checksum()))) {
|
||||
if(filesystem::file_exists(fname + extension) && (force_valid_cache_ || (dir_checksum == filesystem::data_tree_checksum()))) {
|
||||
LOG_CACHE << "found valid cache at '" << fname << extension << "' with defines_map " << defines_string.str() << "\n";
|
||||
log_scope("read cache");
|
||||
try {
|
||||
read_file(fname + extension,cfg);
|
||||
const std::string define_file = fname + ".define" + extension;
|
||||
if (file_exists(define_file))
|
||||
if (filesystem::file_exists(define_file))
|
||||
{
|
||||
config_cache_transaction::instance().add_define_file(define_file);
|
||||
}
|
||||
return;
|
||||
} catch(config::error& e) {
|
||||
ERR_CACHE << "cache " << fname << extension << " is corrupt. Loading from files: "<< e.message<< std::endl;
|
||||
} catch(io_exception&) {
|
||||
} catch(filesystem::io_exception&) {
|
||||
ERR_CACHE << "error reading cache " << fname << extension << ". Loading from files" << std::endl;
|
||||
} catch (boost::iostreams::gzip_error& e) {
|
||||
//read_file -> ... -> read_gz can throw this exception.
|
||||
|
@ -244,9 +244,9 @@ namespace game_config {
|
|||
write_file(fname + extension, cfg);
|
||||
write_file(fname + ".define" + extension, copy_map);
|
||||
config checksum_cfg;
|
||||
data_tree_checksum().write(checksum_cfg);
|
||||
filesystem::data_tree_checksum().write(checksum_cfg);
|
||||
write_file(fname_checksum, checksum_cfg);
|
||||
} catch(io_exception&) {
|
||||
} catch(filesystem::io_exception&) {
|
||||
ERR_CACHE << "could not write to cache '" << fname << "'" << std::endl;
|
||||
}
|
||||
return;
|
||||
|
@ -313,7 +313,7 @@ namespace game_config {
|
|||
|
||||
void config_cache::recheck_filetree_checksum()
|
||||
{
|
||||
data_tree_checksum(true);
|
||||
filesystem::data_tree_checksum(true);
|
||||
}
|
||||
|
||||
void config_cache::add_define(const std::string& define)
|
||||
|
@ -343,7 +343,7 @@ namespace game_config {
|
|||
bool config_cache::clean_cache()
|
||||
{
|
||||
std::vector<std::string> files, dirs;
|
||||
get_files_in_dir(get_cache_dir(), &files, &dirs, ENTIRE_FILE_PATH);
|
||||
filesystem::get_files_in_dir(filesystem::get_cache_dir(), &files, &dirs, filesystem::ENTIRE_FILE_PATH);
|
||||
|
||||
LOG_CACHE << "clean_cache(): " << files.size() << " files, "
|
||||
<< dirs.size() << " dirs to check\n";
|
||||
|
@ -363,7 +363,7 @@ namespace game_config {
|
|||
bool config_cache::purge_cache()
|
||||
{
|
||||
std::vector<std::string> files, dirs;
|
||||
get_files_in_dir(get_cache_dir(), &files, &dirs, ENTIRE_FILE_PATH);
|
||||
filesystem::get_files_in_dir(filesystem::get_cache_dir(), &files, &dirs, filesystem::ENTIRE_FILE_PATH);
|
||||
|
||||
LOG_CACHE << "purge_cache(): deleting " << files.size() << " files, "
|
||||
<< dirs.size() << " dirs\n";
|
||||
|
@ -386,7 +386,7 @@ namespace game_config {
|
|||
BOOST_FOREACH(const std::string& path, paths)
|
||||
{
|
||||
if(!delete_everything) {
|
||||
const std::string& fn = file_name(path);
|
||||
const std::string& fn = filesystem::file_name(path);
|
||||
|
||||
if(utils::wildcard_string_match(fn, exclude_pattern)) {
|
||||
LOG_CACHE << "delete_cache_files(): skipping " << path
|
||||
|
@ -396,7 +396,7 @@ namespace game_config {
|
|||
}
|
||||
|
||||
LOG_CACHE << "delete_cache_files(): deleting " << path << '\n';
|
||||
if(!delete_directory(path)) {
|
||||
if(!filesystem::delete_directory(path)) {
|
||||
ERR_CACHE << "delete_cache_files(): could not delete "
|
||||
<< path << '\n';
|
||||
status = false;
|
||||
|
|
|
@ -386,11 +386,11 @@ create_engine::create_engine(game_display& disp, saved_game& state) :
|
|||
}
|
||||
|
||||
//TODO the editor dir is already configurable, is the preferences value
|
||||
get_files_in_dir(get_user_data_dir() + "/editor/maps", &user_map_names_,
|
||||
NULL, FILE_NAME_ONLY);
|
||||
filesystem::get_files_in_dir(filesystem::get_user_data_dir() + "/editor/maps", &user_map_names_,
|
||||
NULL, filesystem::FILE_NAME_ONLY);
|
||||
|
||||
get_files_in_dir(get_user_data_dir() + "/editor/scenarios", &user_scenario_names_,
|
||||
NULL, FILE_NAME_ONLY);
|
||||
filesystem::get_files_in_dir(filesystem::get_user_data_dir() + "/editor/scenarios", &user_scenario_names_,
|
||||
NULL, filesystem::FILE_NAME_ONLY);
|
||||
|
||||
DBG_MP << "initializing all levels, eras and mods\n";
|
||||
|
||||
|
@ -921,7 +921,7 @@ void create_engine::init_all_levels()
|
|||
for(size_t i = 0; i < user_map_names_.size(); i++)
|
||||
{
|
||||
config user_map_data = gen_mp_data;
|
||||
user_map_data["map_data"] = read_map(user_map_names_[i]);
|
||||
user_map_data["map_data"] = filesystem::read_map(user_map_names_[i]);
|
||||
|
||||
// Check if a file is actually a map.
|
||||
// Note that invalid maps should be displayed in order to
|
||||
|
@ -963,10 +963,10 @@ void create_engine::init_all_levels()
|
|||
{
|
||||
config data;
|
||||
try {
|
||||
read(data, *(preprocess_file(get_user_data_dir() + "/editor/scenarios/" + user_scenario_names_[i])));
|
||||
read(data, *(preprocess_file(filesystem::get_user_data_dir() + "/editor/scenarios/" + user_scenario_names_[i])));
|
||||
} catch (config::error & e) {
|
||||
ERR_CF << "Caught a config error while parsing user made (editor) scenarios:\n" << e.message << std::endl;
|
||||
ERR_CF << "Skipping file: " << (get_user_data_dir() + "/editor/scenarios/" + user_scenario_names_[i]) << std::endl;
|
||||
ERR_CF << "Skipping file: " << (filesystem::get_user_data_dir() + "/editor/scenarios/" + user_scenario_names_[i]) << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -147,8 +147,8 @@ uint32_t send_dbus_notification(DBusConnection *connection, uint32_t replaces_id
|
|||
DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
std::string app_icon_ = normalize_path(game_config::path + "/" + game_config::images::app_icon);
|
||||
if (!file_exists(app_icon_)) {
|
||||
std::string app_icon_ = filesystem::normalize_path(game_config::path + "/" + game_config::images::app_icon);
|
||||
if (!filesystem::file_exists(app_icon_)) {
|
||||
ERR_DU << "Error: Could not find notification icon.\n"
|
||||
<< "raw path =\'" << game_config::path << "\' / \'" << game_config::images::app_icon << "\'\n"
|
||||
<< "normalized path =\'" << app_icon_ << "\'\n";
|
||||
|
|
|
@ -740,8 +740,8 @@ void save_preview_pane::draw_contents()
|
|||
map_data = scenario["map_data"].str();
|
||||
if (map_data.empty() && scenario.has_attribute("map")) {
|
||||
try {
|
||||
map_data = read_map(scenario["map"]);
|
||||
} catch(io_exception& e) {
|
||||
map_data = filesystem::read_map(scenario["map"]);
|
||||
} catch(filesystem::io_exception& e) {
|
||||
ERR_G << "could not read map '" << scenario["map"] << "': " << e.what() << '\n';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ EXIT_STATUS start(const config& game_conf, CVideo& video, const std::string& fil
|
|||
hotkey::set_scope_active(hotkey::SCOPE_EDITOR);
|
||||
editor_controller editor(game_conf, video);
|
||||
if (!filename.empty()) {
|
||||
if (is_directory(filename)) {
|
||||
if (filesystem::is_directory(filename)) {
|
||||
editor.context_manager_->set_default_dir(filename);
|
||||
editor.context_manager_->load_map_dialog(true);
|
||||
} else {
|
||||
|
|
|
@ -146,7 +146,7 @@ context_manager::context_manager(editor_display& gui, const config& game_config)
|
|||
, clipboard_()
|
||||
{
|
||||
if (default_dir_.empty()) {
|
||||
default_dir_ = get_dir(get_user_data_dir() + "/editor");
|
||||
default_dir_ = filesystem::get_dir(filesystem::get_user_data_dir() + "/editor");
|
||||
}
|
||||
create_default_context();
|
||||
init_map_generators(game_config);
|
||||
|
@ -178,7 +178,7 @@ void context_manager::set_default_dir(const std::string& str)
|
|||
|
||||
void context_manager::load_map_dialog(bool force_same_context /* = false */)
|
||||
{
|
||||
std::string fn = directory_name(get_map_context().get_filename());
|
||||
std::string fn = filesystem::directory_name(get_map_context().get_filename());
|
||||
if (fn.empty()) {
|
||||
fn = default_dir_;
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ void context_manager::edit_side_dialog(int side)
|
|||
void context_manager::edit_scenario_dialog()
|
||||
{
|
||||
// TODO
|
||||
//std::string fn = directory_name(get_map_context().get_filename());
|
||||
//std::string fn = filesystem::directory_name(get_map_context().get_filename());
|
||||
|
||||
std::string id = get_map_context().get_id();
|
||||
std::string name = get_map_context().get_name();
|
||||
|
@ -570,7 +570,7 @@ void context_manager::save_map_as_dialog()
|
|||
{
|
||||
std::string input_name = get_map_context().get_filename();
|
||||
if (input_name.empty()) {
|
||||
input_name = get_dir(default_dir_ + "/maps");
|
||||
input_name = filesystem::get_dir(default_dir_ + "/maps");
|
||||
}
|
||||
const std::string old_input_name = input_name;
|
||||
|
||||
|
@ -579,7 +579,7 @@ void context_manager::save_map_as_dialog()
|
|||
input_name = old_input_name;
|
||||
int res = dialogs::show_file_chooser_dialog_save(gui_, input_name, _("Save the Map As"), ".map");
|
||||
if (res == 0) {
|
||||
if (file_exists(input_name)) {
|
||||
if (filesystem::file_exists(input_name)) {
|
||||
res = gui2::show_message(gui_.video(), "",
|
||||
_("The file already exists. Do you want to overwrite it?"), gui2::tmessage::yes_no_buttons);
|
||||
overwrite_res = gui2::twindow::CANCEL == res ? 1 : 0;
|
||||
|
@ -598,7 +598,7 @@ void context_manager::save_scenario_as_dialog()
|
|||
{
|
||||
std::string input_name = get_map_context().get_filename();
|
||||
if (input_name.empty()) {
|
||||
input_name = get_dir(default_dir_ + "/scenarios");
|
||||
input_name = filesystem::get_dir(default_dir_ + "/scenarios");
|
||||
}
|
||||
const std::string old_input_name = input_name;
|
||||
|
||||
|
@ -607,7 +607,7 @@ void context_manager::save_scenario_as_dialog()
|
|||
input_name = old_input_name;
|
||||
int res = dialogs::show_file_chooser_dialog_save(gui_, input_name, _("Save the Scenario As"), ".cfg");
|
||||
if (res == 0) {
|
||||
if (file_exists(input_name)) {
|
||||
if (filesystem::file_exists(input_name)) {
|
||||
res = gui2::show_message(gui_.video(), "",
|
||||
_("The file already exists. Do you want to overwrite it?"), gui2::tmessage::yes_no_buttons);
|
||||
overwrite_res = gui2::twindow::CANCEL == res ? 1 : 0;
|
||||
|
@ -735,7 +735,7 @@ void context_manager::save_all_maps(bool auto_save_windows)
|
|||
switch_context(i);
|
||||
std::string name = get_map_context().get_filename();
|
||||
if(auto_save_windows) {
|
||||
if(name.empty() || is_directory(name)) {
|
||||
if(name.empty() || filesystem::is_directory(name)) {
|
||||
std::ostringstream s;
|
||||
s << default_dir_ << "/" << "window_" << i;
|
||||
name = s.str();
|
||||
|
@ -751,7 +751,7 @@ void context_manager::save_all_maps(bool auto_save_windows)
|
|||
void context_manager::save_map()
|
||||
{
|
||||
const std::string& name = get_map_context().get_filename();
|
||||
if (name.empty() || is_directory(name)) {
|
||||
if (name.empty() || filesystem::is_directory(name)) {
|
||||
if (get_map_context().is_pure_map())
|
||||
save_map_as_dialog();
|
||||
else
|
||||
|
|
|
@ -127,10 +127,10 @@ map_context::map_context(const config& game_config, const std::string& filename,
|
|||
log_scope2(log_editor, "Loading file " + filename);
|
||||
|
||||
// 0.1 File not found
|
||||
if (!file_exists(filename) || is_directory(filename))
|
||||
if (!filesystem::file_exists(filename) || filesystem::is_directory(filename))
|
||||
throw editor_map_load_exception(filename, _("File not found"));
|
||||
|
||||
std::string file_string = read_file(filename);
|
||||
std::string file_string = filesystem::read_file(filename);
|
||||
|
||||
// 0.2 Map file empty
|
||||
if (file_string.empty()) {
|
||||
|
@ -177,8 +177,8 @@ map_context::map_context(const config& game_config, const std::string& filename,
|
|||
// 3.0 Macro referenced pure map
|
||||
const std::string& macro_argument = matched_macro[1];
|
||||
LOG_ED << "Map looks like a scenario, trying {" << macro_argument << "}" << std::endl;
|
||||
std::string new_filename = get_wml_location(macro_argument,
|
||||
directory_name(macro_argument));
|
||||
std::string new_filename = filesystem::get_wml_location(macro_argument,
|
||||
filesystem::directory_name(macro_argument));
|
||||
if (new_filename.empty()) {
|
||||
std::string message = _("The map file looks like a scenario, "
|
||||
"but the map_data value does not point to an existing file")
|
||||
|
@ -187,7 +187,7 @@ map_context::map_context(const config& game_config, const std::string& filename,
|
|||
}
|
||||
LOG_ED << "New filename is: " << new_filename << std::endl;
|
||||
filename_ = new_filename;
|
||||
file_string = read_file(filename_);
|
||||
file_string = filesystem::read_file(filename_);
|
||||
map_ = editor_map::from_string(game_config, file_string);
|
||||
pure_map_ = true;
|
||||
}
|
||||
|
@ -504,7 +504,7 @@ bool map_context::save_scenario()
|
|||
assert(!is_embedded());
|
||||
|
||||
if (scenario_id_.empty())
|
||||
scenario_id_ = file_name(filename_);
|
||||
scenario_id_ = filesystem::file_name(filename_);
|
||||
if (scenario_name_.empty())
|
||||
scenario_name_ = scenario_id_;
|
||||
|
||||
|
@ -515,9 +515,9 @@ bool map_context::save_scenario()
|
|||
out.write(to_config());
|
||||
}
|
||||
if (!wml_stream.str().empty())
|
||||
write_file(get_filename(), wml_stream.str());
|
||||
filesystem::write_file(get_filename(), wml_stream.str());
|
||||
clear_modified();
|
||||
} catch (io_exception& e) {
|
||||
} catch (filesystem::io_exception& e) {
|
||||
utils::string_map symbols;
|
||||
symbols["msg"] = e.what();
|
||||
const std::string msg = vgettext("Could not save the scenario: $msg", symbols);
|
||||
|
@ -534,9 +534,9 @@ bool map_context::save_map()
|
|||
|
||||
try {
|
||||
if (!is_embedded()) {
|
||||
write_file(get_filename(), map_data);
|
||||
filesystem::write_file(get_filename(), map_data);
|
||||
} else {
|
||||
std::string map_string = read_file(get_filename());
|
||||
std::string map_string = filesystem::read_file(get_filename());
|
||||
boost::regex rexpression_map_data("(.*map_data\\s*=\\s*\")(.+?)(\".*)");
|
||||
boost::smatch matched_map_data;
|
||||
if (boost::regex_search(map_string, matched_map_data, rexpression_map_data,
|
||||
|
@ -545,13 +545,13 @@ bool map_context::save_map()
|
|||
ss << matched_map_data[1];
|
||||
ss << map_data;
|
||||
ss << matched_map_data[3];
|
||||
write_file(get_filename(), ss.str());
|
||||
filesystem::write_file(get_filename(), ss.str());
|
||||
} else {
|
||||
throw editor_map_save_exception(_("Could not save into scenario"));
|
||||
}
|
||||
}
|
||||
clear_modified();
|
||||
} catch (io_exception& e) {
|
||||
} catch (filesystem::io_exception& e) {
|
||||
utils::string_map symbols;
|
||||
symbols["msg"] = e.what();
|
||||
const std::string msg = vgettext("Could not save the map: $msg", symbols);
|
||||
|
|
|
@ -63,7 +63,7 @@ void editor_palette<Item>::expand_palette_groups_menu(std::vector<std::string>&
|
|||
str << IMAGE_PREFIX << item_groups[mci].icon;
|
||||
if (mci == active_group_index()) {
|
||||
|
||||
if (file_exists(str.str() + "_30-pressed.png" ) ) {
|
||||
if (filesystem::file_exists(str.str() + "_30-pressed.png" ) ) {
|
||||
str << "_30-pressed.png";
|
||||
} else {
|
||||
str << "_30.png~CS(70,70,0)";
|
||||
|
|
|
@ -81,6 +81,8 @@ namespace {
|
|||
#include <CoreFoundation/CFBase.h>
|
||||
#endif
|
||||
|
||||
namespace filesystem {
|
||||
|
||||
bool ends_with(const std::string& str, const std::string& suffix)
|
||||
{
|
||||
return str.size() >= suffix.size() && std::equal(suffix.begin(),suffix.end(),str.end()-suffix.size());
|
||||
|
@ -293,7 +295,7 @@ std::string get_saves_dir()
|
|||
}
|
||||
#endif
|
||||
|
||||
std::string get_addon_campaigns_dir()
|
||||
std::string get_addons_dir()
|
||||
{
|
||||
const std::string dir_path = get_user_data_dir() + "/data/add-ons";
|
||||
return get_dir(dir_path);
|
||||
|
@ -1349,3 +1351,5 @@ scoped_ostream::~scoped_ostream()
|
|||
{
|
||||
delete stream;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
#include "exceptions.hpp"
|
||||
|
||||
namespace filesystem {
|
||||
|
||||
/** An exception object used when an IO error occurs */
|
||||
struct io_exception : public game::error {
|
||||
io_exception() : game::error("") {}
|
||||
|
@ -67,7 +69,7 @@ std::string get_save_index_file();
|
|||
std::string get_saves_dir();
|
||||
std::string get_intl_dir();
|
||||
std::string get_screenshot_dir();
|
||||
std::string get_addon_campaigns_dir();
|
||||
std::string get_addons_dir();
|
||||
|
||||
/**
|
||||
* Get the next free filename using "name + number (3 digits) + extension"
|
||||
|
@ -288,4 +290,6 @@ public:
|
|||
~scoped_ostream();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
32
src/font.cpp
32
src/font.cpp
|
@ -206,11 +206,11 @@ static TTF_Font* open_font(const std::string& fname, int size)
|
|||
std::string name;
|
||||
if(!game_config::path.empty()) {
|
||||
name = game_config::path + "/fonts/" + fname;
|
||||
if(!file_exists(name)) {
|
||||
if(!filesystem::file_exists(name)) {
|
||||
name = "fonts/" + fname;
|
||||
if(!file_exists(name)) {
|
||||
if(!filesystem::file_exists(name)) {
|
||||
name = fname;
|
||||
if(!file_exists(name)) {
|
||||
if(!filesystem::file_exists(name)) {
|
||||
ERR_FT << "Failed opening font: '" << name << "': No such file or directory" << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -219,8 +219,8 @@ static TTF_Font* open_font(const std::string& fname, int size)
|
|||
|
||||
} else {
|
||||
name = "fonts/" + fname;
|
||||
if(!file_exists(name)) {
|
||||
if(!file_exists(fname)) {
|
||||
if(!filesystem::file_exists(name)) {
|
||||
if(!filesystem::file_exists(fname)) {
|
||||
ERR_FT << "Failed opening font: '" << name << "': No such file or directory" << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -357,9 +357,9 @@ void manager::init() const
|
|||
#endif
|
||||
|
||||
#if CAIRO_HAS_WIN32_FONT
|
||||
BOOST_FOREACH(const std::string& path, get_binary_paths("fonts")) {
|
||||
BOOST_FOREACH(const std::string& path, filesystem::get_binary_paths("fonts")) {
|
||||
std::vector<std::string> files;
|
||||
get_files_in_dir(path, &files, NULL, ENTIRE_FILE_PATH);
|
||||
filesystem::get_files_in_dir(path, &files, NULL, filesystem::ENTIRE_FILE_PATH);
|
||||
BOOST_FOREACH(const std::string& file, files)
|
||||
if(file.substr(file.length() - 4) == ".ttf" || file.substr(file.length() - 4) == ".ttc")
|
||||
AddFontResourceA(file.c_str());
|
||||
|
@ -374,9 +374,9 @@ void manager::deinit() const
|
|||
#endif
|
||||
|
||||
#if CAIRO_HAS_WIN32_FONT
|
||||
BOOST_FOREACH(const std::string& path, get_binary_paths("fonts")) {
|
||||
BOOST_FOREACH(const std::string& path, filesystem::get_binary_paths("fonts")) {
|
||||
std::vector<std::string> files;
|
||||
get_files_in_dir(path, &files, NULL, ENTIRE_FILE_PATH);
|
||||
filesystem::get_files_in_dir(path, &files, NULL, filesystem::ENTIRE_FILE_PATH);
|
||||
BOOST_FOREACH(const std::string& file, files)
|
||||
if(file.substr(file.length() - 4) == ".ttf" || file.substr(file.length() - 4) == ".ttc")
|
||||
RemoveFontResourceA(file.c_str());
|
||||
|
@ -408,17 +408,17 @@ static void set_font_list(const std::vector<subset_descriptor>& fontlist)
|
|||
for(itor = fontlist.begin(); itor != fontlist.end(); ++itor) {
|
||||
// Insert fonts only if the font file exists
|
||||
if(game_config::path.empty() == false) {
|
||||
if(!file_exists(game_config::path + "/fonts/" + itor->name)) {
|
||||
if(!file_exists("fonts/" + itor->name)) {
|
||||
if(!file_exists(itor->name)) {
|
||||
if(!filesystem::file_exists(game_config::path + "/fonts/" + itor->name)) {
|
||||
if(!filesystem::file_exists("fonts/" + itor->name)) {
|
||||
if(!filesystem::file_exists(itor->name)) {
|
||||
WRN_FT << "Failed opening font file '" << itor->name << "': No such file or directory" << std::endl;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(!file_exists("fonts/" + itor->name)) {
|
||||
if(!file_exists(itor->name)) {
|
||||
if(!filesystem::file_exists("fonts/" + itor->name)) {
|
||||
if(!filesystem::file_exists(itor->name)) {
|
||||
WRN_FT << "Failed opening font file '" << itor->name << "': No such file or directory" << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
@ -1425,13 +1425,13 @@ bool load_font_config()
|
|||
//config when changing languages
|
||||
config cfg;
|
||||
try {
|
||||
const std::string& cfg_path = get_wml_location("hardwired/fonts.cfg");
|
||||
const std::string& cfg_path = filesystem::get_wml_location("hardwired/fonts.cfg");
|
||||
if(cfg_path.empty()) {
|
||||
ERR_FT << "could not resolve path to fonts.cfg, file not found\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
scoped_istream stream = preprocess_file(cfg_path);
|
||||
filesystem::scoped_istream stream = preprocess_file(cfg_path);
|
||||
read(cfg, *stream);
|
||||
} catch(config::error &e) {
|
||||
ERR_FT << "could not read fonts.cfg:\n"
|
||||
|
|
|
@ -118,14 +118,14 @@ void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload,
|
|||
// then handle terrains so that they are last loaded from data/.
|
||||
// 2nd everything in userdata.
|
||||
loadscreen::start_stage("verify cache");
|
||||
data_tree_checksum();
|
||||
filesystem::data_tree_checksum();
|
||||
loadscreen::start_stage("create cache");
|
||||
|
||||
// Start transaction so macros are shared.
|
||||
game_config::config_cache_transaction main_transaction;
|
||||
|
||||
// Load the selected core
|
||||
cache_.get_config(get_wml_location(preferences::wml_tree_root()), game_config_);
|
||||
cache_.get_config(filesystem::get_wml_location(preferences::wml_tree_root()), game_config_);
|
||||
// Load the mainline core definitions to make sure switching back is always possible.
|
||||
config default_core_cfg;
|
||||
cache_.get_config(game_config::path + "/data/cores.cfg", default_core_cfg);
|
||||
|
@ -208,15 +208,15 @@ void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload,
|
|||
|
||||
void game_config_manager::load_addons_cfg()
|
||||
{
|
||||
const std::string user_campaign_dir = get_addon_campaigns_dir();
|
||||
const std::string user_campaign_dir = filesystem::get_addons_dir();
|
||||
|
||||
std::vector<std::string> error_addons;
|
||||
std::vector<std::string> user_dirs;
|
||||
std::vector<std::string> user_files;
|
||||
std::vector<std::string> addons_to_load;
|
||||
|
||||
get_files_in_dir(user_campaign_dir, &user_files, &user_dirs,
|
||||
ENTIRE_FILE_PATH);
|
||||
filesystem::get_files_in_dir(user_campaign_dir, &user_files, &user_dirs,
|
||||
filesystem::ENTIRE_FILE_PATH);
|
||||
|
||||
std::vector<std::string> error_log;
|
||||
|
||||
|
@ -228,11 +228,11 @@ void game_config_manager::load_addons_cfg()
|
|||
bool ok = true;
|
||||
// Allowing it if the dir doesn't exist,
|
||||
// for the single-file add-on.
|
||||
if(file_exists(file.substr(0, size_minus_extension))) {
|
||||
if(filesystem::file_exists(file.substr(0, size_minus_extension))) {
|
||||
// Unfortunately, we create the dir plus
|
||||
// _info.cfg ourselves on download.
|
||||
std::vector<std::string> dirs, files;
|
||||
get_files_in_dir(file.substr(0, size_minus_extension),
|
||||
filesystem::get_files_in_dir(file.substr(0, size_minus_extension),
|
||||
&files, &dirs);
|
||||
if(dirs.size() > 0) {
|
||||
ok = false;
|
||||
|
@ -265,7 +265,7 @@ void game_config_manager::load_addons_cfg()
|
|||
BOOST_FOREACH(const std::string& uc, user_dirs) {
|
||||
|
||||
const std::string info_cfg = uc + "/_info.cfg";
|
||||
if (file_exists(info_cfg)) {
|
||||
if (filesystem::file_exists(info_cfg)) {
|
||||
|
||||
config info;
|
||||
cache_.get_config(info_cfg, info);
|
||||
|
@ -280,7 +280,7 @@ void game_config_manager::load_addons_cfg()
|
|||
}
|
||||
|
||||
const std::string main_cfg = uc + "/_main.cfg";
|
||||
if(file_exists(main_cfg)) {
|
||||
if(filesystem::file_exists(main_cfg)) {
|
||||
addons_to_load.push_back(main_cfg);
|
||||
}
|
||||
}
|
||||
|
@ -302,7 +302,7 @@ void game_config_manager::load_addons_cfg()
|
|||
ERR_CONFIG << err.message << '\n';
|
||||
error_addons.push_back(uc);
|
||||
error_log.push_back(err.message);
|
||||
} catch(io_exception&) {
|
||||
} catch(filesystem::io_exception&) {
|
||||
ERR_CONFIG << "error reading usermade add-on '" << uc << "'" << std::endl;
|
||||
error_addons.push_back(uc);
|
||||
}
|
||||
|
@ -358,7 +358,7 @@ void game_config_manager::reload_changed_game_config()
|
|||
// Force a reload of configuration information.
|
||||
cache_.recheck_filetree_checksum();
|
||||
old_defines_map_.clear();
|
||||
clear_binary_paths_cache();
|
||||
filesystem::clear_binary_paths_cache();
|
||||
init_game_config(FORCE_RELOAD);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ private:
|
|||
|
||||
preproc_map old_defines_map_;
|
||||
|
||||
binary_paths_manager paths_manager_;
|
||||
filesystem::binary_paths_manager paths_manager_;
|
||||
|
||||
game_config::config_cache& cache_;
|
||||
};
|
||||
|
|
|
@ -131,11 +131,11 @@ game_launcher::game_launcher(const commandline_options& cmdline_opts, const char
|
|||
#endif
|
||||
)
|
||||
{
|
||||
game_config::path = get_cwd() + '/' + game_config::path;
|
||||
game_config::path = filesystem::get_cwd() + '/' + game_config::path;
|
||||
font_manager_.update_font_path();
|
||||
}
|
||||
|
||||
const std::string app_basename = file_name(appname);
|
||||
const std::string app_basename = filesystem::file_name(appname);
|
||||
jump_to_editor_ = app_basename.find("editor") != std::string::npos;
|
||||
|
||||
if (cmdline_opts_.campaign) {
|
||||
|
@ -285,9 +285,9 @@ game_launcher::game_launcher(const commandline_options& cmdline_opts, const char
|
|||
|
||||
std::cerr << '\n';
|
||||
std::cerr << "Data directory: " << game_config::path
|
||||
<< "\nUser configuration directory: " << get_user_config_dir()
|
||||
<< "\nUser data directory: " << get_user_data_dir()
|
||||
<< "\nCache directory: " << get_cache_dir()
|
||||
<< "\nUser configuration directory: " << filesystem::get_user_config_dir()
|
||||
<< "\nUser data directory: " << filesystem::get_user_data_dir()
|
||||
<< "\nCache directory: " << filesystem::get_cache_dir()
|
||||
<< '\n';
|
||||
|
||||
// disable sound in nosound mode, or when sound engine failed to initialize
|
||||
|
@ -607,7 +607,7 @@ bool game_launcher::load_game()
|
|||
} catch(twml_exception& e) {
|
||||
e.show(disp());
|
||||
return false;
|
||||
} catch(io_exception& e) {
|
||||
} catch(filesystem::io_exception& e) {
|
||||
if(e.message.empty()) {
|
||||
gui2::show_error_message(disp().video(), _("File I/O Error while reading the game"));
|
||||
} else {
|
||||
|
@ -745,7 +745,7 @@ bool game_launcher::goto_editor()
|
|||
{
|
||||
if(jump_to_editor_){
|
||||
jump_to_editor_ = false;
|
||||
if (start_editor(normalize_path(game::load_game_exception::game)) ==
|
||||
if (start_editor(filesystem::normalize_path(game::load_game_exception::game)) ==
|
||||
editor::EXIT_QUIT_TO_DESKTOP)
|
||||
{
|
||||
return false;
|
||||
|
@ -759,12 +759,12 @@ void game_launcher::start_wesnothd()
|
|||
{
|
||||
const std::string wesnothd_program =
|
||||
preferences::get_mp_server_program_name().empty() ?
|
||||
get_program_invocation("wesnothd") : preferences::get_mp_server_program_name();
|
||||
filesystem::get_program_invocation("wesnothd") : preferences::get_mp_server_program_name();
|
||||
|
||||
std::string config = get_user_config_dir() + "/lan_server.cfg";
|
||||
if (!file_exists(config)) {
|
||||
std::string config = filesystem::get_user_config_dir() + "/lan_server.cfg";
|
||||
if (!filesystem::file_exists(config)) {
|
||||
// copy file if it isn't created yet
|
||||
write_file(config, read_file(get_wml_location("lan_server.cfg")));
|
||||
filesystem::write_file(config, filesystem::read_file(filesystem::get_wml_location("lan_server.cfg")));
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
|
|
|
@ -1776,15 +1776,15 @@ std::string show_wesnothd_server_search(display& disp)
|
|||
#endif
|
||||
const std::string filename = "wesnothd";
|
||||
std::string path = WESNOTH_PREFIX + std::string("/bin");
|
||||
if (!is_directory(path))
|
||||
path = get_cwd();
|
||||
if (!filesystem::is_directory(path))
|
||||
path = filesystem::get_cwd();
|
||||
|
||||
#else
|
||||
const std::string filename = "wesnothd.exe";
|
||||
std::string path = get_cwd();
|
||||
std::string path = filesystem::get_cwd();
|
||||
#endif
|
||||
if (!old_path.empty()
|
||||
&& is_directory(old_path))
|
||||
&& filesystem::is_directory(old_path))
|
||||
{
|
||||
path = old_path;
|
||||
}
|
||||
|
|
|
@ -119,8 +119,8 @@ void tcustom_tod::select_file(const std::string& filename,
|
|||
twindow& window)
|
||||
{
|
||||
std::string va = vector_attrib;
|
||||
std::string fn = file_name(filename);
|
||||
std::string dn = directory_name(fn);
|
||||
std::string fn = filesystem::file_name(filename);
|
||||
std::string dn = filesystem::directory_name(fn);
|
||||
if(dn.empty()) {
|
||||
dn = dir;
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace gui2
|
|||
REGISTER_DIALOG(game_cache_options)
|
||||
|
||||
tgame_cache_options::tgame_cache_options()
|
||||
: cache_path_(get_cache_dir())
|
||||
: cache_path_(filesystem::get_cache_dir())
|
||||
, size_label_(NULL)
|
||||
{
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ void tgame_cache_options::update_cache_size_display()
|
|||
return;
|
||||
}
|
||||
|
||||
size_label_->set_label(utils::si_string(dir_size(cache_path_),
|
||||
size_label_->set_label(utils::si_string(filesystem::dir_size(cache_path_),
|
||||
true,
|
||||
_("unit_byte^B")));
|
||||
}
|
||||
|
|
|
@ -71,11 +71,11 @@ tgame_paths::tgame_paths()
|
|||
// NOTE: these path_map_ entries are referenced by the GUI2 WML
|
||||
// definition of this dialog using preprocessor macros.
|
||||
path_map_["datadir"] = game_config::path;
|
||||
path_map_["config"] = get_user_config_dir();
|
||||
path_map_["userdata"] = get_user_data_dir();
|
||||
path_map_["saves"] = get_saves_dir();
|
||||
path_map_["addons"] = get_addon_campaigns_dir();
|
||||
path_map_["cache"] = get_cache_dir();
|
||||
path_map_["config"] = filesystem::get_user_config_dir();
|
||||
path_map_["userdata"] = filesystem::get_user_data_dir();
|
||||
path_map_["saves"] = filesystem::get_saves_dir();
|
||||
path_map_["addons"] = filesystem::get_addons_dir();
|
||||
path_map_["cache"] = filesystem::get_cache_dir();
|
||||
}
|
||||
|
||||
void tgame_paths::pre_show(CVideo& /*video*/, twindow& window)
|
||||
|
|
|
@ -220,7 +220,7 @@ game_info::game_info(const config& game, const config& game_config)
|
|||
map_info = era;
|
||||
|
||||
if(map_data.empty()) {
|
||||
map_data = read_map(game["mp_scenario"]);
|
||||
map_data = filesystem::read_map(game["mp_scenario"]);
|
||||
}
|
||||
|
||||
if(map_data.empty()) {
|
||||
|
|
|
@ -101,8 +101,8 @@ void tmp_create_game::pre_show(CVideo& /*video*/, twindow& window)
|
|||
// User maps
|
||||
/* FIXME implement user maps
|
||||
std::vector<std::string> maps;
|
||||
get_files_in_dir(get_user_data_dir() + "/editor/maps", &maps, NULL,
|
||||
FILE_NAME_ONLY);
|
||||
filesystem::get_files_in_dir(filesystem::get_user_data_dir() + "/editor/maps", &maps, NULL,
|
||||
filesystem::FILE_NAME_ONLY);
|
||||
|
||||
FOREACH(const AUTO& map, maps) {
|
||||
std::map<std::string, t_string> item;
|
||||
|
|
|
@ -65,7 +65,7 @@ REGISTER_DIALOG(screenshot_notification)
|
|||
|
||||
tscreenshot_notification::tscreenshot_notification(const std::string& path,
|
||||
int filesize)
|
||||
: path_(path), screenshots_dir_path_(get_screenshot_dir())
|
||||
: path_(path), screenshots_dir_path_(filesystem::get_screenshot_dir())
|
||||
{
|
||||
register_label("filesize",
|
||||
false,
|
||||
|
@ -76,7 +76,7 @@ tscreenshot_notification::tscreenshot_notification(const std::string& path,
|
|||
void tscreenshot_notification::pre_show(CVideo& /*video*/, twindow& window)
|
||||
{
|
||||
ttext_box& path_box = find_widget<ttext_box>(&window, "path", false);
|
||||
path_box.set_value(file_name(path_));
|
||||
path_box.set_value(filesystem::file_name(path_));
|
||||
path_box.set_active(false);
|
||||
|
||||
tbutton& copy_b = find_widget<tbutton>(&window, "copy", false);
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace
|
|||
|
||||
void strip_trailing_dir_separators(std::string& str)
|
||||
{
|
||||
while(is_path_sep(str[str.size() - 1])) {
|
||||
while(filesystem::is_path_sep(str[str.size() - 1])) {
|
||||
str.erase(str.size() - 1);
|
||||
}
|
||||
}
|
||||
|
@ -46,36 +46,36 @@ std::string format_file_list(const std::vector<std::string>& files_original)
|
|||
return "";
|
||||
}
|
||||
|
||||
const std::string& addons_path = get_addon_campaigns_dir();
|
||||
const std::string& addons_path = filesystem::get_addons_dir();
|
||||
std::vector<std::string> files(files_original);
|
||||
|
||||
BOOST_FOREACH(std::string & file, files)
|
||||
{
|
||||
std::string base;
|
||||
std::string filename = file_name(file);
|
||||
std::string filename = filesystem::file_name(file);
|
||||
std::string parent_path;
|
||||
|
||||
const bool is_main_cfg = filename == "_main.cfg";
|
||||
|
||||
if(is_main_cfg) {
|
||||
parent_path = directory_name(file) + "/..";
|
||||
parent_path = filesystem::directory_name(file) + "/..";
|
||||
} else {
|
||||
parent_path = directory_name(file);
|
||||
parent_path = filesystem::directory_name(file);
|
||||
}
|
||||
|
||||
// Only proceed to pretty-format the filename if it's from the add-ons
|
||||
// directory.
|
||||
if(normalize_path(parent_path) != normalize_path(addons_path)) {
|
||||
if(filesystem::normalize_path(parent_path) != filesystem::normalize_path(addons_path)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(is_main_cfg) {
|
||||
base = directory_name(file);
|
||||
// HACK: fool file_name() into giving us the parent directory name
|
||||
base = filesystem::directory_name(file);
|
||||
// HACK: fool filesystem::file_name() into giving us the parent directory name
|
||||
// alone by making base seem not like a directory path,
|
||||
// otherwise it returns an empty string.
|
||||
strip_trailing_dir_separators(base);
|
||||
base = file_name(base);
|
||||
base = filesystem::file_name(base);
|
||||
} else {
|
||||
base = filename;
|
||||
}
|
||||
|
|
|
@ -494,11 +494,11 @@ void load_settings()
|
|||
try
|
||||
{
|
||||
schema_validation::schema_validator validator(
|
||||
get_wml_location("gui/schema.cfg"));
|
||||
filesystem::get_wml_location("gui/schema.cfg"));
|
||||
preproc_map preproc(
|
||||
game_config::config_cache::instance().get_preproc_map());
|
||||
scoped_istream stream = preprocess_file(
|
||||
get_wml_location("gui/default.cfg"), &preproc);
|
||||
filesystem::scoped_istream stream = preprocess_file(
|
||||
filesystem::get_wml_location("gui/default.cfg"), &preproc);
|
||||
|
||||
read(cfg, *stream, &validator);
|
||||
}
|
||||
|
|
|
@ -294,7 +294,7 @@ void command_executor::set_button_state(display& disp) {
|
|||
|
||||
const hotkey::hotkey_command& command_obj = hotkey::get_hotkey_command(command);
|
||||
std::string tooltip = action.tooltip(i);
|
||||
if (file_exists(game_config::path + "/images/icons/action/" + command + "_25.png" ))
|
||||
if (filesystem::file_exists(game_config::path + "/images/icons/action/" + command + "_25.png" ))
|
||||
button->set_overlay("icons/action/" + command);
|
||||
if (!tooltip.empty())
|
||||
button->set_tooltip_string(tooltip);
|
||||
|
@ -383,7 +383,7 @@ std::string command_executor::get_menu_image(display& disp, const std::string& c
|
|||
if (menu)
|
||||
return "buttons/fold-arrow.png"; // TODO should not be hardcoded
|
||||
|
||||
if (file_exists(game_config::path + "/images/" + base_image_name)) {
|
||||
if (filesystem::file_exists(game_config::path + "/images/" + base_image_name)) {
|
||||
switch (state) {
|
||||
case ACTION_ON:
|
||||
case ACTION_SELECTED:
|
||||
|
@ -632,8 +632,8 @@ void execute_command(display& disp, const hotkey_command& command, command_execu
|
|||
// intentional fall-through
|
||||
case HOTKEY_SCREENSHOT: {
|
||||
std::string name = map_screenshot ? _("Map-Screenshot") : _("Screenshot");
|
||||
std::string filename = get_screenshot_dir() + "/" + name + "_";
|
||||
filename = get_next_filename(filename, ".bmp");
|
||||
std::string filename = filesystem::get_screenshot_dir() + "/" + name + "_";
|
||||
filename = filesystem::get_next_filename(filename, ".bmp");
|
||||
int size = disp.screenshot(filename, map_screenshot);
|
||||
if (size > 0) {
|
||||
gui2::tscreenshot_notification::display(filename, size, disp.video());
|
||||
|
|
|
@ -381,7 +381,7 @@ void hotkey_preferences_dialog::set_hotkey_menu(bool keep_viewport) {
|
|||
const std::string& name = hotkey::get_names(command);
|
||||
|
||||
std::string image_path = "misc/empty.png~CROP(0,0,15,15)";
|
||||
if (file_exists(game_config::path + "/images/icons/action/" + command + "_25.png"))
|
||||
if (filesystem::file_exists(game_config::path + "/images/icons/action/" + command + "_25.png"))
|
||||
image_path = "icons/action/" + command + "_25.png~CROP(3,3,18,18)";
|
||||
|
||||
menu_items.push_back(
|
||||
|
|
|
@ -388,8 +388,8 @@ static bool localized_file_uptodate (const std::string& loc_file)
|
|||
if (fuzzy_localized_files.empty()) {
|
||||
// First call, parse track index to collect fuzzy files by path.
|
||||
std::string fsep = "\xC2\xA6"; // UTF-8 for "broken bar"
|
||||
std::string trackpath = get_binary_file_location("", "l10n-track");
|
||||
std::string contents = read_file(trackpath);
|
||||
std::string trackpath = filesystem::get_binary_file_location("", "l10n-track");
|
||||
std::string contents = filesystem::read_file(trackpath);
|
||||
std::vector<std::string> lines = utils::split(contents, '\n');
|
||||
BOOST_FOREACH(const std::string &line, lines) {
|
||||
size_t p1 = line.find(fsep);
|
||||
|
@ -414,8 +414,8 @@ static bool localized_file_uptodate (const std::string& loc_file)
|
|||
// Localized counterpart may also be requested to have a suffix to base name.
|
||||
static std::string get_localized_path (const std::string& file, const std::string& suff = "")
|
||||
{
|
||||
std::string dir = directory_name(file);
|
||||
std::string base = file_name(file);
|
||||
std::string dir = filesystem::directory_name(file);
|
||||
std::string base = filesystem::file_name(file);
|
||||
const size_t pos_ext = base.rfind(".");
|
||||
std::string loc_base;
|
||||
if (pos_ext != std::string::npos) {
|
||||
|
@ -440,7 +440,7 @@ static std::string get_localized_path (const std::string& file, const std::strin
|
|||
langs.push_back("en_US");
|
||||
BOOST_FOREACH(const std::string &lang, langs) {
|
||||
std::string loc_file = dir + "l10n" + "/" + lang + "/" + loc_base;
|
||||
if (file_exists(loc_file) && localized_file_uptodate(loc_file)) {
|
||||
if (filesystem::file_exists(loc_file) && localized_file_uptodate(loc_file)) {
|
||||
return loc_file;
|
||||
}
|
||||
}
|
||||
|
@ -466,7 +466,7 @@ static surface load_image_file(const image::locator &loc)
|
|||
{
|
||||
surface res;
|
||||
|
||||
std::string location = get_binary_file_location("images", loc.get_filename());
|
||||
std::string location = filesystem::get_binary_file_location("images", loc.get_filename());
|
||||
|
||||
|
||||
{
|
||||
|
@ -610,7 +610,7 @@ static surface apply_light(surface surf, const light_string& ls){
|
|||
|
||||
bool locator::file_exists() const
|
||||
{
|
||||
return !get_binary_file_location("images", val_.filename_).empty();
|
||||
return !filesystem::get_binary_file_location("images", val_.filename_).empty();
|
||||
}
|
||||
|
||||
surface load_from_disk(const locator &loc)
|
||||
|
@ -1138,7 +1138,7 @@ bool exists(const image::locator& i_locator)
|
|||
it = image_existence_map.insert(std::make_pair(i_locator.get_filename(), false));
|
||||
bool &cache = it.first->second;
|
||||
if (it.second)
|
||||
cache = !get_binary_file_location("images", i_locator.get_filename()).empty();
|
||||
cache = !filesystem::get_binary_file_location("images", i_locator.get_filename()).empty();
|
||||
return cache;
|
||||
}
|
||||
|
||||
|
@ -1151,8 +1151,8 @@ static void precache_file_existence_internal(const std::string& dir, const std::
|
|||
|
||||
std::vector<std::string> files_found;
|
||||
std::vector<std::string> dirs_found;
|
||||
get_files_in_dir(checked_dir, &files_found, &dirs_found,
|
||||
FILE_NAME_ONLY, NO_FILTER, DONT_REORDER);
|
||||
filesystem::get_files_in_dir(checked_dir, &files_found, &dirs_found,
|
||||
filesystem::FILE_NAME_ONLY, filesystem::NO_FILTER, filesystem::DONT_REORDER);
|
||||
|
||||
for(std::vector<std::string>::const_iterator f = files_found.begin();
|
||||
f != files_found.end(); ++f) {
|
||||
|
@ -1167,7 +1167,7 @@ static void precache_file_existence_internal(const std::string& dir, const std::
|
|||
|
||||
void precache_file_existence(const std::string& subdir)
|
||||
{
|
||||
const std::vector<std::string>& paths = get_binary_paths("images");
|
||||
const std::vector<std::string>& paths = filesystem::get_binary_paths("images");
|
||||
|
||||
for(std::vector<std::string>::const_iterator p = paths.begin();
|
||||
p != paths.end(); ++p) {
|
||||
|
|
|
@ -96,7 +96,7 @@ bool load_language_list()
|
|||
{
|
||||
config cfg;
|
||||
try {
|
||||
scoped_istream stream = preprocess_file(get_wml_location("hardwired/language.cfg"));
|
||||
filesystem::scoped_istream stream = preprocess_file(filesystem::get_wml_location("hardwired/language.cfg"));
|
||||
read(cfg, *stream);
|
||||
} catch(config::error &) {
|
||||
return false;
|
||||
|
@ -298,9 +298,9 @@ void init_textdomains(const config& cfg)
|
|||
const std::string &path = t["path"];
|
||||
|
||||
if(path.empty()) {
|
||||
t_string::add_textdomain(name, get_intl_dir());
|
||||
t_string::add_textdomain(name, filesystem::get_intl_dir());
|
||||
} else {
|
||||
std::string location = get_binary_dir_location("", path);
|
||||
std::string location = filesystem::get_binary_dir_location("", path);
|
||||
|
||||
if (location.empty()) {
|
||||
//if location is empty, this causes a crash on Windows, so we
|
||||
|
|
|
@ -421,14 +421,14 @@ void menu_handler::scenario_settings_table(int selected)
|
|||
|
||||
void menu_handler::save_map()
|
||||
{
|
||||
std::string input_name = get_dir(get_dir(get_user_data_dir() + "/editor") + "/maps/");
|
||||
std::string input_name = filesystem::get_dir(filesystem::get_dir(filesystem::get_user_data_dir() + "/editor") + "/maps/");
|
||||
int res = 0;
|
||||
int overwrite = 1;
|
||||
do {
|
||||
res = dialogs::show_file_chooser_dialog_save(*gui_, input_name, _("Save the Map As"), ".map");
|
||||
if (res == 0) {
|
||||
|
||||
if (file_exists(input_name)) {
|
||||
if (filesystem::file_exists(input_name)) {
|
||||
const int res = gui2::show_message((*gui_).video(), "", _("The map already exists. Do you want to overwrite it?"), gui2::tmessage::yes_no_buttons);
|
||||
overwrite = res == gui2::twindow::CANCEL ? 1 : 0;
|
||||
}
|
||||
|
@ -440,9 +440,9 @@ void menu_handler::save_map()
|
|||
// Try to save the map, if it fails we reset the filename.
|
||||
if (res == 0) {
|
||||
try {
|
||||
write_file(input_name, map_.write());
|
||||
filesystem::write_file(input_name, map_.write());
|
||||
gui2::show_transient_message(gui_->video(), "", _("Map saved."));
|
||||
} catch (io_exception& e) {
|
||||
} catch (filesystem::io_exception& e) {
|
||||
utils::string_map symbols;
|
||||
symbols["msg"] = e.what();
|
||||
const std::string msg = vgettext("Could not save the map: $msg",symbols);
|
||||
|
@ -451,14 +451,14 @@ void menu_handler::save_map()
|
|||
}
|
||||
|
||||
/*
|
||||
std::string input_name = get_dir(get_dir(get_user_data_dir() + "/editor") + "/maps/");
|
||||
std::string input_name = filesystem::get_dir(filesystem::get_dir(filesystem::get_user_data_dir() + "/editor") + "/maps/");
|
||||
int res = 0;
|
||||
int overwrite = 1;
|
||||
do {
|
||||
res = dialogs::show_file_chooser_dialog_save(*gui_, input_name, _("Save the Map As"));
|
||||
if (res == 0) {
|
||||
|
||||
if (file_exists(input_name)) {
|
||||
if (filesystem::file_exists(input_name)) {
|
||||
const int res = gui2::show_message((*gui_).video(), "", _("The map already exists. Do you want to overwrite it?"), gui2::tmessage::yes_no_buttons);
|
||||
overwrite = res == gui2::twindow::CANCEL ? 1 : 0;
|
||||
}
|
||||
|
@ -479,10 +479,10 @@ void menu_handler::save_map()
|
|||
config_writer writer(str, false);
|
||||
writer.write(file);
|
||||
}
|
||||
write_file(input_name, str.str());
|
||||
filesystem::write_file(input_name, str.str());
|
||||
|
||||
gui2::show_transient_message(gui_->video(), "", _("Map saved."));
|
||||
} catch (io_exception& e) {
|
||||
} catch (filesystem::io_exception& e) {
|
||||
utils::string_map symbols;
|
||||
symbols["msg"] = e.what();
|
||||
const std::string msg = vgettext("Could not save the map: $msg",symbols);
|
||||
|
|
|
@ -568,7 +568,7 @@ void gamebrowser::set_game_items(const config& cfg, const config& game_config)
|
|||
}
|
||||
games_.back().map_data = game["map_data"].str();
|
||||
if(games_.back().map_data.empty()) {
|
||||
games_.back().map_data = read_map(game["map"]);
|
||||
games_.back().map_data = filesystem::read_map(game["map"]);
|
||||
}
|
||||
if(! games_.back().map_data.empty()) {
|
||||
try {
|
||||
|
|
|
@ -1079,7 +1079,7 @@ void send_file(const std::string& filename, connection connection_num, const std
|
|||
return;
|
||||
}
|
||||
|
||||
const int size = file_size(filename);
|
||||
const int size = filesystem::file_size(filename);
|
||||
|
||||
if(size < 0) {
|
||||
ERR_NW << "Could not determine size of file " << filename << ", not sending." << std::endl;
|
||||
|
|
|
@ -462,7 +462,7 @@ typedef util::scoped_resource<int, close_fd> scoped_fd;
|
|||
static SOCKET_STATE send_file(buffer* buf)
|
||||
{
|
||||
size_t upto = 0;
|
||||
size_t filesize = file_size(buf->config_error);
|
||||
size_t filesize = filesystem::file_size(buf->config_error);
|
||||
#ifdef HAVE_SENDFILE
|
||||
// implements linux sendfile support
|
||||
LOG_NW << "send_file use system sendfile: " << (network_use_system_sendfile?"yes":"no") << "\n";
|
||||
|
@ -534,7 +534,7 @@ static SOCKET_STATE send_file(buffer* buf)
|
|||
// reserve 1024*8 bytes buffer
|
||||
buf->raw_buffer.resize(std::min<size_t>(1024*8, filesize));
|
||||
SDLNet_Write32(filesize,&buf->raw_buffer[0]);
|
||||
scoped_istream file_stream = istream_file(buf->config_error);
|
||||
filesystem::scoped_istream file_stream = filesystem::istream_file(buf->config_error);
|
||||
SOCKET_STATE result = send_buffer(buf->sock, buf->raw_buffer, 4);
|
||||
|
||||
if (!file_stream->good()) {
|
||||
|
|
|
@ -30,14 +30,14 @@ config pack_scalar(const std::string &name, const t_string &val)
|
|||
}
|
||||
|
||||
static std::string get_persist_cfg_name(const std::string &name_space) {
|
||||
return (get_dir(get_user_data_dir() + "/persist/") + name_space + ".cfg");
|
||||
return (filesystem::get_dir(filesystem::get_user_data_dir() + "/persist/") + name_space + ".cfg");
|
||||
}
|
||||
|
||||
void persist_file_context::load()
|
||||
{
|
||||
std::string cfg_name = get_persist_cfg_name(namespace_.root_);
|
||||
if (file_exists(cfg_name) && !is_directory(cfg_name)) {
|
||||
scoped_istream file_stream = istream_file(cfg_name);
|
||||
if (filesystem::file_exists(cfg_name) && !filesystem::is_directory(cfg_name)) {
|
||||
filesystem::scoped_istream file_stream = filesystem::istream_file(cfg_name);
|
||||
if (!(file_stream->fail())) {
|
||||
try {
|
||||
read(cfg_,*file_stream);
|
||||
|
@ -178,9 +178,9 @@ bool persist_file_context::save_context() {
|
|||
std::string cfg_name = get_persist_cfg_name(namespace_.root_);
|
||||
if (!cfg_name.empty()) {
|
||||
if (cfg_.empty()) {
|
||||
success = delete_directory(cfg_name);
|
||||
success = filesystem::delete_directory(cfg_name);
|
||||
} else {
|
||||
scoped_ostream out = ostream_file(cfg_name);
|
||||
filesystem::scoped_ostream out = filesystem::ostream_file(cfg_name);
|
||||
if (!out->fail())
|
||||
{
|
||||
config_writer writer(*out,false);
|
||||
|
|
|
@ -60,16 +60,16 @@ base_manager::base_manager()
|
|||
{
|
||||
try{
|
||||
#ifdef DEFAULT_PREFS_PATH
|
||||
scoped_istream stream = istream_file(get_default_prefs_file(),false);
|
||||
filesystem::scoped_istream stream = filesystem::istream_file(filesystem::get_default_prefs_file(),false);
|
||||
read(prefs, *stream);
|
||||
|
||||
config user_prefs;
|
||||
stream = istream_file(get_prefs_file());
|
||||
stream = filesystem::istream_file(filesystem::get_prefs_file());
|
||||
read(user_prefs, *stream);
|
||||
|
||||
prefs.merge_with(user_prefs);
|
||||
#else
|
||||
scoped_istream stream = istream_file(get_prefs_file(),false);
|
||||
filesystem::scoped_istream stream = filesystem::istream_file(filesystem::get_prefs_file(),false);
|
||||
read(prefs, *stream);
|
||||
#endif
|
||||
} catch(const config::error& e) {
|
||||
|
@ -95,15 +95,15 @@ void write_preferences()
|
|||
{
|
||||
#ifndef _WIN32
|
||||
|
||||
bool prefs_file_existed = access(get_prefs_file().c_str(), F_OK) == 0;
|
||||
bool prefs_file_existed = access(filesystem::get_prefs_file().c_str(), F_OK) == 0;
|
||||
|
||||
#endif
|
||||
|
||||
try {
|
||||
scoped_ostream prefs_file = ostream_file(get_prefs_file());
|
||||
filesystem::scoped_ostream prefs_file = filesystem::ostream_file(filesystem::get_prefs_file());
|
||||
write(*prefs_file, prefs);
|
||||
} catch(io_exception&) {
|
||||
ERR_FS << "error writing to preferences file '" << get_prefs_file() << "'" << std::endl;
|
||||
} catch(filesystem::io_exception&) {
|
||||
ERR_FS << "error writing to preferences file '" << filesystem::get_prefs_file() << "'" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
@ -111,8 +111,8 @@ void write_preferences()
|
|||
|
||||
if(!prefs_file_existed) {
|
||||
|
||||
if(chmod(get_prefs_file().c_str(), 0600) == -1) {
|
||||
ERR_FS << "error setting permissions of preferences file '" << get_prefs_file() << "'" << std::endl;
|
||||
if(chmod(filesystem::get_prefs_file().c_str(), 0600) == -1) {
|
||||
ERR_FS << "error setting permissions of preferences file '" << filesystem::get_prefs_file() << "'" << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -128,7 +128,7 @@ void extract_summary_from_config(config &, config &);
|
|||
void save_index_class::rebuild(const std::string& name) {
|
||||
std::string filename = name;
|
||||
replace_space2underbar(filename);
|
||||
time_t modified = file_create_time(get_saves_dir() + "/" + filename);
|
||||
time_t modified = filesystem::file_create_time(filesystem::get_saves_dir() + "/" + filename);
|
||||
rebuild(name, modified);
|
||||
}
|
||||
|
||||
|
@ -170,14 +170,14 @@ config& save_index_class::get(const std::string& name) {
|
|||
void save_index_class::write_save_index() {
|
||||
log_scope("write_save_index()");
|
||||
try {
|
||||
scoped_ostream stream = ostream_file(get_save_index_file());
|
||||
filesystem::scoped_ostream stream = filesystem::ostream_file(filesystem::get_save_index_file());
|
||||
if (preferences::save_compression_format() != compression::NONE) {
|
||||
// TODO: maybe allow writing this using bz2 too?
|
||||
write_gz(*stream, data());
|
||||
} else {
|
||||
write(*stream, data());
|
||||
}
|
||||
} catch(io_exception& e) {
|
||||
} catch(filesystem::io_exception& e) {
|
||||
ERR_SAVE << "error writing to save index file: '" << e.what() << "'" << std::endl;
|
||||
}
|
||||
}
|
||||
|
@ -202,14 +202,14 @@ config& save_index_class::data(const std::string& name) {
|
|||
config& save_index_class::data() {
|
||||
if(loaded_ == false) {
|
||||
try {
|
||||
scoped_istream stream = istream_file(get_save_index_file());
|
||||
filesystem::scoped_istream stream = filesystem::istream_file(filesystem::get_save_index_file());
|
||||
try {
|
||||
read_gz(data_, *stream);
|
||||
} catch (boost::iostreams::gzip_error&) {
|
||||
stream->seekg(0);
|
||||
read(data_, *stream);
|
||||
}
|
||||
} catch(io_exception& e) {
|
||||
} catch(filesystem::io_exception& e) {
|
||||
ERR_SAVE << "error reading save index: '" << e.what() << "'" << std::endl;
|
||||
} catch(config::error& e) {
|
||||
ERR_SAVE << "error parsing save index config file:\n" << e.message << std::endl;
|
||||
|
@ -240,7 +240,7 @@ std::vector<save_info> get_saves_list(const std::string* dir, const std::string*
|
|||
create_save_info creator(dir);
|
||||
|
||||
std::vector<std::string> filenames;
|
||||
get_files_in_dir(creator.dir,&filenames);
|
||||
filesystem::get_files_in_dir(creator.dir,&filenames);
|
||||
|
||||
if (filter) {
|
||||
filenames.erase(std::remove_if(filenames.begin(), filenames.end(),
|
||||
|
@ -305,10 +305,10 @@ bool save_info_less_time::operator() (const save_info& a, const save_info& b) co
|
|||
|
||||
static std::istream* find_save_file(const std::string &name, const std::string &alt_name, const std::vector<std::string> &suffixes) {
|
||||
BOOST_FOREACH(const std::string &suf, suffixes) {
|
||||
std::istream *file_stream = istream_file(get_saves_dir() + "/" + name + suf);
|
||||
std::istream *file_stream = filesystem::istream_file(filesystem::get_saves_dir() + "/" + name + suf);
|
||||
if (file_stream->fail()) {
|
||||
delete file_stream;
|
||||
file_stream = istream_file(get_saves_dir() + "/" + alt_name + suf);
|
||||
file_stream = filesystem::istream_file(filesystem::get_saves_dir() + "/" + alt_name + suf);
|
||||
}
|
||||
if (!file_stream->fail())
|
||||
return file_stream;
|
||||
|
@ -325,7 +325,7 @@ void read_save_file(const std::string& name, config& cfg, std::string* error_log
|
|||
replace_space2underbar(modified_name);
|
||||
|
||||
static const std::vector<std::string> suffixes = boost::assign::list_of("")(".gz")(".bz2");
|
||||
scoped_istream file_stream = find_save_file(modified_name, name, suffixes);
|
||||
filesystem::scoped_istream file_stream = find_save_file(modified_name, name, suffixes);
|
||||
|
||||
cfg.clear();
|
||||
try{
|
||||
|
@ -333,9 +333,9 @@ void read_save_file(const std::string& name, config& cfg, std::string* error_log
|
|||
* Test the modified name, since it might use a .gz
|
||||
* file even when not requested.
|
||||
*/
|
||||
if(is_gzip_file(modified_name)) {
|
||||
if(filesystem::is_gzip_file(modified_name)) {
|
||||
read_gz(cfg, *file_stream);
|
||||
} else if(is_bzip2_file(modified_name)) {
|
||||
} else if(filesystem::is_bzip2_file(modified_name)) {
|
||||
read_bz2(cfg, *file_stream);
|
||||
} else {
|
||||
read(cfg, *file_stream);
|
||||
|
@ -381,8 +381,8 @@ void delete_game(const std::string& name)
|
|||
std::string modified_name = name;
|
||||
replace_space2underbar(modified_name);
|
||||
|
||||
remove((get_saves_dir() + "/" + name).c_str());
|
||||
remove((get_saves_dir() + "/" + modified_name).c_str());
|
||||
remove((filesystem::get_saves_dir() + "/" + name).c_str());
|
||||
remove((filesystem::get_saves_dir() + "/" + modified_name).c_str());
|
||||
|
||||
save_index_manager.remove(name);
|
||||
}
|
||||
|
@ -390,7 +390,7 @@ void delete_game(const std::string& name)
|
|||
|
||||
|
||||
create_save_info::create_save_info(const std::string* d)
|
||||
: dir(d ? *d : get_saves_dir())
|
||||
: dir(d ? *d : filesystem::get_saves_dir())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -398,7 +398,7 @@ save_info create_save_info::operator()(const std::string& filename) const
|
|||
{
|
||||
std::string name = filename;
|
||||
replace_underbar2space(name);
|
||||
time_t modified = file_create_time(dir + "/" + filename);
|
||||
time_t modified = filesystem::file_create_time(dir + "/" + filename);
|
||||
save_index_manager.set_modified(name, modified);
|
||||
return save_info(name, modified);
|
||||
}
|
||||
|
@ -492,7 +492,7 @@ void extract_summary_from_config(config& cfg_save, config& cfg_summary)
|
|||
// We need a binary path-independent path to the leader image here
|
||||
// so it can be displayed for campaign-specific units in the dialog
|
||||
// even when the campaign isn't loaded yet.
|
||||
cfg_summary["leader_image"] = get_independent_image_path(leader_image);
|
||||
cfg_summary["leader_image"] = filesystem::get_independent_image_path(leader_image);
|
||||
|
||||
if(!shrouded) {
|
||||
if(has_snapshot) {
|
||||
|
|
|
@ -352,7 +352,7 @@ void saved_game::expand_random_scenario()
|
|||
}
|
||||
//it looks like we support a map= where map=filename equals more or less map_data={filename}
|
||||
if(starting_pos_["map_data"].empty() && !starting_pos_["map"].empty()) {
|
||||
starting_pos_["map_data"] = read_map(starting_pos_["map"]);
|
||||
starting_pos_["map_data"] = filesystem::read_map(starting_pos_["map"]);
|
||||
}
|
||||
// If the map should be randomly generated
|
||||
// We dont want that we accidently to this twice so we check for starting_pos_["map_data"].empty()
|
||||
|
|
|
@ -67,7 +67,7 @@ bool save_game_exists(const std::string& name, compression::format compressed)
|
|||
|
||||
fname += compression::format_extension(compressed);
|
||||
|
||||
return file_exists(get_saves_dir() + "/" + fname);
|
||||
return filesystem::file_exists(filesystem::get_saves_dir() + "/" + fname);
|
||||
}
|
||||
|
||||
void clean_saves(const std::string& label)
|
||||
|
@ -437,7 +437,7 @@ bool savegame::check_overwrite(CVideo& video)
|
|||
|
||||
void savegame::check_filename(const std::string& filename, CVideo& video)
|
||||
{
|
||||
if (is_compressed_file(filename)) {
|
||||
if (filesystem::is_compressed_file(filename)) {
|
||||
gui2::show_error_message(video, _("Save names should not end on '.gz' or '.bz2'. "
|
||||
"Please remove the extension."));
|
||||
throw illegal_filename_exception();
|
||||
|
@ -514,7 +514,7 @@ void savegame::write_game_to_disk(const std::string& filename)
|
|||
write_game(out);
|
||||
finish_save_game(out);
|
||||
}
|
||||
scoped_ostream os(open_save_game(filename_));
|
||||
filesystem::scoped_ostream os(open_save_game(filename_));
|
||||
(*os) << ss.str();
|
||||
|
||||
if (!os->good()) {
|
||||
|
@ -542,20 +542,20 @@ void savegame::finish_save_game(const config_writer &out)
|
|||
throw game::save_game_failed(_("Could not write to file"));
|
||||
}
|
||||
save_index_manager.remove(gamestate_.classification().label);
|
||||
} catch(io_exception& e) {
|
||||
} catch(filesystem::io_exception& e) {
|
||||
throw game::save_game_failed(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
// Throws game::save_game_failed
|
||||
scoped_ostream savegame::open_save_game(const std::string &label)
|
||||
filesystem::scoped_ostream savegame::open_save_game(const std::string &label)
|
||||
{
|
||||
std::string name = label;
|
||||
replace_space2underbar(name);
|
||||
|
||||
try {
|
||||
return scoped_ostream(ostream_file(get_saves_dir() + "/" + name));
|
||||
} catch(io_exception& e) {
|
||||
return filesystem::scoped_ostream(filesystem::ostream_file(filesystem::get_saves_dir() + "/" + name));
|
||||
} catch(filesystem::io_exception& e) {
|
||||
throw game::save_game_failed(e.what());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ private:
|
|||
/** Update the save_index */
|
||||
void finish_save_game(const config_writer &out);
|
||||
/** Throws game::save_game_failed. */
|
||||
scoped_ostream open_save_game(const std::string &label);
|
||||
filesystem::scoped_ostream open_save_game(const std::string &label);
|
||||
friend class save_info;
|
||||
//before_save (write replay data) changes this so it cannot be const
|
||||
saved_game& gamestate_;
|
||||
|
|
|
@ -1076,7 +1076,7 @@ static int intf_set_variable(lua_State *L)
|
|||
static int intf_have_file(lua_State *L)
|
||||
{
|
||||
char const *m = luaL_checkstring(L, 1);
|
||||
std::string p = get_wml_location(m);
|
||||
std::string p = filesystem::get_wml_location(m);
|
||||
if (p.empty()) { lua_pushboolean(L, false); }
|
||||
else { lua_pushboolean(L, true); }
|
||||
return 1;
|
||||
|
@ -1090,7 +1090,7 @@ static int intf_have_file(lua_State *L)
|
|||
static int intf_dofile(lua_State *L)
|
||||
{
|
||||
char const *m = luaL_checkstring(L, 1);
|
||||
std::string p = get_wml_location(m);
|
||||
std::string p = filesystem::get_wml_location(m);
|
||||
if (p.empty())
|
||||
return luaL_argerror(L, 1, "file not found");
|
||||
|
||||
|
@ -1123,7 +1123,7 @@ static int intf_require(lua_State *L)
|
|||
lua_pop(L, 1);
|
||||
|
||||
|
||||
std::string p = get_wml_location(m);
|
||||
std::string p = filesystem::get_wml_location(m);
|
||||
if (p.empty())
|
||||
return luaL_argerror(L, 1, "file not found");
|
||||
|
||||
|
|
|
@ -448,7 +448,7 @@ class preprocessor_data: preprocessor
|
|||
* Since @ref in_ uses the stream as well this object must be created
|
||||
* before @ref in_ and destroyed after @ref in_ is destroyed.
|
||||
*/
|
||||
scoped_istream in_scope_;
|
||||
filesystem::scoped_istream in_scope_;
|
||||
|
||||
/** Input stream. */
|
||||
buffered_istream in_;
|
||||
|
@ -515,30 +515,30 @@ preprocessor_file::preprocessor_file(preprocessor_streambuf &t, std::string cons
|
|||
pos_(),
|
||||
end_()
|
||||
{
|
||||
if (is_directory(name)) {
|
||||
if (filesystem::is_directory(name)) {
|
||||
|
||||
get_files_in_dir(name, &files_, NULL, ENTIRE_FILE_PATH, SKIP_MEDIA_DIR, DO_REORDER);
|
||||
filesystem::get_files_in_dir(name, &files_, NULL, filesystem::ENTIRE_FILE_PATH, filesystem::SKIP_MEDIA_DIR, filesystem::DO_REORDER);
|
||||
|
||||
BOOST_FOREACH(std::string fname, files_) {
|
||||
size_t cpos = fname.rfind(" ");
|
||||
if (cpos != std::string::npos && cpos >= symbol_index) {
|
||||
std::stringstream ss;
|
||||
ss << "Found filename containing whitespace: '" << file_name(fname) << "' in included directory '" << name << "'.\nThe included symbol probably looks similar to '"
|
||||
<< directory_name(fname.substr(symbol_index)) << "'";
|
||||
ss << "Found filename containing whitespace: '" << filesystem::file_name(fname) << "' in included directory '" << name << "'.\nThe included symbol probably looks similar to '"
|
||||
<< filesystem::directory_name(fname.substr(symbol_index)) << "'";
|
||||
// TODO: find a real linenumber
|
||||
target_.error(ss.str(), -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::istream * file_stream = istream_file(name);
|
||||
std::istream * file_stream = filesystem::istream_file(name);
|
||||
if (!file_stream->good()) {
|
||||
ERR_CF << "Could not open file " << name << std::endl;
|
||||
delete file_stream;
|
||||
}
|
||||
else
|
||||
new preprocessor_data(t, file_stream, "", get_short_wml_path(name),
|
||||
1, directory_name(name), t.textdomain_, NULL);
|
||||
new preprocessor_data(t, file_stream, "", filesystem::get_short_wml_path(name),
|
||||
1, filesystem::directory_name(name), t.textdomain_, NULL);
|
||||
}
|
||||
pos_ = files_.begin();
|
||||
end_ = files_.end();
|
||||
|
@ -899,14 +899,14 @@ bool preprocessor_data::get_chunk()
|
|||
} else if (command == "ifhave") {
|
||||
skip_spaces();
|
||||
std::string const &symbol = read_word();
|
||||
bool found = !get_wml_location(symbol, directory_).empty();
|
||||
bool found = !filesystem::get_wml_location(symbol, directory_).empty();
|
||||
DBG_CF << "testing for file or directory " << symbol << ": "
|
||||
<< (found ? "found" : "not found") << '\n';
|
||||
conditional_skip(!found);
|
||||
} else if (command == "ifnhave") {
|
||||
skip_spaces();
|
||||
std::string const &symbol = read_word();
|
||||
bool found = !get_wml_location(symbol, directory_).empty();
|
||||
bool found = !filesystem::get_wml_location(symbol, directory_).empty();
|
||||
DBG_CF << "testing for file or directory " << symbol << ": "
|
||||
<< (found ? "found" : "not found") << '\n';
|
||||
conditional_skip(found);
|
||||
|
@ -1076,7 +1076,7 @@ bool preprocessor_data::get_chunk()
|
|||
(*defines)[val.arguments[i]] = strings_[token.stack_pos + i + 1];
|
||||
}
|
||||
pop_token();
|
||||
std::string const &dir = directory_name(val.location.substr(0, val.location.find(' ')));
|
||||
std::string const &dir = filesystem::directory_name(val.location.substr(0, val.location.find(' ')));
|
||||
if (!slowpath_) {
|
||||
DBG_CF << "substituting macro " << symbol << '\n';
|
||||
new preprocessor_data(target_, buffer, val.location, "",
|
||||
|
@ -1096,7 +1096,7 @@ bool preprocessor_data::get_chunk()
|
|||
} else if (target_.depth_ < 40) {
|
||||
LOG_CF << "Macro definition not found for " << symbol << " , attempting to open as file.\n";
|
||||
pop_token();
|
||||
std::string nfname = get_wml_location(symbol, directory_);
|
||||
std::string nfname = filesystem::get_wml_location(symbol, directory_);
|
||||
if (!nfname.empty())
|
||||
{
|
||||
if (!slowpath_)
|
||||
|
@ -1185,11 +1185,11 @@ std::istream *preprocess_file(std::string const &fname, preproc_map *defines)
|
|||
void preprocess_resource(const std::string& res_name, preproc_map *defines_map,
|
||||
bool write_cfg, bool write_plain_cfg,std::string target_directory)
|
||||
{
|
||||
if (is_directory(res_name))
|
||||
if (filesystem::is_directory(res_name))
|
||||
{
|
||||
std::vector<std::string> dirs,files;
|
||||
|
||||
get_files_in_dir(res_name, &files, &dirs, ENTIRE_FILE_PATH, SKIP_MEDIA_DIR, DO_REORDER);
|
||||
filesystem::get_files_in_dir(res_name, &files, &dirs, filesystem::ENTIRE_FILE_PATH, filesystem::SKIP_MEDIA_DIR, filesystem::DO_REORDER);
|
||||
|
||||
// subdirectories
|
||||
BOOST_FOREACH(const std::string& dir, dirs)
|
||||
|
@ -1207,7 +1207,7 @@ void preprocess_resource(const std::string& res_name, preproc_map *defines_map,
|
|||
}
|
||||
|
||||
// process only config files.
|
||||
if (ends_with(res_name, ".cfg") == false)
|
||||
if (filesystem::ends_with(res_name, ".cfg") == false)
|
||||
return;
|
||||
|
||||
LOG_PREPROC << "processing resource: " << res_name << '\n';
|
||||
|
@ -1215,7 +1215,7 @@ void preprocess_resource(const std::string& res_name, preproc_map *defines_map,
|
|||
//disable filename encoding to get clear #line in cfg.plain
|
||||
encode_filename = false;
|
||||
|
||||
scoped_istream stream = preprocess_file(res_name, defines_map);
|
||||
filesystem::scoped_istream stream = preprocess_file(res_name, defines_map);
|
||||
std::stringstream ss;
|
||||
// Set the failbit so if we get any preprocessor exceptions (e.g.:preproc_config::error)
|
||||
// they will be propagated in the main program, instead of just setting the
|
||||
|
@ -1233,14 +1233,14 @@ void preprocess_resource(const std::string& res_name, preproc_map *defines_map,
|
|||
std::string streamContent = ss.str();
|
||||
|
||||
read(cfg, streamContent);
|
||||
const std::string preproc_res_name = target_directory + "/" + file_name(res_name);
|
||||
const std::string preproc_res_name = target_directory + "/" + filesystem::file_name(res_name);
|
||||
|
||||
// write the processed cfg file
|
||||
if (write_cfg == true)
|
||||
{
|
||||
LOG_PREPROC << "writing cfg file: " << preproc_res_name << '\n';
|
||||
create_directory_if_missing_recursive(directory_name(preproc_res_name));
|
||||
scoped_ostream outStream(ostream_file(preproc_res_name));
|
||||
filesystem::create_directory_if_missing_recursive(filesystem::directory_name(preproc_res_name));
|
||||
filesystem::scoped_ostream outStream(filesystem::ostream_file(preproc_res_name));
|
||||
write(*outStream, cfg);
|
||||
}
|
||||
|
||||
|
@ -1248,8 +1248,8 @@ void preprocess_resource(const std::string& res_name, preproc_map *defines_map,
|
|||
if (write_plain_cfg == true)
|
||||
{
|
||||
LOG_PREPROC << "writing plain cfg file: " << (preproc_res_name + ".plain") << '\n';
|
||||
create_directory_if_missing_recursive(directory_name(preproc_res_name));
|
||||
write_file(preproc_res_name + ".plain", streamContent);
|
||||
filesystem::create_directory_if_missing_recursive(filesystem::directory_name(preproc_res_name));
|
||||
filesystem::write_file(preproc_res_name + ".plain", streamContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ bool schema_validator::read_config_file(const std::string &filename){
|
|||
try {
|
||||
preproc_map preproc(
|
||||
game_config::config_cache::instance().get_preproc_map());
|
||||
scoped_istream stream = preprocess_file(filename, &preproc);
|
||||
filesystem::scoped_istream stream = preprocess_file(filename, &preproc);
|
||||
read(cfg, *stream);
|
||||
} catch(config::error&) {
|
||||
return false;
|
||||
|
|
|
@ -261,11 +261,11 @@ static lg::log_domain log_server("server");
|
|||
|
||||
void ban_manager::read()
|
||||
{
|
||||
if (filename_.empty() || !file_exists(filename_))
|
||||
if (filename_.empty() || !filesystem::file_exists(filename_))
|
||||
return;
|
||||
LOG_SERVER << "Reading bans from " << filename_ << "\n";
|
||||
config cfg;
|
||||
scoped_istream ban_file = istream_file(filename_);
|
||||
filesystem::scoped_istream ban_file = filesystem::istream_file(filename_);
|
||||
read_gz(cfg, *ban_file);
|
||||
|
||||
BOOST_FOREACH(const config &b, cfg.child_range("ban"))
|
||||
|
@ -319,7 +319,7 @@ static lg::log_domain log_server("server");
|
|||
(*itor)->write(child);
|
||||
}
|
||||
|
||||
scoped_ostream ban_file = ostream_file(filename_);
|
||||
filesystem::scoped_ostream ban_file = filesystem::ostream_file(filename_);
|
||||
config_writer writer(*ban_file, true);
|
||||
writer.write(cfg);
|
||||
}
|
||||
|
|
|
@ -1488,7 +1488,7 @@ void game::save_replay() {
|
|||
std::replace(filename.begin(), filename.end(), ' ', '_');
|
||||
filename.erase(std::remove_if(filename.begin(), filename.end(), is_invalid_filename_char), filename.end());
|
||||
DBG_GAME << "saving replay: " << filename << std::endl;
|
||||
scoped_ostream os(ostream_file(replay_save_path_ + filename));
|
||||
filesystem::scoped_ostream os(filesystem::ostream_file(replay_save_path_ + filename));
|
||||
(*os) << replay.output_compressed(true);
|
||||
|
||||
if (!os->good()) {
|
||||
|
|
|
@ -87,10 +87,10 @@ void room_manager::load_config(const config& cfg)
|
|||
|
||||
void room_manager::read_rooms()
|
||||
{
|
||||
if (!filename_.empty() && file_exists(filename_)) {
|
||||
if (!filename_.empty() && filesystem::file_exists(filename_)) {
|
||||
LOG_LOBBY << "Reading rooms from " << filename_ << "\n";
|
||||
config cfg;
|
||||
scoped_istream file = istream_file(filename_);
|
||||
filesystem::scoped_istream file = filesystem::istream_file(filename_);
|
||||
if (compress_stored_rooms_) {
|
||||
read_gz(cfg, *file);
|
||||
} else {
|
||||
|
@ -130,7 +130,7 @@ void room_manager::write_rooms()
|
|||
}
|
||||
}
|
||||
|
||||
scoped_ostream file = ostream_file(filename_);
|
||||
filesystem::scoped_ostream file = filesystem::ostream_file(filename_);
|
||||
config_writer writer(*file, compress_stored_rooms_);
|
||||
writer.write(cfg);
|
||||
dirty_ = false;
|
||||
|
|
|
@ -474,7 +474,7 @@ config server::read_config() const {
|
|||
config configuration;
|
||||
if (config_file_ == "") return configuration;
|
||||
try {
|
||||
scoped_istream stream = preprocess_file(config_file_);
|
||||
filesystem::scoped_istream stream = preprocess_file(config_file_);
|
||||
read(configuration, *stream);
|
||||
LOG_SERVER << "Server configuration from file: '" << config_file_
|
||||
<< "' read.\n";
|
||||
|
@ -509,7 +509,7 @@ void server::load_config() {
|
|||
save_replays_ = cfg_["save_replays"].to_bool();
|
||||
replay_save_path_ = cfg_["replay_save_path"].str();
|
||||
|
||||
tor_ip_list_ = utils::split(cfg_["tor_ip_list_path"].empty() ? "" : read_file(cfg_["tor_ip_list_path"]), '\n');
|
||||
tor_ip_list_ = utils::split(cfg_["tor_ip_list_path"].empty() ? "" : filesystem::read_file(cfg_["tor_ip_list_path"]), '\n');
|
||||
|
||||
admin_passwd_ = cfg_["passwd"].str();
|
||||
motd_ = cfg_["motd"].str();
|
||||
|
@ -2791,7 +2791,7 @@ int main(int argc, char** argv) {
|
|||
std::string config_file;
|
||||
|
||||
// setting path to currentworking directory
|
||||
game_config::path = get_cwd();
|
||||
game_config::path = filesystem::get_cwd();
|
||||
|
||||
// show 'info' by default
|
||||
lg::set_log_domain_severity("server", lg::info);
|
||||
|
|
|
@ -718,7 +718,7 @@ static Mix_Chunk* load_chunk(const std::string& file, channel_group group)
|
|||
throw chunk_load_exception();
|
||||
}
|
||||
temp_chunk.group = group;
|
||||
std::string const &filename = get_binary_file_location("sounds", file);
|
||||
std::string const &filename = filesystem::get_binary_file_location("sounds", file);
|
||||
|
||||
if (!filename.empty()) {
|
||||
temp_chunk.set_data(Mix_LoadWAV(filename.c_str()));
|
||||
|
|
|
@ -77,7 +77,7 @@ void music_track::resolve()
|
|||
return;
|
||||
}
|
||||
|
||||
file_path_ = get_binary_file_location("music", id_);
|
||||
file_path_ = filesystem::get_binary_file_location("music", id_);
|
||||
|
||||
if (file_path_.empty()) {
|
||||
LOG_AUDIO << "could not find track '" << id_ << "' for track identification\n";
|
||||
|
|
|
@ -118,19 +118,19 @@ main(int argc, char* argv[])
|
|||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
if(!is_directory(root)) {
|
||||
if(file_exists(root)) {
|
||||
if(!filesystem::is_directory(root)) {
|
||||
if(filesystem::file_exists(root)) {
|
||||
std::cerr << "";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if(!make_directory(root)) {
|
||||
if(!filesystem::make_directory(root)) {
|
||||
std::cerr << "";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_FOREACH(const tcreator& creator, creators) {
|
||||
if(!make_directory(root + creator.first)) {
|
||||
if(!filesystem::make_directory(root + creator.first)) {
|
||||
std::cerr << "";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
|
|
@ -362,7 +362,7 @@ BOOST_AUTO_TEST_CASE(test_gui2)
|
|||
cache.add_define("MULTIPLAYER");
|
||||
cache.get_config(game_config::path +"/data", main_config);
|
||||
|
||||
const binary_paths_manager bin_paths_manager(main_config);
|
||||
const filesystem::binary_paths_manager bin_paths_manager(main_config);
|
||||
|
||||
load_language_list();
|
||||
game_config::load_config(main_config.child("game_config"));
|
||||
|
|
|
@ -94,7 +94,7 @@ namespace test {
|
|||
source.release_key(13, keyid);
|
||||
|
||||
std::string fname("test_save");
|
||||
write_file(get_saves_dir() + "/" + fname +".gz", "böö");
|
||||
filesystem::write_file(filesystem::get_saves_dir() + "/" + fname +".gz", "böö");
|
||||
// Start test (set ticks start time)
|
||||
|
||||
// Activated enter press
|
||||
|
@ -123,7 +123,7 @@ namespace test {
|
|||
BOOST_CHECK_MESSAGE(press_return_after->is_fired(), "get_save_name returned before 2nd enter event was sent");
|
||||
BOOST_CHECK_MESSAGE(!release_return_after->is_fired(), "get_save_name returned after 2nd release event was sent");
|
||||
*/
|
||||
remove((get_saves_dir() + "/" + fname + ".gz").c_str());
|
||||
remove((filesystem::get_saves_dir() + "/" + fname + ".gz").c_str());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
|
|
@ -67,7 +67,7 @@ struct wesnoth_global_fixture {
|
|||
|
||||
boost::unit_test::results_reporter::set_stream(reporter);
|
||||
// lg::set_log_domain_severity("all",lg::debug);
|
||||
game_config::path = get_cwd();
|
||||
game_config::path = filesystem::get_cwd();
|
||||
|
||||
|
||||
// Initialize unit tests
|
||||
|
|
|
@ -117,7 +117,7 @@ private:
|
|||
|
||||
std::stringstream ignored_stream_;
|
||||
lg::tredirect_output_setter output_redirect_;
|
||||
binary_paths_manager paths_manager_;
|
||||
filesystem::binary_paths_manager paths_manager_;
|
||||
};
|
||||
} // anonymous namespace
|
||||
|
||||
|
|
|
@ -188,7 +188,7 @@ static std::string create_random_sendfile(size_t size)
|
|||
int *begin = reinterpret_cast<int*>(&buffer[0]);
|
||||
int *end = begin + sizeof(buffer)/sizeof(int);
|
||||
std::string filename = "sendfile.tmp";
|
||||
scoped_ostream file = ostream_file(filename);
|
||||
filesystem::scoped_ostream file = filesystem::ostream_file(filename);
|
||||
std::generate(begin,end,std::rand);
|
||||
while( size > 0
|
||||
&& !file->bad())
|
||||
|
@ -201,7 +201,7 @@ static std::string create_random_sendfile(size_t size)
|
|||
|
||||
static void delete_random_sendfile(const std::string& file)
|
||||
{
|
||||
delete_directory(file);
|
||||
filesystem::delete_directory(file);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
|
@ -244,12 +244,12 @@ WESNOTH_PARAMETERIZED_TEST_CASE( test_multi_sendfile, sendfile_param, sendfile_s
|
|||
std::vector<char> data;
|
||||
|
||||
BOOST_CHECK_PREDICATE(test_utils::one_of<network::connection> , (receive(data,500))(3)(se_client1)(se_client2)(se_client3));
|
||||
BOOST_CHECK_EQUAL(data.size(), static_cast<size_t>(file_size(file)));
|
||||
BOOST_CHECK_EQUAL(data.size(), static_cast<size_t>(filesystem::file_size(file)));
|
||||
BOOST_CHECK_PREDICATE(test_utils::one_of<network::connection> , (receive(data,500))(3)(se_client1)(se_client2)(se_client3));
|
||||
BOOST_CHECK_EQUAL(data.size(), static_cast<size_t>(file_size(file)));
|
||||
BOOST_CHECK_EQUAL(data.size(), static_cast<size_t>(filesystem::file_size(file)));
|
||||
BOOST_CHECK_PREDICATE(test_utils::one_of<network::connection> , (receive(data,500))(3)(se_client1)(se_client2)(se_client3));
|
||||
|
||||
BOOST_CHECK_EQUAL(data.size(), static_cast<size_t>(file_size(file)));
|
||||
BOOST_CHECK_EQUAL(data.size(), static_cast<size_t>(filesystem::file_size(file)));
|
||||
|
||||
network::disconnect(cl_client1);
|
||||
network::disconnect(cl_client2);
|
||||
|
|
|
@ -43,7 +43,7 @@ namespace test_utils {
|
|||
|
||||
class game_config_manager {
|
||||
config cfg_;
|
||||
binary_paths_manager paths_manager_;
|
||||
filesystem::binary_paths_manager paths_manager_;
|
||||
const hotkey::manager hotkey_manager_;
|
||||
font::manager font_manager_;
|
||||
|
||||
|
@ -67,7 +67,7 @@ namespace test_utils {
|
|||
std::setlocale(LC_ALL, "C");
|
||||
std::setlocale(LC_MESSAGES, "");
|
||||
#endif
|
||||
const std::string& intl_dir = get_intl_dir();
|
||||
const std::string& intl_dir = filesystem::get_intl_dir();
|
||||
bindtextdomain ("wesnoth", intl_dir.c_str());
|
||||
bind_textdomain_codeset ("wesnoth", "UTF-8");
|
||||
bindtextdomain ("wesnoth-lib", intl_dir.c_str());
|
||||
|
|
|
@ -37,7 +37,7 @@ const config cutter::load_config(const std::string &filename)
|
|||
config res;
|
||||
|
||||
try {
|
||||
scoped_istream stream = preprocess_file(conf_string);
|
||||
filesystem::scoped_istream stream = preprocess_file(conf_string);
|
||||
read(res, *stream);
|
||||
} catch(config::error& err) {
|
||||
throw exploder_failure("Unable to load the configuration for the file " + filename + ": "+ err.message);
|
||||
|
@ -106,7 +106,7 @@ cutter::surface_map cutter::cut_surface(surface surf, const config& conf)
|
|||
std::string cutter::find_configuration(const std::string &file)
|
||||
{
|
||||
//finds the file prefix.
|
||||
const std::string fname = file_name(file);
|
||||
const std::string fname = filesystem::file_name(file);
|
||||
const std::string::size_type dotpos = fname.rfind('.');
|
||||
|
||||
std::string basename;
|
||||
|
|
|
@ -100,15 +100,15 @@ int main(int argc, char *argv[]){
|
|||
input_dir = "./src";
|
||||
}
|
||||
|
||||
if (! file_exists(input_dir)){
|
||||
if (! filesystem::file_exists(input_dir)){
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::vector<std::string> files;
|
||||
std::vector<std::string> dirs;
|
||||
|
||||
if (is_directory(input_dir)){
|
||||
get_files_in_dir(input_dir, &files, &dirs, ENTIRE_FILE_PATH);
|
||||
if (filesystem::is_directory(input_dir)){
|
||||
filesystem::get_files_in_dir(input_dir, &files, &dirs, filesystem::ENTIRE_FILE_PATH);
|
||||
|
||||
if (files.empty() && dirs.empty()){
|
||||
std::cout << "Some problem with input directory "
|
||||
|
@ -120,7 +120,7 @@ int main(int argc, char *argv[]){
|
|||
while (!dirs.empty()){
|
||||
std::string temp_dir = dirs.back();
|
||||
dirs.pop_back();
|
||||
get_files_in_dir(temp_dir, &files, &dirs, ENTIRE_FILE_PATH);
|
||||
filesystem::get_files_in_dir(temp_dir, &files, &dirs, filesystem::ENTIRE_FILE_PATH);
|
||||
}
|
||||
}else{
|
||||
files.push_back(input_dir);
|
||||
|
@ -132,13 +132,13 @@ int main(int argc, char *argv[]){
|
|||
|
||||
for (;i != files.end(); ++i){
|
||||
bool ok = false;
|
||||
if (file_name((*i)).find(".cpp")!=std::string::npos){
|
||||
if (filesystem::file_name((*i)).find(".cpp")!=std::string::npos){
|
||||
ok = true;
|
||||
} else
|
||||
if (file_name((*i)).find(".hpp")!=std::string::npos){
|
||||
if (filesystem::file_name((*i)).find(".hpp")!=std::string::npos){
|
||||
ok = true;
|
||||
} else
|
||||
if (file_name((*i)).find(".schema")!=std::string::npos){
|
||||
if (filesystem::file_name((*i)).find(".schema")!=std::string::npos){
|
||||
ok = true;
|
||||
}
|
||||
if (ok){
|
||||
|
|
|
@ -64,7 +64,7 @@ int main(int argc, char *argv[]){
|
|||
try {
|
||||
preproc_map preproc(
|
||||
game_config::config_cache::instance().get_preproc_map());
|
||||
scoped_istream stream = preprocess_file(input,
|
||||
filesystem::scoped_istream stream = preprocess_file(input,
|
||||
&preproc);
|
||||
read(cfg, *stream, &validator);
|
||||
} catch(config::error & t) {
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "config.hpp" // for config, config::error, etc
|
||||
#include "cursor.hpp" // for set, CURSOR_TYPE::NORMAL, etc
|
||||
#include "editor/editor_main.hpp"
|
||||
#include "filesystem.hpp" // for file_exists, io_exception, etc
|
||||
#include "filesystem.hpp" // for filesystem::file_exists, filesystem::io_exception, etc
|
||||
#include "font.hpp" // for load_font_config, etc
|
||||
#include "formula.hpp" // for formula_error
|
||||
#include "game_config.hpp" // for path, debug, debug_lua, etc
|
||||
|
@ -133,7 +133,7 @@ static void encode(const std::string & input_file, const std::string & output_fi
|
|||
boost::iostreams::copy(ifile, stream);
|
||||
ifile.close();
|
||||
safe_exit(remove(input_file.c_str()));
|
||||
} catch(io_exception& e) {
|
||||
} catch(filesystem::io_exception& e) {
|
||||
std::cerr << "IO error: " << e.what() << "\n";
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ static void decode(const std::string & input_file, const std::string & output_fi
|
|||
boost::iostreams::copy(stream, ofile);
|
||||
ifile.close();
|
||||
safe_exit(remove(input_file.c_str()));
|
||||
} catch(io_exception& e) {
|
||||
} catch(filesystem::io_exception& e) {
|
||||
std::cerr << "IO error: " << e.what() << "\n";
|
||||
}
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ static void handle_preprocess_command(const commandline_options& cmdline_opts)
|
|||
|
||||
if( cmdline_opts.preprocess_input_macros ) {
|
||||
std::string file = *cmdline_opts.preprocess_input_macros;
|
||||
if ( file_exists( file ) == false )
|
||||
if ( filesystem::file_exists( file ) == false )
|
||||
{
|
||||
std::cerr << "please specify an existing file. File "<< file <<" doesn't exist.\n";
|
||||
return;
|
||||
|
@ -194,7 +194,7 @@ static void handle_preprocess_command(const commandline_options& cmdline_opts)
|
|||
config cfg;
|
||||
|
||||
try {
|
||||
scoped_istream stream = istream_file( file );
|
||||
filesystem::scoped_istream stream = filesystem::istream_file( file );
|
||||
read( cfg, *stream );
|
||||
} catch (config::error & e) {
|
||||
std::cerr << "Caught a config error while parsing file '" << file << "':\n" << e.message << std::endl;
|
||||
|
@ -285,7 +285,7 @@ static void handle_preprocess_command(const commandline_options& cmdline_opts)
|
|||
std::cerr << "writing '" << outputPath << "' with "
|
||||
<< defines_map.size() << " defines.\n";
|
||||
|
||||
scoped_ostream out = ostream_file(outputPath);
|
||||
filesystem::scoped_ostream out = filesystem::ostream_file(outputPath);
|
||||
if (!out->fail())
|
||||
{
|
||||
config_writer writer(*out,false);
|
||||
|
@ -309,17 +309,17 @@ static int process_command_args(const commandline_options& cmdline_opts) {
|
|||
// Options that don't change behavior based on any others should be checked alphabetically below.
|
||||
|
||||
if(cmdline_opts.userconfig_dir) {
|
||||
set_user_config_dir(*cmdline_opts.userconfig_dir);
|
||||
filesystem::set_user_config_dir(*cmdline_opts.userconfig_dir);
|
||||
}
|
||||
if(cmdline_opts.userconfig_path) {
|
||||
std::cout << get_user_config_dir() << '\n';
|
||||
std::cout << filesystem::get_user_config_dir() << '\n';
|
||||
return 0;
|
||||
}
|
||||
if(cmdline_opts.userdata_dir) {
|
||||
set_user_data_dir(*cmdline_opts.userdata_dir);
|
||||
filesystem::set_user_data_dir(*cmdline_opts.userdata_dir);
|
||||
}
|
||||
if(cmdline_opts.userdata_path) {
|
||||
std::cout << get_user_data_dir() << '\n';
|
||||
std::cout << filesystem::get_user_data_dir() << '\n';
|
||||
return 0;
|
||||
}
|
||||
if(cmdline_opts.data_dir) {
|
||||
|
@ -333,10 +333,10 @@ static int process_command_args(const commandline_options& cmdline_opts) {
|
|||
#endif
|
||||
game_config::path = datadir;
|
||||
} else {
|
||||
game_config::path = get_cwd() + '/' + datadir;
|
||||
game_config::path = filesystem::get_cwd() + '/' + datadir;
|
||||
}
|
||||
|
||||
if(!is_directory(game_config::path)) {
|
||||
if(!filesystem::is_directory(game_config::path)) {
|
||||
std::cerr << "Could not find directory '" << game_config::path << "'\n";
|
||||
throw config::error("directory not found");
|
||||
}
|
||||
|
@ -352,7 +352,7 @@ static int process_command_args(const commandline_options& cmdline_opts) {
|
|||
}
|
||||
if(cmdline_opts.gunzip) {
|
||||
const std::string input_file(*cmdline_opts.gunzip);
|
||||
if(!is_gzip_file(input_file)) {
|
||||
if(!filesystem::is_gzip_file(input_file)) {
|
||||
std::cerr << "file '" << input_file << "'isn't a .gz file\n";
|
||||
return 2;
|
||||
}
|
||||
|
@ -362,7 +362,7 @@ static int process_command_args(const commandline_options& cmdline_opts) {
|
|||
}
|
||||
if(cmdline_opts.bunzip2) {
|
||||
const std::string input_file(*cmdline_opts.bunzip2);
|
||||
if(!is_bzip2_file(input_file)) {
|
||||
if(!filesystem::is_bzip2_file(input_file)) {
|
||||
std::cerr << "file '" << input_file << "'isn't a .bz2 file\n";
|
||||
return 2;
|
||||
}
|
||||
|
@ -440,7 +440,7 @@ static int process_command_args(const commandline_options& cmdline_opts) {
|
|||
/**
|
||||
* I would prefer to setup locale first so that early error
|
||||
* messages can get localized, but we need the game_launcher
|
||||
* initialized to have get_intl_dir() to work. Note: setlocale()
|
||||
* initialized to have filesystem::get_intl_dir() to work. Note: setlocale()
|
||||
* does not take GUI language setting into account.
|
||||
*/
|
||||
static void init_locale() {
|
||||
|
@ -450,7 +450,7 @@ static void init_locale() {
|
|||
std::setlocale(LC_ALL, "C");
|
||||
std::setlocale(LC_MESSAGES, "");
|
||||
#endif
|
||||
const std::string& intl_dir = get_intl_dir();
|
||||
const std::string& intl_dir = filesystem::get_intl_dir();
|
||||
bindtextdomain (PACKAGE, intl_dir.c_str());
|
||||
bind_textdomain_codeset (PACKAGE, "UTF-8");
|
||||
bindtextdomain (PACKAGE "-lib", intl_dir.c_str());
|
||||
|
@ -485,7 +485,7 @@ static int do_gameloop(int argc, char** argv)
|
|||
srand(time(NULL));
|
||||
|
||||
commandline_options cmdline_opts = commandline_options(argc,argv);
|
||||
game_config::wesnoth_program_dir = directory_name(argv[0]);
|
||||
game_config::wesnoth_program_dir = filesystem::directory_name(argv[0]);
|
||||
int finished = process_command_args(cmdline_opts);
|
||||
if(finished != -1) {
|
||||
return finished;
|
||||
|
@ -792,7 +792,7 @@ int main(int argc, char** argv)
|
|||
const time_t t = time(NULL);
|
||||
std::cerr << "Started on " << ctime(&t) << "\n";
|
||||
|
||||
const std::string& exe_dir = get_exe_dir();
|
||||
const std::string& exe_dir = filesystem::get_exe_dir();
|
||||
if(!exe_dir.empty()) {
|
||||
// Try to autodetect the location of the game data dir. Note that
|
||||
// the root of the source tree currently doubles as the data dir.
|
||||
|
@ -800,13 +800,13 @@ int main(int argc, char** argv)
|
|||
|
||||
// scons leaves the resulting binaries at the root of the source
|
||||
// tree by default.
|
||||
if(file_exists(exe_dir + "/data/_main.cfg")) {
|
||||
if(filesystem::file_exists(exe_dir + "/data/_main.cfg")) {
|
||||
auto_dir = exe_dir;
|
||||
}
|
||||
// cmake encourages creating a subdir at the root of the source
|
||||
// tree for the build, and the resulting binaries are found in it.
|
||||
else if(file_exists(exe_dir + "/../data/_main.cfg")) {
|
||||
auto_dir = normalize_path(exe_dir + "/..");
|
||||
else if(filesystem::file_exists(exe_dir + "/../data/_main.cfg")) {
|
||||
auto_dir = filesystem::normalize_path(exe_dir + "/..");
|
||||
}
|
||||
|
||||
if(!auto_dir.empty()) {
|
||||
|
|
|
@ -109,7 +109,7 @@ void button::load_images() {
|
|||
sdl::timage pressed_image(image::get_texture(button_image_name_ + "-pressed.png"+ button_image_path_suffix_));
|
||||
sdl::timage active_image(image::get_texture(button_image_name_ + "-active.png"+ button_image_path_suffix_));
|
||||
sdl::timage disabled_image;
|
||||
if (file_exists(game_config::path + "/images/" + button_image_name_ + "-disabled.png"+ button_image_path_suffix_))
|
||||
if (filesystem::file_exists(game_config::path + "/images/" + button_image_name_ + "-disabled.png"+ button_image_path_suffix_))
|
||||
disabled_image = image::get_texture(button_image_name_ + "-disabled.png"+ button_image_path_suffix_);
|
||||
sdl::timage pressed_disabled_image, pressed_active_image, touched_image;
|
||||
|
||||
|
@ -117,15 +117,15 @@ void button::load_images() {
|
|||
overlayImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + ".png"+ button_image_path_suffix_);
|
||||
overlayPressedImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + "-pressed.png"+ button_image_path_suffix_);
|
||||
|
||||
if (file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-active.png"+ button_image_path_suffix_))
|
||||
if (filesystem::file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-active.png"+ button_image_path_suffix_))
|
||||
overlayActiveImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + "-active.png"+ button_image_path_suffix_);
|
||||
|
||||
if (file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-disabled.png"+ button_image_path_suffix_))
|
||||
if (filesystem::file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-disabled.png"+ button_image_path_suffix_))
|
||||
overlayDisabledImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + "-disabled.png"+ button_image_path_suffix_);
|
||||
if (overlayDisabledImage_.null())
|
||||
overlayDisabledImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + ".png~GS()" + button_image_path_suffix_);
|
||||
|
||||
if (file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-disabled-pressed.png"+ button_image_path_suffix_))
|
||||
if (filesystem::file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-disabled-pressed.png"+ button_image_path_suffix_))
|
||||
overlayPressedDisabledImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + "-disabled-pressed.png"+ button_image_path_suffix_);
|
||||
if (overlayPressedDisabledImage_.null())
|
||||
overlayPressedDisabledImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + "-pressed.png~GS()"+ button_image_path_suffix_);
|
||||
|
@ -152,7 +152,7 @@ void button::load_images() {
|
|||
if (pressed_active_image.null())
|
||||
pressed_active_image = pressed_image;
|
||||
|
||||
if (file_exists(game_config::path + "/images/" + button_image_name_ + size_postfix + "-disabled-pressed.png"+ button_image_path_suffix_))
|
||||
if (filesystem::file_exists(game_config::path + "/images/" + button_image_name_ + size_postfix + "-disabled-pressed.png"+ button_image_path_suffix_))
|
||||
pressed_disabled_image = image::get_texture(button_image_name_ + "-disabled-pressed.png"+ button_image_path_suffix_);
|
||||
if (pressed_disabled_image.null())
|
||||
pressed_disabled_image = image::get_texture(button_image_name_ + "-pressed.png~GS()"+ button_image_path_suffix_);
|
||||
|
@ -188,7 +188,7 @@ void button::load_images() {
|
|||
surface pressed_image(image::get_image(button_image_name_ + "-pressed.png"+ button_image_path_suffix_));
|
||||
surface active_image(image::get_image(button_image_name_ + "-active.png"+ button_image_path_suffix_));
|
||||
surface disabled_image;
|
||||
if (file_exists(game_config::path + "/images/" + button_image_name_ + "-disabled.png"+ button_image_path_suffix_))
|
||||
if (filesystem::file_exists(game_config::path + "/images/" + button_image_name_ + "-disabled.png"+ button_image_path_suffix_))
|
||||
disabled_image.assign((image::get_image(button_image_name_ + "-disabled.png"+ button_image_path_suffix_)));
|
||||
surface pressed_disabled_image, pressed_active_image, touched_image;
|
||||
|
||||
|
@ -196,15 +196,15 @@ void button::load_images() {
|
|||
overlayImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + ".png"+ button_image_path_suffix_));
|
||||
overlayPressedImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + "-pressed.png"+ button_image_path_suffix_));
|
||||
|
||||
if (file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-active.png"+ button_image_path_suffix_))
|
||||
if (filesystem::file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-active.png"+ button_image_path_suffix_))
|
||||
overlayActiveImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + "-active.png"+ button_image_path_suffix_));
|
||||
|
||||
if (file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-disabled.png"+ button_image_path_suffix_))
|
||||
if (filesystem::file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-disabled.png"+ button_image_path_suffix_))
|
||||
overlayDisabledImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + "-disabled.png"+ button_image_path_suffix_));
|
||||
if (overlayDisabledImage_.null())
|
||||
overlayDisabledImage_ = image::get_image(button_overlay_image_name_ + size_postfix + ".png~GS()" + button_image_path_suffix_);
|
||||
|
||||
if (file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-disabled-pressed.png"+ button_image_path_suffix_))
|
||||
if (filesystem::file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-disabled-pressed.png"+ button_image_path_suffix_))
|
||||
overlayPressedDisabledImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + "-disabled-pressed.png"+ button_image_path_suffix_));
|
||||
if (overlayPressedDisabledImage_.null())
|
||||
overlayPressedDisabledImage_ = image::get_image(button_overlay_image_name_ + size_postfix + "-pressed.png~GS()"+ button_image_path_suffix_);
|
||||
|
@ -231,7 +231,7 @@ void button::load_images() {
|
|||
if (pressed_active_image.null())
|
||||
pressed_active_image.assign(pressed_image);
|
||||
|
||||
if (file_exists(game_config::path + "/images/" + button_image_name_ + size_postfix + "-disabled-pressed.png"+ button_image_path_suffix_))
|
||||
if (filesystem::file_exists(game_config::path + "/images/" + button_image_name_ + size_postfix + "-disabled-pressed.png"+ button_image_path_suffix_))
|
||||
pressed_disabled_image.assign(image::get_image(button_image_name_ + "-disabled-pressed.png"+ button_image_path_suffix_));
|
||||
if (pressed_disabled_image.null())
|
||||
pressed_disabled_image = image::get_image(button_image_name_ + "-pressed.png~GS()"+ button_image_path_suffix_);
|
||||
|
|
|
@ -39,8 +39,8 @@ file_menu::file_menu(CVideo &disp, std::string start_file)
|
|||
type_a_head_(-1)
|
||||
{
|
||||
// If the start file is not a file or directory, use the root.
|
||||
if((!file_exists(chosen_file_) && !::is_directory(chosen_file_))
|
||||
|| !::is_directory(current_dir_)) {
|
||||
if((!filesystem::file_exists(chosen_file_) && !::filesystem::is_directory(chosen_file_))
|
||||
|| !::filesystem::is_directory(current_dir_)) {
|
||||
current_dir_ = path_delim;
|
||||
chosen_file_ = current_dir_;
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ int file_menu::delete_chosen_file() {
|
|||
}
|
||||
|
||||
bool file_menu::make_directory(const std::string& subdir_name) {
|
||||
bool ret = ::make_directory(add_path(current_dir_, subdir_name));
|
||||
bool ret = ::filesystem::make_directory(add_path(current_dir_, subdir_name));
|
||||
if (ret == false) {
|
||||
// gui2::show_transient_message(disp_.video(), "", _("Creation of the directory failed."));
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ void file_menu::entry_selected(const unsigned entry) {
|
|||
bool file_menu::is_directory(const std::string& fname) const {
|
||||
if(fname == path_up)
|
||||
return true;
|
||||
return ::is_directory(fname);
|
||||
return ::filesystem::is_directory(fname);
|
||||
}
|
||||
|
||||
void file_menu::change_directory(const std::string& path) {
|
||||
|
@ -176,7 +176,7 @@ std::string file_menu::get_choice() const {
|
|||
|
||||
std::string file_menu::get_path(const std::string& file_or_dir) const {
|
||||
std::string res_path = file_or_dir;
|
||||
if (!::is_directory(file_or_dir)) {
|
||||
if (!::filesystem::is_directory(file_or_dir)) {
|
||||
size_t index = file_or_dir.find_last_of(path_delim);
|
||||
if (index != std::string::npos) {
|
||||
res_path = file_or_dir.substr(0, index);
|
||||
|
@ -298,8 +298,8 @@ void file_menu::select_file(const std::string& begin_of_filename)
|
|||
void file_menu::update_file_lists() {
|
||||
files_in_current_dir_.clear();
|
||||
dirs_in_current_dir_.clear();
|
||||
get_files_in_dir(current_dir_, &files_in_current_dir_,
|
||||
&dirs_in_current_dir_, FILE_NAME_ONLY);
|
||||
filesystem::get_files_in_dir(current_dir_, &files_in_current_dir_,
|
||||
&dirs_in_current_dir_, filesystem::FILE_NAME_ONLY);
|
||||
display_current_files();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue