From a723ed31fd4c5b3dbad5f2ad53a6d1556db15569 Mon Sep 17 00:00:00 2001 From: lat9nq Date: Mon, 6 Jul 2020 23:30:49 -0400 Subject: 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(-) (limited to 'src/yuzu/main.cpp') diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 31a635176..c6bf5214e 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(); } -- cgit v1.2.3 From 599b7c26a9accd9e0e58604422473dd75519daee Mon Sep 17 00:00:00 2001 From: lat9nq Date: Tue, 7 Jul 2020 13:47:08 -0400 Subject: main: Don't use as many string copies Co-Authored-By: LC --- src/yuzu/main.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/yuzu/main.cpp') diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index c6bf5214e..e6a1a80a3 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) { -- cgit v1.2.3