Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pcsx2-gsrunner/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ void Host::CommitBaseSettingChanges()
// nothing to save, we're all in memory
}

void Host::CommitSecretsSettingChanges()
{
// ditto
}

void Host::LoadSettings(SettingsInterface& si, std::unique_lock<std::mutex>& lock)
{
}
Expand Down
73 changes: 73 additions & 0 deletions pcsx2-qt/QtHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace QtHost
static bool ParseCommandLineOptions(const QStringList& args, std::shared_ptr<VMBootParameters>& autoboot);
static bool InitializeConfig();
static void SaveSettings();
static void SaveSecretsSettings();
static void HookSignals();
static void RegisterTypes();
static bool RunSetupWizard();
Expand All @@ -86,6 +87,7 @@ namespace QtHost
//////////////////////////////////////////////////////////////////////////
static QTimer* s_settings_save_timer = nullptr;
static std::unique_ptr<INISettingsInterface> s_base_settings_interface;
static std::unique_ptr<INISettingsInterface> s_secrets_settings_interface;
static bool s_batch_mode = false;
static bool s_nogui_mode = false;
static bool s_start_fullscreen_ui = false;
Expand Down Expand Up @@ -1329,6 +1331,7 @@ bool QtHost::InitializeConfig()
// Write crash dumps to the data directory, since that'll be accessible for certain.
CrashHandler::SetWriteDirectory(EmuFolders::DataRoot);

// Load main settings ini
const std::string path = Path::Combine(EmuFolders::Settings, "PCSX2.ini");
const bool settings_exists = FileSystem::FileExists(path.c_str());
Console.WriteLnFmt("Loading config from {}.", path);
Expand Down Expand Up @@ -1369,6 +1372,29 @@ bool QtHost::InitializeConfig()
SaveSettings();
}

// Layer secrets ini on top
const std::string secrets_path = Path::Combine(EmuFolders::Settings, "secrets.ini");
const bool secrets_settings_exists = FileSystem::FileExists(secrets_path.c_str());
Console.WriteLnFmt("Loading secrets from {}.", secrets_path);

s_secrets_settings_interface = std::make_unique<INISettingsInterface>(std::move(secrets_path));
Host::Internal::SetSecretsSettingsLayer(s_secrets_settings_interface.get());
if (!secrets_settings_exists || !s_secrets_settings_interface->Load())
{
if (!s_base_settings_interface->Save(&error))
{
QMessageBox::critical(
nullptr, QStringLiteral("PCSX2"),
QStringLiteral(
"Failed to save secrets to\n\n%1\n\nThe error was: %2\n\nPlease ensure this directory is writable. You "
"can also try portable mode by creating portable.txt in the same directory you installed PCSX2 into.")
.arg(QString::fromStdString(s_secrets_settings_interface->GetFileName()))
.arg(QString::fromStdString(error.GetDescription())));
return false;
}

}

// Setup wizard was incomplete last time?
s_run_setup_wizard =
s_run_setup_wizard || s_base_settings_interface->GetBoolValue("UI", "SetupWizardIncomplete", false);
Expand Down Expand Up @@ -1414,6 +1440,24 @@ void QtHost::SaveSettings()
}
}

void QtHost::SaveSecretsSettings()
{
pxAssertRel(!g_emu_thread->isOnEmuThread(), "Saving should happen on the UI thread.");

{
Error error;
auto lock = Host::GetSettingsLock();
if (!s_secrets_settings_interface->Save(&error))
Console.ErrorFmt("Failed to save settings: {}", error.GetDescription());
}

if (s_settings_save_timer)
{
s_settings_save_timer->deleteLater();
s_settings_save_timer = nullptr;
}
}

void Host::CommitBaseSettingChanges()
{
if (!QtHost::IsOnUIThread())
Expand All @@ -1422,6 +1466,35 @@ void Host::CommitBaseSettingChanges()
return;
}

auto lock = Host::GetSettingsLock();
if (s_settings_save_timer)
return;

s_settings_save_timer = new QTimer;
s_settings_save_timer->connect(s_settings_save_timer, &QTimer::timeout, &QtHost::SaveSecretsSettings);
s_settings_save_timer->setSingleShot(true);
s_settings_save_timer->start(SETTINGS_SAVE_DELAY);

static bool connected = false;
if (!connected)
{
QObject::connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, []() {
delete s_settings_save_timer;
s_settings_save_timer = nullptr;
});

connected = true;
}
}

