Save: Fix issues with adding an extension if missing

- The code should search for the last '.', not the first.
- Case-insensitively compare the extensions.
This commit is contained in:
Ilari Liusvaara 2017-08-08 09:48:53 +03:00
parent 9318e4de94
commit 4c6338888d

View file

@ -82,8 +82,13 @@ filedialog_output_params show_filedialog(wxWindow* parent, const std::string& ti
if(saving && p.types[findex].primaryext != "") {
//Append extension if needed.
std::string ext = p.types[findex].primaryext;
size_t dpos = filename.find_first_of(".");
if(dpos > filename.length() || filename.substr(dpos + 1) != ext)
size_t dpos = filename.find_last_of(".");
std::string extension;
if(dpos < filename.length()) {
extension = filename.substr(dpos + 1);
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
}
if(extension != ext)
filename = filename + "." + ext;
}
filedialog_output_params r;