Merge pull request #2668 from CookiePLMonster/dump-verification

Implement image verification
This commit is contained in:
Connor McLaughlin
2021-10-25 17:30:20 +10:00
committed by GitHub
36 changed files with 497671 additions and 394290 deletions

View File

@ -46,15 +46,19 @@ static bool ReadTrack(CDImage* image, u8 track, MD5Digest* digest, ProgressCallb
progress_callback->PushState();
progress_callback->SetProgressRange(2);
const bool dataTrack = track == 1;
progress_callback->SetProgressRange(dataTrack ? 1 : 2);
u8 progress = 0;
for (u8 index = 0; index < INDICES_TO_READ; index++)
{
progress_callback->SetProgressValue(index);
progress_callback->SetProgressValue(progress);
// skip index 0 if data track
if (track == 1 && index == 0)
if (dataTrack && index == 0)
continue;
progress++;
progress_callback->PushState();
if (!ReadIndex(image, track, index, digest, progress_callback))
{
@ -66,7 +70,7 @@ static bool ReadTrack(CDImage* image, u8 track, MD5Digest* digest, ProgressCallb
progress_callback->PopState();
}
progress_callback->SetProgressValue(INDICES_TO_READ);
progress_callback->SetProgressValue(progress);
progress_callback->PopState();
return true;
}
@ -78,6 +82,17 @@ std::string HashToString(const Hash& hash)
hash[9], hash[10], hash[11], hash[12], hash[13], hash[14], hash[15]);
}
std::optional<Hash> HashFromString(const std::string_view& str) {
auto decoded = StringUtil::DecodeHex(str);
if (decoded && decoded->size() == std::tuple_size_v<Hash>)
{
Hash result;
std::copy(decoded->begin(), decoded->end(), result.begin());
return result;
}
return std::nullopt;
}
bool GetImageHash(CDImage* image, Hash* out_hash,
ProgressCallback* progress_callback /*= ProgressCallback::NullProgressCallback*/)
{

View File

@ -2,6 +2,7 @@
#include "progress_callback.h"
#include "types.h"
#include <array>
#include <optional>
#include <string>
class CDImage;
@ -10,6 +11,7 @@ namespace CDImageHasher {
using Hash = std::array<u8, 16>;
std::string HashToString(const Hash& hash);
std::optional<Hash> HashFromString(const std::string_view& str);
bool GetImageHash(CDImage* image, Hash* out_hash,
ProgressCallback* progress_callback = ProgressCallback::NullProgressCallback);