From 83f9add68b6f0ec04edc65aa2b846a6d5acf475f Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Sun, 11 Aug 2024 20:01:52 -0700 Subject: [PATCH] Config: Allow specifying portable directory relative path in portable.txt --- pcsx2/Pcsx2Config.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pcsx2/Pcsx2Config.cpp b/pcsx2/Pcsx2Config.cpp index 9a715c06b3..fc87c91c99 100644 --- a/pcsx2/Pcsx2Config.cpp +++ b/pcsx2/Pcsx2Config.cpp @@ -170,6 +170,7 @@ namespace EmuFolders std::string Videos; static bool ShouldUsePortableMode(); + static std::string GetPortableModePath(); } // namespace EmuFolders TraceFiltersEE::TraceFiltersEE() @@ -1910,6 +1911,14 @@ bool EmuFolders::ShouldUsePortableMode() return FileSystem::FileExists(Path::Combine(AppRoot, "portable.ini").c_str()) || FileSystem::FileExists(Path::Combine(AppRoot, "portable.txt").c_str()); } +std::string EmuFolders::GetPortableModePath() +{ + const auto portable_txt_path = Path::Combine(AppRoot, "portable.txt"); + const auto portable_path = FileSystem::ReadFileToString(portable_txt_path.c_str()).value_or(""); + const auto trimmed_path = StringUtil::StripWhitespace(portable_path); + return std::string(trimmed_path); +} + bool EmuFolders::SetDataDirectory(Error* error) { if (!ShouldUsePortableMode()) @@ -1954,7 +1963,7 @@ bool EmuFolders::SetDataDirectory(Error* error) // couldn't determine the data directory, or using portable mode? fallback to portable. if (DataRoot.empty()) - DataRoot = AppRoot; + DataRoot = Path::Combine(AppRoot, GetPortableModePath()); // inis is always below the data root Settings = Path::Combine(DataRoot, "inis");