std::vector<save_info> manager::get_saves_list(const std::string *dir, const std::string* filter) { // Don't use a reference, it seems to break on arklinux with GCC-4.3. std::string saves_dir = (dir) ? *dir : get_saves_dir(); #ifdef _WIN32 conv_ansi_utf8(saves_dir, false); #endif std::vector<std::string> saves; get_files_in_dir(saves_dir,&saves); std::vector<save_info> res; for(std::vector<std::string>::iterator i = saves.begin(); i != saves.end(); ++i) { if(filter && std::search(i->begin(), i->end(), filter->begin(), filter->end()) == i->end()) { continue; } const time_t modified = file_create_time(saves_dir + "/" + *i); // replace_underbar2space(*i); #ifdef _WIN32 res.push_back(save_info(conv_ansi_utf8_2(*i, true), modified)); #else res.push_back(save_info(*i, modified)); #endif } std::sort(res.begin(),res.end(),save_info_less_time()); return res; }
void replace_space2underbar(std::string &name) { LOG_SAVE << "conv(U2A)-from:[" << name << "]" << std::endl; conv_ansi_utf8(name, false); LOG_SAVE << "conv(U2A)-to:[" << name << "]" << std::endl; LOG_SAVE << "replace_underbar2space-from:[" << name << "]" << std::endl; std::replace(name.begin(), name.end(), ' ', '_'); LOG_SAVE << "replace_underbar2space-to:[" << name << "]" << std::endl; }
bool manager::save_game_exists(const std::string& name) { // std::string fname = name; // replace_space2underbar(fname); std::string fullname = get_saves_dir() + "/" + name + ".sav"; #ifdef _WIN32 conv_ansi_utf8(fullname, false); #endif return file_exists(fullname); }
std::string get_saves_dir() { const std::string dir_path = get_user_data_dir_utf8() + "/saves"; std::string dir_path_ansi = dir_path; #ifdef _WIN32 conv_ansi_utf8(dir_path_ansi, false); #endif if (get_dir(dir_path_ansi).empty()) { return ""; } return dir_path; // return get_dir(dir_path); }
void manager::delete_game(const std::string& name) { // std::string modified_name = name; // replace_space2underbar(modified_name); std::string fullname = get_saves_dir() + "/" + name; #ifdef _WIN32 conv_ansi_utf8(fullname, false); #endif remove(fullname.c_str()); // remove((get_saves_dir() + "/" + modified_name).c_str()); }
void manager::remove_old_auto_saves(const int autosavemax, const int infinite_auto_saves) { std::string auto_save = _("Auto-Save"); int countdown = autosavemax; if (countdown == infinite_auto_saves) return; #ifdef _WIN32 conv_ansi_utf8(auto_save, false); #endif std::vector<save_info> games = get_saves_list(NULL, &auto_save); for (std::vector<save_info>::iterator i = games.begin(); i != games.end(); ++i) { if (countdown-- <= 0) { LOG_SAVE << "Deleting savegame '" << i->name << "'\n"; delete_game(i->name); } } }