From 3b697c071d4489d5067cbfb02f1c0f00fa707da5 Mon Sep 17 00:00:00 2001 From: Hielke Morsink Date: Thu, 22 Mar 2018 22:09:37 +0100 Subject: [PATCH] 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. --- src/openrct2-ui/UiContext.Linux.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/openrct2-ui/UiContext.Linux.cpp b/src/openrct2-ui/UiContext.Linux.cpp index 2fa859d8f4..af47284af7 100644 --- a/src/openrct2-ui/UiContext.Linux.cpp +++ b/src/openrct2-ui/UiContext.Linux.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -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); }