Qt: Make image verification cancellable

This commit is contained in:
Stenzek 2024-11-16 12:59:34 +10:00
parent 194e9bbbe5
commit 49b669c8be
No known key found for this signature in database
2 changed files with 9 additions and 0 deletions

View File

@ -403,6 +403,7 @@ void GameSummaryWidget::onComputeHashClicked()
}
QtModalProgressCallback progress_callback(this);
progress_callback.SetCancellable(true);
progress_callback.SetProgressRange(image->GetTrackCount());
std::vector<CDImageHasher::Hash> track_hashes;
@ -419,6 +420,10 @@ void GameSummaryWidget::onComputeHashClicked()
if (!CDImageHasher::GetTrackHash(image.get(), track, &hash, &progress_callback))
{
progress_callback.PopState();
if (progress_callback.IsCancelled())
return;
calculate_hash_success = false;
break;
}

View File

@ -40,6 +40,9 @@ bool CDImageHasher::ReadIndex(CDImage* image, u8 track, u8 index, MD5Digest* dig
if ((lba % update_interval) == 0)
progress_callback->SetProgressValue(lba);
if (progress_callback->IsCancelled())
return false;
if (!image->ReadRawSector(sector.data(), nullptr))
{
progress_callback->FormatModalError("Failed to read sector {} from image", image->GetPositionOnDisc());
@ -112,6 +115,7 @@ bool CDImageHasher::GetImageHash(CDImage* image, Hash* out_hash,
{
MD5Digest digest;
progress_callback->SetCancellable(true);
progress_callback->SetProgressRange(image->GetTrackCount());
progress_callback->SetProgressValue(0);
progress_callback->PushState();