From de95354d517db07200a03f97991dfd08199015c9 Mon Sep 17 00:00:00 2001 From: KamFretoZ <14798312+kamfretoz@users.noreply.github.com> Date: Thu, 23 Jan 2025 20:25:52 +0700 Subject: [PATCH] Qt: Add Portable Mode launch argument --- pcsx2-qt/QtHost.cpp | 6 ++++++ pcsx2/Config.h | 1 + pcsx2/Pcsx2Config.cpp | 12 ++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pcsx2-qt/QtHost.cpp b/pcsx2-qt/QtHost.cpp index 04eb781767d71..be8c3f4c5dd53 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 current user's Documents 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 37e4a7dffcc31..7d76df7a451c5 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 ae9fcb2605df2..5806c11682f67 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()