Qt: Implement option for organizing screenshots in folders by game name

This commit is contained in:
Fabian Thomys 2025-07-01 08:07:48 +02:00
parent e936398e17
commit cfb4317706
7 changed files with 86 additions and 8 deletions

View File

@ -34,10 +34,12 @@
#include "pcsx2/Recording/InputRecording.h"
#include "pcsx2/Recording/InputRecordingControls.h"
#include "pcsx2/SIO/Sio.h"
#include "pcsx2/GS/GSExtra.h"
#include "common/Assertions.h"
#include "common/CocoaTools.h"
#include "common/FileSystem.h"
#include "common/Path.h"
#include <QtCore/QDateTime>
#include <QtCore/QDir>
@ -1454,6 +1456,8 @@ void MainWindow::onGameListEntryContextMenuRequested(const QPoint& point)
connect(menu.addAction(tr("Check Wiki Page")), &QAction::triggered, [this, entry]() { goToWikiPage(entry); });
}
action = menu.addAction(tr("Open Screenshots Folder"));
connect(action, &QAction::triggered, [this, entry]() { openScreenshotsFolderForGame(entry); });
menu.addSeparator();
if (!s_vm_valid)
@ -2905,6 +2909,39 @@ void MainWindow::goToWikiPage(const GameList::Entry* entry)
QtUtils::OpenURL(this, fmt::format("https://wiki.pcsx2.net/{}", entry->serial).c_str());
}
void MainWindow::openScreenshotsFolderForGame(const GameList::Entry* entry)
{
if (!entry || entry->title.empty())
return;
// if disabled open the snapshots folder
if (!EmuConfig.GS.OrganizeScreenshotsByGame)
{
QtUtils::OpenURL(this, QUrl::fromLocalFile(QString::fromStdString(EmuFolders::Snapshots)));
return;
}
std::string game_name = entry->title;
Path::SanitizeFileName(&game_name);
if (game_name.length() > 219)
{
game_name.resize(219);
}
const std::string game_dir = Path::Combine(EmuFolders::Snapshots, game_name);
if (!FileSystem::DirectoryExists(game_dir.c_str()))
{
if (!FileSystem::CreateDirectoryPath(game_dir.c_str(), false))
{
QMessageBox::critical(this, tr("Error"), tr("Failed to create screenshots directory '%1'.").arg(QString::fromStdString(game_dir)));
return;
}
}
const QFileInfo fi(QString::fromStdString(game_dir));
QtUtils::OpenURL(this, QUrl::fromLocalFile(fi.absoluteFilePath()));
}
std::optional<bool> MainWindow::promptForResumeState(const QString& save_state_path)
{
if (save_state_path.isEmpty())

View File

@ -274,6 +274,7 @@ private:
void setGameListEntryCoverImage(const GameList::Entry* entry);
void clearGameListEntryPlayTime(const GameList::Entry* entry);
void goToWikiPage(const GameList::Entry* entry);
void openScreenshotsFolderForGame(const GameList::Entry* entry);
std::optional<bool> promptForResumeState(const QString& save_state_path);
void loadSaveStateSlot(s32 slot, bool load_backup = false);

View File

@ -2,8 +2,10 @@
// SPDX-License-Identifier: GPL-3.0+
#include <QtWidgets/QMessageBox>
#include <algorithm>
#include "FolderSettingsWidget.h"
#include "pcsx2/GS/GS.h"
#include "SettingWidgetBinder.h"
#include "SettingsWindow.h"
@ -18,8 +20,14 @@ FolderSettingsWidget::FolderSettingsWidget(SettingsWindow* dialog, QWidget* pare
SettingWidgetBinder::BindWidgetToFolderSetting(sif, m_ui.cheats, m_ui.cheatsBrowse, m_ui.cheatsOpen, m_ui.cheatsReset, "Folders", "Cheats", Path::Combine(EmuFolders::DataRoot, "cheats"));
SettingWidgetBinder::BindWidgetToFolderSetting(sif, m_ui.covers, m_ui.coversBrowse, m_ui.coversOpen, m_ui.coversReset, "Folders", "Covers", Path::Combine(EmuFolders::DataRoot, "covers"));
SettingWidgetBinder::BindWidgetToFolderSetting(sif, m_ui.snapshots, m_ui.snapshotsBrowse, m_ui.snapshotsOpen, m_ui.snapshotsReset, "Folders", "Snapshots", Path::Combine(EmuFolders::DataRoot, "snaps"));
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.organizeScreenshotsByGame, "EmuCore/GS", "OrganizeScreenshotsByGame", false);
connect(m_ui.organizeScreenshotsByGame, &QCheckBox::checkStateChanged, this, [](int state) {
GSConfig.OrganizeScreenshotsByGame = (state == Qt::Checked);
});
SettingWidgetBinder::BindWidgetToFolderSetting(sif, m_ui.saveStates, m_ui.saveStatesBrowse, m_ui.saveStatesOpen, m_ui.saveStatesReset, "Folders", "SaveStates", Path::Combine(EmuFolders::DataRoot, "sstates"));
SettingWidgetBinder::BindWidgetToFolderSetting(sif, m_ui.videoDumpingDirectory, m_ui.videoDumpingDirectoryBrowse, m_ui.videoDumpingDirectoryOpen, m_ui.videoDumpingDirectoryReset, "Folders", "Videos", Path::Combine(EmuFolders::DataRoot, "videos"));
dialog->registerWidgetHelp(m_ui.organizeScreenshotsByGame, tr("Organize Screenshots by Game"), tr("Unchecked"),
tr("When enabled, screenshots will be saved in a folder with the game's name, instead of all being saved in the Snapshots folder"));
}
FolderSettingsWidget::~FolderSettingsWidget() = default;

