diff --git a/rpcs3/Emu/Cell/Modules/cellPhotoExport.cpp b/rpcs3/Emu/Cell/Modules/cellPhotoExport.cpp index 8a264bc721..473bd435e7 100644 --- a/rpcs3/Emu/Cell/Modules/cellPhotoExport.cpp +++ b/rpcs3/Emu/Cell/Modules/cellPhotoExport.cpp @@ -1,5 +1,6 @@ #include "stdafx.h" #include "Emu/Cell/PPUModule.h" +#include "Emu/System.h" #include "Emu/IdManager.h" #include "Emu/VFS.h" #include "cellSysutil.h" @@ -107,30 +108,16 @@ bool check_photo_path(const std::string& file_path) return true; } -std::string get_available_photo_path(const std::string& filename) +std::string get_available_photo_path(std::string_view filename) { - const std::string photo_dir = "/dev_hdd0/photo/"; - std::string dst_path = vfs::get(photo_dir + filename); - - // Do not overwrite existing files. Add a suffix instead. - for (u32 i = 0; fs::exists(dst_path); i++) + std::string_view extension = ".png"; + if (const auto extension_start = filename.find_last_of('.'); + extension_start != umax) { - const std::string suffix = fmt::format("_%d", i); - std::string new_filename = filename; - - if (const usz pos = new_filename.find_last_of('.'); pos != std::string::npos) - { - new_filename.insert(pos, suffix); - } - else - { - new_filename.append(suffix); - } - - dst_path = vfs::get(photo_dir + new_filename); + extension = filename.substr(extension_start); } - return dst_path; + return Emu.GetCallbacks().get_photo_path(fmt::format("%s%s", Emu.GetTitle(), extension)); } diff --git a/rpcs3/Emu/Cell/Modules/cellScreenshot.cpp b/rpcs3/Emu/Cell/Modules/cellScreenshot.cpp index baf9ee380d..060683bdea 100644 --- a/rpcs3/Emu/Cell/Modules/cellScreenshot.cpp +++ b/rpcs3/Emu/Cell/Modules/cellScreenshot.cpp @@ -46,22 +46,6 @@ std::string screenshot_info::get_game_comment() const return game_comment; } -std::string screenshot_info::get_screenshot_path(s32 year, s32 month, s32 day, s32 hour, s32 minute, s32 second) const -{ - u32 counter = 0; - const std::string path = vfs::get(fmt::format("/dev_hdd0/photo/%04d/%02d/%02d/%s %02d-%02d-%04d %02d-%02d-%02d", - year, month, day, vfs::escape(get_photo_title(), true), day, month, year, hour, minute, second)); - constexpr std::string_view extension = ".png"; - std::string suffix = std::string(extension); - - while (!Emu.IsStopped() && fs::is_file(path + suffix)) - { - suffix = fmt::format(" %d%s", ++counter, extension); - } - - return path + suffix; -} - error_code cellScreenShotSetParameter(vm::cptr param) { diff --git a/rpcs3/Emu/Cell/Modules/cellScreenshot.h b/rpcs3/Emu/Cell/Modules/cellScreenshot.h index de84257c7b..e581400dcd 100644 --- a/rpcs3/Emu/Cell/Modules/cellScreenshot.h +++ b/rpcs3/Emu/Cell/Modules/cellScreenshot.h @@ -44,7 +44,6 @@ struct screenshot_info std::string get_photo_title() const; std::string get_game_title() const; std::string get_game_comment() const; - std::string get_screenshot_path(s32 year, s32 month, s32 day, s32 hour, s32 minute, s32 second) const; }; struct screenshot_manager : public screenshot_info diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index 088fc70ef5..5288d72a1e 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -101,6 +101,7 @@ struct EmuCallbacks std::function get_localized_string; std::function get_localized_u32string; std::function get_localized_setting; + std::function get_photo_path; std::function)> play_sound; std::function get_image_info; // (filename, sub_type, width, height, CellSearchOrientation) std::function get_scaled_image; // (filename, target_width, target_height, width, height, dst, force_fit) diff --git a/rpcs3/main_application.cpp b/rpcs3/main_application.cpp index a1bc443cd0..ff3b70f952 100644 --- a/rpcs3/main_application.cpp +++ b/rpcs3/main_application.cpp @@ -18,6 +18,7 @@ #include "Emu/Io/Null/NullMouseHandler.h" #include "Emu/Io/KeyboardHandler.h" #include "Emu/Io/MouseHandler.h" +#include "Emu/VFS.h" #include "Input/basic_keyboard_handler.h" #include "Input/basic_mouse_handler.h" #include "Input/raw_mouse_handler.h" @@ -36,6 +37,7 @@ #include "Emu/Audio/FAudio/faudio_enumerator.h" #endif +#include #include // This shouldn't be outside rpcs3qt... #include // This shouldn't be outside rpcs3qt... #include // This shouldn't be outside rpcs3qt... @@ -377,5 +379,33 @@ EmuCallbacks main_application::CreateCallbacks() callbacks.enable_gamemode = [](bool enabled){ enable_gamemode(enabled); }; + callbacks.get_photo_path = [](std::string_view title) + { + const QDateTime date_time = QDateTime::currentDateTime(); + const QDate date = date_time.date(); + const QTime time = date_time.time(); + + std::string_view extension = ".png"; + if (const auto extension_start = title.find_last_of('.'); + extension_start != umax) + { + extension = title.substr(extension_start); + title = title.substr(0, extension_start); + } + + std::string suffix = std::string(extension); + const std::string path = vfs::get(fmt::format("/dev_hdd0/photo/%04d/%02d/%02d/%s %02d-%02d-%04d %02d-%02d-%02d", + date.year(), date.month(), date.day(), vfs::escape(title, true), + date.day(), date.month(), date.year(), time.hour(), time.minute(), time.second())); + + u32 counter = 0; + while (!Emu.IsStopped() && fs::is_file(path + suffix)) + { + suffix = fmt::format(" %d%s", ++counter, extension); + } + + return path + suffix; + }; + return callbacks; } diff --git a/rpcs3/rpcs3qt/gs_frame.cpp b/rpcs3/rpcs3qt/gs_frame.cpp index a2f122ecbb..483f5affdc 100644 --- a/rpcs3/rpcs3qt/gs_frame.cpp +++ b/rpcs3/rpcs3qt/gs_frame.cpp @@ -1040,9 +1040,7 @@ void gs_frame::take_screenshot(std::vector&& data, u32 sshot_width, u32 ssho } } - const QDate date = date_time.date(); - const QTime time = date_time.time(); - const std::string cell_sshot_filename = manager.get_screenshot_path(date.year(), date.month(), date.day(), time.hour(), time.minute(), time.second()); + const std::string cell_sshot_filename = Emu.GetCallbacks().get_photo_path(manager.get_photo_title() + ".png"); const std::string cell_sshot_dir = fs::get_parent_dir(cell_sshot_filename); screenshot_log.notice("Saving cell screenshot to %s", cell_sshot_filename);