UI: Monitor cheat file changes on cheat editor.

This way if they switch apps or whatever, it'll update when they come
back.  This also means constant disk access, but it should be cached
anyway.
This commit is contained in:
Unknown W. Brackets committed 2020-04-11 12:57:35 -07:00
1 parent 29808ae53b
commit 698dfa74b4
2 files changed
+36 -3

No files matched your search

+32 -3
View File
@@ -15,9 +15,10 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "ext/cityhash/city.h"
#include "i18n/i18n.h"
#include "ui/ui.h"
#include "util/text/utf8.h"
#include "i18n/i18n.h"
#include "Common/FileUtil.h"
#include "Core/Core.h"
@@ -28,6 +29,8 @@
#include "UI/GameInfoCache.h"
#include "UI/CwCheatScreen.h"
static const int FILE_CHECK_FRAME_INTERVAL = 53;
CwCheatScreen::CwCheatScreen(std::string gamePath)
: UIDialogScreenWithBackground() {
gamePath_ = gamePath;
@@ -43,10 +46,20 @@ void CwCheatScreen::LoadCheatInfo() {
gameTitle = g_paramSFO.GenerateFakeID(gamePath_);
}
// We won't parse this, just using it to detect changes to the file.
std::string str;
if (readFileToString(true, activeCheatFile.c_str(), str)) {
fileCheckHash_ = CityHash64(str.c_str(), str.size());
}
fileCheckCounter_ = 0;
CWCheatEngine *cheatEngine2 = new CWCheatEngine();
cheatEngine2->CreateCheatFile();
fileInfo_ = cheatEngine2->FileInfo();
delete cheatEngine2;
// Let's also trigger a reload, in case it changed.
g_Config.bReloadCheats = true;
}
void CwCheatScreen::CreateViews() {
@@ -79,7 +92,7 @@ void CwCheatScreen::CreateViews() {
rightColumn->Add(new ItemHeader(cw->T("Cheats")));
for (size_t i = 0; i < fileInfo_.size(); ++i) {
rightColumn->Add(new CheatCheckBox(&fileInfo_[i].enabled, fileInfo_[i].name))->OnClick.Add([=](UI::EventParams &) {
return OnCheckBox(i);
return OnCheckBox((int)i);
});
}
@@ -91,6 +104,23 @@ void CwCheatScreen::CreateViews() {
AddStandardBack(root_);
}
void CwCheatScreen::update() {
if (fileCheckCounter_++ >= FILE_CHECK_FRAME_INTERVAL) {
// Check if the file has changed. If it has, we'll reload.
std::string str;
if (readFileToString(true, activeCheatFile.c_str(), str)) {
uint64_t newHash = CityHash64(str.c_str(), str.size());
if (newHash != fileCheckHash_) {
// This will update the hash.
RecreateViews();
}
}
fileCheckCounter_ = 0;
}
UIDialogScreenWithBackground::update();
}
void CwCheatScreen::onFinish(DialogResult result) {
if (result != DR_BACK) // This only works for BACK here.
return;
@@ -130,7 +160,6 @@ UI::EventReturn CwCheatScreen::OnEditCheatFile(UI::EventParams &params) {
if (MIPSComp::jit) {
MIPSComp::jit->ClearCache();
}
TriggerFinish(DR_OK);
#if PPSSPP_PLATFORM(UWP)
LaunchBrowser(activeCheatFile.c_str());
#else
+4
View File
@@ -15,6 +15,7 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <cstdint>
#include <functional>
#include "ui/view.h"
@@ -38,6 +39,7 @@ public:
UI::EventReturn OnEditCheatFile(UI::EventParams &params);
UI::EventReturn OnEnableAll(UI::EventParams &params);
void update() override;
void onFinish(DialogResult result) override;
protected:
@@ -52,6 +54,8 @@ private:
UI::ScrollView *rightScroll_ = nullptr;
std::vector<CheatFileInfo> fileInfo_;
std::string gamePath_;
int fileCheckCounter_ = 0;
uint64_t fileCheckHash_;
bool enableAllFlag_ = false;
};