Add Copy button for calculated CRCs on game info screen

This commit is contained in:
Henrik Rydgård 2024-09-02 22:48:47 +02:00
parent ff195a92b0
commit d6b4a76e98
7 changed files with 34 additions and 3 deletions

View File

@ -146,6 +146,7 @@ enum SystemProperty {
SYSPROP_HAS_ACCELEROMETER, // Used to enable/disable tilt input settings
SYSPROP_HAS_OPEN_DIRECTORY,
SYSPROP_HAS_LOGIN_DIALOG,
SYSPROP_HAS_TEXT_CLIPBOARD,
SYSPROP_HAS_TEXT_INPUT_DIALOG, // Indicates that System_InputBoxGetString is available.
SYSPROP_CAN_CREATE_SHORTCUT,

View File

@ -247,6 +247,8 @@ float System_GetPropertyFloat(SystemProperty prop) {
bool System_GetPropertyBool(SystemProperty prop) {
switch (prop) {
case SYSPROP_HAS_TEXT_CLIPBOARD:
return true;
case SYSPROP_HAS_BACK_BUTTON:
return true;
case SYSPROP_HAS_IMAGE_BROWSER:

View File

@ -543,6 +543,7 @@ float System_GetPropertyFloat(SystemProperty prop) {
bool System_GetPropertyBool(SystemProperty prop) {
switch (prop) {
case SYSPROP_HAS_TEXT_CLIPBOARD:
case SYSPROP_CAN_SHOW_FILE:
#if PPSSPP_PLATFORM(WINDOWS) || PPSSPP_PLATFORM(MAC) || (PPSSPP_PLATFORM(LINUX) && !PPSSPP_PLATFORM(ANDROID))
return true;

View File

@ -81,6 +81,9 @@ void GameScreen::update() {
CRC32string = int2hexstr(crcvalue);
tvCRC_->SetVisibility(UI::V_VISIBLE);
tvCRC_->SetText(CRC32string);
if (tvCRCCopy_) {
tvCRCCopy_->SetVisibility(UI::V_VISIBLE);
}
if (btnCalcCRC_) {
btnCalcCRC_->SetVisibility(UI::V_GONE);
}
@ -145,9 +148,27 @@ void GameScreen::CreateViews() {
tvPlayTime_ = infoLayout->Add(new TextView("", ALIGN_LEFT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
tvPlayTime_->SetShadow(true);
tvPlayTime_->SetVisibility(V_GONE);
tvCRC_ = infoLayout->Add(new TextView("", ALIGN_LEFT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
LinearLayout *crcHoriz = infoLayout->Add(new LinearLayout(ORIENT_HORIZONTAL));
tvCRC_ = crcHoriz->Add(new TextView("", ALIGN_LEFT, true, new LinearLayoutParams(0.0, G_VCENTER)));
tvCRC_->SetShadow(true);
tvCRC_->SetVisibility(Reporting::HasCRC(gamePath_) ? V_VISIBLE : V_GONE);
Visibility crcVisibility = Reporting::HasCRC(gamePath_) ? V_VISIBLE : V_GONE;
tvCRC_->SetVisibility(crcVisibility);
if (System_GetPropertyBool(SYSPROP_HAS_TEXT_CLIPBOARD)) {
tvCRCCopy_ = crcHoriz->Add(new Button(di->T("Copy to clipboard"), new LinearLayoutParams(0.0, G_VCENTER)));
tvCRCCopy_->OnClick.Add([this](UI::EventParams &) {
u32 crc = Reporting::RetrieveCRC(gamePath_);
char buffer[16];
snprintf(buffer, sizeof(buffer), "%08X", crc);
System_CopyStringToClipboard(buffer);
return UI::EVENT_DONE;
});
tvCRCCopy_->SetVisibility(crcVisibility);
tvCRCCopy_->SetScale(0.82f);
} else {
tvCRCCopy_ = nullptr;
}
tvVerified_ = infoLayout->Add(new NoticeView(NoticeLevel::INFO, ga->T("Click \"Calculate CRC\" to verify ISO"), "", new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
tvVerified_->SetVisibility(UI::V_GONE);
tvVerified_->SetSquishy(true);
@ -170,6 +191,7 @@ void GameScreen::CreateViews() {
tvRegion_ = nullptr;
tvPlayTime_ = nullptr;
tvCRC_ = nullptr;
tvCRCCopy_ = nullptr;
tvVerified_ = nullptr;
}
@ -360,6 +382,9 @@ ScreenRenderFlags GameScreen::render(ScreenRenderMode mode) {
std::string crc = StringFromFormat("%08X", crcVal);
tvCRC_->SetText(ReplaceAll(rp->T("FeedbackCRCValue", "Disc CRC: %1"), "%1", crc));
tvCRC_->SetVisibility(UI::V_VISIBLE);
if (tvCRCCopy_) {
tvCRCCopy_->SetVisibility(UI::V_VISIBLE);
}
// Let's check the CRC in the game database, looking up the ID and also matching the crc.
std::vector<GameDBInfo> dbInfos;

View File

@ -75,6 +75,7 @@ private:
UI::TextView *tvPlayTime_ = nullptr;
UI::TextView *tvCRC_ = nullptr;
UI::TextView *tvID_ = nullptr;
UI::Button *tvCRCCopy_ = nullptr;
NoticeView *tvVerified_ = nullptr;
UI::Choice *btnGameSettings_ = nullptr;

View File

@ -408,6 +408,7 @@ void System_Toast(std::string_view str) {}
bool System_GetPropertyBool(SystemProperty prop) {
switch (prop) {
case SYSPROP_HAS_TEXT_CLIPBOARD:
case SYSPROP_HAS_OPEN_DIRECTORY:
{
return !IsXBox();

View File

@ -355,6 +355,7 @@ float System_GetPropertyFloat(SystemProperty prop) {
bool System_GetPropertyBool(SystemProperty prop) {
switch (prop) {
case SYSPROP_HAS_TEXT_CLIPBOARD:
case SYSPROP_HAS_DEBUGGER:
case SYSPROP_HAS_FILE_BROWSER:
case SYSPROP_HAS_FOLDER_BROWSER:
@ -910,7 +911,6 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin
std::string controlsConfigFilename = "";
const std::wstring controlsOption = L"--controlconfig=";
for (size_t i = 1; i < wideArgs.size(); ++i) {
if (wideArgs[i][0] == L'\0')
continue;