11#include <QApplication>
20#include <QStackedWidget>
34 const QString& gamePath,
int steamAppId)
39 steamAppId_ = steamAppId;
45 service_->cancelVerification(gameId_.toStdString());
52 emit
progress(
"Starting verification...", 0,
"", 0, 0);
63 status =
"Starting...";
66 status =
"Loading manifest...";
69 status =
"Verifying files...";
75 status =
"Failed: " + QString::fromStdString(p.errorMessage);
82 emit
progress(status, p.percentComplete, QString::fromStdString(p.currentFile),
83 p.filesProcessed, p.totalFiles);
93 result = service_->verifySteamGame(
static_cast<uint32_t
>(steamAppId_),
94 gamePath_.toStdString(), progressCallback);
99 result = service_->verifyGame(gameId_.toStdString(), gamePath_.toStdString(),
103 result.
gameName = gameName_.toStdString();
107 emit
error(
"Verification cancelled");
113 catch (
const std::exception& e)
115 emit
error(QString(
"Verification failed: %1").arg(e.what()));
125 : QWidget(parent), result_(
result),
126 themeManager_(themeManager ? themeManager : &
ThemeManager::instance())
128 auto* layout =
new QHBoxLayout(
this);
129 layout->setContentsMargins(8, 4, 8, 4);
130 layout->setSpacing(12);
133 statusIcon_ =
new QLabel;
134 statusIcon_->setFixedWidth(24);
135 statusIcon_->setAlignment(Qt::AlignCenter);
140 statusIcon_->setText(
"\xE2\x9C\x93");
143 statusIcon_->setText(
"\xE2\x9C\x97");
146 statusIcon_->setText(
"\xE2\x9D\x93");
149 statusIcon_->setText(
"\xE2\x9A\xA0");
152 statusIcon_->setText(
"\xE2\x9E\x95");
155 statusIcon_->setText(
"\xE2\x80\xA2");
158 layout->addWidget(statusIcon_);
161 auto* textLayout =
new QVBoxLayout;
162 textLayout->setSpacing(2);
164 pathLabel_ =
new QLabel(QString::fromStdString(
result.path.string()));
165 pathLabel_->setTextInteractionFlags(Qt::TextSelectableByMouse);
167 detailLabel_ =
new QLabel;
175 detail = QString(
"Corrupted (expected: %1, got: %2)")
176 .arg(QString::fromStdString(
result.expectedChecksum).left(16))
177 .arg(QString::fromStdString(
result.actualChecksum).left(16));
180 detail =
"File missing";
183 detail = QString(
"Size mismatch (expected: %1, got: %2)")
184 .arg(QLocale().formattedDataSize(
result.expectedSize))
185 .arg(QLocale().formattedDataSize(
result.actualSize));
188 detail =
"Extra file (not in manifest)";
193 detailLabel_->setText(detail);
195 textLayout->addWidget(pathLabel_);
196 textLayout->addWidget(detailLabel_);
198 layout->addLayout(textLayout, 1);
206 const auto& c = themeManager_->colors();
209 switch (result_.status)
212 statusColor = c.success;
216 statusColor = c.error;
220 statusColor = c.warning;
223 statusColor = c.textMuted;
226 statusIcon_->setStyleSheet(QString(
"font-size: 16px; color: %1;").arg(statusColor.name()));
227 pathLabel_->setStyleSheet(QString(
"color: %1; font-weight: bold;").arg(c.textPrimary.name()));
228 detailLabel_->setStyleSheet(QString(
"color: %1; font-size: 11px;").arg(c.textSecondary.name()));
236 : QWidget(parent), themeManager_(themeManager ? themeManager : &
ThemeManager::instance())
238 auto* layout =
new QVBoxLayout(
this);
239 layout->setSpacing(16);
242 auto* headerLayout =
new QHBoxLayout;
244 statusIcon_ =
new QLabel;
245 statusIcon_->setFixedSize(48, 48);
246 statusIcon_->setAlignment(Qt::AlignCenter);
248 statusLabel_ =
new QLabel;
250 headerLayout->addWidget(statusIcon_);
251 headerLayout->addWidget(statusLabel_, 1);
252 layout->addLayout(headerLayout);
255 integrityBar_ =
new QProgressBar;
256 integrityBar_->setMinimum(0);
257 integrityBar_->setMaximum(100);
258 integrityBar_->setTextVisible(
true);
259 integrityBar_->setFormat(
"Integrity: %p%");
260 layout->addWidget(integrityBar_);
263 auto* statsLayout =
new QGridLayout;
264 statsLayout->setSpacing(8);
266 auto addStatRow = [&](
int row,
const QString& label, QLabel*& valueLabel)
268 auto* labelWidget =
new QLabel(label);
269 labelWidget->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
270 valueLabel =
new QLabel(
"-");
271 valueLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
272 statsLayout->addWidget(labelWidget, row, 0);
273 statsLayout->addWidget(valueLabel, row, 1);
276 addStatRow(0,
"Total Files:", totalFilesLabel_);
277 addStatRow(1,
"Valid:", validFilesLabel_);
278 addStatRow(2,
"Invalid:", invalidFilesLabel_);
279 addStatRow(3,
"Missing:", missingFilesLabel_);
280 addStatRow(4,
"Extra:", extraFilesLabel_);
281 addStatRow(5,
"Total Size:", totalSizeLabel_);
282 addStatRow(6,
"Verification Time:", timeLabel_);
284 layout->addLayout(statsLayout);
285 layout->addStretch();
294 const auto& c = themeManager_->colors();
299 statusIcon_->setText(
"\xE2\x9C\x93");
300 statusIcon_->setStyleSheet(QString(
"font-size: 36px; color: %1;").arg(c.success.name()));
301 statusLabel_->setText(
"<b>All Files Verified</b><br>Game installation is intact.");
302 statusLabel_->setStyleSheet(QString(
"color: %1;").arg(c.success.name()));
306 statusIcon_->setText(
"\xE2\x9A\xA0");
307 statusIcon_->setStyleSheet(QString(
"font-size: 36px; color: %1;").arg(c.warning.name()));
310 issues += QString(
"%1 missing, ").arg(result.
missingFiles);
312 issues += QString(
"%1 corrupted, ").arg(result.
invalidFiles);
313 if (!issues.isEmpty())
315 statusLabel_->setText(QString(
"<b>Issues Found</b><br>%1").arg(issues));
316 statusLabel_->setStyleSheet(QString(
"color: %1;").arg(c.warning.name()));
321 integrityBar_->setValue(integrity);
324 totalFilesLabel_->setText(QString::number(result.
totalFiles));
325 validFilesLabel_->setText(
326 QString(
"<span style='color:%1'>%2</span>").arg(c.success.name()).arg(result.
validFiles));
327 invalidFilesLabel_->setText(
328 QString(
"<span style='color:%1'>%2</span>")
329 .arg(result.
invalidFiles > 0 ? c.error.name() : c.textPrimary.name())
331 missingFilesLabel_->setText(
332 QString(
"<span style='color:%1'>%2</span>")
333 .arg(result.
missingFiles > 0 ? c.error.name() : c.textPrimary.name())
335 extraFilesLabel_->setText(
336 QString(
"<span style='color:%1'>%2</span>")
337 .arg(result.
extraFiles > 0 ? c.warning.name() : c.textPrimary.name())
339 totalSizeLabel_->setText(QLocale().formattedDataSize(result.
totalBytes));
342 int minutes = seconds / 60;
343 seconds = seconds % 60;
345 timeLabel_->setText(QString(
"%1m %2s").arg(minutes).arg(seconds));
347 timeLabel_->setText(QString(
"%1s").arg(seconds));
352 statusIcon_->clear();
353 statusLabel_->clear();
354 integrityBar_->setValue(0);
355 totalFilesLabel_->setText(
"-");
356 validFilesLabel_->setText(
"-");
357 invalidFilesLabel_->setText(
"-");
358 missingFilesLabel_->setText(
"-");
359 extraFilesLabel_->setText(
"-");
360 totalSizeLabel_->setText(
"-");
361 timeLabel_->setText(
"-");
366 const auto& c = themeManager_->colors();
368 QString progressStyle =
369 QString(
"QProgressBar { "
370 " border: 1px solid %1; "
371 " border-radius: 4px; "
374 " text-align: center; "
377 "QProgressBar::chunk { "
379 " border-radius: 3px; "
381 .arg(c.border.name(), c.inputBackground.name(), c.textPrimary.name(), c.success.name());
383 integrityBar_->setStyleSheet(progressStyle);
386 for (
auto* label : findChildren<QLabel*>())
388 if (label != statusIcon_ && label != statusLabel_ && label != validFilesLabel_ &&
389 label != invalidFilesLabel_ && label != missingFilesLabel_ && label != extraFilesLabel_)
391 QPalette p = label->palette();
392 p.setColor(QPalette::WindowText, c.textPrimary);
393 label->setPalette(p);
403 : QDialog(parent), themeManager_(themeManager ? themeManager : &
ThemeManager::instance())
405 setWindowTitle(
"Verify Game Files");
406 setMinimumSize(550, 450);
423 workerThread_->quit();
424 workerThread_->wait(3000);
425 delete workerThread_;
430 const QString& gamePath,
int steamAppId)
433 gameName_ = gameName;
434 gamePath_ = gamePath;
435 steamAppId_ = steamAppId;
438 gameNameLabel_->setText(gameName);
439 gamePathLabel_->setText(gamePath);
440 gameTypeLabel_->setText(steamAppId > 0 ? QString(
"Steam Game (App ID: %1)").arg(steamAppId)
449void GameVerificationDialog::setupUI()
451 auto* mainLayout =
new QVBoxLayout(
this);
452 mainLayout->setSpacing(16);
453 mainLayout->setContentsMargins(20, 20, 20, 20);
456 pageStack_ =
new QStackedWidget;
459 startPage_ =
new QWidget;
460 setupGameInfoSection(startPage_);
461 pageStack_->addWidget(startPage_);
464 progressPage_ =
new QWidget;
465 setupProgressSection(progressPage_);
466 pageStack_->addWidget(progressPage_);
469 resultsPage_ =
new QWidget;
470 setupResultsSection(resultsPage_);
471 pageStack_->addWidget(resultsPage_);
473 mainLayout->addWidget(pageStack_);
476void GameVerificationDialog::setupGameInfoSection(QWidget* container)
478 auto* layout =
new QVBoxLayout(container);
479 layout->setSpacing(16);
482 auto* infoLabel =
new QLabel(
483 "Verify the integrity of game files by checking them against the expected checksums.\n"
484 "This can help identify corrupted or modified files.");
485 infoLabel->setWordWrap(
true);
486 layout->addWidget(infoLabel);
489 auto* infoGroup =
new QGroupBox(
"Game Information");
490 auto* infoLayout =
new QGridLayout(infoGroup);
491 infoLayout->setSpacing(8);
493 infoLayout->addWidget(
new QLabel(
"Game:"), 0, 0);
494 gameNameLabel_ =
new QLabel;
495 gameNameLabel_->setWordWrap(
true);
496 infoLayout->addWidget(gameNameLabel_, 0, 1);
498 infoLayout->addWidget(
new QLabel(
"Path:"), 1, 0);
499 gamePathLabel_ =
new QLabel;
500 gamePathLabel_->setWordWrap(
true);
501 gamePathLabel_->setTextInteractionFlags(Qt::TextSelectableByMouse);
502 infoLayout->addWidget(gamePathLabel_, 1, 1);
504 infoLayout->addWidget(
new QLabel(
"Type:"), 2, 0);
505 gameTypeLabel_ =
new QLabel;
506 infoLayout->addWidget(gameTypeLabel_, 2, 1);
508 infoLayout->setColumnStretch(1, 1);
509 layout->addWidget(infoGroup);
511 layout->addStretch();
514 auto* buttonLayout =
new QHBoxLayout;
515 buttonLayout->addStretch();
517 verifyBtn_ =
new QPushButton(
"Verify Files");
518 verifyBtn_->setMinimumWidth(150);
519 connect(verifyBtn_, &QPushButton::clicked,
this, &GameVerificationDialog::onVerifyClicked);
520 buttonLayout->addWidget(verifyBtn_);
522 layout->addLayout(buttonLayout);
525void GameVerificationDialog::setupProgressSection(QWidget* container)
527 auto* layout =
new QVBoxLayout(container);
528 layout->setAlignment(Qt::AlignCenter);
529 layout->setSpacing(16);
531 layout->addStretch();
534 progressStatusLabel_ =
new QLabel(
"Verifying...");
535 progressStatusLabel_->setAlignment(Qt::AlignCenter);
536 layout->addWidget(progressStatusLabel_);
539 progressBar_ =
new QProgressBar;
540 progressBar_->setMinimum(0);
541 progressBar_->setMaximum(100);
542 progressBar_->setMinimumWidth(400);
543 layout->addWidget(progressBar_);
546 progressFileLabel_ =
new QLabel;
547 progressFileLabel_->setAlignment(Qt::AlignCenter);
548 progressFileLabel_->setWordWrap(
true);
549 layout->addWidget(progressFileLabel_);
552 progressCountLabel_ =
new QLabel;
553 progressCountLabel_->setAlignment(Qt::AlignCenter);
554 layout->addWidget(progressCountLabel_);
556 layout->addStretch();
559 auto* buttonLayout =
new QHBoxLayout;
560 buttonLayout->addStretch();
562 cancelBtn_ =
new QPushButton(
"Cancel");
563 cancelBtn_->setMinimumWidth(100);
564 connect(cancelBtn_, &QPushButton::clicked,
this, &GameVerificationDialog::onCancelClicked);
565 buttonLayout->addWidget(cancelBtn_);
567 buttonLayout->addStretch();
568 layout->addLayout(buttonLayout);
570 layout->addStretch();
573void GameVerificationDialog::setupResultsSection(QWidget* container)
575 auto* layout =
new QVBoxLayout(container);
576 layout->setSpacing(16);
579 summaryWidget_ =
new VerificationSummaryWidget(
this, themeManager_);
580 layout->addWidget(summaryWidget_);
583 showDetailsBtn_ =
new QPushButton(
"Show Details");
584 showDetailsBtn_->setCheckable(
true);
585 showDetailsBtn_->setChecked(
false);
586 connect(showDetailsBtn_, &QPushButton::toggled,
this,
587 &GameVerificationDialog::onShowDetailsToggled);
588 layout->addWidget(showDetailsBtn_);
590 detailsGroup_ =
new QGroupBox(
"File Details");
591 detailsGroup_->setVisible(
false);
592 auto* detailsLayout =
new QVBoxLayout(detailsGroup_);
594 fileTable_ =
new QTableWidget;
595 fileTable_->setColumnCount(3);
596 fileTable_->setHorizontalHeaderLabels({
"Status",
"File",
"Details"});
597 fileTable_->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
598 fileTable_->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
599 fileTable_->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
600 fileTable_->setSelectionBehavior(QAbstractItemView::SelectRows);
601 fileTable_->setSelectionMode(QAbstractItemView::SingleSelection);
602 fileTable_->setEditTriggers(QAbstractItemView::NoEditTriggers);
603 fileTable_->setMinimumHeight(200);
605 detailsLayout->addWidget(fileTable_);
606 layout->addWidget(detailsGroup_);
609 auto* buttonLayout =
new QHBoxLayout;
611 verifyAgainBtn_ =
new QPushButton(
"Verify Again");
612 connect(verifyAgainBtn_, &QPushButton::clicked,
this, &GameVerificationDialog::onVerifyClicked);
613 buttonLayout->addWidget(verifyAgainBtn_);
615 buttonLayout->addStretch();
617 closeBtn_ =
new QPushButton(
"Close");
618 closeBtn_->setMinimumWidth(100);
619 connect(closeBtn_, &QPushButton::clicked,
this, &GameVerificationDialog::onCloseClicked);
620 buttonLayout->addWidget(closeBtn_);
622 layout->addLayout(buttonLayout);
625void GameVerificationDialog::showPage(
int index)
627 pageStack_->setCurrentIndex(index);
630void GameVerificationDialog::onVerifyClicked()
635 if (gamePath_.isEmpty())
644 progressBar_->setValue(0);
645 progressStatusLabel_->setText(
"Starting verification...");
646 progressFileLabel_->clear();
647 progressCountLabel_->clear();
650 workerThread_ =
new QThread(
this);
651 worker_ =
new VerificationWorker;
652 worker_->setGameInfo(gameId_, gameName_, gamePath_, steamAppId_);
653 worker_->moveToThread(workerThread_);
660 Qt::QueuedConnection);
662 Qt::QueuedConnection);
664 Qt::QueuedConnection);
668 connect(workerThread_, &QThread::finished, worker_, &QObject::deleteLater);
670 workerThread_->start();
673void GameVerificationDialog::onCancelClicked()
681void GameVerificationDialog::onCloseClicked()
686void GameVerificationDialog::onProgress(
const QString& status,
int percent,
687 const QString& currentFile,
int filesProcessed,
690 progressStatusLabel_->setText(status);
691 progressBar_->setValue(percent);
693 if (!currentFile.isEmpty())
696 QString displayFile = currentFile;
697 if (displayFile.length() > 60)
699 displayFile =
"..." + displayFile.right(57);
701 progressFileLabel_->setText(displayFile);
706 progressCountLabel_->setText(QString(
"File %1 of %2").arg(filesProcessed).arg(totalFiles));
718 summaryWidget_->setResult(result);
728void GameVerificationDialog::onError(
const QString& message)
731 progressStatusLabel_->setText(
"Error: " + message);
734 QTimer::singleShot(2000,
this, [
this]() { showPage(0); });
737void GameVerificationDialog::onShowDetailsToggled(
bool checked)
739 detailsGroup_->setVisible(checked);
740 showDetailsBtn_->setText(checked ?
"Hide Details" :
"Show Details");
745 resize(width(), qMax(height(), 650));
749void GameVerificationDialog::updateFileList()
751 fileTable_->setRowCount(0);
753 const auto& c = themeManager_->colors();
756 std::vector<const FileVerificationResult*> sortedFiles;
757 sortedFiles.reserve(result_.files.size());
758 for (
const auto& file : result_.files)
760 sortedFiles.push_back(&file);
763 std::sort(sortedFiles.begin(), sortedFiles.end(),
764 [](
const FileVerificationResult* a,
const FileVerificationResult* b)
767 bool aIssue = a->status != VerificationStatus::Valid;
768 bool bIssue = b->status != VerificationStatus::Valid;
769 if (aIssue != bIssue)
770 return aIssue > bIssue;
772 return a->path < b->path;
775 for (
const auto* file : sortedFiles)
777 int row = fileTable_->rowCount();
778 fileTable_->insertRow(row);
783 switch (file->status)
786 statusText =
"\xE2\x9C\x93";
787 statusColor = c.success;
790 statusText =
"\xE2\x9C\x97";
791 statusColor = c.error;
794 statusText =
"\xE2\x9D\x93";
795 statusColor = c.error;
798 statusText =
"\xE2\x9A\xA0";
799 statusColor = c.warning;
802 statusText =
"\xE2\x9E\x95";
803 statusColor = c.info;
806 statusText =
"\xE2\x80\xA2";
807 statusColor = c.textMuted;
810 auto* statusItem =
new QTableWidgetItem(statusText);
811 statusItem->setForeground(statusColor);
812 statusItem->setTextAlignment(Qt::AlignCenter);
813 fileTable_->setItem(row, 0, statusItem);
816 auto* pathItem =
new QTableWidgetItem(QString::fromStdString(file->path.string()));
817 fileTable_->setItem(row, 1, pathItem);
821 auto* detailItem =
new QTableWidgetItem(detail);
822 detailItem->setForeground(statusColor);
823 fileTable_->setItem(row, 2, detailItem);
827QString GameVerificationDialog::formatBytes(int64_t bytes)
const
829 return QLocale().formattedDataSize(bytes);
832QString GameVerificationDialog::formatDuration(
int ms)
const
834 int seconds = ms / 1000;
835 int minutes = seconds / 60;
836 seconds = seconds % 60;
839 return QString(
"%1m %2s").arg(minutes).arg(seconds);
840 return QString(
"%1s").arg(seconds);
843void GameVerificationDialog::applyTheme()
845 const auto& c = themeManager_->colors();
848 setStyleSheet(QString(
"QDialog { background-color: %1; }").arg(c.windowBackground.name()));
851 QString groupBoxStyle = QString(
"QGroupBox { "
852 " font-weight: bold; "
853 " border: 1px solid %1; "
854 " border-radius: 6px; "
855 " margin-top: 12px; "
856 " padding-top: 8px; "
858 "QGroupBox::title { "
859 " subcontrol-origin: margin; "
864 .arg(c.border.name(), c.textPrimary.name());
866 for (
auto* groupBox : findChildren<QGroupBox*>())
868 groupBox->setStyleSheet(groupBoxStyle);
873 for (
auto* label : findChildren<QLabel*>())
875 QPalette p = label->palette();
876 p.setColor(QPalette::WindowText, c.textPrimary);
877 label->setPalette(p);
881 QString progressStyle =
882 QString(
"QProgressBar { "
883 " border: 1px solid %1; "
884 " border-radius: 4px; "
887 " text-align: center; "
890 "QProgressBar::chunk { "
892 " border-radius: 3px; "
894 .arg(c.border.name(), c.inputBackground.name(), c.textPrimary.name(), c.accent.name());
896 progressBar_->setStyleSheet(progressStyle);
899 QString buttonStyle = QString(
"QPushButton { "
900 " background-color: %1; "
901 " border: 1px solid %2; "
902 " border-radius: 6px; "
903 " padding: 8px 16px; "
905 " font-weight: 500; "
907 "QPushButton:hover { "
908 " background-color: %4; "
910 "QPushButton:pressed { "
911 " background-color: %5; "
913 "QPushButton:disabled { "
914 " background-color: %6; "
917 .arg(c.cardBackground.name(), c.border.name(), c.textPrimary.name(),
918 c.hoverBackground.name(), c.panelBackground.name(),
919 c.cardBackground.name(), c.textMuted.name());
921 QString primaryButtonStyle = QString(
"QPushButton { "
922 " background-color: %1; "
924 " border-radius: 6px; "
925 " padding: 8px 16px; "
927 " font-weight: bold; "
929 "QPushButton:hover { "
930 " background-color: %2; "
932 "QPushButton:pressed { "
933 " background-color: %3; "
935 .arg(c.accent.name(), c.accentHover.name(),
936 c.accentPressed.name(), c.textOnAccent.name());
938 for (
auto* btn : findChildren<QPushButton*>())
940 btn->setStyleSheet(buttonStyle);
943 verifyBtn_->setStyleSheet(primaryButtonStyle);
944 verifyAgainBtn_->setStyleSheet(buttonStyle);
945 closeBtn_->setStyleSheet(primaryButtonStyle);
948 QString tableStyle = QString(
"QTableWidget { "
949 " background-color: %1; "
950 " border: 1px solid %2; "
951 " border-radius: 4px; "
952 " gridline-color: %2; "
955 "QTableWidget::item { "
958 "QTableWidget::item:selected { "
959 " background-color: %4; "
961 "QHeaderView::section { "
962 " background-color: %5; "
966 " border-bottom: 1px solid %2; "
968 .arg(c.inputBackground.name(), c.border.name(), c.textPrimary.name(),
969 c.hoverBackground.name(), c.panelBackground.name());
971 fileTable_->setStyleSheet(tableStyle);
975 summaryWidget_->applyTheme();
Service for verifying game file integrity.
GameVerificationDialog(QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
void setGame(const QString &gameId, const QString &gameName, const QString &gamePath, int steamAppId=0)
~GameVerificationDialog() override
void themeChanged()
Emitted when theme or accent color changes.
void setGameInfo(const QString &gameId, const QString &gameName, const QString &gamePath, int steamAppId)
VerificationWorker(QObject *parent=nullptr)
void finished(bool success, const GameVerificationResult &result)
void progress(const QString &status, int percent, const QString ¤tFile, int filesProcessed, int totalFiles)
void error(const QString &message)
@ Missing
File doesn't exist.
@ Valid
File matches expected checksum/size.
@ Invalid
File doesn't match (corrupted or modified).
@ ExtraFile
File exists but not in manifest.
@ SizeMismatch
File exists but wrong size.
std::string verificationStatusName(VerificationStatus status)
Get human-readable name for verification status.
Result of verifying a single file.
Complete verification result for a game.
float getCompletionPercentage() const
Progress information during verification.