From 784e803f98eb74392ed7faf8955df7d88c9fffa2 Mon Sep 17 00:00:00 2001 From: sum2012 Date: Sat, 30 Jan 2021 07:03:52 +0800 Subject: [PATCH] Add CRC32 calc Fix #13964 Thanks @unknownbrackets --- UI/GameScreen.cpp | 29 +++++++++++++++++++++++++++++ UI/GameScreen.h | 4 ++++ 2 files changed, 33 insertions(+) diff --git a/UI/GameScreen.cpp b/UI/GameScreen.cpp index 697a2145c9..61d72a9fd7 100644 --- a/UI/GameScreen.cpp +++ b/UI/GameScreen.cpp @@ -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 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 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; diff --git a/UI/GameScreen.h b/UI/GameScreen.h index 2e7fa3f596..ca9c0793bf 100644 --- a/UI/GameScreen.h +++ b/UI/GameScreen.h @@ -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_;