1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Only append default extension when none is provided

This should give Linux the same behaviour as Windows. It requires testing, I don't have access to a Linux machine.
This commit is contained in:
Hielke Morsink
2018-03-22 22:09:37 +01:00
parent 6528a2fe37
commit 3b697c071d

View File

@@ -20,6 +20,7 @@
#include <sstream>
#include <stdexcept>
#include <openrct2/common.h>
#include <openrct2/core/Path.hpp>
#include <openrct2/core/String.hpp>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/ui/UiContext.h>
@@ -169,13 +170,13 @@ namespace OpenRCT2 { namespace Ui
// 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
const utf8 * filename = Path::GetFileName(output.c_str());
// If there is no extension, append the pattern
const utf8 * extension = Path::GetExtension(filename);
result = output;
if (extension[0] == '\0' && !defaultExtension.empty())
{
result = output.append(defaultExtension);
}