mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
VolumeVerifier: Calculate CRC32/MD5/SHA-1
This commit is contained in:
@ -5,12 +5,17 @@
|
||||
#include "DolphinQt/Config/VerifyWidget.h"
|
||||
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QProgressDialog>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "DiscIO/Volume.h"
|
||||
#include "DiscIO/VolumeVerifier.h"
|
||||
|
||||
@ -23,6 +28,7 @@ VerifyWidget::VerifyWidget(std::shared_ptr<DiscIO::Volume> volume) : m_volume(st
|
||||
|
||||
layout->addWidget(m_problems);
|
||||
layout->addWidget(m_summary_text);
|
||||
layout->addLayout(m_hash_layout);
|
||||
layout->addWidget(m_verify_button);
|
||||
|
||||
layout->setStretchFactor(m_problems, 5);
|
||||
@ -44,17 +50,47 @@ void VerifyWidget::CreateWidgets()
|
||||
m_summary_text = new QTextEdit(this);
|
||||
m_summary_text->setReadOnly(true);
|
||||
|
||||
m_hash_layout = new QFormLayout(this);
|
||||
std::tie(m_crc32_checkbox, m_crc32_line_edit) = AddHashLine(m_hash_layout, tr("CRC32:"));
|
||||
std::tie(m_md5_checkbox, m_md5_line_edit) = AddHashLine(m_hash_layout, tr("MD5:"));
|
||||
std::tie(m_sha1_checkbox, m_sha1_line_edit) = AddHashLine(m_hash_layout, tr("SHA-1:"));
|
||||
|
||||
m_verify_button = new QPushButton(tr("Verify Integrity"), this);
|
||||
}
|
||||
|
||||
std::pair<QCheckBox*, QLineEdit*> VerifyWidget::AddHashLine(QFormLayout* layout, QString text)
|
||||
{
|
||||
QLineEdit* line_edit = new QLineEdit(this);
|
||||
line_edit->setReadOnly(true);
|
||||
QCheckBox* checkbox = new QCheckBox(tr("Calculate"), this);
|
||||
checkbox->setChecked(true);
|
||||
|
||||
QHBoxLayout* hbox_layout = new QHBoxLayout(this);
|
||||
hbox_layout->addWidget(line_edit);
|
||||
hbox_layout->addWidget(checkbox);
|
||||
|
||||
layout->addRow(text, hbox_layout);
|
||||
|
||||
return std::pair(checkbox, line_edit);
|
||||
}
|
||||
|
||||
void VerifyWidget::ConnectWidgets()
|
||||
{
|
||||
connect(m_verify_button, &QPushButton::clicked, this, &VerifyWidget::Verify);
|
||||
}
|
||||
|
||||
static void SetHash(QLineEdit* line_edit, const std::vector<u8>& hash)
|
||||
{
|
||||
const QByteArray byte_array = QByteArray::fromRawData(reinterpret_cast<const char*>(hash.data()),
|
||||
static_cast<int>(hash.size()));
|
||||
line_edit->setText(QString::fromLatin1(byte_array.toHex()));
|
||||
}
|
||||
|
||||
void VerifyWidget::Verify()
|
||||
{
|
||||
DiscIO::VolumeVerifier verifier(*m_volume);
|
||||
DiscIO::VolumeVerifier verifier(
|
||||
*m_volume,
|
||||
{m_crc32_checkbox->isChecked(), m_md5_checkbox->isChecked(), m_sha1_checkbox->isChecked()});
|
||||
|
||||
// We have to divide the number of processed bytes with something so it won't make ints overflow
|
||||
constexpr int DIVISOR = 0x100;
|
||||
@ -104,6 +140,10 @@ void VerifyWidget::Verify()
|
||||
SetProblemCellText(i, 0, QString::fromStdString(problem.text));
|
||||
SetProblemCellText(i, 1, severity);
|
||||
}
|
||||
|
||||
SetHash(m_crc32_line_edit, result.hashes.crc32);
|
||||
SetHash(m_md5_line_edit, result.hashes.md5);
|
||||
SetHash(m_sha1_line_edit, result.hashes.sha1);
|
||||
}
|
||||
|
||||
void VerifyWidget::SetProblemCellText(int row, int column, QString text)
|
||||
|
Reference in New Issue
Block a user