From 3848155c42964cc3fd0b614a8f5cca3159bef31b Mon Sep 17 00:00:00 2001 From: lat9nq Date: Mon, 6 Jul 2020 23:24:15 -0400 Subject: [PATCH 1/7] common: Add a screenshots directory Adds a screenshots directory as a path managed by FileUtil. --- src/common/common_paths.h | 1 + src/common/file_util.cpp | 1 + src/common/file_util.h | 1 + 3 files changed, 3 insertions(+) diff --git a/src/common/common_paths.h b/src/common/common_paths.h index 076752d3b6..3c593d5f6c 100644 --- a/src/common/common_paths.h +++ b/src/common/common_paths.h @@ -35,6 +35,7 @@ #define KEYS_DIR "keys" #define LOAD_DIR "load" #define DUMP_DIR "dump" +#define SCREENSHOTS_DIR "screenshots" #define SHADER_DIR "shader" #define LOG_DIR "log" diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 45b750e1eb..4ede9f72cd 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -695,6 +695,7 @@ const std::string& GetUserPath(UserPath path, const std::string& new_path) { paths.emplace(UserPath::NANDDir, user_path + NAND_DIR DIR_SEP); paths.emplace(UserPath::LoadDir, user_path + LOAD_DIR DIR_SEP); paths.emplace(UserPath::DumpDir, user_path + DUMP_DIR DIR_SEP); + paths.emplace(UserPath::ScreenshotsDir, user_path + SCREENSHOTS_DIR DIR_SEP); paths.emplace(UserPath::ShaderDir, user_path + SHADER_DIR DIR_SEP); paths.emplace(UserPath::SysDataDir, user_path + SYSDATA_DIR DIR_SEP); paths.emplace(UserPath::KeysDir, user_path + KEYS_DIR DIR_SEP); diff --git a/src/common/file_util.h b/src/common/file_util.h index f7a0c33fae..187b93161c 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -32,6 +32,7 @@ enum class UserPath { SDMCDir, LoadDir, DumpDir, + ScreenshotsDir, ShaderDir, SysDataDir, UserDir, From 71b902cf622e02341334dcb16d70142503e0d045 Mon Sep 17 00:00:00 2001 From: lat9nq Date: Mon, 20 Jul 2020 23:03:49 -0400 Subject: [PATCH 2/7] configuration: Setup UI to config screenshot path and saving This adds two options to the General -> UI tab. The first disables picking a place to save the file. The second chooses a default directory for saving screenshots. --- src/yuzu/configuration/config.cpp | 31 +++++++++++++++-- src/yuzu/configuration/config.h | 2 ++ src/yuzu/configuration/configure_ui.cpp | 18 ++++++++++ src/yuzu/configuration/configure_ui.ui | 45 +++++++++++++++++++++++-- src/yuzu/uisettings.h | 2 +- 5 files changed, 93 insertions(+), 5 deletions(-) diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 59a193eddf..eb73481bd2 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -578,7 +578,6 @@ void Config::ReadPathValues() { UISettings::values.roms_path = ReadSetting(QStringLiteral("romsPath")).toString(); UISettings::values.symbols_path = ReadSetting(QStringLiteral("symbolsPath")).toString(); - UISettings::values.screenshot_path = ReadSetting(QStringLiteral("screenshotPath")).toString(); UISettings::values.game_dir_deprecated = ReadSetting(QStringLiteral("gameListRootDir"), QStringLiteral(".")).toString(); UISettings::values.game_dir_deprecated_deepscan = @@ -675,6 +674,22 @@ void Config::ReadRendererValues() { qt_config->endGroup(); } +void Config::ReadScreenshotValues() { + qt_config->beginGroup(QStringLiteral("Screenshots")); + + UISettings::values.enable_screenshot_save_as = + ReadSetting(QStringLiteral("enable_screenshot_save_as"), true).toBool(); + FileUtil::GetUserPath( + FileUtil::UserPath::ScreenshotsDir, + qt_config + ->value(QStringLiteral("screenshot_path"), QString::fromStdString(FileUtil::GetUserPath( + FileUtil::UserPath::ScreenshotsDir))) + .toString() + .toStdString()); + + qt_config->endGroup(); +} + void Config::ReadShortcutValues() { qt_config->beginGroup(QStringLiteral("Shortcuts")); @@ -756,6 +771,7 @@ void Config::ReadUIValues() { ReadUIGamelistValues(); ReadUILayoutValues(); ReadPathValues(); + ReadScreenshotValues(); ReadShortcutValues(); UISettings::values.single_window_mode = @@ -1085,7 +1101,6 @@ void Config::SavePathValues() { WriteSetting(QStringLiteral("romsPath"), UISettings::values.roms_path); WriteSetting(QStringLiteral("symbolsPath"), UISettings::values.symbols_path); - WriteSetting(QStringLiteral("screenshotPath"), UISettings::values.screenshot_path); qt_config->beginWriteArray(QStringLiteral("gamedirs")); for (int i = 0; i < UISettings::values.game_dirs.size(); ++i) { qt_config->setArrayIndex(i); @@ -1164,6 +1179,17 @@ void Config::SaveRendererValues() { qt_config->endGroup(); } +void Config::SaveScreenshotValues() { + qt_config->beginGroup(QStringLiteral("Screenshots")); + + WriteSetting(QStringLiteral("enableScreenshotSaveAs"), + UISettings::values.enable_screenshot_save_as); + WriteSetting(QStringLiteral("screenshotPath"), + QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir))); + + qt_config->endGroup(); +} + void Config::SaveShortcutValues() { qt_config->beginGroup(QStringLiteral("Shortcuts")); @@ -1226,6 +1252,7 @@ void Config::SaveUIValues() { SaveUIGamelistValues(); SaveUILayoutValues(); SavePathValues(); + SaveScreenshotValues(); SaveShortcutValues(); WriteSetting(QStringLiteral("singleWindowMode"), UISettings::values.single_window_mode, true); diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h index 8e815f8295..e5f39b0406 100644 --- a/src/yuzu/configuration/config.h +++ b/src/yuzu/configuration/config.h @@ -51,6 +51,7 @@ private: void ReadPathValues(); void ReadCpuValues(); void ReadRendererValues(); + void ReadScreenshotValues(); void ReadShortcutValues(); void ReadSystemValues(); void ReadUIValues(); @@ -76,6 +77,7 @@ private: void SavePathValues(); void SaveCpuValues(); void SaveRendererValues(); + void SaveScreenshotValues(); void SaveShortcutValues(); void SaveSystemValues(); void SaveUIValues(); diff --git a/src/yuzu/configuration/configure_ui.cpp b/src/yuzu/configuration/configure_ui.cpp index 24b6c5b722..fdf9d3351d 100644 --- a/src/yuzu/configuration/configure_ui.cpp +++ b/src/yuzu/configuration/configure_ui.cpp @@ -4,9 +4,11 @@ #include #include +#include #include #include "common/common_types.h" +#include "common/file_util.h" #include "core/settings.h" #include "ui_configure_ui.h" #include "yuzu/configuration/configure_ui.h" @@ -55,6 +57,14 @@ ConfigureUi::ConfigureUi(QWidget* parent) : QWidget(parent), ui(new Ui::Configur [=]() { ConfigureUi::UpdateSecondRowComboBox(); }); connect(ui->row_2_text_combobox, QOverload::of(&QComboBox::activated), [=]() { ConfigureUi::UpdateFirstRowComboBox(); }); + + // Set screenshot path to user specification. + connect(ui->screenshot_path_button, &QToolButton::pressed, this, [this] { + const QString& filename = QFileDialog::getExistingDirectory( + this, tr("Select Screenshots Path..."), + QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir))); + ui->screenshot_path_edit->setText(filename); + }); } ConfigureUi::~ConfigureUi() = default; @@ -66,6 +76,10 @@ void ConfigureUi::ApplyConfiguration() { UISettings::values.icon_size = ui->icon_size_combobox->currentData().toUInt(); UISettings::values.row_1_text_id = ui->row_1_text_combobox->currentData().toUInt(); UISettings::values.row_2_text_id = ui->row_2_text_combobox->currentData().toUInt(); + + UISettings::values.enable_screenshot_save_as = ui->enable_screenshot_save_as->isChecked(); + FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir, + ui->screenshot_path_edit->text().toStdString()); Settings::Apply(); } @@ -80,6 +94,10 @@ void ConfigureUi::SetConfiguration() { ui->show_add_ons->setChecked(UISettings::values.show_add_ons); ui->icon_size_combobox->setCurrentIndex( ui->icon_size_combobox->findData(UISettings::values.icon_size)); + + ui->enable_screenshot_save_as->setChecked(UISettings::values.enable_screenshot_save_as); + ui->screenshot_path_edit->setText( + QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir))); } void ConfigureUi::changeEvent(QEvent* event) { diff --git a/src/yuzu/configuration/configure_ui.ui b/src/yuzu/configuration/configure_ui.ui index 0b81747d70..d895b799f1 100644 --- a/src/yuzu/configuration/configure_ui.ui +++ b/src/yuzu/configuration/configure_ui.ui @@ -6,8 +6,8 @@ 0 0 - 300 - 377 + 363 + 391 @@ -127,6 +127,47 @@ + + + + Screenshots + + + + + + + + Ask Where To Save Screenshots (Windows Only) + + + + + + + + + Screenshots Path: + + + + + + + + + + ... + + + + + + + + + + diff --git a/src/yuzu/uisettings.h b/src/yuzu/uisettings.h index 6cc65736de..e82318d50d 100644 --- a/src/yuzu/uisettings.h +++ b/src/yuzu/uisettings.h @@ -66,11 +66,11 @@ struct Values { // Discord RPC bool enable_discord_presence; + bool enable_screenshot_save_as; u16 screenshot_resolution_factor; QString roms_path; QString symbols_path; - QString screenshot_path; QString game_dir_deprecated; bool game_dir_deprecated_deepscan; QVector game_dirs; From a723ed31fd4c5b3dbad5f2ad53a6d1556db15569 Mon Sep 17 00:00:00 2001 From: lat9nq Date: Mon, 6 Jul 2020 23:30:49 -0400 Subject: [PATCH 3/7] main: rewrite (save as) screenshot saving This picks a default directory and file name. If on Windows and save-as screenshot saving is enabled, it asks the user, first defaulting to the default screenshot path, and with a default filename in the format `[title_id]_[year-mt-dy_hr-mn-sc-msc].png`. Otherwise, or on Linux for now, it simply saves a file in that directory with that file name. --- src/yuzu/main.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 31a6351769..c6bf5214e1 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -2153,17 +2153,26 @@ void GMainWindow::OnToggleFilterBar() { void GMainWindow::OnCaptureScreenshot() { OnPauseGame(); - QFileDialog png_dialog(this, tr("Capture Screenshot"), UISettings::values.screenshot_path, - tr("PNG Image (*.png)")); - png_dialog.setAcceptMode(QFileDialog::AcceptSave); - png_dialog.setDefaultSuffix(QStringLiteral("png")); - if (png_dialog.exec()) { - const QString path = png_dialog.selectedFiles().first(); - if (!path.isEmpty()) { - UISettings::values.screenshot_path = QFileInfo(path).path(); - render_window->CaptureScreenshot(UISettings::values.screenshot_resolution_factor, path); + + const u64 title_id = Core::System::GetInstance().CurrentProcess()->GetTitleID(); + const auto screenshot_path = FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir); + const auto date = QDateTime::currentDateTime() + .toString(QStringLiteral("yyyy-MM-dd_hh-mm-ss-zzz")) + .toStdString(); + QString filename = QString::fromStdString(screenshot_path + fmt::format("{:016X}", title_id) + + "_" + date + ".png"); + +#ifdef _WIN32 + if (UISettings::values.enable_screenshot_save_as) { + filename = QFileDialog::getSaveFileName(this, tr("Capture Screenshot"), filename, + tr("PNG Image (*.png)")); + if (filename.isEmpty()) { + OnStartGame(); + return; } } +#endif + render_window->CaptureScreenshot(UISettings::values.screenshot_resolution_factor, filename); OnStartGame(); } From 599b7c26a9accd9e0e58604422473dd75519daee Mon Sep 17 00:00:00 2001 From: lat9nq Date: Tue, 7 Jul 2020 13:47:08 -0400 Subject: [PATCH 4/7] main: Don't use as many string copies Co-Authored-By: LC --- src/yuzu/main.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index c6bf5214e1..e6a1a80a33 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -2155,12 +2155,14 @@ void GMainWindow::OnCaptureScreenshot() { OnPauseGame(); const u64 title_id = Core::System::GetInstance().CurrentProcess()->GetTitleID(); - const auto screenshot_path = FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir); - const auto date = QDateTime::currentDateTime() - .toString(QStringLiteral("yyyy-MM-dd_hh-mm-ss-zzz")) - .toStdString(); - QString filename = QString::fromStdString(screenshot_path + fmt::format("{:016X}", title_id) + - "_" + date + ".png"); + const auto screenshot_path = + QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir)); + const auto date = + QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd_hh-mm-ss-zzz")); + QString filename = QStringLiteral("%1%2_%3.png") + .arg(screenshot_path) + .arg(title_id, 16, 16, QLatin1Char{'0'}) + .arg(date); #ifdef _WIN32 if (UISettings::values.enable_screenshot_save_as) { From 19250aadeee730a555ece749e7b3104bbd486f10 Mon Sep 17 00:00:00 2001 From: lat9nq Date: Mon, 20 Jul 2020 23:11:46 -0400 Subject: [PATCH 5/7] configure_ui: don't use an empty string If the user had cancelled, it would clear the text box. That behavior was sanitized underneath, but may anyways cause inconveniences. --- src/yuzu/configuration/configure_ui.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/yuzu/configuration/configure_ui.cpp b/src/yuzu/configuration/configure_ui.cpp index fdf9d3351d..5c916a0dd2 100644 --- a/src/yuzu/configuration/configure_ui.cpp +++ b/src/yuzu/configuration/configure_ui.cpp @@ -63,7 +63,9 @@ ConfigureUi::ConfigureUi(QWidget* parent) : QWidget(parent), ui(new Ui::Configur const QString& filename = QFileDialog::getExistingDirectory( this, tr("Select Screenshots Path..."), QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir))); - ui->screenshot_path_edit->setText(filename); + if (!filename.isEmpty()) { + ui->screenshot_path_edit->setText(filename); + } }); } From e35239b86128535d4ac308856ce2a928654f5dcb Mon Sep 17 00:00:00 2001 From: lat9nq Date: Mon, 20 Jul 2020 23:19:07 -0400 Subject: [PATCH 6/7] configure_ui: Ensure a separator follows the returned path --- src/yuzu/configuration/configure_ui.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/yuzu/configuration/configure_ui.cpp b/src/yuzu/configuration/configure_ui.cpp index 5c916a0dd2..91c21c5723 100644 --- a/src/yuzu/configuration/configure_ui.cpp +++ b/src/yuzu/configuration/configure_ui.cpp @@ -60,9 +60,11 @@ ConfigureUi::ConfigureUi(QWidget* parent) : QWidget(parent), ui(new Ui::Configur // Set screenshot path to user specification. connect(ui->screenshot_path_button, &QToolButton::pressed, this, [this] { - const QString& filename = QFileDialog::getExistingDirectory( - this, tr("Select Screenshots Path..."), - QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir))); + const QString& filename = + QFileDialog::getExistingDirectory( + this, tr("Select Screenshots Path..."), + QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir))) + + QDir::separator(); if (!filename.isEmpty()) { ui->screenshot_path_edit->setText(filename); } From 156bf5b2976b9df3451a06ca32092c252c6f039f Mon Sep 17 00:00:00 2001 From: lat9nq Date: Sun, 26 Jul 2020 13:29:47 -0400 Subject: [PATCH 7/7] config: Make the save-as identifier more consistent Solves an issue with restoring the value upon reloading program. --- src/yuzu/configuration/config.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index eb73481bd2..11633fd909 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -1182,9 +1182,9 @@ void Config::SaveRendererValues() { void Config::SaveScreenshotValues() { qt_config->beginGroup(QStringLiteral("Screenshots")); - WriteSetting(QStringLiteral("enableScreenshotSaveAs"), + WriteSetting(QStringLiteral("enable_screenshot_save_as"), UISettings::values.enable_screenshot_save_as); - WriteSetting(QStringLiteral("screenshotPath"), + WriteSetting(QStringLiteral("screenshot_path"), QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir))); qt_config->endGroup();