From 93c0ef68b6708b1bc6ce2925397b832d2ba351bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 28 Oct 2023 06:50:57 -0500 Subject: [PATCH 1/3] Add progress bar to CRC calculation --- Core/FileSystems/BlockDevices.cpp | 17 --------------- Core/FileSystems/BlockDevices.h | 1 - Core/Reporting.cpp | 35 ++++++++++++++++++++++++++++++- UI/GameScreen.cpp | 2 +- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/Core/FileSystems/BlockDevices.cpp b/Core/FileSystems/BlockDevices.cpp index eaeb4c6261ee..b5a1ca0a8a63 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 0865eaa202b7..b8f6c1113716 100644 --- a/Core/FileSystems/BlockDevices.h +++ b/Core/FileSystems/BlockDevices.h @@ -51,7 +51,6 @@ class BlockDevice { } 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 df6c7a84f581..1725627959e8 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 1b1be8b0beca..f8f30aba3287 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; From 391d45cc03acf0d5b06502ccbb7d871c26145e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 28 Oct 2023 06:51:27 -0500 Subject: [PATCH 2/3] Typo fix, see #18384 --- assets/lang/pt_BR.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/lang/pt_BR.ini b/assets/lang/pt_BR.ini index 950c9b9fe626..309a91c4165d 100644 --- a/assets/lang/pt_BR.ini +++ b/assets/lang/pt_BR.ini @@ -81,7 +81,7 @@ Unofficial achievements = Conquistas não oficiais [Audio] Alternate speed volume = Velocidade alternativa do volume -Audio backend = Backed do áudio (requer reiniciar) +Audio backend = Backend do áudio (requer reiniciar) Audio file format not supported. Must be WAV. = Formato do arquivo de áudio não suportado. Deve ser WAV. Audio Error = Erro do Áudio AudioBufferingForBluetooth = Buffer amigável do Bluetooth (mais lento) From ce83fec20651222131ef9b88ba2dfb0554b66608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 29 Oct 2023 23:39:25 -0600 Subject: [PATCH 3/3] Linux buildfix attempt --- unittest/TestThreadManager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/unittest/TestThreadManager.cpp b/unittest/TestThreadManager.cpp index f6a11f2fa363..10a8b581b768 100644 --- a/unittest/TestThreadManager.cpp +++ b/unittest/TestThreadManager.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "Common/Log.h" #include "Common/TimeUtil.h"