diff --git a/Core/FileSystems/BlockDevices.cpp b/Core/FileSystems/BlockDevices.cpp index eaeb4c6261..b5a1ca0a8a 100644 --- a/Core/FileSystems/BlockDevices.cpp +++ b/Core/FileSystems/BlockDevices.cpp @@ -65,23 +65,6 @@ BlockDevice *constructBlockDevice(FileLoader *fileLoader) { return new FileBlockDevice(fileLoader); } -u32 BlockDevice::CalculateCRC(volatile bool *cancel) { - u32 crc = crc32(0, Z_NULL, 0); - - u8 block[2048]; - for (u32 i = 0; i < GetNumBlocks(); ++i) { - if (cancel && *cancel) - return 0; - if (!ReadBlock(i, block, true)) { - ERROR_LOG(FILESYS, "Failed to read block for CRC"); - return 0; - } - crc = crc32(crc, block, 2048); - } - - return crc; -} - void BlockDevice::NotifyReadError() { auto err = GetI18NCategory(I18NCat::ERRORS); if (!reportedError_) { diff --git a/Core/FileSystems/BlockDevices.h b/Core/FileSystems/BlockDevices.h index 0865eaa202..b8f6c11137 100644 --- a/Core/FileSystems/BlockDevices.h +++ b/Core/FileSystems/BlockDevices.h @@ -51,7 +51,6 @@ public: } virtual bool IsDisc() const = 0; - u32 CalculateCRC(volatile bool *cancel = nullptr); void NotifyReadError(); protected: diff --git a/Core/Reporting.cpp b/Core/Reporting.cpp index df6c7a84f5..1725627959 100644 --- a/Core/Reporting.cpp +++ b/Core/Reporting.cpp @@ -24,12 +24,19 @@ #include #include +// for crc32 +extern "C" { +#include "zlib.h" +} + #include "Core/Reporting.h" #include "Common/File/VFS/VFS.h" #include "Common/CPUDetect.h" #include "Common/File/FileUtil.h" #include "Common/Serialize/SerializeFuncs.h" #include "Common/StringUtils.h" +#include "Common/System/OSD.h" +#include "Common/Data/Text/I18n.h" #include "Core/Core.h" #include "Core/CoreTiming.h" #include "Core/Config.h" @@ -108,6 +115,31 @@ namespace Reporting static volatile bool crcCancel = false; static std::thread crcThread; + static u32 CalculateCRC(BlockDevice *blockDevice, volatile bool *cancel) { + auto ga = GetI18NCategory(I18NCat::GAME); + + u32 crc = crc32(0, Z_NULL, 0); + + u8 block[2048]; + u32 numBlocks = blockDevice->GetNumBlocks(); + for (u32 i = 0; i < numBlocks; ++i) { + if (cancel && *cancel) { + g_OSD.RemoveProgressBar("crc", false, 0.0f); + return 0; + } + if (!blockDevice->ReadBlock(i, block, true)) { + ERROR_LOG(FILESYS, "Failed to read block for CRC"); + g_OSD.RemoveProgressBar("crc", false, 0.0f); + return 0; + } + crc = crc32(crc, block, 2048); + g_OSD.SetProgressBar("crc", std::string(ga->T("Calculate CRC")), 0.0f, (float)numBlocks, (float)i, 0.5f); + } + + g_OSD.RemoveProgressBar("crc", true, 0.0f); + return crc; + } + static int CalculateCRCThread() { SetCurrentThreadName("ReportCRC"); @@ -118,7 +150,7 @@ namespace Reporting u32 crc = 0; if (blockDevice) { - crc = blockDevice->CalculateCRC(&crcCancel); + crc = CalculateCRC(blockDevice, &crcCancel); } delete blockDevice; @@ -128,6 +160,7 @@ namespace Reporting crcResults[crcFilename] = crc; crcPending = false; crcCond.notify_one(); + return 0; } diff --git a/UI/GameScreen.cpp b/UI/GameScreen.cpp index 1b1be8b0be..f8f30aba32 100644 --- a/UI/GameScreen.cpp +++ b/UI/GameScreen.cpp @@ -130,7 +130,7 @@ void GameScreen::CreateViews() { tvCRC_ = infoLayout->Add(new TextView("", ALIGN_LEFT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT))); tvCRC_->SetShadow(true); tvCRC_->SetVisibility(Reporting::HasCRC(gamePath_) ? V_VISIBLE : V_GONE); - tvVerified_ = infoLayout->Add(new NoticeView(NoticeLevel::INFO, ga->T("Click Calculate CRC to verify"), "", new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT))); + 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); } else { tvTitle_ = nullptr;