diff --git a/src/common/path_util.cpp b/src/common/path_util.cpp index 6bc73ee43..702d0fabc 100644 --- a/src/common/path_util.cpp +++ b/src/common/path_util.cpp @@ -17,6 +17,8 @@ #ifdef _WIN32 // This is the maximum number of UTF-16 code units permissible in Windows file paths #define MAX_PATH 260 +#include +#include #else // This is the maximum number of UTF-8 code units permissible in all other OSes' file paths #define MAX_PATH 1024 @@ -106,6 +108,10 @@ static auto UserPaths = [] { } else { user_dir = std::filesystem::path(getenv("HOME")) / ".local" / "share" / "shadPS4"; } +#elif _WIN32 + TCHAR appdata[MAX_PATH] = {0}; + SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, appdata); + user_dir = std::filesystem::path(appdata) / "shadPS4"; #endif } diff --git a/src/qt_gui/settings_dialog.cpp b/src/qt_gui/settings_dialog.cpp index 8bd72a237..69f5d3c8a 100644 --- a/src/qt_gui/settings_dialog.cpp +++ b/src/qt_gui/settings_dialog.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "common/config.h" @@ -234,6 +235,21 @@ SettingsDialog::SettingsDialog(std::span physical_devices, Common::FS::GetUserPath(Common::FS::PathType::CustomTrophy)); QDesktopServices::openUrl(QUrl::fromLocalFile(userPath)); }); + + connect(ui->PortableUserButton, &QPushButton::clicked, this, []() { + QString userDir; + Common::FS::PathToQString(userDir, std::filesystem::current_path() / "user"); + if (std::filesystem::exists(std::filesystem::current_path() / "user")) { + QMessageBox::information(NULL, "Cannot create portable user folder", + userDir + " already exists"); + } else { + std::filesystem::copy(Common::FS::GetUserPath(Common::FS::PathType::UserDir), + std::filesystem::current_path() / "user", + std::filesystem::copy_options::recursive); + QMessageBox::information(NULL, "Portable user folder created", + userDir + " successfully created"); + } + }); } // Input TAB @@ -344,6 +360,7 @@ SettingsDialog::SettingsDialog(std::span physical_devices, ui->saveDataGroupBox->installEventFilter(this); ui->currentSaveDataPath->installEventFilter(this); ui->browseButton->installEventFilter(this); + ui->PortableUserFolderGroupBox->installEventFilter(this); // Debug ui->debugDump->installEventFilter(this); @@ -650,6 +667,8 @@ void SettingsDialog::updateNoteTextEdit(const QString& elementName) { text = tr("Add:\\nAdd a folder to the list."); } else if (elementName == "removeFolderButton") { text = tr("Remove:\\nRemove a folder from the list."); + } else if (elementName == "PortableUserFolderGroupBox") { + text = tr("Portable user folder:\\nStores shadPS4 settings and data that will be applied only to the shadPS4 build located in the current folder. Restart the app after creating the portable user folder to begin using it."); } // Save Data diff --git a/src/qt_gui/settings_dialog.ui b/src/qt_gui/settings_dialog.ui index 7db0afa59..5600a0db7 100644 --- a/src/qt_gui/settings_dialog.ui +++ b/src/qt_gui/settings_dialog.ui @@ -31,7 +31,7 @@ Settings - + :/images/shadps4.ico:/images/shadps4.ico @@ -59,7 +59,7 @@ - 0 + 5 @@ -74,7 +74,7 @@ 0 0 946 - 545 + 536 @@ -130,9 +130,6 @@ 9 - - Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop - @@ -455,7 +452,7 @@ 0 0 946 - 545 + 536 @@ -904,7 +901,7 @@ 0 0 946 - 545 + 536 @@ -1199,7 +1196,7 @@ 0 0 946 - 545 + 536 @@ -1306,14 +1303,14 @@ Top - + Bottom - + @@ -1335,8 +1332,7 @@ - - + @@ -1442,7 +1438,7 @@ 0 0 946 - 545 + 536 @@ -1726,7 +1722,7 @@ 0 0 946 - 545 + 536 @@ -1800,6 +1796,58 @@ + + + + Portable User Folder + + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Create Portable User Folder from Common User Folder + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + @@ -1816,7 +1864,7 @@ 0 0 946 - 545 + 536 @@ -2068,6 +2116,8 @@ - + + +