From 73bdf7481e244118bfb3102870dfc0404639f3db Mon Sep 17 00:00:00 2001 From: Eladash Date: Fri, 10 Sep 2021 21:27:33 +0300 Subject: [PATCH] Emu: Fix disc game move from hdd0/game --- Utilities/File.cpp | 4 ++-- Utilities/File.h | 2 +- rpcs3/Emu/System.cpp | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Utilities/File.cpp b/Utilities/File.cpp index 5dd2357f57..8729999fd8 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -383,12 +383,12 @@ shared_ptr fs::set_virtual_device(const std::string& name, shar return get_device_manager().set_device(name, std::move(device)); } -std::string fs::get_parent_dir(const std::string& path) +std::string fs::get_parent_dir(const std::string& path, u32 levels) { std::string_view result = path; // Number of path components to remove - usz to_remove = 1; + usz to_remove = levels; while (to_remove--) { diff --git a/Utilities/File.h b/Utilities/File.h index 20ed7760a2..58fed4ce39 100644 --- a/Utilities/File.h +++ b/Utilities/File.h @@ -156,7 +156,7 @@ namespace fs shared_ptr set_virtual_device(const std::string& name, shared_ptr device); // Try to get parent directory (returns empty string on failure) - std::string get_parent_dir(const std::string& path); + std::string get_parent_dir(const std::string& path, u32 levels = 1); // Get file information bool stat(const std::string& path, stat_t& info); diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 2105e0c748..033bb298e5 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -881,8 +881,10 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool // Booting disc game from wrong location sys_log.error("Disc game %s found at invalid location /dev_hdd0/game/", m_title_id); + const std::string dst_dir = hdd0_disc + sfb_dir.substr(hdd0_game.size()); + // Move and retry from correct location - if (fs::rename(elf_dir + "/../../", hdd0_disc + elf_dir.substr(hdd0_game.size()) + "/../../", false)) + if (fs::create_path(fs::get_parent_dir(dst_dir)) && fs::rename(sfb_dir, dst_dir, false)) { sys_log.success("Disc game %s moved to special location /dev_hdd0/disc/", m_title_id); return m_path = hdd0_disc + m_path.substr(hdd0_game.size()), Load(m_title_id, add_only);