From f84173e5ccd0ead5b4ea1dbca47b2a9a4724b4d5 Mon Sep 17 00:00:00 2001 From: KamFretoZ <14798312+kamfretoz@users.noreply.github.com> Date: Tue, 4 Feb 2025 05:20:32 +0700 Subject: [PATCH] Qt: Add Portable Mode launch argument (#12230) --- pcsx2-qt/QtHost.cpp | 6 ++++++ pcsx2/Config.h | 1 + pcsx2/Pcsx2Config.cpp | 27 +++++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/pcsx2-qt/QtHost.cpp b/pcsx2-qt/QtHost.cpp index 04eb781767..2375c70d9f 100644 --- a/pcsx2-qt/QtHost.cpp +++ b/pcsx2-qt/QtHost.cpp @@ -2040,6 +2040,7 @@ void QtHost::PrintCommandLineHelp(const std::string_view progname) std::fprintf(stderr, " -version: Displays version information and exits.\n"); std::fprintf(stderr, " -batch: Enables batch mode (exits after shutting down).\n"); std::fprintf(stderr, " -nogui: Hides main window while running (implies batch mode).\n"); + std::fprintf(stderr, " -portable: Force enable portable mode to store data in local PCSX2 path instead of the default configuration path.\n"); std::fprintf(stderr, " -elf : Overrides the boot ELF with the specified filename.\n"); std::fprintf(stderr, " -gameargs : passes the specified quoted space-delimited string of launch arguments.\n"); std::fprintf(stderr, " -disc : Uses the specified host DVD drive as a source.\n"); @@ -2111,6 +2112,11 @@ bool QtHost::ParseCommandLineOptions(const QStringList& args, std::shared_ptrfast_boot = true; diff --git a/pcsx2/Config.h b/pcsx2/Config.h index 37e4a7dffc..7d76df7a45 100644 --- a/pcsx2/Config.h +++ b/pcsx2/Config.h @@ -1328,6 +1328,7 @@ struct Pcsx2Config std::string CurrentIRX; std::string CurrentGameArgs; AspectRatioType CurrentAspectRatio = AspectRatioType::RAuto4_3_3_2; + bool IsPortableMode = false; Pcsx2Config(); void LoadSave(SettingsWrapper& wrap); diff --git a/pcsx2/Pcsx2Config.cpp b/pcsx2/Pcsx2Config.cpp index ae9fcb2605..9197fb2e1c 100644 --- a/pcsx2/Pcsx2Config.cpp +++ b/pcsx2/Pcsx2Config.cpp @@ -2036,6 +2036,7 @@ void Pcsx2Config::CopyRuntimeConfig(Pcsx2Config& cfg) CurrentIRX = std::move(cfg.CurrentIRX); CurrentGameArgs = std::move(cfg.CurrentGameArgs); CurrentAspectRatio = cfg.CurrentAspectRatio; + IsPortableMode = cfg.IsPortableMode; for (u32 i = 0; i < sizeof(Mcd) / sizeof(Mcd[0]); i++) { @@ -2122,8 +2123,15 @@ bool EmuFolders::SetResourcesDirectory() bool EmuFolders::ShouldUsePortableMode() { - // Check whether portable.ini exists in the program directory. - return FileSystem::FileExists(Path::Combine(AppRoot, "portable.ini").c_str()) || FileSystem::FileExists(Path::Combine(AppRoot, "portable.txt").c_str()); + // Check whether portable.ini/txt exists in the program directory or the `-portable` launch arguments have been passed. + if (FileSystem::FileExists(Path::Combine(AppRoot, "portable.ini").c_str()) || + FileSystem::FileExists(Path::Combine(AppRoot, "portable.txt").c_str()) || + EmuConfig.IsPortableMode) + { + return true; + } + + return false; } std::string EmuFolders::GetPortableModePath() @@ -2178,7 +2186,22 @@ bool EmuFolders::SetDataDirectory(Error* error) // couldn't determine the data directory, or using portable mode? fallback to portable. if (DataRoot.empty()) + { +#if defined(__linux__) + // special check if we're on appimage + // always make sure that DataRoot + // is adjacent next to the appimage + if (getenv("APPIMAGE")) + { + std::string_view appimage_path = Path::GetDirectory(getenv("APPIMAGE")); + DataRoot = Path::RealPath(Path::Combine(appimage_path, "PCSX2")); + } + else DataRoot = Path::Combine(AppRoot, GetPortableModePath()); +#else + DataRoot = Path::Combine(AppRoot, GetPortableModePath()); +#endif + } // inis is always below the data root Settings = Path::Combine(DataRoot, "inis");