1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-21 14:02:59 +01:00

Fix #3510: Auto append file extension when not specified on save

This commit is contained in:
Daniel Trujillo Viedma
2017-10-10 09:55:40 +02:00
committed by Michael Steenbeek
parent 5cc5761a25
commit 9dc04ed07a

View File

@@ -160,7 +160,21 @@ namespace OpenRCT2 { namespace Ui
std::string output;
if (Execute(cmd, &output) == 0)
{
result = output;
// The default file extension is taken from the **first** available filter, since
// we cannot obtain it from zenity's output. This means that the FileDialogDesc::Filters
// array must be carefully populated, at least the first element.
std::string pattern = desc.Filters[0].Pattern;
std::string defaultExtension = pattern.substr(pattern.find_last_of('.'));
int dotPosition = output.size() - defaultExtension.size();
// Add the default extension if no extension is specified
if (output.substr(dotPosition, defaultExtension.size()).compare(defaultExtension) == 0)
{
result = output;
}
else
{
result = output.append(defaultExtension);
}
}
break;
}