Skip to content

Commit

Permalink
Merge pull request #18386 from hrydgard/crc-progress-bar
Browse files Browse the repository at this point in the history
CRC calculation on game screen: Show progress bar
  • Loading branch information
hrydgard authored Oct 30, 2023
2 parents 8e43a9a + ce83fec commit 8ce639f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 21 deletions.
17 changes: 0 additions & 17 deletions Core/FileSystems/BlockDevices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand Down
1 change: 0 additions & 1 deletion Core/FileSystems/BlockDevices.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class BlockDevice {
}
virtual bool IsDisc() const = 0;

u32 CalculateCRC(volatile bool *cancel = nullptr);
void NotifyReadError();

protected:
Expand Down
35 changes: 34 additions & 1 deletion Core/Reporting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,19 @@
#include <cstdlib>
#include <cstdarg>

// 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"
Expand Down Expand Up @@ -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");

Expand All @@ -118,7 +150,7 @@ namespace Reporting

u32 crc = 0;
if (blockDevice) {
crc = blockDevice->CalculateCRC(&crcCancel);
crc = CalculateCRC(blockDevice, &crcCancel);
}

delete blockDevice;
Expand All @@ -128,6 +160,7 @@ namespace Reporting
crcResults[crcFilename] = crc;
crcPending = false;
crcCond.notify_one();

return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion UI/GameScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/pt_BR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions unittest/TestThreadManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <thread>
#include <vector>
#include <cstdio>

#include "Common/Log.h"
#include "Common/TimeUtil.h"
Expand Down

0 comments on commit 8ce639f

Please sign in to comment.