void Host::CommitSecretsSettingChanges()
{
if (!QtHost::IsOnUIThread())
{
QtHost::RunOnUIThread(&Host::CommitSecretsSettingChanges);
return;
}

auto lock = Host::GetSettingsLock();
if (s_settings_save_timer)
return;
Expand Down
6 changes: 4 additions & 2 deletions pcsx2/Achievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "common/MD5Digest.h"
#include "common/Path.h"
#include "common/ScopedGuard.h"
#include "common/SettingsInterface.h"
#include "common/SmallString.h"
#include "common/StringUtil.h"
#include "common/Timer.h"
Expand Down Expand Up @@ -433,7 +434,7 @@ bool Achievements::Initialize()
IdentifyGame(VMManager::GetDiscCRC(), VMManager::GetCurrentCRC());

const std::string username = Host::GetBaseStringSettingValue("Achievements", "Username");
const std::string api_token = Host::GetBaseStringSettingValue("Achievements", "Token");
const std::string api_token = Host::GetStringSettingValue("Achievements", "Token");
if (!username.empty() && !api_token.empty())
{
Console.WriteLn("Achievements: Attempting login with user '%s'...", username.c_str());
Expand Down Expand Up @@ -1772,9 +1773,10 @@ void Achievements::ClientLoginWithPasswordCallback(int result, const char* error

// Store configuration.
Host::SetBaseStringSettingValue("Achievements", "Username", params->username);
Host::SetBaseStringSettingValue("Achievements", "Token", user->token);
Host::SetBaseStringSettingValue("Achievements", "LoginTimestamp", fmt::format("{}", std::time(nullptr)).c_str());
Host::Internal::GetSecretsSettingsLayer()->SetStringValue("Achievements", "Token", user->token);
Host::CommitBaseSettingChanges();
Host::CommitSecretsSettingChanges();

ShowLoginSuccess(client);
}
Expand Down
14 changes: 13 additions & 1 deletion pcsx2/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ SettingsInterface* Host::Internal::GetBaseSettingsLayer()
return s_layered_settings_interface.GetLayer(LayeredSettingsInterface::LAYER_BASE);
}

SettingsInterface* Host::Internal::GetSecretsSettingsLayer()
{
return s_layered_settings_interface.GetLayer(LayeredSettingsInterface::LAYER_SECRETS);
}

SettingsInterface* Host::Internal::GetGameSettingsLayer()
{
return s_layered_settings_interface.GetLayer(LayeredSettingsInterface::LAYER_GAME);
Expand All @@ -377,10 +382,17 @@ SettingsInterface* Host::Internal::GetInputSettingsLayer()
void Host::Internal::SetBaseSettingsLayer(SettingsInterface* sif)
{
pxAssertRel(s_layered_settings_interface.GetLayer(LayeredSettingsInterface::LAYER_BASE) == nullptr,
"Base layer has not been set");
"Base layer has already been set");
s_layered_settings_interface.SetLayer(LayeredSettingsInterface::LAYER_BASE, sif);
}

void Host::Internal::SetSecretsSettingsLayer(SettingsInterface* sif)
{
pxAssertRel(s_layered_settings_interface.GetLayer(LayeredSettingsInterface::LAYER_SECRETS) == nullptr,
"Secrets layer has already been set");
s_layered_settings_interface.SetLayer(LayeredSettingsInterface::LAYER_SECRETS, sif);
}

void Host::Internal::SetGameSettingsLayer(SettingsInterface* sif, std::unique_lock<std::mutex>& settings_lock)
{
s_layered_settings_interface.SetLayer(LayeredSettingsInterface::LAYER_GAME, sif);
Expand Down
7 changes: 7 additions & 0 deletions pcsx2/Host.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ namespace Host
bool ContainsBaseSettingValue(const char* section, const char* key);
void RemoveBaseSettingValue(const char* section, const char* key);
void CommitBaseSettingChanges();
void CommitSecretsSettingChanges();

/// Settings access, thread-safe.
std::string GetStringSettingValue(const char* section, const char* key, const char* default_value = "");
Expand Down Expand Up @@ -151,6 +152,9 @@ namespace Host
/// Retrieves the base settings layer. Must call with lock held.
SettingsInterface* GetBaseSettingsLayer();

/// Retrieves the base settings layer. Must call with lock held.
SettingsInterface* GetSecretsSettingsLayer();

/// Retrieves the game settings layer, if present. Must call with lock held.
SettingsInterface* GetGameSettingsLayer();

Expand All @@ -160,6 +164,9 @@ namespace Host
/// Sets the base settings layer. Should be called by the host at initialization time.
void SetBaseSettingsLayer(SettingsInterface* sif);

/// Sets the secrets settings layer. Should follow call to SetBaseSettingsLayer.
void SetSecretsSettingsLayer(SettingsInterface* sif);

/// Sets the game settings layer. Called by VMManager when the game changes.
void SetGameSettingsLayer(SettingsInterface* sif, std::unique_lock<std::mutex>& settings_lock);

Expand Down
1 change: 1 addition & 0 deletions pcsx2/LayeredSettingsInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class LayeredSettingsInterface final : public SettingsInterface
LAYER_GAME,
LAYER_INPUT,
LAYER_BASE,
LAYER_SECRETS,
NUM_LAYERS
};

Expand Down
4 changes: 4 additions & 0 deletions tests/ctest/core/StubHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ void Host::CommitBaseSettingChanges()
{
}

void Host::CommitSecretsSettingChanges()
{
}

void Host::LoadSettings(SettingsInterface& si, std::unique_lock<std::mutex>& lock)
{
}
Expand Down