System: Pull screenshot format from path extension

This commit is contained in:
Stenzek 2025-04-19 22:49:16 +10:00
parent 1f10cac42a
commit 437430cbc4
No known key found for this signature in database
3 changed files with 25 additions and 1 deletions

View File

@ -2131,6 +2131,21 @@ const char* Settings::GetDisplayScreenshotFormatExtension(DisplayScreenshotForma
return s_display_screenshot_format_extensions[static_cast<size_t>(format)]; return s_display_screenshot_format_extensions[static_cast<size_t>(format)];
} }
std::optional<DisplayScreenshotFormat> 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<DisplayScreenshotFormat>(index);
index++;
}
return std::nullopt;
}
static constexpr const std::array s_memory_card_type_names = { static constexpr const std::array s_memory_card_type_names = {
"None", "Shared", "PerGame", "PerGameTitle", "PerGameFileTitle", "NonPersistent", "None", "Shared", "PerGame", "PerGameTitle", "PerGameFileTitle", "NonPersistent",
}; };

View File

@ -547,6 +547,7 @@ struct Settings : public GPUSettings
static const char* GetDisplayScreenshotFormatName(DisplayScreenshotFormat mode); static const char* GetDisplayScreenshotFormatName(DisplayScreenshotFormat mode);
static const char* GetDisplayScreenshotFormatDisplayName(DisplayScreenshotFormat mode); static const char* GetDisplayScreenshotFormatDisplayName(DisplayScreenshotFormat mode);
static const char* GetDisplayScreenshotFormatExtension(DisplayScreenshotFormat mode); static const char* GetDisplayScreenshotFormatExtension(DisplayScreenshotFormat mode);
static std::optional<DisplayScreenshotFormat> GetDisplayScreenshotFormatFromFileName(const std::string_view filename);
static std::optional<MemoryCardType> ParseMemoryCardTypeName(const char* str); static std::optional<MemoryCardType> ParseMemoryCardTypeName(const char* str);
static const char* GetMemoryCardTypeName(MemoryCardType type); static const char* GetMemoryCardTypeName(MemoryCardType type);

View File

@ -5277,8 +5277,16 @@ void System::SaveScreenshot(const char* path, DisplayScreenshotMode mode, Displa
return; return;
std::string auto_path; std::string auto_path;
if (!path) if (!path || path[0] == '\0')
{
path = (auto_path = GetScreenshotPath(Settings::GetDisplayScreenshotFormatExtension(format))).c_str(); 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); GPUBackend::RenderScreenshotToFile(path, mode, quality, true);
} }