mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-02 02:33:43 +01:00
Add progress bar to CRC calculation
This commit is contained in:
1 parent
8e43a9a204
commit
93c0ef68b6
4 files changed
+35
-20
No files matched your search
@@ -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_) {
|
||||
|
||||
@@ -51,7 +51,6 @@ public:
|
||||
}
|
||||
virtual bool IsDisc() const = 0;
|
||||
|
||||
u32 CalculateCRC(volatile bool *cancel = nullptr);
|
||||
void NotifyReadError();
|
||||
|
||||
protected:
|
||||
|
||||
+34
-1
@@ -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"
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user