Skip to content

Commit bd486f1

Browse files
kamfretozF0bes
authored andcommitted
Qt: Add -datapath launch argument
1 parent f7ef43b commit bd486f1

3 files changed

Lines changed: 52 additions & 37 deletions

File tree

pcsx2-qt/QtHost.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,7 +2086,8 @@ void QtHost::PrintCommandLineHelp(const std::string_view progname)
20862086
std::fprintf(stderr, " -version: Displays version information and exits.\n");
20872087
std::fprintf(stderr, " -batch: Enables batch mode (exits after shutting down).\n");
20882088
std::fprintf(stderr, " -nogui: Hides main window while running (implies batch mode).\n");
2089-
std::fprintf(stderr, " -portable: Force enable portable mode to store data in local PCSX2 path instead of the default configuration path.\n");
2089+
std::fprintf(stderr, " -portable: Force enable portable mode to store data in local PCSX2 path instead of the default configuration path. Overrides '-datapath'.\n");
2090+
std::fprintf(stderr, " -datapath <path>: Specify the directory to be used for all application data.\n");
20902091
std::fprintf(stderr, " -elf <file>: Overrides the boot ELF with the specified filename.\n");
20912092
std::fprintf(stderr, " -gameargs <string>: passes the specified quoted space-delimited string of launch arguments.\n");
20922093
std::fprintf(stderr, " -disc <path>: Uses the specified host DVD drive as a source.\n");
@@ -2165,6 +2166,12 @@ bool QtHost::ParseCommandLineOptions(const QStringList& args, std::shared_ptr<VM
21652166
EmuConfig.IsPortableMode = true;
21662167
continue;
21672168
}
2169+
else if (CHECK_ARG_PARAM(QStringLiteral("-datapath")))
2170+
{
2171+
std::string path = (++it)->toStdString();
2172+
EmuConfig.CustomDataPath = path;
2173+
continue;
2174+
}
21682175
else if (CHECK_ARG(QStringLiteral("-fastboot")))
21692176
{
21702177
AutoBoot(autoboot)->fast_boot = true;
@@ -2297,7 +2304,7 @@ bool QtHost::ParseCommandLineOptions(const QStringList& args, std::shared_ptr<VM
22972304
Console.Warning("Skipping autoboot due to no boot parameters.");
22982305
autoboot.reset();
22992306
}
2300-
2307+
23012308
if(autoboot && autoboot->start_turbo.value_or(false) && autoboot->start_unlimited.value_or(false))
23022309
{
23032310
Console.Warning("Both turbo and unlimited frame limit modes requested. Using unlimited.");

pcsx2/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,7 @@ struct Pcsx2Config
14031403
std::string CurrentBlockdump;
14041404
std::string CurrentIRX;
14051405
std::string CurrentGameArgs;
1406+
std::string CustomDataPath;
14061407
AspectRatioType CurrentAspectRatio = AspectRatioType::RAuto4_3_3_2;
14071408
// Fall back aspect ratio for games that have patches (when AspectRatioType::RAuto4_3_3_2) is active.
14081409
float CurrentCustomAspectRatio = 0.f;

pcsx2/Pcsx2Config.cpp

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,51 +2195,58 @@ std::string EmuFolders::GetPortableModePath()
21952195

21962196
bool EmuFolders::SetDataDirectory(Error* error)
21972197
{
2198+
// Portable mode has the absolute priority.
21982199
if (!ShouldUsePortableMode())
21992200
{
2200-
#if defined(_WIN32)
2201-
// On Windows, use My Documents\PCSX2 to match old installs.
2202-
PWSTR documents_directory;
2203-
if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Documents, 0, NULL, &documents_directory)))
2201+
// Also check if the user has overriden the DataRoot path.
2202+
if (EmuConfig.CustomDataPath.empty())
22042203
{
2205-
if (std::wcslen(documents_directory) > 0)
2206-
DataRoot = Path::Combine(StringUtil::WideStringToUTF8String(documents_directory), "PCSX2");
2207-
CoTaskMemFree(documents_directory);
2208-
}
2204+
#if defined(_WIN32)
2205+
// On Windows, use My Documents\PCSX2 to match old installs.
2206+
PWSTR documents_directory;
2207+
if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Documents, 0, NULL, &documents_directory)))
2208+
{
2209+
if (std::wcslen(documents_directory) > 0)
2210+
DataRoot = Path::Combine(StringUtil::WideStringToUTF8String(documents_directory), "PCSX2");
2211+
CoTaskMemFree(documents_directory);
2212+
}
22092213
#elif defined(__linux__) || defined(__FreeBSD__)
2210-
// Use $XDG_CONFIG_HOME/PCSX2 if it exists.
2211-
const char* xdg_config_home = getenv("XDG_CONFIG_HOME");
2212-
if (xdg_config_home && Path::IsAbsolute(xdg_config_home))
2213-
{
2214-
DataRoot = Path::RealPath(Path::Combine(xdg_config_home, "PCSX2"));
2215-
}
2216-
else
2217-
{
2218-
// Use ~/PCSX2 for non-XDG, and ~/.config/PCSX2 for XDG.
2219-
const char* home_dir = getenv("HOME");
2220-
if (home_dir)
2214+
// Use $XDG_CONFIG_HOME/PCSX2 if it exists.
2215+
const char* xdg_config_home = getenv("XDG_CONFIG_HOME");
2216+
if (xdg_config_home && Path::IsAbsolute(xdg_config_home))
22212217
{
2222-
// ~/.config should exist, but just in case it doesn't and this is a fresh profile..
2223-
const std::string config_dir(Path::Combine(home_dir, ".config"));
2224-
if (!FileSystem::DirectoryExists(config_dir.c_str()))
2225-
FileSystem::CreateDirectoryPath(config_dir.c_str(), false);
2226-
2227-
DataRoot = Path::RealPath(Path::Combine(config_dir, "PCSX2"));
2218+
DataRoot = Path::RealPath(Path::Combine(xdg_config_home, "PCSX2"));
2219+
}
2220+
else
2221+
{
2222+
// Use ~/PCSX2 for non-XDG, and ~/.config/PCSX2 for XDG.
2223+
const char* home_dir = getenv("HOME");
2224+
if (home_dir)
2225+
{
2226+
// ~/.config should exist, but just in case it doesn't and this is a fresh profile..
2227+
const std::string config_dir(Path::Combine(home_dir, ".config"));
2228+
if (!FileSystem::DirectoryExists(config_dir.c_str()))
2229+
FileSystem::CreateDirectoryPath(config_dir.c_str(), false);
2230+
2231+
DataRoot = Path::RealPath(Path::Combine(config_dir, "PCSX2"));
2232+
}
22282233
}
2229-
}
22302234
#elif defined(__APPLE__)
2231-
static constexpr char MAC_DATA_DIR[] = "Library/Application Support/PCSX2";
2232-
const char* home_dir = getenv("HOME");
2233-
if (home_dir)
2234-
DataRoot = Path::RealPath(Path::Combine(home_dir, MAC_DATA_DIR));
2235+
static constexpr char MAC_DATA_DIR[] = "Library/Application Support/PCSX2";
2236+
const char* home_dir = getenv("HOME");
2237+
if (home_dir)
2238+
DataRoot = Path::RealPath(Path::Combine(home_dir, MAC_DATA_DIR));
22352239
#endif
2236-
}
2240+
}
2241+
else // Otherwise use the custom path provided by the user
2242+
DataRoot = Path::RealPath(Path::Combine(EmuConfig.CustomDataPath, "PCSX2"));
2243+
}
22372244

2238-
// couldn't determine the data directory, or using portable mode? fallback to portable.
2245+
// Couldn't determine the data directory, or using portable mode? fallback to portable.
22392246
if (DataRoot.empty())
22402247
{
22412248
#if defined(__linux__)
2242-
// special check if we're on appimage
2249+
// Special check if we're on appimage
22432250
// always make sure that DataRoot
22442251
// is adjacent next to the appimage
22452252
if (getenv("APPIMAGE"))
@@ -2254,10 +2261,10 @@ bool EmuFolders::SetDataDirectory(Error* error)
22542261
#endif
22552262
}
22562263

2257-
// inis is always below the data root
2264+
// Inis is always below the data root
22582265
Settings = Path::Combine(DataRoot, "inis");
22592266

2260-
// make sure it exists
2267+
// Make sure it exists
22612268
Console.WriteLnFmt("DataRoot Directory: {}", DataRoot);
22622269
return (FileSystem::EnsureDirectoryExists(DataRoot.c_str(), false, error) &&
22632270
FileSystem::EnsureDirectoryExists(Settings.c_str(), false, error));

0 commit comments

Comments
 (0)