diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 07c39a13f..1c48e9fe7 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -2131,6 +2131,21 @@ const char* Settings::GetDisplayScreenshotFormatExtension(DisplayScreenshotForma return s_display_screenshot_format_extensions[static_cast(format)]; } +std::optional Settings::GetDisplayScreenshotFormatFromFileName(const std::string_view filename) +{ + const std::string_view extension = Path::GetExtension(filename); + int index = 0; + for (const char* name : s_display_screenshot_format_extensions) + { + if (StringUtil::EqualNoCase(extension, name)) + return static_cast(index); + + index++; + } + + return std::nullopt; +} + static constexpr const std::array s_memory_card_type_names = { "None", "Shared", "PerGame", "PerGameTitle", "PerGameFileTitle", "NonPersistent", }; diff --git a/src/core/settings.h b/src/core/settings.h index e99cda12a..c7d223a33 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -547,6 +547,7 @@ struct Settings : public GPUSettings static const char* GetDisplayScreenshotFormatName(DisplayScreenshotFormat mode); static const char* GetDisplayScreenshotFormatDisplayName(DisplayScreenshotFormat mode); static const char* GetDisplayScreenshotFormatExtension(DisplayScreenshotFormat mode); + static std::optional GetDisplayScreenshotFormatFromFileName(const std::string_view filename); static std::optional ParseMemoryCardTypeName(const char* str); static const char* GetMemoryCardTypeName(MemoryCardType type); diff --git a/src/core/system.cpp b/src/core/system.cpp index 0cb1af31a..702256e86 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -5277,8 +5277,16 @@ void System::SaveScreenshot(const char* path, DisplayScreenshotMode mode, Displa return; std::string auto_path; - if (!path) + if (!path || path[0] == '\0') + { path = (auto_path = GetScreenshotPath(Settings::GetDisplayScreenshotFormatExtension(format))).c_str(); + } + else + { + // If the user chose a specific format, use that. + format = + Settings::GetDisplayScreenshotFormatFromFileName(FileSystem::GetDisplayNameFromPath(path)).value_or(format); + } GPUBackend::RenderScreenshotToFile(path, mode, quality, true); }