summaryrefslogtreecommitdiff
path: root/Source/Core/DolphinQt/Config/ARCodeWidget.cpp
diff options
context:
space:
mode:
authorConnor McLaughlin <stenzek@gmail.com>2019-08-09 23:42:55 +1000
committerGitHub <noreply@github.com>2019-08-09 23:42:55 +1000
commit8be5ee9fe2d5552856249cea1406cfc14b352fac (patch)
treed66aefd7f58d9e623cf64bb10b0dff3ff5a10d4c /Source/Core/DolphinQt/Config/ARCodeWidget.cpp
parent48ca2c6f2e70111cf72052d5d258328c2fdb9afd (diff)
parentff8f627499ca3eb8ac5f07cf5ced97f0d8b57ed1 (diff)
Merge pull request #8277 from lioncash/code
DolphinQt/Config/ARCodeWidget: Avoid unnecessary disk operations
Diffstat (limited to 'Source/Core/DolphinQt/Config/ARCodeWidget.cpp')
-rw-r--r--Source/Core/DolphinQt/Config/ARCodeWidget.cpp53
1 files changed, 30 insertions, 23 deletions
diff --git a/Source/Core/DolphinQt/Config/ARCodeWidget.cpp b/Source/Core/DolphinQt/Config/ARCodeWidget.cpp
index b03ebce983..eca7ccf705 100644
--- a/Source/Core/DolphinQt/Config/ARCodeWidget.cpp
+++ b/Source/Core/DolphinQt/Config/ARCodeWidget.cpp
@@ -36,13 +36,15 @@ ARCodeWidget::ARCodeWidget(const UICommon::GameFile& game, bool restart_required
// will always be stored in GS/${GAMEID}.ini
game_ini_local.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini");
- IniFile game_ini_default = SConfig::GetInstance().LoadDefaultGameIni(m_game_id, m_game_revision);
+ const IniFile game_ini_default = SConfig::LoadDefaultGameIni(m_game_id, m_game_revision);
m_ar_codes = ActionReplay::LoadCodes(game_ini_default, game_ini_local);
UpdateList();
OnSelectionChanged();
}
+ARCodeWidget::~ARCodeWidget() = default;
+
void ARCodeWidget::CreateWidgets()
{
m_warning = new CheatWarningWidget(m_game_id, m_restart_required, this);
@@ -168,11 +170,13 @@ void ARCodeWidget::UpdateList()
void ARCodeWidget::SaveCodes()
{
+ const auto ini_path =
+ std::string(File::GetUserPath(D_GAMESETTINGS_IDX)).append(m_game_id).append(".ini");
+
IniFile game_ini_local;
- game_ini_local.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini");
+ game_ini_local.Load(ini_path);
ActionReplay::SaveCodes(&game_ini_local, m_ar_codes);
-
- game_ini_local.Save(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini");
+ game_ini_local.Save(ini_path);
}
void ARCodeWidget::AddCode(ActionReplay::ARCode code)
@@ -189,40 +193,43 @@ void ARCodeWidget::OnCodeAddClicked()
ar.active = true;
CheatCodeEditor ed(this);
-
ed.SetARCode(&ar);
+ if (ed.exec() == QDialog::Rejected)
+ return;
- if (ed.exec())
- {
- m_ar_codes.push_back(std::move(ar));
+ m_ar_codes.push_back(std::move(ar));
- UpdateList();
- SaveCodes();
- }
+ UpdateList();
+ SaveCodes();
}
void ARCodeWidget::OnCodeEditClicked()
{
- auto items = m_code_list->selectedItems();
-
+ const auto items = m_code_list->selectedItems();
if (items.empty())
return;
- const auto* selected = items[0];
-
+ const auto* const selected = items[0];
auto& current_ar = m_ar_codes[m_code_list->row(selected)];
- bool user_defined = current_ar.user_defined;
-
- ActionReplay::ARCode ar = current_ar;
-
CheatCodeEditor ed(this);
+ if (current_ar.user_defined)
+ {
+ ed.SetARCode(&current_ar);
- ed.SetARCode(user_defined ? &current_ar : &ar);
- ed.exec();
+ if (ed.exec() == QDialog::Rejected)
+ return;
+ }
+ else
+ {
+ ActionReplay::ARCode ar = current_ar;
+ ed.SetARCode(&ar);
+
+ if (ed.exec() == QDialog::Rejected)
+ return;
- if (!user_defined)
- m_ar_codes.push_back(ar);
+ m_ar_codes.push_back(std::move(ar));
+ }
SaveCodes();
UpdateList();