move the check for illegal characters and the suffix .gz in filenames...
...to get_save_name so that it's always used
This commit is contained in:
parent
269e73839b
commit
094af61f8f
3 changed files with 31 additions and 26 deletions
|
@ -221,6 +221,11 @@ void show_objectives(game_display& disp, const config& level, const std::string&
|
|||
).show();
|
||||
}
|
||||
|
||||
bool is_illegal_file_char(char c)
|
||||
{
|
||||
return c == '/' || c == '\\' || c == ':';
|
||||
}
|
||||
|
||||
int get_save_name(display & disp,const std::string& message, const std::string& txt_label,
|
||||
std::string* fname, gui::DIALOG_TYPE dialog_type, const std::string& title,
|
||||
const bool has_exit_button, const bool ask_for_filename)
|
||||
|
@ -261,13 +266,30 @@ int get_save_name(display & disp,const std::string& message, const std::string&
|
|||
ask = true;
|
||||
}
|
||||
|
||||
if (std::count_if(fname->begin(),fname->end(),is_illegal_file_char)) {
|
||||
gui::message_dialog(disp, _("Error"),
|
||||
_("Save names may not contain colons, slashes, or backslashes. "
|
||||
"Please choose a different name.")).show();
|
||||
overwrite = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_gzip_file(*fname)) {
|
||||
gui::message_dialog(disp, _("Error"),
|
||||
_("Save names should not end on '.gz'. "
|
||||
"Please choose a different name.")).show();
|
||||
overwrite = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (res == 0 && save_game_exists(*fname)) {
|
||||
overwrite = gui::dialog(disp,_("Overwrite?"),
|
||||
_("Save already exists. Do you want to overwrite it?"), gui::YES_NO).show();
|
||||
} else {
|
||||
overwrite = 0;
|
||||
}
|
||||
} while ((res==0)&&(overwrite!=0));
|
||||
} while ((res == 0) && (overwrite != 0));
|
||||
|
||||
if(ignore_opt) {
|
||||
quit_prompt = -1;
|
||||
}
|
||||
|
|
|
@ -50,8 +50,11 @@ bool animate_unit_advancement(const game_data& info,unit_map& units, gamemap::lo
|
|||
|
||||
void show_objectives(game_display& disp, const config& level, const std::string& objectives);
|
||||
|
||||
// check if a character is valid for a filename
|
||||
bool is_illegal_file_char(char c);
|
||||
|
||||
// Ask user if I should really save the game and what name I should use
|
||||
// returns 0 iff user wants to save the game
|
||||
// returns 0 if user wants to save the game
|
||||
int get_save_name(display & disp,const std::string& message, const std::string& txt_label,
|
||||
std::string* fname, gui::DIALOG_TYPE dialog_type=gui::YES_NO,
|
||||
const std::string& title="", const bool has_exit_button=false,
|
||||
|
|
|
@ -315,11 +315,6 @@ namespace events{
|
|||
}
|
||||
}
|
||||
|
||||
static bool is_illegal_file_char(char c)
|
||||
{
|
||||
return c == '/' || c == '\\' || c == ':';
|
||||
}
|
||||
|
||||
menu_handler::menu_handler(game_display* gui, unit_map& units, std::vector<team>& teams,
|
||||
const config& level, const game_data& gameinfo, const gamemap& map,
|
||||
const config& game_config, const gamestatus& status, game_state& gamestate,
|
||||
|
@ -726,28 +721,13 @@ private:
|
|||
label = message;
|
||||
}
|
||||
|
||||
label.erase(std::remove_if(label.begin(),label.end(),is_illegal_file_char),label.end());
|
||||
label.erase(std::remove_if(label.begin(), label.end(),
|
||||
dialogs::is_illegal_file_char), label.end());
|
||||
|
||||
const int res = dialog_type == gui::NULL_DIALOG ? 0 : dialogs::get_save_name(*gui_,message,_("Name:"),&label,dialog_type, "", has_exit_button);
|
||||
const int res = dialog_type == gui::NULL_DIALOG ? 0
|
||||
: dialogs::get_save_name(*gui_,message, _("Name: "), &label,dialog_type, "", has_exit_button);
|
||||
|
||||
if(res == 0) {
|
||||
|
||||
if(std::count_if(label.begin(),label.end(),is_illegal_file_char)) {
|
||||
gui::message_dialog(*gui_, _("Error"),
|
||||
_("Save names may not contain colons, slashes, or backslashes. "
|
||||
"Please choose a different name.")).show();
|
||||
save_game(message,dialog_type);
|
||||
return;
|
||||
}
|
||||
|
||||
if(is_gzip_file(label)) {
|
||||
gui::message_dialog(*gui_, _("Error"),
|
||||
_("Save names should not end on '.gz'. "
|
||||
"Please choose a different name.")).show();
|
||||
save_game(message,dialog_type);
|
||||
return;
|
||||
}
|
||||
|
||||
config snapshot;
|
||||
if (!replay)
|
||||
write_game_snapshot(snapshot);
|
||||
|
|
Loading…
Add table
Reference in a new issue