Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autosaves are not deleted if scenario name contains special characters #4116

Open
slavrenyuk opened this issue Jun 12, 2019 · 0 comments

Comments

Projects
None yet
2 participants
@slavrenyuk
Copy link

commented Jun 12, 2019

If scenario name contains special characters, they are removed before using the scenario name as a part of a save file name. Here is the code.

wesnoth/src/savegame.cpp

Lines 417 to 433 in 60fd504

bool savegame::is_illegal_file_char(char c)
{
return c == '/' || c == '\\' || c == ':' || (c >= 0x00 && c < 0x20)
#ifdef _WIN32
|| c == '?' || c == '|' || c == '<' || c == '>' || c == '*' || c == '"'
#endif
;
}
std::string savegame::create_filename(unsigned int turn_number) const
{
std::string filename = create_initial_filename(turn_number);
filename.erase(std::remove_if(filename.begin(), filename.end(),
is_illegal_file_char), filename.end());
std::replace(filename.begin(), filename.end(), '_', ' ');
return filename;
}

However, code that cleans auto saves doesn't remove the special characters.

wesnoth/src/savegame.cpp

Lines 67 to 78 in 60fd504

void clean_saves(const std::string& label)
{
std::vector<save_info> games = get_saves_list();
std::string prefix = label + "-" + _("Auto-Save");
LOG_SAVE << "Cleaning saves with prefix '" << prefix << "'\n";
for (std::vector<save_info>::iterator i = games.begin(); i != games.end(); ++i) {
if (i->name().compare(0, prefix.length(), prefix) == 0) {
LOG_SAVE << "Deleting savegame '" << i->name() << "'\n";
delete_game(i->name());
}
}
}

As a result, auto saves are not deleted.

It is proposed to add the code that removes special characters (as well as replaces underscore with whitespaces) to the clean_saves method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.