mirror of
https://github.com/ARMSX2/ARMSX2.git
synced 2026-08-24 16:50:16 -07:00
Qt: Implement settings reset
This commit is contained in:
committed by
refractionpcsx2
parent
d86abebb50
commit
e4df563811
@@ -454,7 +454,8 @@ void AutoUpdaterDialog::checkIfUpdateNeeded()
|
||||
|
||||
void AutoUpdaterDialog::skipThisUpdateClicked()
|
||||
{
|
||||
QtHost::SetBaseStringSettingValue("AutoUpdater", "LastVersion", m_latest_version.toUtf8().constData());
|
||||
Host::SetBaseStringSettingValue("AutoUpdater", "LastVersion", m_latest_version.toUtf8().constData());
|
||||
Host::CommitBaseSettingChanges();
|
||||
done(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -347,7 +347,8 @@ void GameListWidget::onTableViewHeaderSortIndicatorChanged(int, Qt::SortOrder)
|
||||
void GameListWidget::listZoom(float delta)
|
||||
{
|
||||
const float new_scale = std::clamp(m_model->getCoverScale() + delta, MIN_SCALE, MAX_SCALE);
|
||||
QtHost::SetBaseFloatSettingValue("UI", "GameListCoverArtScale", new_scale);
|
||||
Host::SetBaseFloatSettingValue("UI", "GameListCoverArtScale", new_scale);
|
||||
Host::CommitBaseSettingChanges();
|
||||
m_model->setCoverScale(new_scale);
|
||||
m_model->updateCacheSize(width(), height());
|
||||
updateListFont();
|
||||
@@ -368,7 +369,8 @@ void GameListWidget::gridIntScale(int int_scale)
|
||||
{
|
||||
const float new_scale = std::clamp(static_cast<float>(int_scale) / 100.0f, MIN_SCALE, MAX_SCALE);
|
||||
|
||||
QtHost::SetBaseFloatSettingValue("UI", "GameListCoverArtScale", new_scale);
|
||||
Host::SetBaseFloatSettingValue("UI", "GameListCoverArtScale", new_scale);
|
||||
Host::CommitBaseSettingChanges();
|
||||
m_model->setCoverScale(new_scale);
|
||||
m_model->updateCacheSize(width(), height());
|
||||
updateListFont();
|
||||
@@ -389,7 +391,8 @@ void GameListWidget::showGameList()
|
||||
return;
|
||||
}
|
||||
|
||||
QtHost::SetBaseBoolSettingValue("UI", "GameListGridView", false);
|
||||
Host::SetBaseBoolSettingValue("UI", "GameListGridView", false);
|
||||
Host::CommitBaseSettingChanges();
|
||||
m_ui.stack->setCurrentIndex(0);
|
||||
resizeTableViewColumnsToFit();
|
||||
updateToolbar();
|
||||
@@ -405,7 +408,8 @@ void GameListWidget::showGameGrid()
|
||||
return;
|
||||
}
|
||||
|
||||
QtHost::SetBaseBoolSettingValue("UI", "GameListGridView", true);
|
||||
Host::SetBaseBoolSettingValue("UI", "GameListGridView", true);
|
||||
Host::CommitBaseSettingChanges();
|
||||
m_ui.stack->setCurrentIndex(1);
|
||||
updateToolbar();
|
||||
emit layoutChange();
|
||||
@@ -416,7 +420,8 @@ void GameListWidget::setShowCoverTitles(bool enabled)
|
||||
if (m_model->getShowCoverTitles() == enabled)
|
||||
return;
|
||||
|
||||
QtHost::SetBaseBoolSettingValue("UI", "GameListShowCoverTitles", enabled);
|
||||
Host::SetBaseBoolSettingValue("UI", "GameListShowCoverTitles", enabled);
|
||||
Host::CommitBaseSettingChanges();
|
||||
m_model->setShowCoverTitles(enabled);
|
||||
if (isShowingGameGrid())
|
||||
m_model->refresh();
|
||||
@@ -508,14 +513,16 @@ void GameListWidget::saveTableViewColumnVisibilitySettings()
|
||||
for (int column = 0; column < GameListModel::Column_Count; column++)
|
||||
{
|
||||
const bool visible = !m_table_view->isColumnHidden(column);
|
||||
QtHost::SetBaseBoolSettingValue("GameListTableView", getColumnVisibilitySettingsKeyName(column).c_str(), visible);
|
||||
Host::SetBaseBoolSettingValue("GameListTableView", getColumnVisibilitySettingsKeyName(column).c_str(), visible);
|
||||
Host::CommitBaseSettingChanges();
|
||||
}
|
||||
}
|
||||
|
||||
void GameListWidget::saveTableViewColumnVisibilitySettings(int column)
|
||||
{
|
||||
const bool visible = !m_table_view->isColumnHidden(column);
|
||||
QtHost::SetBaseBoolSettingValue("GameListTableView", getColumnVisibilitySettingsKeyName(column).c_str(), visible);
|
||||
Host::SetBaseBoolSettingValue("GameListTableView", getColumnVisibilitySettingsKeyName(column).c_str(), visible);
|
||||
Host::CommitBaseSettingChanges();
|
||||
}
|
||||
|
||||
void GameListWidget::loadTableViewColumnSortSettings()
|
||||
@@ -538,11 +545,12 @@ void GameListWidget::saveTableViewColumnSortSettings()
|
||||
|
||||
if (sort_column >= 0 && sort_column < GameListModel::Column_Count)
|
||||
{
|
||||
QtHost::SetBaseStringSettingValue(
|
||||
Host::SetBaseStringSettingValue(
|
||||
"GameListTableView", "SortColumn", GameListModel::getColumnName(static_cast<GameListModel::Column>(sort_column)));
|
||||
}
|
||||
|
||||
QtHost::SetBaseBoolSettingValue("GameListTableView", "SortDescending", sort_descending);
|
||||
Host::SetBaseBoolSettingValue("GameListTableView", "SortDescending", sort_descending);
|
||||
Host::CommitBaseSettingChanges();
|
||||
}
|
||||
|
||||
const GameList::Entry* GameListWidget::getSelectedEntry() const
|
||||
|
||||
+53
-8
@@ -401,6 +401,37 @@ void MainWindow::recreate()
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
void MainWindow::recreateSettings()
|
||||
{
|
||||
QString current_category;
|
||||
if (m_settings_dialog)
|
||||
{
|
||||
current_category = m_settings_dialog->getCategory();
|
||||
m_settings_dialog->hide();
|
||||
m_settings_dialog->deleteLater();
|
||||
m_settings_dialog = nullptr;
|
||||
}
|
||||
|
||||
doSettings(current_category.toUtf8().constData());
|
||||
}
|
||||
|
||||
void MainWindow::resetSettings(bool ui)
|
||||
{
|
||||
Host::RequestResetSettings(false, true, false, false, ui);
|
||||
|
||||
if (ui)
|
||||
{
|
||||
// UI reset includes theme (and eventually language).
|
||||
// Just updating the theme here, when there's no change, causes Qt to get very confused..
|
||||
// So, we'll just tear down everything and recreate. We'll need to do that for language
|
||||
// resets eventaully anyway.
|
||||
recreate();
|
||||
}
|
||||
|
||||
// g_main_window here for recreate() case above.
|
||||
g_main_window->recreateSettings();
|
||||
}
|
||||
|
||||
void MainWindow::updateApplicationTheme()
|
||||
{
|
||||
if (!s_unthemed_style_name_set)
|
||||
@@ -734,7 +765,8 @@ void MainWindow::onBlockDumpActionToggled(bool checked)
|
||||
return;
|
||||
}
|
||||
|
||||
QtHost::SetBaseStringSettingValue("EmuCore", "BlockDumpSaveDirectory", new_dir.toUtf8().constData());
|
||||
Host::SetBaseStringSettingValue("EmuCore", "BlockDumpSaveDirectory", new_dir.toUtf8().constData());
|
||||
Host::CommitBaseSettingChanges();
|
||||
}
|
||||
|
||||
void MainWindow::saveStateToConfig()
|
||||
@@ -747,7 +779,10 @@ void MainWindow::saveStateToConfig()
|
||||
const QByteArray geometry_b64 = geometry.toBase64();
|
||||
const std::string old_geometry_b64 = Host::GetBaseStringSettingValue("UI", "MainWindowGeometry");
|
||||
if (old_geometry_b64 != geometry_b64.constData())
|
||||
QtHost::SetBaseStringSettingValue("UI", "MainWindowGeometry", geometry_b64.constData());
|
||||
{
|
||||
Host::SetBaseStringSettingValue("UI", "MainWindowGeometry", geometry_b64.constData());
|
||||
Host::CommitBaseSettingChanges();
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
@@ -755,7 +790,10 @@ void MainWindow::saveStateToConfig()
|
||||
const QByteArray state_b64 = state.toBase64();
|
||||
const std::string old_state_b64 = Host::GetBaseStringSettingValue("UI", "MainWindowState");
|
||||
if (old_state_b64 != state_b64.constData())
|
||||
QtHost::SetBaseStringSettingValue("UI", "MainWindowState", state_b64.constData());
|
||||
{
|
||||
Host::SetBaseStringSettingValue("UI", "MainWindowState", state_b64.constData());
|
||||
Host::CommitBaseSettingChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1306,19 +1344,22 @@ void MainWindow::onSaveStateMenuAboutToShow()
|
||||
|
||||
void MainWindow::onViewToolbarActionToggled(bool checked)
|
||||
{
|
||||
QtHost::SetBaseBoolSettingValue("UI", "ShowToolbar", checked);
|
||||
Host::SetBaseBoolSettingValue("UI", "ShowToolbar", checked);
|
||||
Host::CommitBaseSettingChanges();
|
||||
m_ui.toolBar->setVisible(checked);
|
||||
}
|
||||
|
||||
void MainWindow::onViewLockToolbarActionToggled(bool checked)
|
||||
{
|
||||
QtHost::SetBaseBoolSettingValue("UI", "LockToolbar", checked);
|
||||
Host::SetBaseBoolSettingValue("UI", "LockToolbar", checked);
|
||||
Host::CommitBaseSettingChanges();
|
||||
m_ui.toolBar->setMovable(!checked);
|
||||
}
|
||||
|
||||
void MainWindow::onViewStatusBarActionToggled(bool checked)
|
||||
{
|
||||
QtHost::SetBaseBoolSettingValue("UI", "ShowStatusBar", checked);
|
||||
Host::SetBaseBoolSettingValue("UI", "ShowStatusBar", checked);
|
||||
Host::CommitBaseSettingChanges();
|
||||
m_ui.statusBar->setVisible(checked);
|
||||
}
|
||||
|
||||
@@ -1386,7 +1427,8 @@ void MainWindow::onAboutActionTriggered()
|
||||
void MainWindow::onCheckForUpdatesActionTriggered()
|
||||
{
|
||||
// Wipe out the last version, that way it displays the update if we've previously skipped it.
|
||||
QtHost::RemoveBaseSettingValue("AutoUpdater", "LastVersion");
|
||||
Host::RemoveBaseSettingValue("AutoUpdater", "LastVersion");
|
||||
Host::CommitBaseSettingChanges();
|
||||
checkForUpdates(true);
|
||||
}
|
||||
|
||||
@@ -2029,7 +2071,10 @@ void MainWindow::saveDisplayWindowGeometryToConfig()
|
||||
const QByteArray geometry_b64 = geometry.toBase64();
|
||||
const std::string old_geometry_b64 = Host::GetBaseStringSettingValue("UI", "DisplayWindowGeometry");
|
||||
if (old_geometry_b64 != geometry_b64.constData())
|
||||
QtHost::SetBaseStringSettingValue("UI", "DisplayWindowGeometry", geometry_b64.constData());
|
||||
{
|
||||
Host::SetBaseStringSettingValue("UI", "DisplayWindowGeometry", geometry_b64.constData());
|
||||
Host::CommitBaseSettingChanges();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::restoreDisplayWindowGeometryFromConfig()
|
||||
|
||||
@@ -85,6 +85,7 @@ public:
|
||||
void initialize();
|
||||
void connectVMThreadSignals(EmuThread* thread);
|
||||
void startupUpdateCheck();
|
||||
void resetSettings(bool ui);
|
||||
|
||||
/// Locks the VM by pausing it, while a popup dialog is displayed.
|
||||
VMLock pauseAndLockVM();
|
||||
@@ -167,8 +168,6 @@ private Q_SLOTS:
|
||||
|
||||
void onGameChanged(const QString& path, const QString& serial, const QString& name, quint32 crc);
|
||||
|
||||
void recreate();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent* event) override;
|
||||
void closeEvent(QCloseEvent* event) override;
|
||||
@@ -186,6 +185,8 @@ private:
|
||||
|
||||
void setupAdditionalUi();
|
||||
void connectSignals();
|
||||
void recreate();
|
||||
void recreateSettings();
|
||||
|
||||
void saveStateToConfig();
|
||||
void restoreStateFromConfig();
|
||||
|
||||
+63
-218
@@ -24,8 +24,6 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "common/RedtapeWindows.h"
|
||||
#include <KnownFolders.h>
|
||||
#include <ShlObj.h>
|
||||
#endif
|
||||
|
||||
#include "common/Assertions.h"
|
||||
@@ -39,6 +37,7 @@
|
||||
|
||||
#include "pcsx2/CDVD/CDVDcommon.h"
|
||||
#include "pcsx2/DebugTools/Debug.h"
|
||||
#include "pcsx2/Frontend/CommonHost.h"
|
||||
#include "pcsx2/Frontend/GameList.h"
|
||||
#include "pcsx2/Frontend/INISettingsInterface.h"
|
||||
#include "pcsx2/Frontend/LogSink.h"
|
||||
@@ -52,7 +51,6 @@
|
||||
#include "QtUtils.h"
|
||||
#include "svnrev.h"
|
||||
|
||||
static constexpr u32 SETTINGS_VERSION = 1;
|
||||
static constexpr u32 SETTINGS_SAVE_DELAY = 1000;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -64,14 +62,8 @@ static void PrintCommandLineHelp(const char* progname);
|
||||
static std::shared_ptr<VMBootParameters>& AutoBoot(std::shared_ptr<VMBootParameters>& autoboot);
|
||||
static bool ParseCommandLineOptions(int argc, char* argv[], std::shared_ptr<VMBootParameters>& autoboot);
|
||||
static bool InitializeConfig();
|
||||
static bool ShouldUsePortableMode();
|
||||
static void SetAppRoot();
|
||||
static void SetResourcesDirectory();
|
||||
static void SetDataDirectory();
|
||||
static void HookSignals();
|
||||
static bool SetCriticalFolders();
|
||||
static void SetDefaultConfig();
|
||||
static void SaveSettings();
|
||||
static void HookSignals();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -89,225 +81,54 @@ static bool s_start_fullscreen_ui_fullscreen = false;
|
||||
// Initialization/Shutdown
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool QtHost::SetCriticalFolders()
|
||||
{
|
||||
SetAppRoot();
|
||||
SetResourcesDirectory();
|
||||
SetDataDirectory();
|
||||
|
||||
// logging of directories in case something goes wrong super early
|
||||
Console.WriteLn("AppRoot Directory: %s", EmuFolders::AppRoot.c_str());
|
||||
Console.WriteLn("DataRoot Directory: %s", EmuFolders::DataRoot.c_str());
|
||||
Console.WriteLn("Resources Directory: %s", EmuFolders::Resources.c_str());
|
||||
|
||||
// allow SetDataDirectory() to change settings directory (if we want to split config later on)
|
||||
if (EmuFolders::Settings.empty())
|
||||
EmuFolders::Settings = Path::Combine(EmuFolders::DataRoot, "inis");
|
||||
|
||||
// Write crash dumps to the data directory, since that'll be accessible for certain.
|
||||
CrashHandler::SetWriteDirectory(EmuFolders::DataRoot);
|
||||
|
||||
// the resources directory should exist, bail out if not
|
||||
if (!FileSystem::DirectoryExists(EmuFolders::Resources.c_str()))
|
||||
{
|
||||
QMessageBox::critical(nullptr, QStringLiteral("Error"),
|
||||
QStringLiteral("Resources directory is missing, your installation is incomplete."));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QtHost::ShouldUsePortableMode()
|
||||
{
|
||||
// Check whether portable.ini exists in the program directory.
|
||||
return FileSystem::FileExists(Path::Combine(EmuFolders::AppRoot, "portable.ini").c_str());
|
||||
}
|
||||
|
||||
void QtHost::SetAppRoot()
|
||||
{
|
||||
std::string program_path(FileSystem::GetProgramPath());
|
||||
Console.WriteLn("Program Path: %s", program_path.c_str());
|
||||
|
||||
EmuFolders::AppRoot = Path::Canonicalize(Path::GetDirectory(program_path));
|
||||
}
|
||||
|
||||
void QtHost::SetResourcesDirectory()
|
||||
{
|
||||
#ifndef __APPLE__
|
||||
// On Windows/Linux, these are in the binary directory.
|
||||
EmuFolders::Resources = Path::Combine(EmuFolders::AppRoot, "resources");
|
||||
#else
|
||||
// On macOS, this is in the bundle resources directory.
|
||||
EmuFolders::Resources = Path::Canonicalize(Path::Combine(EmuFolders::AppRoot, "../Resources"));
|
||||
#endif
|
||||
}
|
||||
|
||||
void QtHost::SetDataDirectory()
|
||||
{
|
||||
if (ShouldUsePortableMode())
|
||||
{
|
||||
EmuFolders::DataRoot = EmuFolders::AppRoot;
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
// On Windows, use My Documents\PCSX2 to match old installs.
|
||||
PWSTR documents_directory;
|
||||
if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Documents, 0, NULL, &documents_directory)))
|
||||
{
|
||||
if (std::wcslen(documents_directory) > 0)
|
||||
EmuFolders::DataRoot = Path::Combine(StringUtil::WideStringToUTF8String(documents_directory), "PCSX2");
|
||||
CoTaskMemFree(documents_directory);
|
||||
}
|
||||
#elif defined(__linux__)
|
||||
// Use $XDG_CONFIG_HOME/PCSX2 if it exists.
|
||||
const char* xdg_config_home = getenv("XDG_CONFIG_HOME");
|
||||
if (xdg_config_home && Path::IsAbsolute(xdg_config_home))
|
||||
{
|
||||
EmuFolders::DataRoot = Path::Combine(xdg_config_home, "PCSX2");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use ~/PCSX2 for non-XDG, and ~/.config/PCSX2 for XDG.
|
||||
// Maybe we should drop the former when Qt goes live.
|
||||
const char* home_dir = getenv("HOME");
|
||||
if (home_dir)
|
||||
{
|
||||
#ifndef XDG_STD
|
||||
EmuFolders::DataRoot = Path::Combine(home_dir, "PCSX2");
|
||||
#else
|
||||
// ~/.config should exist, but just in case it doesn't and this is a fresh profile..
|
||||
const std::string config_dir(Path::Combine(home_dir, ".config"));
|
||||
if (!FileSystem::DirectoryExists(config_dir.c_str()))
|
||||
FileSystem::CreateDirectoryPath(config_dir.c_str(), false);
|
||||
|
||||
EmuFolders::DataRoot = Path::Combine(config_dir, "PCSX2");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
static constexpr char MAC_DATA_DIR[] = "Library/Application Support/PCSX2";
|
||||
const char* home_dir = getenv("HOME");
|
||||
if (home_dir)
|
||||
EmuFolders::DataRoot = Path::Combine(home_dir, MAC_DATA_DIR);
|
||||
#endif
|
||||
|
||||
// make sure it exists
|
||||
if (!EmuFolders::DataRoot.empty() && !FileSystem::DirectoryExists(EmuFolders::DataRoot.c_str()))
|
||||
{
|
||||
// we're in trouble if we fail to create this directory... but try to hobble on with portable
|
||||
if (!FileSystem::CreateDirectoryPath(EmuFolders::DataRoot.c_str(), false))
|
||||
EmuFolders::DataRoot.clear();
|
||||
}
|
||||
|
||||
// couldn't determine the data directory? fallback to portable.
|
||||
if (EmuFolders::DataRoot.empty())
|
||||
EmuFolders::DataRoot = EmuFolders::AppRoot;
|
||||
}
|
||||
|
||||
bool QtHost::InitializeConfig()
|
||||
{
|
||||
if (!SetCriticalFolders())
|
||||
if (!CommonHost::InitializeCriticalFolders())
|
||||
{
|
||||
QMessageBox::critical(nullptr, QStringLiteral("PCSX2"),
|
||||
QStringLiteral("One or more critical directories are missing, your installation may be incomplete."));
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string path(Path::Combine(EmuFolders::Settings, "PCSX2.ini"));
|
||||
Console.WriteLn("Loading config from %s.", path.c_str());
|
||||
|
||||
s_base_settings_interface = std::make_unique<INISettingsInterface>(std::move(path));
|
||||
Host::Internal::SetBaseSettingsLayer(s_base_settings_interface.get());
|
||||
|
||||
uint settings_version;
|
||||
if (!s_base_settings_interface->Load() ||
|
||||
!s_base_settings_interface->GetUIntValue("UI", "SettingsVersion", &settings_version) ||
|
||||
settings_version != SETTINGS_VERSION)
|
||||
if (!s_base_settings_interface->Load() || !CommonHost::CheckSettingsVersion())
|
||||
{
|
||||
QMessageBox::critical(
|
||||
g_main_window, qApp->translate("QtHost", "Settings Reset"),
|
||||
qApp->translate("QtHost", "Settings do not exist or are the incorrect version, resetting to defaults."));
|
||||
SetDefaultConfig();
|
||||
s_base_settings_interface->Save();
|
||||
// If the config file doesn't exist, assume this is a new install and don't prompt to overwrite.
|
||||
if (FileSystem::FileExists(s_base_settings_interface->GetFileName().c_str()) &&
|
||||
QMessageBox::question(nullptr, QStringLiteral("PCSX2"),
|
||||
QStringLiteral("Settings failed to load, or are the incorrect version. Clicking Yes will reset all settings to defaults. Do you want to continue?")) != QMessageBox::Yes)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CommonHost::SetDefaultSettings(*s_base_settings_interface, true, true, true, true, true);
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
// TODO: Handle reset to defaults if load fails.
|
||||
EmuFolders::LoadConfig(*s_base_settings_interface.get());
|
||||
EmuFolders::EnsureFoldersExist();
|
||||
CommonHost::LoadStartupSettings();
|
||||
Host::UpdateLogging(QtHost::InNoGUIMode());
|
||||
return true;
|
||||
}
|
||||
|
||||
void QtHost::SetDefaultConfig()
|
||||
void Host::SetDefaultUISettings(SettingsInterface& si)
|
||||
{
|
||||
EmuFolders::SetDefaults();
|
||||
EmuFolders::EnsureFoldersExist();
|
||||
Host::SetDefaultLoggingSettings(si);
|
||||
|
||||
SettingsInterface& si = *s_base_settings_interface.get();
|
||||
si.SetUIntValue("UI", "SettingsVersion", SETTINGS_VERSION);
|
||||
VMManager::SetDefaultSettings(si);
|
||||
EmuFolders::Save(si);
|
||||
PAD::SetDefaultControllerConfig(si);
|
||||
PAD::SetDefaultHotkeyConfig(si);
|
||||
}
|
||||
|
||||
void QtHost::SetBaseBoolSettingValue(const char* section, const char* key, bool value)
|
||||
{
|
||||
auto lock = Host::GetSettingsLock();
|
||||
s_base_settings_interface->SetBoolValue(section, key, value);
|
||||
QueueSettingsSave();
|
||||
}
|
||||
|
||||
void QtHost::SetBaseIntSettingValue(const char* section, const char* key, int value)
|
||||
{
|
||||
auto lock = Host::GetSettingsLock();
|
||||
s_base_settings_interface->SetIntValue(section, key, value);
|
||||
QueueSettingsSave();
|
||||
}
|
||||
|
||||
void QtHost::SetBaseFloatSettingValue(const char* section, const char* key, float value)
|
||||
{
|
||||
auto lock = Host::GetSettingsLock();
|
||||
s_base_settings_interface->SetFloatValue(section, key, value);
|
||||
QueueSettingsSave();
|
||||
}
|
||||
|
||||
void QtHost::SetBaseStringSettingValue(const char* section, const char* key, const char* value)
|
||||
{
|
||||
auto lock = Host::GetSettingsLock();
|
||||
s_base_settings_interface->SetStringValue(section, key, value);
|
||||
QueueSettingsSave();
|
||||
}
|
||||
|
||||
void QtHost::SetBaseStringListSettingValue(const char* section, const char* key, const std::vector<std::string>& values)
|
||||
{
|
||||
auto lock = Host::GetSettingsLock();
|
||||
s_base_settings_interface->SetStringList(section, key, values);
|
||||
QueueSettingsSave();
|
||||
}
|
||||
|
||||
bool QtHost::AddBaseValueToStringList(const char* section, const char* key, const char* value)
|
||||
{
|
||||
auto lock = Host::GetSettingsLock();
|
||||
if (!s_base_settings_interface->AddToStringList(section, key, value))
|
||||
return false;
|
||||
|
||||
QueueSettingsSave();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QtHost::RemoveBaseValueFromStringList(const char* section, const char* key, const char* value)
|
||||
{
|
||||
auto lock = Host::GetSettingsLock();
|
||||
if (!s_base_settings_interface->RemoveFromStringList(section, key, value))
|
||||
return false;
|
||||
|
||||
QueueSettingsSave();
|
||||
return true;
|
||||
}
|
||||
|
||||
void QtHost::RemoveBaseSettingValue(const char* section, const char* key)
|
||||
{
|
||||
auto lock = Host::GetSettingsLock();
|
||||
s_base_settings_interface->DeleteValue(section, key);
|
||||
QueueSettingsSave();
|
||||
si.SetBoolValue("UI", "InhibitScreensaver", true);
|
||||
si.SetBoolValue("UI", "ConfirmShutdown", true);
|
||||
si.SetBoolValue("UI", "StartPaused", false);
|
||||
si.SetBoolValue("UI", "PauseOnFocusLoss", false);
|
||||
si.SetBoolValue("UI", "StartFullscreen", false);
|
||||
si.SetBoolValue("UI", "DoubleClickTogglesFullscreen", true);
|
||||
si.SetBoolValue("UI", "HideMouseCursor", false);
|
||||
si.SetBoolValue("UI", "RenderToSeparateWindow", false);
|
||||
si.SetBoolValue("UI", "HideMainWindowWhenRunning", false);
|
||||
si.SetBoolValue("UI", "DisableWindowResize", false);
|
||||
si.SetStringValue("UI", "Theme", MainWindow::DEFAULT_THEME_NAME);
|
||||
}
|
||||
|
||||
void QtHost::SaveSettings()
|
||||
@@ -324,13 +145,20 @@ void QtHost::SaveSettings()
|
||||
s_settings_save_timer.release();
|
||||
}
|
||||
|
||||
void QtHost::QueueSettingsSave()
|
||||
void Host::CommitBaseSettingChanges()
|
||||
{
|
||||
if (!QtHost::IsOnUIThread())
|
||||
{
|
||||
QtHost::RunOnUIThread(&Host::CommitBaseSettingChanges);
|
||||
return;
|
||||
}
|
||||
|
||||
auto lock = Host::GetSettingsLock();
|
||||
if (s_settings_save_timer)
|
||||
return;
|
||||
|
||||
s_settings_save_timer = std::make_unique<QTimer>();
|
||||
s_settings_save_timer->connect(s_settings_save_timer.get(), &QTimer::timeout, SaveSettings);
|
||||
s_settings_save_timer->connect(s_settings_save_timer.get(), &QTimer::timeout, &QtHost::SaveSettings);
|
||||
s_settings_save_timer->setSingleShot(true);
|
||||
s_settings_save_timer->start(SETTINGS_SAVE_DELAY);
|
||||
}
|
||||
@@ -345,6 +173,12 @@ bool QtHost::InNoGUIMode()
|
||||
return s_nogui_mode;
|
||||
}
|
||||
|
||||
bool QtHost::IsOnUIThread()
|
||||
{
|
||||
QThread* ui_thread = qApp->thread();
|
||||
return (QThread::currentThread() == ui_thread);
|
||||
}
|
||||
|
||||
void QtHost::RunOnUIThread(const std::function<void()>& func, bool block /*= false*/)
|
||||
{
|
||||
// main window always exists, so it's fine to attach it to that.
|
||||
@@ -353,6 +187,21 @@ void QtHost::RunOnUIThread(const std::function<void()>& func, bool block /*= fal
|
||||
Q_ARG(const std::function<void()>&, func));
|
||||
}
|
||||
|
||||
bool Host::RequestResetSettings(bool folders, bool core, bool controllers, bool hotkeys, bool ui)
|
||||
{
|
||||
{
|
||||
auto lock = Host::GetSettingsLock();
|
||||
CommonHost::SetDefaultSettings(*s_base_settings_interface.get(), folders, core, controllers, hotkeys, ui);
|
||||
}
|
||||
Host::CommitBaseSettingChanges();
|
||||
|
||||
g_emu_thread->applySettings();
|
||||
if (folders)
|
||||
g_emu_thread->updateEmuFolders();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QString QtHost::GetAppNameAndVersion()
|
||||
{
|
||||
QString ret;
|
||||
@@ -725,11 +574,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
// Bail out if we can't find any config.
|
||||
if (!QtHost::InitializeConfig())
|
||||
{
|
||||
// NOTE: No point translating this, because no config means the language won't be loaded anyway.
|
||||
QMessageBox::critical(nullptr, QStringLiteral("Error"), QStringLiteral("Failed to initialize config."));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Set theme before creating any windows.
|
||||
MainWindow::updateApplicationTheme();
|
||||
|
||||
+3
-11
@@ -46,6 +46,9 @@ namespace QtHost
|
||||
/// Sets NoGUI mode (implys batch mode, does not display main window, exits on shutdown).
|
||||
bool InNoGUIMode();
|
||||
|
||||
/// Returns true if the calling thread is the UI thread.
|
||||
bool IsOnUIThread();
|
||||
|
||||
/// Executes a function on the UI thread.
|
||||
void RunOnUIThread(const std::function<void()>& func, bool block = false);
|
||||
|
||||
@@ -58,17 +61,6 @@ namespace QtHost
|
||||
/// Returns the base path for resources. This may be : prefixed, if we're using embedded resources.
|
||||
QString GetResourcesBasePath();
|
||||
|
||||
/// Thread-safe settings access.
|
||||
void SetBaseBoolSettingValue(const char* section, const char* key, bool value);
|
||||
void SetBaseIntSettingValue(const char* section, const char* key, int value);
|
||||
void SetBaseFloatSettingValue(const char* section, const char* key, float value);
|
||||
void SetBaseStringSettingValue(const char* section, const char* key, const char* value);
|
||||
void SetBaseStringListSettingValue(const char* section, const char* key, const std::vector<std::string>& values);
|
||||
bool AddBaseValueToStringList(const char* section, const char* key, const char* value);
|
||||
bool RemoveBaseValueFromStringList(const char* section, const char* key, const char* value);
|
||||
void RemoveBaseSettingValue(const char* section, const char* key);
|
||||
void QueueSettingsSave();
|
||||
|
||||
/// VM state, safe to access on UI thread.
|
||||
bool IsVMValid();
|
||||
bool IsVMPaused();
|
||||
|
||||
@@ -613,7 +613,8 @@ namespace SettingWidgetBinder
|
||||
|
||||
Accessor::connectValueChanged(widget, [widget, section = std::move(section), key = std::move(key)]() {
|
||||
const bool new_value = Accessor::getBoolValue(widget);
|
||||
QtHost::SetBaseBoolSettingValue(section.c_str(), key.c_str(), new_value);
|
||||
Host::SetBaseBoolSettingValue(section.c_str(), key.c_str(), new_value);
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->applySettings();
|
||||
});
|
||||
}
|
||||
@@ -653,7 +654,8 @@ namespace SettingWidgetBinder
|
||||
|
||||
Accessor::connectValueChanged(widget, [widget, section = std::move(section), key = std::move(key), option_offset]() {
|
||||
const int new_value = Accessor::getIntValue(widget);
|
||||
QtHost::SetBaseIntSettingValue(section.c_str(), key.c_str(), new_value + option_offset);
|
||||
Host::SetBaseIntSettingValue(section.c_str(), key.c_str(), new_value + option_offset);
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->applySettings();
|
||||
});
|
||||
}
|
||||
@@ -692,7 +694,8 @@ namespace SettingWidgetBinder
|
||||
|
||||
Accessor::connectValueChanged(widget, [widget, section = std::move(section), key = std::move(key)]() {
|
||||
const float new_value = Accessor::getFloatValue(widget);
|
||||
QtHost::SetBaseFloatSettingValue(section.c_str(), key.c_str(), new_value);
|
||||
Host::SetBaseFloatSettingValue(section.c_str(), key.c_str(), new_value);
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->applySettings();
|
||||
});
|
||||
}
|
||||
@@ -732,7 +735,8 @@ namespace SettingWidgetBinder
|
||||
|
||||
Accessor::connectValueChanged(widget, [widget, section = std::move(section), key = std::move(key), range]() {
|
||||
const float new_value = (static_cast<float>(Accessor::getIntValue(widget)) / range);
|
||||
QtHost::SetBaseFloatSettingValue(section.c_str(), key.c_str(), new_value);
|
||||
Host::SetBaseFloatSettingValue(section.c_str(), key.c_str(), new_value);
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->applySettings();
|
||||
});
|
||||
}
|
||||
@@ -773,10 +777,11 @@ namespace SettingWidgetBinder
|
||||
Accessor::connectValueChanged(widget, [widget, section = std::move(section), key = std::move(key)]() {
|
||||
const QString new_value = Accessor::getStringValue(widget);
|
||||
if (!new_value.isEmpty())
|
||||
QtHost::SetBaseStringSettingValue(section.c_str(), key.c_str(), new_value.toUtf8().constData());
|
||||
Host::SetBaseStringSettingValue(section.c_str(), key.c_str(), new_value.toUtf8().constData());
|
||||
else
|
||||
QtHost::RemoveBaseSettingValue(section.c_str(), key.c_str());
|
||||
Host::RemoveBaseSettingValue(section.c_str(), key.c_str());
|
||||
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->applySettings();
|
||||
});
|
||||
}
|
||||
@@ -835,7 +840,8 @@ namespace SettingWidgetBinder
|
||||
Accessor::connectValueChanged(widget, [widget, section = std::move(section), key = std::move(key), to_string_function]() {
|
||||
const DataType value = static_cast<DataType>(static_cast<UnderlyingType>(Accessor::getIntValue(widget)));
|
||||
const char* string_value = to_string_function(value);
|
||||
QtHost::SetBaseStringSettingValue(section.c_str(), key.c_str(), string_value);
|
||||
Host::SetBaseStringSettingValue(section.c_str(), key.c_str(), string_value);
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->applySettings();
|
||||
});
|
||||
}
|
||||
@@ -896,7 +902,8 @@ namespace SettingWidgetBinder
|
||||
|
||||
Accessor::connectValueChanged(widget, [widget, section = std::move(section), key = std::move(key), enum_names]() {
|
||||
const UnderlyingType value = static_cast<UnderlyingType>(Accessor::getIntValue(widget));
|
||||
QtHost::SetBaseStringSettingValue(section.c_str(), key.c_str(), enum_names[value]);
|
||||
Host::SetBaseStringSettingValue(section.c_str(), key.c_str(), enum_names[value]);
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->applySettings();
|
||||
});
|
||||
}
|
||||
@@ -959,7 +966,8 @@ namespace SettingWidgetBinder
|
||||
|
||||
Accessor::connectValueChanged(widget, [widget, section = std::move(section), key = std::move(key), enum_values]() {
|
||||
const int value = Accessor::getIntValue(widget);
|
||||
QtHost::SetBaseStringSettingValue(section.c_str(), key.c_str(), enum_values[value]);
|
||||
Host::SetBaseStringSettingValue(section.c_str(), key.c_str(), enum_values[value]);
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->applySettings();
|
||||
});
|
||||
}
|
||||
@@ -996,13 +1004,14 @@ namespace SettingWidgetBinder
|
||||
if (!new_value.empty())
|
||||
{
|
||||
std::string relative_path(Path::MakeRelative(new_value, EmuFolders::DataRoot));
|
||||
QtHost::SetBaseStringSettingValue(section.c_str(), key.c_str(), relative_path.c_str());
|
||||
Host::SetBaseStringSettingValue(section.c_str(), key.c_str(), relative_path.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
QtHost::RemoveBaseSettingValue(section.c_str(), key.c_str());
|
||||
Host::RemoveBaseSettingValue(section.c_str(), key.c_str());
|
||||
}
|
||||
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->updateEmuFolders();
|
||||
});
|
||||
|
||||
|
||||
@@ -130,7 +130,8 @@ void BIOSSettingsWidget::listRefreshed(const QVector<BIOSInfo>& items)
|
||||
|
||||
void BIOSSettingsWidget::listItemChanged(const QTreeWidgetItem* current, const QTreeWidgetItem* previous)
|
||||
{
|
||||
QtHost::SetBaseStringSettingValue("Filenames", "BIOS", current->text(0).toUtf8().constData());
|
||||
Host::SetBaseStringSettingValue("Filenames", "BIOS", current->text(0).toUtf8().constData());
|
||||
Host::CommitBaseSettingChanges();
|
||||
}
|
||||
|
||||
BIOSSettingsWidget::RefreshThread::RefreshThread(BIOSSettingsWidget* parent, const QString& directory)
|
||||
|
||||
@@ -199,13 +199,17 @@ void ControllerBindingWidget::onClearBindingsClicked()
|
||||
{
|
||||
auto lock = Host::GetSettingsLock();
|
||||
PAD::ClearPortBindings(*Host::Internal::GetBaseSettingsLayer(), m_port_number);
|
||||
Host::CommitBaseSettingChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
PAD::ClearPortBindings(*m_dialog->getProfileSettingsInterface(), m_port_number);
|
||||
m_dialog->getProfileSettingsInterface()->Save();
|
||||
}
|
||||
|
||||
saveAndRefresh();
|
||||
// force a refresh after clearing
|
||||
g_emu_thread->applySettings();
|
||||
onTypeChanged();
|
||||
}
|
||||
|
||||
void ControllerBindingWidget::doDeviceAutomaticBinding(const QString& device)
|
||||
@@ -223,27 +227,27 @@ void ControllerBindingWidget::doDeviceAutomaticBinding(const QString& device)
|
||||
{
|
||||
auto lock = Host::GetSettingsLock();
|
||||
result = PAD::MapController(*Host::Internal::GetBaseSettingsLayer(), m_port_number, mapping);
|
||||
if (result)
|
||||
Host::CommitBaseSettingChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = PAD::MapController(*m_dialog->getProfileSettingsInterface(), m_port_number, mapping);
|
||||
m_dialog->getProfileSettingsInterface()->Save();
|
||||
g_emu_thread->reloadInputBindings();
|
||||
if (result)
|
||||
{
|
||||
m_dialog->getProfileSettingsInterface()->Save();
|
||||
g_emu_thread->reloadInputBindings();
|
||||
}
|
||||
}
|
||||
|
||||
// force a refresh after mapping
|
||||
if (result)
|
||||
saveAndRefresh();
|
||||
{
|
||||
g_emu_thread->applySettings();
|
||||
onTypeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void ControllerBindingWidget::saveAndRefresh()
|
||||
{
|
||||
onTypeChanged();
|
||||
QtHost::QueueSettingsSave();
|
||||
g_emu_thread->applySettings();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ControllerMacroWidget::ControllerMacroWidget(ControllerBindingWidget* parent)
|
||||
|
||||
@@ -58,7 +58,6 @@ private:
|
||||
void populateControllerTypes();
|
||||
void updateHeaderToolButtons();
|
||||
void doDeviceAutomaticBinding(const QString& device);
|
||||
void saveAndRefresh();
|
||||
|
||||
Ui::ControllerBindingWidget m_ui;
|
||||
|
||||
|
||||
@@ -63,7 +63,8 @@ namespace ControllerSettingWidgetBinder
|
||||
|
||||
Accessor::connectValueChanged(widget, [widget, section = std::move(section), key = std::move(key)]() {
|
||||
const bool new_value = Accessor::getBoolValue(widget);
|
||||
QtHost::SetBaseBoolSettingValue(section.c_str(), key.c_str(), new_value);
|
||||
Host::SetBaseBoolSettingValue(section.c_str(), key.c_str(), new_value);
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->applySettings();
|
||||
});
|
||||
}
|
||||
@@ -94,7 +95,8 @@ namespace ControllerSettingWidgetBinder
|
||||
|
||||
Accessor::connectValueChanged(widget, [widget, section = std::move(section), key = std::move(key)]() {
|
||||
const float new_value = Accessor::getFloatValue(widget);
|
||||
QtHost::SetBaseFloatSettingValue(section.c_str(), key.c_str(), new_value);
|
||||
Host::SetBaseFloatSettingValue(section.c_str(), key.c_str(), new_value);
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->applySettings();
|
||||
});
|
||||
}
|
||||
@@ -127,7 +129,8 @@ namespace ControllerSettingWidgetBinder
|
||||
|
||||
Accessor::connectValueChanged(widget, [widget, section = std::move(section), key = std::move(key), range]() {
|
||||
const float new_value = (static_cast<float>(Accessor::getIntValue(widget)) / range);
|
||||
QtHost::SetBaseFloatSettingValue(section.c_str(), key.c_str(), new_value);
|
||||
Host::SetBaseFloatSettingValue(section.c_str(), key.c_str(), new_value);
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->applySettings();
|
||||
});
|
||||
}
|
||||
@@ -166,10 +169,11 @@ namespace ControllerSettingWidgetBinder
|
||||
Accessor::connectValueChanged(widget, [widget, section = std::move(section), key = std::move(key)]() {
|
||||
const QString new_value = Accessor::getStringValue(widget);
|
||||
if (!new_value.isEmpty())
|
||||
QtHost::SetBaseStringSettingValue(section.c_str(), key.c_str(), new_value.toUtf8().constData());
|
||||
Host::SetBaseStringSettingValue(section.c_str(), key.c_str(), new_value.toUtf8().constData());
|
||||
else
|
||||
QtHost::RemoveBaseSettingValue(section.c_str(), key.c_str());
|
||||
Host::RemoveBaseSettingValue(section.c_str(), key.c_str());
|
||||
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->applySettings();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "Settings/ControllerBindingWidgets.h"
|
||||
#include "Settings/HotkeySettingsWidget.h"
|
||||
|
||||
#include "pcsx2/Frontend/CommonHost.h"
|
||||
#include "pcsx2/Frontend/INISettingsInterface.h"
|
||||
#include "pcsx2/PAD/Host/PAD.h"
|
||||
#include "pcsx2/Sio.h"
|
||||
@@ -162,7 +163,7 @@ void ControllerSettingsDialog::onLoadProfileClicked()
|
||||
{
|
||||
auto lock = Host::GetSettingsLock();
|
||||
PAD::CopyConfiguration(Host::Internal::GetBaseSettingsLayer(), *m_profile_interface, true, true, false);
|
||||
QtHost::QueueSettingsSave();
|
||||
Host::CommitBaseSettingChanges();
|
||||
}
|
||||
|
||||
g_emu_thread->applySettings();
|
||||
@@ -206,9 +207,8 @@ void ControllerSettingsDialog::onRestoreDefaultsClicked()
|
||||
// actually restore it
|
||||
{
|
||||
auto lock = Host::GetSettingsLock();
|
||||
PAD::SetDefaultControllerConfig(*Host::Internal::GetBaseSettingsLayer());
|
||||
PAD::SetDefaultHotkeyConfig(*Host::Internal::GetBaseSettingsLayer());
|
||||
QtHost::QueueSettingsSave();
|
||||
CommonHost::SetDefaultSettings(*Host::Internal::GetBaseSettingsLayer(), false, false, true, true, false);
|
||||
Host::CommitBaseSettingChanges();
|
||||
}
|
||||
|
||||
g_emu_thread->applySettings();
|
||||
@@ -295,7 +295,8 @@ void ControllerSettingsDialog::setBoolValue(const char* section, const char* key
|
||||
}
|
||||
else
|
||||
{
|
||||
QtHost::SetBaseBoolSettingValue(section, key, value);
|
||||
Host::SetBaseBoolSettingValue(section, key, value);
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->applySettings();
|
||||
}
|
||||
}
|
||||
@@ -310,7 +311,8 @@ void ControllerSettingsDialog::setIntValue(const char* section, const char* key,
|
||||
}
|
||||
else
|
||||
{
|
||||
QtHost::SetBaseIntSettingValue(section, key, value);
|
||||
Host::SetBaseIntSettingValue(section, key, value);
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->applySettings();
|
||||
}
|
||||
}
|
||||
@@ -325,7 +327,8 @@ void ControllerSettingsDialog::setStringValue(const char* section, const char* k
|
||||
}
|
||||
else
|
||||
{
|
||||
QtHost::SetBaseStringSettingValue(section, key, value);
|
||||
Host::SetBaseStringSettingValue(section, key, value);
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->applySettings();
|
||||
}
|
||||
}
|
||||
@@ -340,7 +343,8 @@ void ControllerSettingsDialog::clearSettingValue(const char* section, const char
|
||||
}
|
||||
else
|
||||
{
|
||||
QtHost::RemoveBaseSettingValue(section, key);
|
||||
Host::RemoveBaseSettingValue(section, key);
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->applySettings();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,9 +65,10 @@ GameListSettingsWidget::~GameListSettingsWidget() = default;
|
||||
|
||||
bool GameListSettingsWidget::addExcludedPath(const std::string& path)
|
||||
{
|
||||
if (!QtHost::AddBaseValueToStringList("GameList", "ExcludedPaths", path.c_str()))
|
||||
if (!Host::AddBaseValueToStringList("GameList", "ExcludedPaths", path.c_str()))
|
||||
return false;
|
||||
|
||||
Host::CommitBaseSettingChanges();
|
||||
m_ui.excludedPaths->addItem(QString::fromStdString(path));
|
||||
g_main_window->refreshGameList(false);
|
||||
return true;
|
||||
@@ -107,14 +108,15 @@ void GameListSettingsWidget::addPathToTable(const std::string& path, bool recurs
|
||||
const std::string path(item->text().toStdString());
|
||||
if (state == Qt::Checked)
|
||||
{
|
||||
QtHost::RemoveBaseValueFromStringList("GameList", "Paths", path.c_str());
|
||||
QtHost::AddBaseValueToStringList("GameList", "RecursivePaths", path.c_str());
|
||||
Host::RemoveBaseValueFromStringList("GameList", "Paths", path.c_str());
|
||||
Host::AddBaseValueToStringList("GameList", "RecursivePaths", path.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
QtHost::RemoveBaseValueFromStringList("GameList", "RecursivePaths", path.c_str());
|
||||
QtHost::AddBaseValueToStringList("GameList", "Paths", path.c_str());
|
||||
Host::RemoveBaseValueFromStringList("GameList", "RecursivePaths", path.c_str());
|
||||
Host::AddBaseValueToStringList("GameList", "Paths", path.c_str());
|
||||
}
|
||||
Host::CommitBaseSettingChanges();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -138,8 +140,9 @@ void GameListSettingsWidget::refreshDirectoryList()
|
||||
void GameListSettingsWidget::addSearchDirectory(const QString& path, bool recursive)
|
||||
{
|
||||
const std::string spath(path.toStdString());
|
||||
QtHost::RemoveBaseValueFromStringList("GameList", recursive ? "Paths" : "RecursivePaths", spath.c_str());
|
||||
QtHost::AddBaseValueToStringList("GameList", recursive ? "RecursivePaths" : "Paths", spath.c_str());
|
||||
Host::RemoveBaseValueFromStringList("GameList", recursive ? "Paths" : "RecursivePaths", spath.c_str());
|
||||
Host::AddBaseValueToStringList("GameList", recursive ? "RecursivePaths" : "Paths", spath.c_str());
|
||||
Host::CommitBaseSettingChanges();
|
||||
refreshDirectoryList();
|
||||
g_main_window->refreshGameList(false);
|
||||
}
|
||||
@@ -147,12 +150,13 @@ void GameListSettingsWidget::addSearchDirectory(const QString& path, bool recurs
|
||||
void GameListSettingsWidget::removeSearchDirectory(const QString& path)
|
||||
{
|
||||
const std::string spath(path.toStdString());
|
||||
if (!QtHost::RemoveBaseValueFromStringList("GameList", "Paths", spath.c_str()) &&
|
||||
!QtHost::RemoveBaseValueFromStringList("GameList", "RecursivePaths", spath.c_str()))
|
||||
if (!Host::RemoveBaseValueFromStringList("GameList", "Paths", spath.c_str()) &&
|
||||
!Host::RemoveBaseValueFromStringList("GameList", "RecursivePaths", spath.c_str()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Host::CommitBaseSettingChanges();
|
||||
refreshDirectoryList();
|
||||
g_main_window->refreshGameList(false);
|
||||
}
|
||||
@@ -228,7 +232,9 @@ void GameListSettingsWidget::onRemoveExcludedPathButtonClicked()
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
QtHost::RemoveBaseValueFromStringList("GameList", "ExcludedPaths", item->text().toUtf8().constData());
|
||||
if (Host::RemoveBaseValueFromStringList("GameList", "ExcludedPaths", item->text().toUtf8().constData()))
|
||||
Host::CommitBaseSettingChanges();
|
||||
|
||||
delete item;
|
||||
|
||||
g_main_window->refreshGameList(false);
|
||||
|
||||
@@ -259,9 +259,10 @@ void InputBindingDialog::saveListToSettings()
|
||||
else
|
||||
{
|
||||
if (!m_bindings.empty())
|
||||
QtHost::SetBaseStringListSettingValue(m_section_name.c_str(), m_key_name.c_str(), m_bindings);
|
||||
Host::SetBaseStringListSettingValue(m_section_name.c_str(), m_key_name.c_str(), m_bindings);
|
||||
else
|
||||
QtHost::RemoveBaseSettingValue(m_section_name.c_str(), m_key_name.c_str());
|
||||
Host::RemoveBaseSettingValue(m_section_name.c_str(), m_key_name.c_str());
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->reloadInputBindings();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,7 +236,8 @@ void InputBindingWidget::setNewBinding()
|
||||
}
|
||||
else
|
||||
{
|
||||
QtHost::SetBaseStringSettingValue(m_section_name.c_str(), m_key_name.c_str(), new_binding.c_str());
|
||||
Host::SetBaseStringSettingValue(m_section_name.c_str(), m_key_name.c_str(), new_binding.c_str());
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->reloadInputBindings();
|
||||
}
|
||||
}
|
||||
@@ -256,7 +257,8 @@ void InputBindingWidget::clearBinding()
|
||||
}
|
||||
else
|
||||
{
|
||||
QtHost::RemoveBaseSettingValue(m_section_name.c_str(), m_key_name.c_str());
|
||||
Host::RemoveBaseSettingValue(m_section_name.c_str(), m_key_name.c_str());
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->reloadInputBindings();
|
||||
}
|
||||
reloadBinding();
|
||||
@@ -413,7 +415,8 @@ void InputVibrationBindingWidget::setKey(ControllerSettingsDialog* dialog, std::
|
||||
void InputVibrationBindingWidget::clearBinding()
|
||||
{
|
||||
m_binding = {};
|
||||
QtHost::RemoveBaseSettingValue(m_section_name.c_str(), m_key_name.c_str());
|
||||
Host::RemoveBaseSettingValue(m_section_name.c_str(), m_key_name.c_str());
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->reloadInputBindings();
|
||||
setText(QString());
|
||||
}
|
||||
@@ -448,7 +451,8 @@ void InputVibrationBindingWidget::onClicked()
|
||||
|
||||
const QString new_value(input_dialog.textValue());
|
||||
m_binding = new_value.toStdString();
|
||||
QtHost::SetBaseStringSettingValue(m_section_name.c_str(), m_key_name.c_str(), m_binding.c_str());
|
||||
Host::SetBaseStringSettingValue(m_section_name.c_str(), m_key_name.c_str(), m_binding.c_str());
|
||||
Host::CommitBaseSettingChanges();
|
||||
setText(new_value);
|
||||
}
|
||||
|
||||
|
||||
@@ -146,9 +146,6 @@ void SettingsDialog::setupUi(const GameList::Entry* game)
|
||||
connect(m_ui.settingsCategory, &QListWidget::currentRowChanged, this, &SettingsDialog::onCategoryCurrentRowChanged);
|
||||
connect(m_ui.closeButton, &QPushButton::clicked, this, &SettingsDialog::accept);
|
||||
connect(m_ui.restoreDefaultsButton, &QPushButton::clicked, this, &SettingsDialog::onRestoreDefaultsClicked);
|
||||
|
||||
// TODO: Remove this once they're implemented.
|
||||
m_ui.restoreDefaultsButton->setVisible(false);
|
||||
}
|
||||
|
||||
SettingsDialog::~SettingsDialog()
|
||||
@@ -164,6 +161,11 @@ void SettingsDialog::closeEvent(QCloseEvent*)
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
QString SettingsDialog::getCategory() const
|
||||
{
|
||||
return m_ui.settingsCategory->item(m_ui.settingsCategory->currentRow())->text();
|
||||
}
|
||||
|
||||
void SettingsDialog::setCategory(const char* category)
|
||||
{
|
||||
// the titles in the category list will be translated.
|
||||
@@ -188,14 +190,20 @@ void SettingsDialog::onCategoryCurrentRowChanged(int row)
|
||||
|
||||
void SettingsDialog::onRestoreDefaultsClicked()
|
||||
{
|
||||
if (QMessageBox::question(this, tr("Confirm Restore Defaults"),
|
||||
tr("Are you sure you want to restore the default settings? Any preferences will be lost."), QMessageBox::Yes,
|
||||
QMessageBox::No) != QMessageBox::Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
QMessageBox msgbox(this);
|
||||
msgbox.setIcon(QMessageBox::Question);
|
||||
msgbox.setWindowTitle(tr("Confirm Restore Defaults"));
|
||||
msgbox.setText(tr("Are you sure you want to restore the default settings? Any preferences will be lost."));
|
||||
|
||||
// TODO
|
||||
QCheckBox* ui_cb = new QCheckBox(tr("Reset UI Settings"), &msgbox);
|
||||
msgbox.setCheckBox(ui_cb);
|
||||
msgbox.addButton(QMessageBox::Yes);
|
||||
msgbox.addButton(QMessageBox::No);
|
||||
msgbox.setDefaultButton(QMessageBox::Yes);
|
||||
if (msgbox.exec() != QMessageBox::Yes)
|
||||
return;
|
||||
|
||||
g_main_window->resetSettings(ui_cb->isChecked());
|
||||
}
|
||||
|
||||
void SettingsDialog::addWidget(QWidget* widget, QString title, QString icon, QString help_text)
|
||||
@@ -376,7 +384,8 @@ void SettingsDialog::setBoolSettingValue(const char* section, const char* key, s
|
||||
}
|
||||
else
|
||||
{
|
||||
value.has_value() ? QtHost::SetBaseBoolSettingValue(section, key, value.value()) : QtHost::RemoveBaseSettingValue(section, key);
|
||||
value.has_value() ? Host::SetBaseBoolSettingValue(section, key, value.value()) : Host::RemoveBaseSettingValue(section, key);
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->applySettings();
|
||||
}
|
||||
}
|
||||
@@ -391,7 +400,8 @@ void SettingsDialog::setIntSettingValue(const char* section, const char* key, st
|
||||
}
|
||||
else
|
||||
{
|
||||
value.has_value() ? QtHost::SetBaseIntSettingValue(section, key, value.value()) : QtHost::RemoveBaseSettingValue(section, key);
|
||||
value.has_value() ? Host::SetBaseIntSettingValue(section, key, value.value()) : Host::RemoveBaseSettingValue(section, key);
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->applySettings();
|
||||
}
|
||||
}
|
||||
@@ -406,7 +416,8 @@ void SettingsDialog::setFloatSettingValue(const char* section, const char* key,
|
||||
}
|
||||
else
|
||||
{
|
||||
value.has_value() ? QtHost::SetBaseFloatSettingValue(section, key, value.value()) : QtHost::RemoveBaseSettingValue(section, key);
|
||||
value.has_value() ? Host::SetBaseFloatSettingValue(section, key, value.value()) : Host::RemoveBaseSettingValue(section, key);
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->applySettings();
|
||||
}
|
||||
}
|
||||
@@ -421,7 +432,8 @@ void SettingsDialog::setStringSettingValue(const char* section, const char* key,
|
||||
}
|
||||
else
|
||||
{
|
||||
value.has_value() ? QtHost::SetBaseStringSettingValue(section, key, value.value()) : QtHost::RemoveBaseSettingValue(section, key);
|
||||
value.has_value() ? Host::SetBaseStringSettingValue(section, key, value.value()) : Host::RemoveBaseSettingValue(section, key);
|
||||
Host::CommitBaseSettingChanges();
|
||||
g_emu_thread->applySettings();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@ public:
|
||||
void registerWidgetHelp(QObject* object, QString title, QString recommended_value, QString text);
|
||||
bool eventFilter(QObject* object, QEvent* event) override;
|
||||
|
||||
QString getCategory() const;
|
||||
void setCategory(const char* category);
|
||||
|
||||
// Helper functions for reading effective setting values (from game -> global settings).
|
||||
|
||||
@@ -1063,8 +1063,10 @@ endif()
|
||||
|
||||
if(PCSX2_CORE)
|
||||
list(APPEND pcsx2FrontendSources
|
||||
Frontend/CommonHost.cpp
|
||||
Frontend/FullscreenUI.cpp
|
||||
Frontend/GameList.cpp
|
||||
Frontend/HostSettings.cpp
|
||||
Frontend/ImGuiFullscreen.cpp
|
||||
Frontend/INISettingsInterface.cpp
|
||||
Frontend/InputManager.cpp
|
||||
@@ -1072,10 +1074,10 @@ if(PCSX2_CORE)
|
||||
Frontend/LayeredSettingsInterface.cpp
|
||||
Frontend/LogSink.cpp
|
||||
GSDumpReplayer.cpp
|
||||
HostSettings.cpp
|
||||
VMManager.cpp
|
||||
)
|
||||
list(APPEND pcsx2FrontendHeaders
|
||||
Frontend/CommonHost.h
|
||||
Frontend/FullscreenUI.h
|
||||
Frontend/GameList.h
|
||||
Frontend/ImGuiFullscreen.h
|
||||
|
||||
+2
-3
@@ -1048,10 +1048,9 @@ namespace EmuFolders
|
||||
extern std::string InputProfiles;
|
||||
|
||||
// Assumes that AppRoot and DataRoot have been initialized.
|
||||
void SetDefaults();
|
||||
bool EnsureFoldersExist();
|
||||
void SetDefaults(SettingsInterface& si);
|
||||
void LoadConfig(SettingsInterface& si);
|
||||
void Save(SettingsInterface& si);
|
||||
bool EnsureFoldersExist();
|
||||
} // namespace EmuFolders
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
/* PCSX2 - PS2 Emulator for PCs
|
||||
* Copyright (C) 2002-2022 PCSX2 Dev Team
|
||||
*
|
||||
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU Lesser General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with PCSX2.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "common/Assertions.h"
|
||||
#include "common/CrashHandler.h"
|
||||
#include "common/FileSystem.h"
|
||||
#include "common/Path.h"
|
||||
#include "Frontend/CommonHost.h"
|
||||
#include "Frontend/LayeredSettingsInterface.h"
|
||||
#include "GS.h"
|
||||
#include "GS/Renderers/HW/GSTextureReplacements.h"
|
||||
#include "Host.h"
|
||||
#include "HostSettings.h"
|
||||
#include "MemoryCardFile.h"
|
||||
#include "PAD/Host/PAD.h"
|
||||
#include "Sio.h"
|
||||
#include "VMManager.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "common/RedtapeWindows.h"
|
||||
#include <KnownFolders.h>
|
||||
#include <ShlObj.h>
|
||||
#endif
|
||||
|
||||
static constexpr u32 SETTINGS_VERSION = 1;
|
||||
|
||||
namespace CommonHost
|
||||
{
|
||||
static void SetAppRoot();
|
||||
static void SetResourcesDirectory();
|
||||
static bool ShouldUsePortableMode();
|
||||
static void SetDataDirectory();
|
||||
static void SetCommonDefaultSettings(SettingsInterface& si);
|
||||
} // namespace CommonHost
|
||||
|
||||
bool CommonHost::InitializeCriticalFolders()
|
||||
{
|
||||
SetAppRoot();
|
||||
SetResourcesDirectory();
|
||||
SetDataDirectory();
|
||||
|
||||
// logging of directories in case something goes wrong super early
|
||||
Console.WriteLn("AppRoot Directory: %s", EmuFolders::AppRoot.c_str());
|
||||
Console.WriteLn("DataRoot Directory: %s", EmuFolders::DataRoot.c_str());
|
||||
Console.WriteLn("Resources Directory: %s", EmuFolders::Resources.c_str());
|
||||
|
||||
// allow SetDataDirectory() to change settings directory (if we want to split config later on)
|
||||
if (EmuFolders::Settings.empty())
|
||||
EmuFolders::Settings = Path::Combine(EmuFolders::DataRoot, "inis");
|
||||
|
||||
// Write crash dumps to the data directory, since that'll be accessible for certain.
|
||||
CrashHandler::SetWriteDirectory(EmuFolders::DataRoot);
|
||||
|
||||
// the resources directory should exist, bail out if not
|
||||
if (!FileSystem::DirectoryExists(EmuFolders::Resources.c_str()))
|
||||
{
|
||||
Console.Error("Resources directory is missing.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CommonHost::SetAppRoot()
|
||||
{
|
||||
std::string program_path(FileSystem::GetProgramPath());
|
||||
Console.WriteLn("Program Path: %s", program_path.c_str());
|
||||
|
||||
EmuFolders::AppRoot = Path::Canonicalize(Path::GetDirectory(program_path));
|
||||
}
|
||||
|
||||
void CommonHost::SetResourcesDirectory()
|
||||
{
|
||||
#ifndef __APPLE__
|
||||
// On Windows/Linux, these are in the binary directory.
|
||||
EmuFolders::Resources = Path::Combine(EmuFolders::AppRoot, "resources");
|
||||
#else
|
||||
// On macOS, this is in the bundle resources directory.
|
||||
EmuFolders::Resources = Path::Canonicalize(Path::Combine(EmuFolders::AppRoot, "../Resources"));
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CommonHost::ShouldUsePortableMode()
|
||||
{
|
||||
// Check whether portable.ini exists in the program directory.
|
||||
return FileSystem::FileExists(Path::Combine(EmuFolders::AppRoot, "portable.ini").c_str());
|
||||
}
|
||||
|
||||
void CommonHost::SetDataDirectory()
|
||||
{
|
||||
if (ShouldUsePortableMode())
|
||||
{
|
||||
EmuFolders::DataRoot = EmuFolders::AppRoot;
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
// On Windows, use My Documents\PCSX2 to match old installs.
|
||||
PWSTR documents_directory;
|
||||
if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Documents, 0, NULL, &documents_directory)))
|
||||
{
|
||||
if (std::wcslen(documents_directory) > 0)
|
||||
EmuFolders::DataRoot = Path::Combine(StringUtil::WideStringToUTF8String(documents_directory), "PCSX2");
|
||||
CoTaskMemFree(documents_directory);
|
||||
}
|
||||
#elif defined(__linux__)
|
||||
// Use $XDG_CONFIG_HOME/PCSX2 if it exists.
|
||||
const char* xdg_config_home = getenv("XDG_CONFIG_HOME");
|
||||
if (xdg_config_home && Path::IsAbsolute(xdg_config_home))
|
||||
{
|
||||
EmuFolders::DataRoot = Path::Combine(xdg_config_home, "PCSX2");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use ~/PCSX2 for non-XDG, and ~/.config/PCSX2 for XDG.
|
||||
// Maybe we should drop the former when Qt goes live.
|
||||
const char* home_dir = getenv("HOME");
|
||||
if (home_dir)
|
||||
{
|
||||
#ifndef XDG_STD
|
||||
EmuFolders::DataRoot = Path::Combine(home_dir, "PCSX2");
|
||||
#else
|
||||
// ~/.config should exist, but just in case it doesn't and this is a fresh profile..
|
||||
const std::string config_dir(Path::Combine(home_dir, ".config"));
|
||||
if (!FileSystem::DirectoryExists(config_dir.c_str()))
|
||||
FileSystem::CreateDirectoryPath(config_dir.c_str(), false);
|
||||
|
||||
EmuFolders::DataRoot = Path::Combine(config_dir, "PCSX2");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
static constexpr char MAC_DATA_DIR[] = "Library/Application Support/PCSX2";
|
||||
const char* home_dir = getenv("HOME");
|
||||
if (home_dir)
|
||||
EmuFolders::DataRoot = Path::Combine(home_dir, MAC_DATA_DIR);
|
||||
#endif
|
||||
|
||||
// make sure it exists
|
||||
if (!EmuFolders::DataRoot.empty() && !FileSystem::DirectoryExists(EmuFolders::DataRoot.c_str()))
|
||||
{
|
||||
// we're in trouble if we fail to create this directory... but try to hobble on with portable
|
||||
if (!FileSystem::CreateDirectoryPath(EmuFolders::DataRoot.c_str(), false))
|
||||
EmuFolders::DataRoot.clear();
|
||||
}
|
||||
|
||||
// couldn't determine the data directory? fallback to portable.
|
||||
if (EmuFolders::DataRoot.empty())
|
||||
EmuFolders::DataRoot = EmuFolders::AppRoot;
|
||||
}
|
||||
|
||||
bool CommonHost::CheckSettingsVersion()
|
||||
{
|
||||
SettingsInterface* bsi = Host::Internal::GetBaseSettingsLayer();
|
||||
|
||||
uint settings_version;
|
||||
return (bsi->GetUIntValue("UI", "SettingsVersion", &settings_version) && settings_version == SETTINGS_VERSION);
|
||||
}
|
||||
|
||||
void CommonHost::LoadStartupSettings()
|
||||
{
|
||||
SettingsInterface* bsi = Host::Internal::GetBaseSettingsLayer();
|
||||
EmuFolders::LoadConfig(*bsi);
|
||||
EmuFolders::EnsureFoldersExist();
|
||||
}
|
||||
|
||||
void CommonHost::SetDefaultSettings(SettingsInterface& si, bool folders, bool core, bool controllers, bool hotkeys, bool ui)
|
||||
{
|
||||
if (si.GetUIntValue("UI", "SettingsVersion", 0u) != SETTINGS_VERSION)
|
||||
si.SetUIntValue("UI", "SettingsVersion", SETTINGS_VERSION);
|
||||
|
||||
if (folders)
|
||||
EmuFolders::SetDefaults(si);
|
||||
if (core)
|
||||
{
|
||||
VMManager::SetDefaultSettings(si);
|
||||
SetCommonDefaultSettings(si);
|
||||
}
|
||||
if (controllers)
|
||||
PAD::SetDefaultControllerConfig(si);
|
||||
if (hotkeys)
|
||||
PAD::SetDefaultHotkeyConfig(si);
|
||||
if (ui)
|
||||
Host::SetDefaultUISettings(si);
|
||||
}
|
||||
|
||||
void CommonHost::SetCommonDefaultSettings(SettingsInterface& si)
|
||||
{
|
||||
// Nothing here yet.
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user