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:
DanielSvoboda 2025-03-22 19:27:42 -03:00 committed by GitHub
parent d7b947dd79
commit 0fa1220eca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 170 additions and 29 deletions

View file

@ -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);
}
}