Skip to content

Commit

Permalink
Fix browsing for Cheat DB files. Easy now after the refactor!
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Mar 23, 2023
1 parent ac66dee commit e218673
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
1 change: 1 addition & 0 deletions Common/System/Request.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ enum class BrowseFileType {
BOOTABLE,
IMAGE,
INI,
DB,
ANY,
};

Expand Down
3 changes: 3 additions & 0 deletions Qt/QtMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ bool MainUI::HandleCustomEvent(QEvent *e) {
case BrowseFileType::INI:
filter = "INI files (*.ini)";
break;
case BrowseFileType::DB:
filter = "DB files (*.db)";
break;
case BrowseFileType::ANY:
break;
}
Expand Down
28 changes: 12 additions & 16 deletions UI/CwCheatScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "Common/File/FileUtil.h"
#include "Common/StringUtils.h"
#include "Common/System/System.h"
#include "Common/System/Request.h"
#include "Core/Core.h"
#include "Core/Config.h"
#include "Core/CwCheat.h"
Expand Down Expand Up @@ -152,21 +153,6 @@ void CwCheatScreen::onFinish(DialogResult result) {
}
}

void CwCheatScreen::sendMessage(const char *message, const char *value) {
// Always call the base class method first to handle the most common messages.
UIDialogScreenWithGameBackground::sendMessage(message, value);
if (!strcmp(message, "browse_fileSelect")) {
Path path(value);
INFO_LOG(SYSTEM, "Attempting to load cheats from: '%s'", path.ToVisualString().c_str());
if (ImportCheats(path)) {
g_Config.bReloadCheats = true;
} else {
// Show an error message?
}
RecreateViews();
}
}

UI::EventReturn CwCheatScreen::OnEnableAll(UI::EventParams &params) {
enableAllFlag_ = !enableAllFlag_;

Expand Down Expand Up @@ -220,7 +206,17 @@ static char *GetLineNoNewline(char *temp, int sz, FILE *fp) {
}

UI::EventReturn CwCheatScreen::OnImportBrowse(UI::EventParams &params) {
System_SendMessage("browse_file", "");
System_BrowseForFile("Open cheat DB file", BrowseFileType::DB, [&](const std::string &value, int) {
Path path(value);
INFO_LOG(SYSTEM, "Attempting to load cheats from: '%s'", path.ToVisualString().c_str());
if (ImportCheats(path)) {
g_Config.bReloadCheats = true;
} else {
// Show an error message?
}
RecreateViews();
// Chose a cheat file.
});
return UI::EVENT_DONE;
}

Expand Down
2 changes: 0 additions & 2 deletions UI/CwCheatScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class CwCheatScreen : public UIDialogScreenWithGameBackground {
UI::EventReturn OnEditCheatFile(UI::EventParams &params);
UI::EventReturn OnEnableAll(UI::EventParams &params);

void sendMessage(const char *message, const char *value) override;

void update() override;
void onFinish(DialogResult result) override;

Expand Down
3 changes: 3 additions & 0 deletions UWP/PPSSPP_UWPMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
case BrowseFileType::INI:
picker->FileTypeFilter->Append(".ini");
break;
case BrowseFileType::DB:
picker->FileTypeFilter->Append(".db");
break;
case BrowseFileType::ANY:
picker->FileTypeFilter->Append("*");
break;
Expand Down
3 changes: 3 additions & 0 deletions Windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,9 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
case BrowseFileType::INI:
filter = MakeFilter(L"Ini files (*.ini)|*.ini|All files (*.*)|*.*||");
break;
case BrowseFileType::DB:
filter = MakeFilter(L"Cheat db files (*.db)|*.db|All files (*.*)|*.*||");
break;
case BrowseFileType::ANY:
filter = MakeFilter(L"All files (*.*)|*.*||");
break;
Expand Down

0 comments on commit e218673

Please sign in to comment.