game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
game_verification_dialog.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// qt/game_verification_dialog.cpp
4// ==============================================================================
5// Implementation of game file verification dialog
6// ==============================================================================
7
9#include "theme_manager.h"
10
11#include <QApplication>
12#include <QDateTime>
13#include <QFileInfo>
14#include <QGridLayout>
15#include <QGroupBox>
16#include <QHBoxLayout>
17#include <QHeaderView>
18#include <QLocale>
19#include <QScrollArea>
20#include <QStackedWidget>
21#include <QTextEdit>
22#include <QVBoxLayout>
23
24// ==============================================================================
25// VerificationWorker Implementation
26// ==============================================================================
27
29 : QObject(parent), service_(std::make_unique<FileVerificationService>())
30{
31}
32
33void VerificationWorker::setGameInfo(const QString& gameId, const QString& gameName,
34 const QString& gamePath, int steamAppId)
35{
36 gameId_ = gameId;
37 gameName_ = gameName;
38 gamePath_ = gamePath;
39 steamAppId_ = steamAppId;
40}
41
43{
44 cancelled_ = true;
45 service_->cancelVerification(gameId_.toStdString());
46}
47
49{
50 cancelled_ = false;
51
52 emit progress("Starting verification...", 0, "", 0, 0);
53
54 auto progressCallback = [this](const VerificationProgress& p)
55 {
56 if (cancelled_)
57 return;
58
59 QString status;
60 switch (p.state)
61 {
63 status = "Starting...";
64 break;
66 status = "Loading manifest...";
67 break;
69 status = "Verifying files...";
70 break;
72 status = "Completed";
73 break;
75 status = "Failed: " + QString::fromStdString(p.errorMessage);
76 break;
78 status = "Cancelled";
79 break;
80 }
81
82 emit progress(status, p.percentComplete, QString::fromStdString(p.currentFile),
83 p.filesProcessed, p.totalFiles);
84 };
85
87
88 try
89 {
90 if (steamAppId_ > 0)
91 {
92 // Use Steam verification for Steam games
93 result = service_->verifySteamGame(static_cast<uint32_t>(steamAppId_),
94 gamePath_.toStdString(), progressCallback);
95 }
96 else
97 {
98 // Use generic verification for non-Steam games
99 result = service_->verifyGame(gameId_.toStdString(), gamePath_.toStdString(),
100 progressCallback);
101 }
102
103 result.gameName = gameName_.toStdString();
104
105 if (cancelled_)
106 {
107 emit error("Verification cancelled");
108 return;
109 }
110
111 emit finished(true, result);
112 }
113 catch (const std::exception& e)
114 {
115 emit error(QString("Verification failed: %1").arg(e.what()));
116 }
117}
118
119// ==============================================================================
120// FileResultWidget Implementation
121// ==============================================================================
122
124 ThemeManager* themeManager)
125 : QWidget(parent), result_(result),
126 themeManager_(themeManager ? themeManager : &ThemeManager::instance())
127{
128 auto* layout = new QHBoxLayout(this);
129 layout->setContentsMargins(8, 4, 8, 4);
130 layout->setSpacing(12);
131
132 // Status icon
133 statusIcon_ = new QLabel;
134 statusIcon_->setFixedWidth(24);
135 statusIcon_->setAlignment(Qt::AlignCenter);
136
137 switch (result.status)
138 {
140 statusIcon_->setText("\xE2\x9C\x93"); // Check mark
141 break;
143 statusIcon_->setText("\xE2\x9C\x97"); // X mark
144 break;
146 statusIcon_->setText("\xE2\x9D\x93"); // Question mark
147 break;
149 statusIcon_->setText("\xE2\x9A\xA0"); // Warning
150 break;
152 statusIcon_->setText("\xE2\x9E\x95"); // Plus
153 break;
154 default:
155 statusIcon_->setText("\xE2\x80\xA2"); // Bullet
156 }
157
158 layout->addWidget(statusIcon_);
159
160 // Path and details
161 auto* textLayout = new QVBoxLayout;
162 textLayout->setSpacing(2);
163
164 pathLabel_ = new QLabel(QString::fromStdString(result.path.string()));
165 pathLabel_->setTextInteractionFlags(Qt::TextSelectableByMouse);
166
167 detailLabel_ = new QLabel;
168 QString detail;
169 switch (result.status)
170 {
172 detail = "Valid";
173 break;
175 detail = QString("Corrupted (expected: %1, got: %2)")
176 .arg(QString::fromStdString(result.expectedChecksum).left(16))
177 .arg(QString::fromStdString(result.actualChecksum).left(16));
178 break;
180 detail = "File missing";
181 break;
183 detail = QString("Size mismatch (expected: %1, got: %2)")
184 .arg(QLocale().formattedDataSize(result.expectedSize))
185 .arg(QLocale().formattedDataSize(result.actualSize));
186 break;
188 detail = "Extra file (not in manifest)";
189 break;
190 default:
191 detail = "Unknown";
192 }
193 detailLabel_->setText(detail);
194
195 textLayout->addWidget(pathLabel_);
196 textLayout->addWidget(detailLabel_);
197
198 layout->addLayout(textLayout, 1);
199
200 applyTheme();
201 connect(themeManager_, &ThemeManager::themeChanged, this, &FileResultWidget::applyTheme);
202}
203
205{
206 const auto& c = themeManager_->colors();
207
208 QColor statusColor;
209 switch (result_.status)
210 {
212 statusColor = c.success;
213 break;
216 statusColor = c.error;
217 break;
220 statusColor = c.warning;
221 break;
222 default:
223 statusColor = c.textMuted;
224 }
225
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()));
229}
230
231// ==============================================================================
232// VerificationSummaryWidget Implementation
233// ==============================================================================
234
236 : QWidget(parent), themeManager_(themeManager ? themeManager : &ThemeManager::instance())
237{
238 auto* layout = new QVBoxLayout(this);
239 layout->setSpacing(16);
240
241 // Status header
242 auto* headerLayout = new QHBoxLayout;
243
244 statusIcon_ = new QLabel;
245 statusIcon_->setFixedSize(48, 48);
246 statusIcon_->setAlignment(Qt::AlignCenter);
247
248 statusLabel_ = new QLabel;
249
250 headerLayout->addWidget(statusIcon_);
251 headerLayout->addWidget(statusLabel_, 1);
252 layout->addLayout(headerLayout);
253
254 // Integrity bar
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_);
261
262 // Statistics grid
263 auto* statsLayout = new QGridLayout;
264 statsLayout->setSpacing(8);
265
266 auto addStatRow = [&](int row, const QString& label, QLabel*& valueLabel)
267 {
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);
274 };
275
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_);
283
284 layout->addLayout(statsLayout);
285 layout->addStretch();
286
287 applyTheme();
288 connect(themeManager_, &ThemeManager::themeChanged, this,
290}
291
293{
294 const auto& c = themeManager_->colors();
295
296 // Update status
297 if (result.isComplete())
298 {
299 statusIcon_->setText("\xE2\x9C\x93"); // Check mark
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()));
303 }
304 else
305 {
306 statusIcon_->setText("\xE2\x9A\xA0"); // Warning
307 statusIcon_->setStyleSheet(QString("font-size: 36px; color: %1;").arg(c.warning.name()));
308 QString issues;
309 if (result.missingFiles > 0)
310 issues += QString("%1 missing, ").arg(result.missingFiles);
311 if (result.invalidFiles > 0)
312 issues += QString("%1 corrupted, ").arg(result.invalidFiles);
313 if (!issues.isEmpty())
314 issues.chop(2); // Remove trailing ", "
315 statusLabel_->setText(QString("<b>Issues Found</b><br>%1").arg(issues));
316 statusLabel_->setStyleSheet(QString("color: %1;").arg(c.warning.name()));
317 }
318
319 // Update integrity bar
320 int integrity = static_cast<int>(result.getCompletionPercentage());
321 integrityBar_->setValue(integrity);
322
323 // Update statistics
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())
330 .arg(result.invalidFiles));
331 missingFilesLabel_->setText(
332 QString("<span style='color:%1'>%2</span>")
333 .arg(result.missingFiles > 0 ? c.error.name() : c.textPrimary.name())
334 .arg(result.missingFiles));
335 extraFilesLabel_->setText(
336 QString("<span style='color:%1'>%2</span>")
337 .arg(result.extraFiles > 0 ? c.warning.name() : c.textPrimary.name())
338 .arg(result.extraFiles));
339 totalSizeLabel_->setText(QLocale().formattedDataSize(result.totalBytes));
340
341 int seconds = result.totalTimeMs / 1000;
342 int minutes = seconds / 60;
343 seconds = seconds % 60;
344 if (minutes > 0)
345 timeLabel_->setText(QString("%1m %2s").arg(minutes).arg(seconds));
346 else
347 timeLabel_->setText(QString("%1s").arg(seconds));
348}
349
351{
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("-");
362}
363
365{
366 const auto& c = themeManager_->colors();
367
368 QString progressStyle =
369 QString("QProgressBar { "
370 " border: 1px solid %1; "
371 " border-radius: 4px; "
372 " background: %2; "
373 " height: 24px; "
374 " text-align: center; "
375 " color: %3; "
376 "} "
377 "QProgressBar::chunk { "
378 " background: %4; "
379 " border-radius: 3px; "
380 "}")
381 .arg(c.border.name(), c.inputBackground.name(), c.textPrimary.name(), c.success.name());
382
383 integrityBar_->setStyleSheet(progressStyle);
384
385 // Update labels
386 for (auto* label : findChildren<QLabel*>())
387 {
388 if (label != statusIcon_ && label != statusLabel_ && label != validFilesLabel_ &&
389 label != invalidFilesLabel_ && label != missingFilesLabel_ && label != extraFilesLabel_)
390 {
391 QPalette p = label->palette();
392 p.setColor(QPalette::WindowText, c.textPrimary);
393 label->setPalette(p);
394 }
395 }
396}
397
398// ==============================================================================
399// GameVerificationDialog Implementation
400// ==============================================================================
401
403 : QDialog(parent), themeManager_(themeManager ? themeManager : &ThemeManager::instance())
404{
405 setWindowTitle("Verify Game Files");
406 setMinimumSize(550, 450);
407 resize(600, 500);
408
409 setupUI();
410 applyTheme();
411
412 connect(themeManager_, &ThemeManager::themeChanged, this, &GameVerificationDialog::applyTheme);
413}
414
416{
417 if (workerThread_)
418 {
419 if (worker_)
420 {
421 worker_->cancel();
422 }
423 workerThread_->quit();
424 workerThread_->wait(3000);
425 delete workerThread_;
426 }
427}
428
429void GameVerificationDialog::setGame(const QString& gameId, const QString& gameName,
430 const QString& gamePath, int steamAppId)
431{
432 gameId_ = gameId;
433 gameName_ = gameName;
434 gamePath_ = gamePath;
435 steamAppId_ = steamAppId;
436
437 // Update UI
438 gameNameLabel_->setText(gameName);
439 gamePathLabel_->setText(gamePath);
440 gameTypeLabel_->setText(steamAppId > 0 ? QString("Steam Game (App ID: %1)").arg(steamAppId)
441 : "Non-Steam Game");
442
443 // Reset state
444 verified_ = false;
445 result_ = GameVerificationResult();
446 showPage(0);
447}
448
449void GameVerificationDialog::setupUI()
450{
451 auto* mainLayout = new QVBoxLayout(this);
452 mainLayout->setSpacing(16);
453 mainLayout->setContentsMargins(20, 20, 20, 20);
454
455 // Page stack
456 pageStack_ = new QStackedWidget;
457
458 // Page 0: Start page
459 startPage_ = new QWidget;
460 setupGameInfoSection(startPage_);
461 pageStack_->addWidget(startPage_);
462
463 // Page 1: Progress page
464 progressPage_ = new QWidget;
465 setupProgressSection(progressPage_);
466 pageStack_->addWidget(progressPage_);
467
468 // Page 2: Results page
469 resultsPage_ = new QWidget;
470 setupResultsSection(resultsPage_);
471 pageStack_->addWidget(resultsPage_);
472
473 mainLayout->addWidget(pageStack_);
474}
475
476void GameVerificationDialog::setupGameInfoSection(QWidget* container)
477{
478 auto* layout = new QVBoxLayout(container);
479 layout->setSpacing(16);
480
481 // Info label
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);
487
488 // Game info group
489 auto* infoGroup = new QGroupBox("Game Information");
490 auto* infoLayout = new QGridLayout(infoGroup);
491 infoLayout->setSpacing(8);
492
493 infoLayout->addWidget(new QLabel("Game:"), 0, 0);
494 gameNameLabel_ = new QLabel;
495 gameNameLabel_->setWordWrap(true);
496 infoLayout->addWidget(gameNameLabel_, 0, 1);
497
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);
503
504 infoLayout->addWidget(new QLabel("Type:"), 2, 0);
505 gameTypeLabel_ = new QLabel;
506 infoLayout->addWidget(gameTypeLabel_, 2, 1);
507
508 infoLayout->setColumnStretch(1, 1);
509 layout->addWidget(infoGroup);
510
511 layout->addStretch();
512
513 // Verify button
514 auto* buttonLayout = new QHBoxLayout;
515 buttonLayout->addStretch();
516
517 verifyBtn_ = new QPushButton("Verify Files");
518 verifyBtn_->setMinimumWidth(150);
519 connect(verifyBtn_, &QPushButton::clicked, this, &GameVerificationDialog::onVerifyClicked);
520 buttonLayout->addWidget(verifyBtn_);
521
522 layout->addLayout(buttonLayout);
523}
524
525void GameVerificationDialog::setupProgressSection(QWidget* container)
526{
527 auto* layout = new QVBoxLayout(container);
528 layout->setAlignment(Qt::AlignCenter);
529 layout->setSpacing(16);
530
531 layout->addStretch();
532
533 // Status
534 progressStatusLabel_ = new QLabel("Verifying...");
535 progressStatusLabel_->setAlignment(Qt::AlignCenter);
536 layout->addWidget(progressStatusLabel_);
537
538 // Progress bar
539 progressBar_ = new QProgressBar;
540 progressBar_->setMinimum(0);
541 progressBar_->setMaximum(100);
542 progressBar_->setMinimumWidth(400);
543 layout->addWidget(progressBar_);
544
545 // Current file
546 progressFileLabel_ = new QLabel;
547 progressFileLabel_->setAlignment(Qt::AlignCenter);
548 progressFileLabel_->setWordWrap(true);
549 layout->addWidget(progressFileLabel_);
550
551 // File count
552 progressCountLabel_ = new QLabel;
553 progressCountLabel_->setAlignment(Qt::AlignCenter);
554 layout->addWidget(progressCountLabel_);
555
556 layout->addStretch();
557
558 // Cancel button
559 auto* buttonLayout = new QHBoxLayout;
560 buttonLayout->addStretch();
561
562 cancelBtn_ = new QPushButton("Cancel");
563 cancelBtn_->setMinimumWidth(100);
564 connect(cancelBtn_, &QPushButton::clicked, this, &GameVerificationDialog::onCancelClicked);
565 buttonLayout->addWidget(cancelBtn_);
566
567 buttonLayout->addStretch();
568 layout->addLayout(buttonLayout);
569
570 layout->addStretch();
571}
572
573void GameVerificationDialog::setupResultsSection(QWidget* container)
574{
575 auto* layout = new QVBoxLayout(container);
576 layout->setSpacing(16);
577
578 // Summary widget
579 summaryWidget_ = new VerificationSummaryWidget(this, themeManager_);
580 layout->addWidget(summaryWidget_);
581
582 // Details section (collapsible)
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_);
589
590 detailsGroup_ = new QGroupBox("File Details");
591 detailsGroup_->setVisible(false);
592 auto* detailsLayout = new QVBoxLayout(detailsGroup_);
593
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);
604
605 detailsLayout->addWidget(fileTable_);
606 layout->addWidget(detailsGroup_);
607
608 // Buttons
609 auto* buttonLayout = new QHBoxLayout;
610
611 verifyAgainBtn_ = new QPushButton("Verify Again");
612 connect(verifyAgainBtn_, &QPushButton::clicked, this, &GameVerificationDialog::onVerifyClicked);
613 buttonLayout->addWidget(verifyAgainBtn_);
614
615 buttonLayout->addStretch();
616
617 closeBtn_ = new QPushButton("Close");
618 closeBtn_->setMinimumWidth(100);
619 connect(closeBtn_, &QPushButton::clicked, this, &GameVerificationDialog::onCloseClicked);
620 buttonLayout->addWidget(closeBtn_);
621
622 layout->addLayout(buttonLayout);
623}
624
625void GameVerificationDialog::showPage(int index)
626{
627 pageStack_->setCurrentIndex(index);
628}
629
630void GameVerificationDialog::onVerifyClicked()
631{
632 if (verifying_)
633 return;
634
635 if (gamePath_.isEmpty())
636 {
637 return;
638 }
639
640 verifying_ = true;
641 showPage(1);
642
643 // Reset progress
644 progressBar_->setValue(0);
645 progressStatusLabel_->setText("Starting verification...");
646 progressFileLabel_->clear();
647 progressCountLabel_->clear();
648
649 // Setup worker thread
650 workerThread_ = new QThread(this);
651 worker_ = new VerificationWorker;
652 worker_->setGameInfo(gameId_, gameName_, gamePath_, steamAppId_);
653 worker_->moveToThread(workerThread_);
654
655 // Explicit Qt::QueuedConnection for worker -> GUI signals. Auto-connection
656 // resolves correctly today (worker is in workerThread_), but making intent
657 // explicit avoids ambiguity if anything moves the worker's thread affinity.
658 connect(workerThread_, &QThread::started, worker_, &VerificationWorker::doVerify);
659 connect(worker_, &VerificationWorker::progress, this, &GameVerificationDialog::onProgress,
660 Qt::QueuedConnection);
661 connect(worker_, &VerificationWorker::finished, this, &GameVerificationDialog::onFinished,
662 Qt::QueuedConnection);
663 connect(worker_, &VerificationWorker::error, this, &GameVerificationDialog::onError,
664 Qt::QueuedConnection);
665
666 connect(worker_, &VerificationWorker::finished, workerThread_, &QThread::quit);
667 connect(worker_, &VerificationWorker::error, workerThread_, &QThread::quit);
668 connect(workerThread_, &QThread::finished, worker_, &QObject::deleteLater);
669
670 workerThread_->start();
671}
672
673void GameVerificationDialog::onCancelClicked()
674{
675 if (worker_)
676 {
677 worker_->cancel();
678 }
679}
680
681void GameVerificationDialog::onCloseClicked()
682{
683 accept();
684}
685
686void GameVerificationDialog::onProgress(const QString& status, int percent,
687 const QString& currentFile, int filesProcessed,
688 int totalFiles)
689{
690 progressStatusLabel_->setText(status);
691 progressBar_->setValue(percent);
692
693 if (!currentFile.isEmpty())
694 {
695 // Truncate long paths
696 QString displayFile = currentFile;
697 if (displayFile.length() > 60)
698 {
699 displayFile = "..." + displayFile.right(57);
700 }
701 progressFileLabel_->setText(displayFile);
702 }
703
704 if (totalFiles > 0)
705 {
706 progressCountLabel_->setText(QString("File %1 of %2").arg(filesProcessed).arg(totalFiles));
707 }
708}
709
710void GameVerificationDialog::onFinished(bool success, const GameVerificationResult& result)
711{
712 verifying_ = false;
713 verified_ = success;
714 result_ = result;
715
716 if (success)
717 {
718 summaryWidget_->setResult(result);
719 updateFileList();
720 showPage(2);
721 }
722 else
723 {
724 showPage(0);
725 }
726}
727
728void GameVerificationDialog::onError(const QString& message)
729{
730 verifying_ = false;
731 progressStatusLabel_->setText("Error: " + message);
732
733 // Show error for a moment then return to start page
734 QTimer::singleShot(2000, this, [this]() { showPage(0); });
735}
736
737void GameVerificationDialog::onShowDetailsToggled(bool checked)
738{
739 detailsGroup_->setVisible(checked);
740 showDetailsBtn_->setText(checked ? "Hide Details" : "Show Details");
741
742 // Resize dialog if needed
743 if (checked)
744 {
745 resize(width(), qMax(height(), 650));
746 }
747}
748
749void GameVerificationDialog::updateFileList()
750{
751 fileTable_->setRowCount(0);
752
753 const auto& c = themeManager_->colors();
754
755 // Show invalid/missing files first, then valid files
756 std::vector<const FileVerificationResult*> sortedFiles;
757 sortedFiles.reserve(result_.files.size());
758 for (const auto& file : result_.files)
759 {
760 sortedFiles.push_back(&file);
761 }
762
763 std::sort(sortedFiles.begin(), sortedFiles.end(),
764 [](const FileVerificationResult* a, const FileVerificationResult* b)
765 {
766 // Invalid/missing first
767 bool aIssue = a->status != VerificationStatus::Valid;
768 bool bIssue = b->status != VerificationStatus::Valid;
769 if (aIssue != bIssue)
770 return aIssue > bIssue;
771 // Then by path
772 return a->path < b->path;
773 });
774
775 for (const auto* file : sortedFiles)
776 {
777 int row = fileTable_->rowCount();
778 fileTable_->insertRow(row);
779
780 // Status icon
781 QString statusText;
782 QColor statusColor;
783 switch (file->status)
784 {
786 statusText = "\xE2\x9C\x93";
787 statusColor = c.success;
788 break;
790 statusText = "\xE2\x9C\x97";
791 statusColor = c.error;
792 break;
794 statusText = "\xE2\x9D\x93";
795 statusColor = c.error;
796 break;
798 statusText = "\xE2\x9A\xA0";
799 statusColor = c.warning;
800 break;
802 statusText = "\xE2\x9E\x95";
803 statusColor = c.info;
804 break;
805 default:
806 statusText = "\xE2\x80\xA2";
807 statusColor = c.textMuted;
808 }
809
810 auto* statusItem = new QTableWidgetItem(statusText);
811 statusItem->setForeground(statusColor);
812 statusItem->setTextAlignment(Qt::AlignCenter);
813 fileTable_->setItem(row, 0, statusItem);
814
815 // File path
816 auto* pathItem = new QTableWidgetItem(QString::fromStdString(file->path.string()));
817 fileTable_->setItem(row, 1, pathItem);
818
819 // Details
820 QString detail = QString::fromStdString(verificationStatusName(file->status));
821 auto* detailItem = new QTableWidgetItem(detail);
822 detailItem->setForeground(statusColor);
823 fileTable_->setItem(row, 2, detailItem);
824 }
825}
826
827QString GameVerificationDialog::formatBytes(int64_t bytes) const
828{
829 return QLocale().formattedDataSize(bytes);
830}
831
832QString GameVerificationDialog::formatDuration(int ms) const
833{
834 int seconds = ms / 1000;
835 int minutes = seconds / 60;
836 seconds = seconds % 60;
837
838 if (minutes > 0)
839 return QString("%1m %2s").arg(minutes).arg(seconds);
840 return QString("%1s").arg(seconds);
841}
842
843void GameVerificationDialog::applyTheme()
844{
845 const auto& c = themeManager_->colors();
846
847 // Dialog background
848 setStyleSheet(QString("QDialog { background-color: %1; }").arg(c.windowBackground.name()));
849
850 // Group boxes
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; "
857 "} "
858 "QGroupBox::title { "
859 " subcontrol-origin: margin; "
860 " left: 10px; "
861 " padding: 0 5px; "
862 " color: %2; "
863 "}")
864 .arg(c.border.name(), c.textPrimary.name());
865
866 for (auto* groupBox : findChildren<QGroupBox*>())
867 {
868 groupBox->setStyleSheet(groupBoxStyle);
869 }
870
871 // Labels — palette route composes with parent stylesheets without
872 // fighting Qt's CSS cascade.
873 for (auto* label : findChildren<QLabel*>())
874 {
875 QPalette p = label->palette();
876 p.setColor(QPalette::WindowText, c.textPrimary);
877 label->setPalette(p);
878 }
879
880 // Progress bar
881 QString progressStyle =
882 QString("QProgressBar { "
883 " border: 1px solid %1; "
884 " border-radius: 4px; "
885 " background: %2; "
886 " height: 24px; "
887 " text-align: center; "
888 " color: %3; "
889 "} "
890 "QProgressBar::chunk { "
891 " background: %4; "
892 " border-radius: 3px; "
893 "}")
894 .arg(c.border.name(), c.inputBackground.name(), c.textPrimary.name(), c.accent.name());
895
896 progressBar_->setStyleSheet(progressStyle);
897
898 // Buttons
899 QString buttonStyle = QString("QPushButton { "
900 " background-color: %1; "
901 " border: 1px solid %2; "
902 " border-radius: 6px; "
903 " padding: 8px 16px; "
904 " color: %3; "
905 " font-weight: 500; "
906 "} "
907 "QPushButton:hover { "
908 " background-color: %4; "
909 "} "
910 "QPushButton:pressed { "
911 " background-color: %5; "
912 "} "
913 "QPushButton:disabled { "
914 " background-color: %6; "
915 " color: %7; "
916 "}")
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());
920
921 QString primaryButtonStyle = QString("QPushButton { "
922 " background-color: %1; "
923 " border: none; "
924 " border-radius: 6px; "
925 " padding: 8px 16px; "
926 " color: %4; "
927 " font-weight: bold; "
928 "} "
929 "QPushButton:hover { "
930 " background-color: %2; "
931 "} "
932 "QPushButton:pressed { "
933 " background-color: %3; "
934 "}")
935 .arg(c.accent.name(), c.accentHover.name(),
936 c.accentPressed.name(), c.textOnAccent.name());
937
938 for (auto* btn : findChildren<QPushButton*>())
939 {
940 btn->setStyleSheet(buttonStyle);
941 }
942
943 verifyBtn_->setStyleSheet(primaryButtonStyle);
944 verifyAgainBtn_->setStyleSheet(buttonStyle);
945 closeBtn_->setStyleSheet(primaryButtonStyle);
946
947 // Table
948 QString tableStyle = QString("QTableWidget { "
949 " background-color: %1; "
950 " border: 1px solid %2; "
951 " border-radius: 4px; "
952 " gridline-color: %2; "
953 " color: %3; "
954 "} "
955 "QTableWidget::item { "
956 " padding: 4px; "
957 "} "
958 "QTableWidget::item:selected { "
959 " background-color: %4; "
960 "} "
961 "QHeaderView::section { "
962 " background-color: %5; "
963 " color: %3; "
964 " padding: 6px; "
965 " border: none; "
966 " border-bottom: 1px solid %2; "
967 "}")
968 .arg(c.inputBackground.name(), c.border.name(), c.textPrimary.name(),
969 c.hoverBackground.name(), c.panelBackground.name());
970
971 fileTable_->setStyleSheet(tableStyle);
972
973 // Update summary widget
974 if (summaryWidget_)
975 summaryWidget_->applyTheme();
976}
const FileVerificationResult & result() const
FileResultWidget(const FileVerificationResult &result, QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
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)
void themeChanged()
Emitted when theme or accent color changes.
void setResult(const GameVerificationResult &result)
VerificationSummaryWidget(QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
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 &currentFile, 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.
Progress information during verification.