Qt: Fix empty gamesettings ini being saved on close

This commit is contained in:
Stenzek
2026-07-06 12:31:59 +10:00
parent fa19df308c
commit 2b1de6278d
5 changed files with 17 additions and 1 deletions
+5 -1
View File
@@ -2114,10 +2114,12 @@ void FullscreenUI::DrawSettingsWindow()
if (s_settings_locals.game_settings_interface)
{
Error error;
s_settings_locals.game_settings_interface->RemoveEmptySections();
if (s_settings_locals.game_settings_interface->IsEmpty())
{
// prevent empty ini from being saved if it was modified and transitioned back to empty
s_settings_locals.game_settings_interface->SetDirty(false);
if (FileSystem::FileExists(s_settings_locals.game_settings_interface->GetPath().c_str()))
{
INFO_LOG("Removing empty game settings {}", s_settings_locals.game_settings_interface->GetPath());
@@ -2131,6 +2133,8 @@ void FullscreenUI::DrawSettingsWindow()
}
else
{
s_settings_locals.game_settings_interface->RemoveEmptySections();
if (!s_settings_locals.game_settings_interface->Save(&error))
{
OpenInfoMessageDialog(
+3
View File
@@ -683,6 +683,9 @@ bool QtHost::SaveGameSettings(SettingsInterface* sif, bool delete_if_empty)
{
INFO_LOG("Removing empty gamesettings ini {}", Path::GetFileName(ini->GetPath()));
// prevent empty ini from being saved if it was modified and transitioned back to empty
ini->SetDirty(false);
// grab the settings lock while we're writing the file, that way the CPU thread doesn't try
// to read it at the same time.
const auto lock = Core::GetSettingsLock();
+3
View File
@@ -77,6 +77,9 @@ SettingsWindow::SettingsWindow(const GameList::Entry* entry, std::unique_ptr<INI
SettingsWindow::~SettingsWindow()
{
if (m_sif && m_sif->IsDirty()) [[unlikely]]
WARNING_LOG("File {} was dirty when SettingsWindow was closed", Path::GetFileName(m_sif->GetPath()));
if (isPerGameSettings())
s_open_game_properties_dialogs.removeOne(this);
}
+5
View File
@@ -31,6 +31,11 @@ INISettingsInterface::~INISettingsInterface()
Save();
}
void INISettingsInterface::SetDirty(bool dirty)
{
m_dirty = dirty;
}
void INISettingsInterface::SetPath(std::string path)
{
m_dirty |= (path != m_path);
+1
View File
@@ -41,6 +41,7 @@ public:
ALWAYS_INLINE bool IsDirty() const { return m_dirty; }
ALWAYS_INLINE const std::string& GetPath() const { return m_path; }
void SetDirty(bool dirty);
void SetPath(std::string path);
bool Load(Error* error = nullptr);