yuzu: Add settings reset button to general configuration

Builds on german77's work to reset all settings back to their defaults.
This include UISettings and Settings values structs, but does not affect
save profiles, input profiles, and game directories.

This works from a button input in configure_general. When activated, it
calls a callback to close the whole configure dialog, then GMainWindow
deletes the old configuration, both on disk and in memory, and
reinitalizes a new one. It also resets a portion of the UI and calls the
telemetry window prompt.
This commit is contained in:
lat9nq
2021-05-25 20:49:42 -04:00
parent 8aeb425669
commit 4a3d57e469
8 changed files with 111 additions and 23 deletions

View File

@ -2587,14 +2587,49 @@ void GMainWindow::OnConfigure() {
&GMainWindow::OnLanguageChanged);
const auto result = configure_dialog.exec();
if (result != QDialog::Accepted && !UISettings::values.configuration_applied) {
if (result != QDialog::Accepted && !UISettings::values.configuration_applied &&
!UISettings::values.reset_to_defaults) {
// Runs if the user hit Cancel or closed the window, and did not ever press the Apply button
// or `Reset to Defaults` button
return;
} else if (result == QDialog::Accepted) {
// Only apply new changes if user hit Okay
// This is here to avoid applying changes if the user hit Apply, made some changes, then hit
// Cancel
configure_dialog.ApplyConfiguration();
controller_dialog->refreshConfiguration();
}
} else if (UISettings::values.reset_to_defaults) {
LOG_INFO(Frontend, "Resetting all settings to defaults");
if (!Common::FS::RemoveFile(config->GetConfigFilePath())) {
LOG_WARNING(Frontend, "Failed to remove configuration file");
}
if (!Common::FS::RemoveDirContentsRecursively(
Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir) / "custom")) {
LOG_WARNING(Frontend, "Failed to remove custom configuration files");
}
if (!Common::FS::RemoveDirRecursively(
Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) / "game_list")) {
LOG_WARNING(Frontend, "Failed to remove game metadata cache files");
}
configure_dialog.ApplyConfiguration();
// Explicitly save the game directories, since reinitializing config does not do so.
QVector<UISettings::GameDir> old_game_dirs = UISettings::values.game_dirs;
QVector<u64> old_favorited_ids = UISettings::values.favorited_ids;
Settings::values.disabled_addons.clear();
config = std::make_unique<Config>();
UISettings::values.reset_to_defaults = false;
UISettings::values.game_dirs = old_game_dirs;
UISettings::values.favorited_ids = old_favorited_ids;
InitializeRecentFileMenuActions();
SetDefaultUIGeometry();
RestoreUIState();
ShowTelemetryCallout();
}
controller_dialog->refreshConfiguration();
InitializeHotkeys();