mirror of
https://github.com/stenzek/duckstation.git
synced 2026-07-11 01:24:11 +02:00
Qt: Fix empty gamesettings ini being saved on close
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user