Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt: Add Portable Mode launch argument #12230

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pcsx2-qt/QtHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <file>: Overrides the boot ELF with the specified filename.\n");
std::fprintf(stderr, " -gameargs <string>: passes the specified quoted space-delimited string of launch arguments.\n");
std::fprintf(stderr, " -disc <path>: Uses the specified host DVD drive as a source.\n");
Expand Down Expand Up @@ -2111,6 +2112,11 @@ bool QtHost::ParseCommandLineOptions(const QStringList& args, std::shared_ptr<VM
s_nogui_mode = true;
continue;
}
else if (CHECK_ARG(QStringLiteral("-portable")))
{
EmuConfig.IsPortableMode = true;
continue;
}
else if (CHECK_ARG(QStringLiteral("-fastboot")))
{
AutoBoot(autoboot)->fast_boot = true;
Expand Down
1 change: 1 addition & 0 deletions pcsx2/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 25 additions & 2 deletions pcsx2/Pcsx2Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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");
Expand Down
Loading