View File

@ -175,12 +175,19 @@
</item>
<item row="0" column="0" colspan="4">
<widget class="QLabel" name="snaphotsLabel">
<property name="text">
<string>Used for screenshots and saving GS dumps.</string>
</property>
</widget>
</item>
</layout>
<property name="text">
<string>Used for screenshots and saving GS dumps.</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="4">
<widget class="QCheckBox" name="organizeScreenshotsByGame">
<property name="text">
<string>Save Screenshots in Game-Specific Folders</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">

View File

@ -781,7 +781,8 @@ struct Pcsx2Config
EnableVideoCaptureParameters : 1,
VideoCaptureAutoResolution : 1,
EnableAudioCapture : 1,
EnableAudioCaptureParameters : 1;
EnableAudioCaptureParameters : 1,
OrganizeScreenshotsByGame : 1;
};
};

View File

@ -876,7 +876,30 @@ static std::string GSGetBaseFilename()
std::string GSGetBaseSnapshotFilename()
{
// prepend snapshots directory
return Path::Combine(EmuFolders::Snapshots, GSGetBaseFilename());
std::string base_path = EmuFolders::Snapshots;
// If organize by game is enabled, create a game-specific folder
if (GSConfig.OrganizeScreenshotsByGame)
{
std::string game_name = VMManager::GetTitle(true);
if (!game_name.empty())
{
Path::SanitizeFileName(&game_name);
if (game_name.length() > 219)
{
game_name.resize(219);
}
const std::string game_dir = Path::Combine(base_path, game_name);
if (!FileSystem::DirectoryExists(game_dir.c_str()))
{
FileSystem::CreateDirectoryPath(game_dir.c_str(), false);
}
base_path = game_dir;
}
}
return Path::Combine(base_path, GSGetBaseFilename());
}
std::string GSGetBaseVideoFilename()

View File

@ -920,6 +920,7 @@ void Pcsx2Config::GSOptions::LoadSave(SettingsWrapper& wrap)
SettingsWrapIntEnumEx(ScreenshotSize, "ScreenshotSize");
SettingsWrapIntEnumEx(ScreenshotFormat, "ScreenshotFormat");
SettingsWrapEntry(ScreenshotQuality);
SettingsWrapBitBool(OrganizeScreenshotsByGame);
SettingsWrapEntry(StretchY);
SettingsWrapEntryEx(Crop[0], "CropLeft");
SettingsWrapEntryEx(Crop[1], "CropTop");