mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-04-20 03:24:49 +00:00
Add option to enable/disable game folders individually (#2662)
* Add option to enable/disable game folders individually A checkbox (button to select) game folders has been added to the menu, allowing you to Enable/Disable them without having to remove the folder. config.toml is now saved in alphabetical order * ordering is separation in a function * remove my comment in portuguese :)
This commit is contained in:
parent
d7b947dd79
commit
0fa1220eca
3 changed files with 170 additions and 29 deletions
|
@ -81,7 +81,7 @@ static std::string trophyKey;
|
|||
|
||||
// Gui
|
||||
static bool load_game_size = true;
|
||||
std::vector<std::filesystem::path> settings_install_dirs = {};
|
||||
static std::vector<GameInstallDir> settings_install_dirs = {};
|
||||
std::filesystem::path settings_addon_install_dir = {};
|
||||
std::filesystem::path save_data_path = {};
|
||||
u32 main_window_geometry_x = 400;
|
||||
|
@ -519,22 +519,34 @@ void setMainWindowGeometry(u32 x, u32 y, u32 w, u32 h) {
|
|||
main_window_geometry_h = h;
|
||||
}
|
||||
|
||||
bool addGameInstallDir(const std::filesystem::path& dir) {
|
||||
if (std::find(settings_install_dirs.begin(), settings_install_dirs.end(), dir) ==
|
||||
settings_install_dirs.end()) {
|
||||
settings_install_dirs.push_back(dir);
|
||||
return true;
|
||||
bool addGameInstallDir(const std::filesystem::path& dir, bool enabled) {
|
||||
for (const auto& install_dir : settings_install_dirs) {
|
||||
if (install_dir.path == dir) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
settings_install_dirs.push_back({dir, enabled});
|
||||
return true;
|
||||
}
|
||||
|
||||
void removeGameInstallDir(const std::filesystem::path& dir) {
|
||||
auto iterator = std::find(settings_install_dirs.begin(), settings_install_dirs.end(), dir);
|
||||
auto iterator =
|
||||
std::find_if(settings_install_dirs.begin(), settings_install_dirs.end(),
|
||||
[&dir](const GameInstallDir& install_dir) { return install_dir.path == dir; });
|
||||
if (iterator != settings_install_dirs.end()) {
|
||||
settings_install_dirs.erase(iterator);
|
||||
}
|
||||
}
|
||||
|
||||
void setGameInstallDirEnabled(const std::filesystem::path& dir, bool enabled) {
|
||||
auto iterator =
|
||||
std::find_if(settings_install_dirs.begin(), settings_install_dirs.end(),
|
||||
[&dir](const GameInstallDir& install_dir) { return install_dir.path == dir; });
|
||||
if (iterator != settings_install_dirs.end()) {
|
||||
iterator->enabled = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
void setAddonInstallDir(const std::filesystem::path& dir) {
|
||||
settings_addon_install_dir = dir;
|
||||
}
|
||||
|
@ -590,8 +602,15 @@ void setEmulatorLanguage(std::string language) {
|
|||
emulator_language = language;
|
||||
}
|
||||
|
||||
void setGameInstallDirs(const std::vector<std::filesystem::path>& settings_install_dirs_config) {
|
||||
settings_install_dirs = settings_install_dirs_config;
|
||||
void setGameInstallDirs(const std::vector<std::filesystem::path>& dirs_config) {
|
||||
settings_install_dirs.clear();
|
||||
for (const auto& dir : dirs_config) {
|
||||
settings_install_dirs.push_back({dir, true});
|
||||
}
|
||||
}
|
||||
|
||||
void setAllGameInstallDirs(const std::vector<GameInstallDir>& dirs_config) {
|
||||
settings_install_dirs = dirs_config;
|
||||
}
|
||||
|
||||
void setSaveDataPath(const std::filesystem::path& path) {
|
||||
|
@ -614,7 +633,17 @@ u32 getMainWindowGeometryH() {
|
|||
return main_window_geometry_h;
|
||||
}
|
||||
|
||||
const std::vector<std::filesystem::path>& getGameInstallDirs() {
|
||||
const std::vector<std::filesystem::path> getGameInstallDirs() {
|
||||
std::vector<std::filesystem::path> enabled_dirs;
|
||||
for (const auto& dir : settings_install_dirs) {
|
||||
if (dir.enabled) {
|
||||
enabled_dirs.push_back(dir.path);
|
||||
}
|
||||
}
|
||||
return enabled_dirs;
|
||||
}
|
||||
|
||||
const std::vector<GameInstallDir>& getAllGameInstallDirs() {
|
||||
return settings_install_dirs;
|
||||
}
|
||||
|
||||
|
@ -809,8 +838,23 @@ void load(const std::filesystem::path& path) {
|
|||
|
||||
const auto install_dir_array =
|
||||
toml::find_or<std::vector<std::string>>(gui, "installDirs", {});
|
||||
for (const auto& dir : install_dir_array) {
|
||||
addGameInstallDir(std::filesystem::path{dir});
|
||||
|
||||
std::vector<bool> install_dirs_enabled;
|
||||
try {
|
||||
install_dirs_enabled = toml::find<std::vector<bool>>(gui, "installDirsEnabled");
|
||||
} catch (...) {
|
||||
// If it does not exist, assume that all are enabled.
|
||||
install_dirs_enabled.resize(install_dir_array.size(), true);
|
||||
}
|
||||
|
||||
if (install_dirs_enabled.size() < install_dir_array.size()) {
|
||||
install_dirs_enabled.resize(install_dir_array.size(), true);
|
||||
}
|
||||
|
||||
settings_install_dirs.clear();
|
||||
for (size_t i = 0; i < install_dir_array.size(); i++) {
|
||||
settings_install_dirs.push_back(
|
||||
{std::filesystem::path{install_dir_array[i]}, install_dirs_enabled[i]});
|
||||
}
|
||||
|
||||
save_data_path = toml::find_fs_path_or(gui, "saveDataPath", {});
|
||||
|
@ -853,6 +897,37 @@ void load(const std::filesystem::path& path) {
|
|||
}
|
||||
}
|
||||
|
||||
void sortTomlSections(toml::ordered_value& data) {
|
||||
toml::ordered_value ordered_data;
|
||||
std::vector<std::string> section_order = {"General", "Input", "GPU", "Vulkan",
|
||||
"Debug", "Keys", "GUI", "Settings"};
|
||||
|
||||
for (const auto& section : section_order) {
|
||||
if (data.contains(section)) {
|
||||
std::vector<std::string> keys;
|
||||
for (const auto& item : data.at(section).as_table()) {
|
||||
keys.push_back(item.first);
|
||||
}
|
||||
|
||||
std::sort(keys.begin(), keys.end(), [](const std::string& a, const std::string& b) {
|
||||
return std::lexicographical_compare(
|
||||
a.begin(), a.end(), b.begin(), b.end(), [](char a_char, char b_char) {
|
||||
return std::tolower(a_char) < std::tolower(b_char);
|
||||
});
|
||||
});
|
||||
|
||||
toml::ordered_value ordered_section;
|
||||
for (const auto& key : keys) {
|
||||
ordered_section[key] = data.at(section).at(key);
|
||||
}
|
||||
|
||||
ordered_data[section] = ordered_section;
|
||||
}
|
||||
}
|
||||
|
||||
data = ordered_data;
|
||||
}
|
||||
|
||||
void save(const std::filesystem::path& path) {
|
||||
toml::ordered_value data;
|
||||
|
||||
|
@ -922,14 +997,37 @@ void save(const std::filesystem::path& path) {
|
|||
data["Debug"]["CollectShader"] = isShaderDebug;
|
||||
data["Debug"]["isSeparateLogFilesEnabled"] = isSeparateLogFilesEnabled;
|
||||
data["Debug"]["FPSColor"] = isFpsColor;
|
||||
|
||||
data["Keys"]["TrophyKey"] = trophyKey;
|
||||
|
||||
std::vector<std::string> install_dirs;
|
||||
for (const auto& dirString : settings_install_dirs) {
|
||||
install_dirs.emplace_back(std::string{fmt::UTF(dirString.u8string()).data});
|
||||
std::vector<bool> install_dirs_enabled;
|
||||
|
||||
// temporary structure for ordering
|
||||
struct DirEntry {
|
||||
std::string path_str;
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
std::vector<DirEntry> sorted_dirs;
|
||||
for (const auto& dirInfo : settings_install_dirs) {
|
||||
sorted_dirs.push_back(
|
||||
{std::string{fmt::UTF(dirInfo.path.u8string()).data}, dirInfo.enabled});
|
||||
}
|
||||
|
||||
// Sort directories alphabetically
|
||||
std::sort(sorted_dirs.begin(), sorted_dirs.end(), [](const DirEntry& a, const DirEntry& b) {
|
||||
return std::lexicographical_compare(
|
||||
a.path_str.begin(), a.path_str.end(), b.path_str.begin(), b.path_str.end(),
|
||||
[](char a_char, char b_char) { return std::tolower(a_char) < std::tolower(b_char); });
|
||||
});
|
||||
|
||||
for (const auto& entry : sorted_dirs) {
|
||||
install_dirs.push_back(entry.path_str);
|
||||
install_dirs_enabled.push_back(entry.enabled);
|
||||
}
|
||||
|
||||
data["GUI"]["installDirs"] = install_dirs;
|
||||
data["GUI"]["installDirsEnabled"] = install_dirs_enabled;
|
||||
data["GUI"]["saveDataPath"] = std::string{fmt::UTF(save_data_path.u8string()).data};
|
||||
data["GUI"]["loadGameSizeEnabled"] = load_game_size;
|
||||
|
||||
|
@ -940,9 +1038,13 @@ void save(const std::filesystem::path& path) {
|
|||
data["GUI"]["showBackgroundImage"] = showBackgroundImage;
|
||||
data["Settings"]["consoleLanguage"] = m_language;
|
||||
|
||||
// Sorting of TOML sections
|
||||
sortTomlSections(data);
|
||||
|
||||
std::ofstream file(path, std::ios::binary);
|
||||
file << data;
|
||||
file.close();
|
||||
|
||||
saveMainWindow(path);
|
||||
}
|
||||
|
||||
|
@ -984,6 +1086,9 @@ void saveMainWindow(const std::filesystem::path& path) {
|
|||
data["GUI"]["elfDirs"] = m_elf_viewer;
|
||||
data["GUI"]["recentFiles"] = m_recent_files;
|
||||
|
||||
// Sorting of TOML sections
|
||||
sortTomlSections(data);
|
||||
|
||||
std::ofstream file(path, std::ios::binary);
|
||||
file << data;
|
||||
file.close();
|
||||
|
|
|
@ -9,6 +9,11 @@
|
|||
|
||||
namespace Config {
|
||||
|
||||
struct GameInstallDir {
|
||||
std::filesystem::path path;
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
enum HideCursorState : s16 { Never, Idle, Always };
|
||||
|
||||
void load(const std::filesystem::path& path);
|
||||
|
@ -98,7 +103,8 @@ void setUserName(const std::string& type);
|
|||
void setUpdateChannel(const std::string& type);
|
||||
void setChooseHomeTab(const std::string& type);
|
||||
void setSeparateUpdateEnabled(bool use);
|
||||
void setGameInstallDirs(const std::vector<std::filesystem::path>& settings_install_dirs_config);
|
||||
void setGameInstallDirs(const std::vector<std::filesystem::path>& dirs_config);
|
||||
void setAllGameInstallDirs(const std::vector<GameInstallDir>& dirs_config);
|
||||
void setSaveDataPath(const std::filesystem::path& path);
|
||||
void setCompatibilityEnabled(bool use);
|
||||
void setCheckCompatibilityOnStartup(bool use);
|
||||
|
@ -133,8 +139,9 @@ void setVkGuestMarkersEnabled(bool enable);
|
|||
|
||||
// Gui
|
||||
void setMainWindowGeometry(u32 x, u32 y, u32 w, u32 h);
|
||||
bool addGameInstallDir(const std::filesystem::path& dir);
|
||||
bool addGameInstallDir(const std::filesystem::path& dir, bool enabled = true);
|
||||
void removeGameInstallDir(const std::filesystem::path& dir);
|
||||
void setGameInstallDirEnabled(const std::filesystem::path& dir, bool enabled);
|
||||
void setAddonInstallDir(const std::filesystem::path& dir);
|
||||
void setMainWindowTheme(u32 theme);
|
||||
void setIconSize(u32 size);
|
||||
|
@ -153,7 +160,8 @@ u32 getMainWindowGeometryX();
|
|||
u32 getMainWindowGeometryY();
|
||||
u32 getMainWindowGeometryW();
|
||||
u32 getMainWindowGeometryH();
|
||||
const std::vector<std::filesystem::path>& getGameInstallDirs();
|
||||
const std::vector<std::filesystem::path> getGameInstallDirs();
|
||||
const std::vector<GameInstallDir>& getAllGameInstallDirs();
|
||||
std::filesystem::path getAddonInstallDir();
|
||||
u32 getMainWindowTheme();
|
||||
u32 getIconSize();
|
||||
|
|
|
@ -246,12 +246,13 @@ SettingsDialog::SettingsDialog(std::span<const QString> physical_devices,
|
|||
// PATH TAB
|
||||
{
|
||||
connect(ui->addFolderButton, &QPushButton::clicked, this, [this]() {
|
||||
const auto config_dir = Config::getGameInstallDirs();
|
||||
QString file_path_string =
|
||||
QFileDialog::getExistingDirectory(this, tr("Directory to install games"));
|
||||
auto file_path = Common::FS::PathFromQString(file_path_string);
|
||||
if (!file_path.empty() && Config::addGameInstallDir(file_path)) {
|
||||
if (!file_path.empty() && Config::addGameInstallDir(file_path, true)) {
|
||||
QListWidgetItem* item = new QListWidgetItem(file_path_string);
|
||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
||||
item->setCheckState(Qt::Checked);
|
||||
ui->gameFoldersListWidget->addItem(item);
|
||||
}
|
||||
});
|
||||
|
@ -783,6 +784,17 @@ void SettingsDialog::UpdateSettings() {
|
|||
emit BackgroundOpacityChanged(ui->backgroundImageOpacitySlider->value());
|
||||
Config::setShowBackgroundImage(ui->showBackgroundImageCheckBox->isChecked());
|
||||
|
||||
std::vector<Config::GameInstallDir> dirs_with_states;
|
||||
for (int i = 0; i < ui->gameFoldersListWidget->count(); i++) {
|
||||
QListWidgetItem* item = ui->gameFoldersListWidget->item(i);
|
||||
QString path_string = item->text();
|
||||
auto path = Common::FS::PathFromQString(path_string);
|
||||
bool enabled = (item->checkState() == Qt::Checked);
|
||||
|
||||
dirs_with_states.push_back({path, enabled});
|
||||
}
|
||||
Config::setAllGameInstallDirs(dirs_with_states);
|
||||
|
||||
#ifdef ENABLE_DISCORD_RPC
|
||||
auto* rpc = Common::Singleton<DiscordRPCHandler::RPC>::Instance();
|
||||
if (Config::getEnableDiscordRPC()) {
|
||||
|
@ -797,6 +809,7 @@ void SettingsDialog::UpdateSettings() {
|
|||
}
|
||||
|
||||
void SettingsDialog::ResetInstallFolders() {
|
||||
ui->gameFoldersListWidget->clear();
|
||||
|
||||
std::filesystem::path userdir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
|
||||
const toml::value data = toml::parse(userdir / "config.toml");
|
||||
|
@ -805,21 +818,36 @@ void SettingsDialog::ResetInstallFolders() {
|
|||
const toml::value& gui = data.at("GUI");
|
||||
const auto install_dir_array =
|
||||
toml::find_or<std::vector<std::string>>(gui, "installDirs", {});
|
||||
std::vector<std::filesystem::path> settings_install_dirs_config = {};
|
||||
|
||||
for (const auto& dir : install_dir_array) {
|
||||
if (std::find(settings_install_dirs_config.begin(), settings_install_dirs_config.end(),
|
||||
dir) == settings_install_dirs_config.end()) {
|
||||
settings_install_dirs_config.push_back(dir);
|
||||
}
|
||||
std::vector<bool> install_dirs_enabled;
|
||||
try {
|
||||
install_dirs_enabled = toml::find<std::vector<bool>>(gui, "installDirsEnabled");
|
||||
} catch (...) {
|
||||
// If it does not exist, assume that all are enabled.
|
||||
install_dirs_enabled.resize(install_dir_array.size(), true);
|
||||
}
|
||||
|
||||
for (const auto& dir : settings_install_dirs_config) {
|
||||
if (install_dirs_enabled.size() < install_dir_array.size()) {
|
||||
install_dirs_enabled.resize(install_dir_array.size(), true);
|
||||
}
|
||||
|
||||
std::vector<Config::GameInstallDir> settings_install_dirs_config;
|
||||
|
||||
for (size_t i = 0; i < install_dir_array.size(); i++) {
|
||||
std::filesystem::path dir = install_dir_array[i];
|
||||
bool enabled = install_dirs_enabled[i];
|
||||
|
||||
settings_install_dirs_config.push_back({dir, enabled});
|
||||
|
||||
QString path_string;
|
||||
Common::FS::PathToQString(path_string, dir);
|
||||
|
||||
QListWidgetItem* item = new QListWidgetItem(path_string);
|
||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
||||
item->setCheckState(enabled ? Qt::Checked : Qt::Unchecked);
|
||||
ui->gameFoldersListWidget->addItem(item);
|
||||
}
|
||||
Config::setGameInstallDirs(settings_install_dirs_config);
|
||||
|
||||
Config::setAllGameInstallDirs(settings_install_dirs_config);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue