Add CRC32 calc

Fix #13964
Thanks @unknownbrackets
This commit is contained in:
sum2012 2021-01-30 07:03:52 +08:00
parent 54849075aa
commit 784e803f98
2 changed files with 33 additions and 0 deletions

View file

@ -40,6 +40,7 @@
#include "UI/MiscScreens.h"
#include "UI/MainScreen.h"
#include "UI/BackgroundAudio.h"
#include "Core/Reporting.h"
GameScreen::GameScreen(const std::string &gamePath) : UIDialogScreenWithGameBackground(gamePath) {
g_BackgroundAudio.SetGame(gamePath);
@ -48,6 +49,27 @@ GameScreen::GameScreen(const std::string &gamePath) : UIDialogScreenWithGameBack
GameScreen::~GameScreen() {
}
template <typename I> std::string int2hexstr(I w, size_t hex_len = sizeof(I) << 1) {
static const char* digits = "0123456789ABCDEF";
std::string rc(hex_len, '0');
for (size_t i = 0, j = (hex_len - 1) * 4; i < hex_len; ++i, j -= 4)
rc[i] = digits[(w >> j) & 0x0f];
return rc;
}
void GameScreen::update() {
UIScreen::update();
// Has the user requested a CRC32?
if (CRC32string == "...") {
// Wait until the CRC32 is ready. It might take time on some devices.
if (Reporting::HasCRC(gamePath_)) {
uint32_t crcvalue = Reporting::RetrieveCRC(gamePath_);
CRC32string = int2hexstr(crcvalue);
}
}
}
void GameScreen::CreateViews() {
std::shared_ptr<GameInfo> info = g_gameInfoCache->GetInfo(NULL, gamePath_, GAMEINFO_WANTBG | GAMEINFO_WANTSIZE);
@ -143,6 +165,7 @@ void GameScreen::CreateViews() {
btnSetBackground_ = rightColumnItems->Add(new Choice(ga->T("Use UI background")));
btnSetBackground_->OnClick.Handle(this, &GameScreen::OnSetBackground);
btnSetBackground_->SetVisibility(V_GONE);
rightColumnItems->Add(new ChoiceWithValueDisplay(&CRC32string, ga->T("CRC32 CALC"), (const char*)nullptr))->OnClick.Handle(this, &GameScreen::OnDoCRC32);
}
UI::Choice *GameScreen::AddOtherChoice(UI::Choice *choice) {
@ -265,6 +288,12 @@ UI::EventReturn GameScreen::OnCwCheat(UI::EventParams &e) {
return UI::EVENT_DONE;
}
UI::EventReturn GameScreen::OnDoCRC32(UI::EventParams& e) {
CRC32string = "...";
return UI::EVENT_DONE;
}
UI::EventReturn GameScreen::OnSwitchBack(UI::EventParams &e) {
TriggerFinish(DR_OK);
return UI::EVENT_DONE;

View file

@ -33,6 +33,8 @@ public:
GameScreen(const std::string &gamePath);
~GameScreen();
void update() override;
void render() override;
std::string tag() const override { return "game"; }
@ -43,6 +45,7 @@ protected:
void CallbackDeleteSaveData(bool yes);
void CallbackDeleteGame(bool yes);
bool isRecentGame(const std::string &gamePath);
std::string CRC32string = "";
private:
UI::Choice *AddOtherChoice(UI::Choice *choice);
@ -60,6 +63,7 @@ private:
UI::EventReturn OnDeleteConfig(UI::EventParams &e);
UI::EventReturn OnCwCheat(UI::EventParams &e);
UI::EventReturn OnSetBackground(UI::EventParams &e);
UI::EventReturn OnDoCRC32(UI::EventParams& e);
// As we load metadata in the background, we need to be able to update these after the fact.
UI::TextView *tvTitle_;