Merge pull request #8277 from lioncash/code
DolphinQt/Config/ARCodeWidget: Avoid unnecessary disk operations
This commit is contained in:
commit
8be5ee9fe2
|
@ -21,6 +21,7 @@
|
||||||
#include <QTableWidget>
|
#include <QTableWidget>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
|
#include "Core/ActionReplay.h"
|
||||||
#include "Core/ConfigManager.h"
|
#include "Core/ConfigManager.h"
|
||||||
#include "Core/Core.h"
|
#include "Core/Core.h"
|
||||||
#include "Core/Debugger/PPCDebugInterface.h"
|
#include "Core/Debugger/PPCDebugInterface.h"
|
||||||
|
|
|
@ -36,13 +36,15 @@ ARCodeWidget::ARCodeWidget(const UICommon::GameFile& game, bool restart_required
|
||||||
// will always be stored in GS/${GAMEID}.ini
|
// will always be stored in GS/${GAMEID}.ini
|
||||||
game_ini_local.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".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);
|
m_ar_codes = ActionReplay::LoadCodes(game_ini_default, game_ini_local);
|
||||||
|
|
||||||
UpdateList();
|
UpdateList();
|
||||||
OnSelectionChanged();
|
OnSelectionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ARCodeWidget::~ARCodeWidget() = default;
|
||||||
|
|
||||||
void ARCodeWidget::CreateWidgets()
|
void ARCodeWidget::CreateWidgets()
|
||||||
{
|
{
|
||||||
m_warning = new CheatWarningWidget(m_game_id, m_restart_required, this);
|
m_warning = new CheatWarningWidget(m_game_id, m_restart_required, this);
|
||||||
|
@ -168,11 +170,13 @@ void ARCodeWidget::UpdateList()
|
||||||
|
|
||||||
void ARCodeWidget::SaveCodes()
|
void ARCodeWidget::SaveCodes()
|
||||||
{
|
{
|
||||||
IniFile game_ini_local;
|
const auto ini_path =
|
||||||
game_ini_local.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini");
|
std::string(File::GetUserPath(D_GAMESETTINGS_IDX)).append(m_game_id).append(".ini");
|
||||||
ActionReplay::SaveCodes(&game_ini_local, m_ar_codes);
|
|
||||||
|
|
||||||
game_ini_local.Save(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini");
|
IniFile game_ini_local;
|
||||||
|
game_ini_local.Load(ini_path);
|
||||||
|
ActionReplay::SaveCodes(&game_ini_local, m_ar_codes);
|
||||||
|
game_ini_local.Save(ini_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARCodeWidget::AddCode(ActionReplay::ARCode code)
|
void ARCodeWidget::AddCode(ActionReplay::ARCode code)
|
||||||
|
@ -189,40 +193,43 @@ void ARCodeWidget::OnCodeAddClicked()
|
||||||
ar.active = true;
|
ar.active = true;
|
||||||
|
|
||||||
CheatCodeEditor ed(this);
|
CheatCodeEditor ed(this);
|
||||||
|
|
||||||
ed.SetARCode(&ar);
|
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();
|
UpdateList();
|
||||||
SaveCodes();
|
SaveCodes();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARCodeWidget::OnCodeEditClicked()
|
void ARCodeWidget::OnCodeEditClicked()
|
||||||
{
|
{
|
||||||
auto items = m_code_list->selectedItems();
|
const auto items = m_code_list->selectedItems();
|
||||||
|
|
||||||
if (items.empty())
|
if (items.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto* selected = items[0];
|
const auto* const selected = items[0];
|
||||||
|
|
||||||
auto& current_ar = m_ar_codes[m_code_list->row(selected)];
|
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);
|
CheatCodeEditor ed(this);
|
||||||
|
if (current_ar.user_defined)
|
||||||
|
{
|
||||||
|
ed.SetARCode(¤t_ar);
|
||||||
|
|
||||||
ed.SetARCode(user_defined ? ¤t_ar : &ar);
|
if (ed.exec() == QDialog::Rejected)
|
||||||
ed.exec();
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ActionReplay::ARCode ar = current_ar;
|
||||||
|
ed.SetARCode(&ar);
|
||||||
|
|
||||||
if (!user_defined)
|
if (ed.exec() == QDialog::Rejected)
|
||||||
m_ar_codes.push_back(ar);
|
return;
|
||||||
|
|
||||||
|
m_ar_codes.push_back(std::move(ar));
|
||||||
|
}
|
||||||
|
|
||||||
SaveCodes();
|
SaveCodes();
|
||||||
UpdateList();
|
UpdateList();
|
||||||
|
|
|
@ -10,7 +10,11 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Core/ActionReplay.h"
|
|
||||||
|
namespace ActionReplay
|
||||||
|
{
|
||||||
|
struct ARCode;
|
||||||
|
}
|
||||||
|
|
||||||
namespace UICommon
|
namespace UICommon
|
||||||
{
|
{
|
||||||
|
@ -28,6 +32,7 @@ class ARCodeWidget : public QWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ARCodeWidget(const UICommon::GameFile& game, bool restart_required = true);
|
explicit ARCodeWidget(const UICommon::GameFile& game, bool restart_required = true);
|
||||||
|
~ARCodeWidget() override;
|
||||||
|
|
||||||
void AddCode(ActionReplay::ARCode code);
|
void AddCode(ActionReplay::ARCode code);
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "Common/IniFile.h"
|
#include "Common/IniFile.h"
|
||||||
|
|
||||||
#include "Core/ConfigManager.h"
|
#include "Core/ConfigManager.h"
|
||||||
|
#include "Core/GeckoCode.h"
|
||||||
#include "Core/GeckoCodeConfig.h"
|
#include "Core/GeckoCodeConfig.h"
|
||||||
|
|
||||||
#include "DolphinQt/Config/CheatCodeEditor.h"
|
#include "DolphinQt/Config/CheatCodeEditor.h"
|
||||||
|
@ -40,12 +41,14 @@ GeckoCodeWidget::GeckoCodeWidget(const UICommon::GameFile& game, bool restart_re
|
||||||
// will always be stored in GS/${GAMEID}.ini
|
// will always be stored in GS/${GAMEID}.ini
|
||||||
game_ini_local.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".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_gecko_codes = Gecko::LoadCodes(game_ini_default, game_ini_local);
|
m_gecko_codes = Gecko::LoadCodes(game_ini_default, game_ini_local);
|
||||||
|
|
||||||
UpdateList();
|
UpdateList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GeckoCodeWidget::~GeckoCodeWidget() = default;
|
||||||
|
|
||||||
void GeckoCodeWidget::CreateWidgets()
|
void GeckoCodeWidget::CreateWidgets()
|
||||||
{
|
{
|
||||||
m_warning = new CheatWarningWidget(m_game_id, m_restart_required, this);
|
m_warning = new CheatWarningWidget(m_game_id, m_restart_required, this);
|
||||||
|
@ -185,33 +188,29 @@ void GeckoCodeWidget::AddCode()
|
||||||
|
|
||||||
CheatCodeEditor ed(this);
|
CheatCodeEditor ed(this);
|
||||||
ed.SetGeckoCode(&code);
|
ed.SetGeckoCode(&code);
|
||||||
|
if (ed.exec() == QDialog::Rejected)
|
||||||
|
return;
|
||||||
|
|
||||||
if (ed.exec())
|
m_gecko_codes.push_back(std::move(code));
|
||||||
{
|
SaveCodes();
|
||||||
m_gecko_codes.push_back(std::move(code));
|
UpdateList();
|
||||||
SaveCodes();
|
|
||||||
UpdateList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeckoCodeWidget::EditCode()
|
void GeckoCodeWidget::EditCode()
|
||||||
{
|
{
|
||||||
const auto* item = m_code_list->currentItem();
|
const auto* item = m_code_list->currentItem();
|
||||||
|
|
||||||
if (item == nullptr)
|
if (item == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const int index = item->data(Qt::UserRole).toInt();
|
const int index = item->data(Qt::UserRole).toInt();
|
||||||
|
|
||||||
CheatCodeEditor ed(this);
|
CheatCodeEditor ed(this);
|
||||||
|
|
||||||
ed.SetGeckoCode(&m_gecko_codes[index]);
|
ed.SetGeckoCode(&m_gecko_codes[index]);
|
||||||
|
if (ed.exec() == QDialog::Rejected)
|
||||||
|
return;
|
||||||
|
|
||||||
if (ed.exec())
|
SaveCodes();
|
||||||
{
|
UpdateList();
|
||||||
SaveCodes();
|
|
||||||
UpdateList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeckoCodeWidget::RemoveCode()
|
void GeckoCodeWidget::RemoveCode()
|
||||||
|
@ -229,12 +228,13 @@ void GeckoCodeWidget::RemoveCode()
|
||||||
|
|
||||||
void GeckoCodeWidget::SaveCodes()
|
void GeckoCodeWidget::SaveCodes()
|
||||||
{
|
{
|
||||||
|
const auto ini_path =
|
||||||
|
std::string(File::GetUserPath(D_GAMESETTINGS_IDX)).append(m_game_id).append(".ini");
|
||||||
|
|
||||||
IniFile game_ini_local;
|
IniFile game_ini_local;
|
||||||
game_ini_local.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini");
|
game_ini_local.Load(ini_path);
|
||||||
|
|
||||||
Gecko::SaveCodes(game_ini_local, m_gecko_codes);
|
Gecko::SaveCodes(game_ini_local, m_gecko_codes);
|
||||||
|
game_ini_local.Save(ini_path);
|
||||||
game_ini_local.Save(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeckoCodeWidget::OnContextMenuRequested()
|
void GeckoCodeWidget::OnContextMenuRequested()
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Core/GeckoCode.h"
|
|
||||||
|
|
||||||
class CheatWarningWidget;
|
class CheatWarningWidget;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
|
@ -19,6 +18,11 @@ class QListWidgetItem;
|
||||||
class QTextEdit;
|
class QTextEdit;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
|
|
||||||
|
namespace Gecko
|
||||||
|
{
|
||||||
|
class GeckoCode;
|
||||||
|
}
|
||||||
|
|
||||||
namespace UICommon
|
namespace UICommon
|
||||||
{
|
{
|
||||||
class GameFile;
|
class GameFile;
|
||||||
|
@ -29,6 +33,7 @@ class GeckoCodeWidget : public QWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit GeckoCodeWidget(const UICommon::GameFile& game, bool restart_required = true);
|
explicit GeckoCodeWidget(const UICommon::GameFile& game, bool restart_required = true);
|
||||||
|
~GeckoCodeWidget() override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void OpenGeneralSettings();
|
void OpenGeneralSettings();
|
||||||
|
|
Loading…
Reference in New Issue