From 03a46a499e20b545127898a92ab1b0df87f3b848 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Tue, 27 Jul 2021 03:54:16 +0200 Subject: [PATCH] System: make IsPathInsideDir a member function --- rpcs3/Emu/System.cpp | 19 +++++++++---------- rpcs3/Emu/System.h | 3 +++ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 48d1c6ff0c..9594a4d259 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -799,23 +799,17 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool return game_boot_result::no_errors; } - // Check if path is inside the specified directory - auto is_path_inside_path = [this](std::string_view path, std::string_view dir) - { - return (GetCallbacks().resolve_path(path) + '/').starts_with(GetCallbacks().resolve_path(dir) + '/'); - }; - // Detect boot location constexpr usz game_dir_size = 8; // size of PS3_GAME and PS3_GMXX const std::string hdd0_game = vfs::get("/dev_hdd0/game/"); const std::string hdd0_disc = vfs::get("/dev_hdd0/disc/"); - const bool from_hdd0_game = is_path_inside_path(m_path, hdd0_game); - const bool from_dev_flash = is_path_inside_path(m_path, g_cfg.vfs.get_dev_flash()); + const bool from_hdd0_game = IsPathInsideDir(m_path, hdd0_game); + const bool from_dev_flash = IsPathInsideDir(m_path, g_cfg.vfs.get_dev_flash()); #ifdef _WIN32 // m_path might be passed from command line with differences in uppercase/lowercase on windows. - if ((!from_hdd0_game && is_path_inside_path(fmt::to_lower(m_path), fmt::to_lower(hdd0_game))) || - (!from_dev_flash && is_path_inside_path(fmt::to_lower(m_path), fmt::to_lower(g_cfg.vfs.get_dev_flash())))) + if ((!from_hdd0_game && IsPathInsideDir(fmt::to_lower(m_path), fmt::to_lower(hdd0_game))) || + (!from_dev_flash && IsPathInsideDir(fmt::to_lower(m_path), fmt::to_lower(g_cfg.vfs.get_dev_flash())))) { // Let's just abort to prevent errors down the line. sys_log.error("The boot path seems to contain incorrectly cased characters. Please adjust the path and try again."); @@ -1796,4 +1790,9 @@ std::set Emulator::GetGameDirs() const return dirs; } +bool Emulator::IsPathInsideDir(std::string_view path, std::string_view dir) const +{ + return (GetCallbacks().resolve_path(path) + '/').starts_with(GetCallbacks().resolve_path(dir) + '/'); +}; + Emulator Emu; diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index 268565f106..2cb4c08888 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -246,6 +246,9 @@ public: void ConfigurePPUCache() const; std::set GetGameDirs() const; + + // Check if path is inside the specified directory + bool IsPathInsideDir(std::string_view path, std::string_view dir) const; }; extern Emulator Emu;