game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
runner_manager_dialog.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// runner_manager_dialog.cpp
4// ==============================================================================
5// Runner Management Dialog implementation
6// ==============================================================================
7
11#include "theme_manager.h"
12#include "util/logger.h"
13
14#include <QComboBox>
15#include <QDateTime>
16#include <QDir>
17#include <QGroupBox>
18#include <QHBoxLayout>
19#include <QJsonArray>
20#include <QJsonDocument>
21#include <QJsonObject>
22#include <QLabel>
23#include <QLineEdit>
24#include <QMessageBox>
25#include <QProcess>
26#include <QStandardPaths>
27#include <QVBoxLayout>
28#include <QtConcurrent/QtConcurrent>
29
30#include <filesystem>
31#include <system_error>
32
33// ==============================================================================
34// Constructor / Destructor
35// ==============================================================================
36
38 : QDialog(parent), themeManager_(themeManager ? themeManager : &ThemeManager::instance())
39{
40 setWindowTitle("Runner Manager");
41 setMinimumSize(700, 500);
42 resize(850, 600);
43
44 setupUI();
45 applyTheme();
46
47 // Initialize fetch watcher
48 fetchWatcher_ = new QFutureWatcher<QString>(this);
49 connect(fetchWatcher_, &QFutureWatcher<QString>::finished, this,
50 [this]()
51 {
52 if (!fetchWatcher_->isCanceled())
53 {
54 parseGitHubReleases(fetchWatcher_->result(), "github");
55 }
56 refreshAvailableBtn_->setEnabled(true);
57 refreshAvailableBtn_->setText("Refresh");
58 });
59
60 connect(themeManager_, &ThemeManager::themeChanged, this, &RunnerManagerDialog::applyTheme);
61
62 // Initial data load
63 populateInstalledRunners();
64 fetchAvailableRunners();
65}
66
68{
69 if (fetchWatcher_ && fetchWatcher_->isRunning())
70 {
71 fetchWatcher_->cancel();
72 fetchWatcher_->waitForFinished();
73 }
74}
75
76// ==============================================================================
77// UI Setup
78// ==============================================================================
79
80void RunnerManagerDialog::setupUI()
81{
82 auto* mainLayout = new QVBoxLayout(this);
83 mainLayout->setSpacing(12);
84
85 // Header
86 auto* headerLabel = new QLabel("<b>Manage Proton & Wine Runners</b>");
87 headerLabel->setStyleSheet("font-size: 14px;");
88 mainLayout->addWidget(headerLabel);
89
90 // Tab widget
91 tabWidget_ = new QTabWidget();
92 mainLayout->addWidget(tabWidget_);
93
94 // Create tabs
95 auto* installedTab = new QWidget();
96 auto* availableTab = new QWidget();
97 auto* downloadsTab = new QWidget();
98
99 tabWidget_->addTab(installedTab, "Installed");
100 tabWidget_->addTab(availableTab, "Available");
101 tabWidget_->addTab(downloadsTab, "Downloads");
102
103 setupInstalledTab(installedTab);
104 setupAvailableTab(availableTab);
105 setupDownloadsTab(downloadsTab);
106
107 // Close button
108 auto* buttonLayout = new QHBoxLayout();
109 buttonLayout->addStretch();
110 auto* closeBtn = new QPushButton("Close");
111 connect(closeBtn, &QPushButton::clicked, this, &QDialog::accept);
112 buttonLayout->addWidget(closeBtn);
113 mainLayout->addLayout(buttonLayout);
114}
115
116void RunnerManagerDialog::setupInstalledTab(QWidget* tab)
117{
118 auto* layout = new QVBoxLayout(tab);
119
120 // Installed runners list
121 auto* listGroup = new QGroupBox("Installed Runners");
122 auto* listLayout = new QVBoxLayout(listGroup);
123
124 installedList_ = new QListWidget();
125 installedList_->setAlternatingRowColors(true);
126 connect(installedList_, &QListWidget::currentRowChanged, this,
127 &RunnerManagerDialog::onInstalledSelectionChanged);
128 listLayout->addWidget(installedList_);
129
130 layout->addWidget(listGroup);
131
132 // Info panel
133 installedInfoLabel_ = new QLabel("Select a runner to see details");
134 installedInfoLabel_->setWordWrap(true);
135 installedInfoLabel_->setMinimumHeight(60);
136 layout->addWidget(installedInfoLabel_);
137
138 // Buttons
139 auto* btnLayout = new QHBoxLayout();
140
141 refreshInstalledBtn_ = new QPushButton("Refresh");
142 connect(refreshInstalledBtn_, &QPushButton::clicked, this,
143 &RunnerManagerDialog::onRefreshInstalled);
144 btnLayout->addWidget(refreshInstalledBtn_);
145
146 btnLayout->addStretch();
147
148 removeBtn_ = new QPushButton("Remove Selected");
149 removeBtn_->setEnabled(false);
150 connect(removeBtn_, &QPushButton::clicked, this, &RunnerManagerDialog::onRemoveSelected);
151 btnLayout->addWidget(removeBtn_);
152
153 layout->addLayout(btnLayout);
154}
155
156void RunnerManagerDialog::setupAvailableTab(QWidget* tab)
157{
158 auto* layout = new QVBoxLayout(tab);
159
160 // Filter bar
161 auto* filterLayout = new QHBoxLayout();
162 filterLayout->addWidget(new QLabel("Source:"));
163
164 sourceFilter_ = new QComboBox();
165 sourceFilter_->addItem("All Sources", "");
166 sourceFilter_->addItem("GE-Proton", "proton-ge");
167 sourceFilter_->addItem("Wine-GE", "wine-ge");
168 connect(sourceFilter_, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
169 [this](int)
170 {
171 // Filter the list based on selection
172 QString filter = sourceFilter_->currentData().toString();
173 for (int i = 0; i < availableList_->count(); ++i)
174 {
175 auto* item = availableList_->item(i);
176 QString type = item->data(Qt::UserRole + 1).toString();
177 item->setHidden(!filter.isEmpty() && type != filter);
178 }
179 });
180 filterLayout->addWidget(sourceFilter_);
181 filterLayout->addStretch();
182
183 refreshAvailableBtn_ = new QPushButton("Refresh");
184 connect(refreshAvailableBtn_, &QPushButton::clicked, this,
185 &RunnerManagerDialog::onRefreshAvailable);
186 filterLayout->addWidget(refreshAvailableBtn_);
187
188 layout->addLayout(filterLayout);
189
190 // Split view: list and release notes
191 auto* splitLayout = new QHBoxLayout();
192
193 // Available runners list
194 auto* listGroup = new QGroupBox("Available Runners");
195 auto* listLayout = new QVBoxLayout(listGroup);
196
197 availableList_ = new QListWidget();
198 availableList_->setAlternatingRowColors(true);
199 connect(availableList_, &QListWidget::currentRowChanged, this,
200 &RunnerManagerDialog::onAvailableSelectionChanged);
201 listLayout->addWidget(availableList_);
202
203 splitLayout->addWidget(listGroup, 1);
204
205 // Release notes panel
206 auto* notesGroup = new QGroupBox("Release Notes");
207 auto* notesLayout = new QVBoxLayout(notesGroup);
208
209 releaseNotesText_ = new QTextEdit();
210 releaseNotesText_->setReadOnly(true);
211 releaseNotesText_->setPlaceholderText("Select a runner to view release notes");
212 notesLayout->addWidget(releaseNotesText_);
213
214 splitLayout->addWidget(notesGroup, 1);
215
216 layout->addLayout(splitLayout);
217
218 // Info and download button
219 auto* bottomLayout = new QHBoxLayout();
220
221 availableInfoLabel_ = new QLabel("Select a runner to download");
222 availableInfoLabel_->setWordWrap(true);
223 bottomLayout->addWidget(availableInfoLabel_, 1);
224
225 downloadBtn_ = new QPushButton("Download && Install");
226 downloadBtn_->setEnabled(false);
227 connect(downloadBtn_, &QPushButton::clicked, this, &RunnerManagerDialog::onDownloadSelected);
228 bottomLayout->addWidget(downloadBtn_);
229
230 layout->addLayout(bottomLayout);
231}
232
233void RunnerManagerDialog::setupDownloadsTab(QWidget* tab)
234{
235 auto* layout = new QVBoxLayout(tab);
236
237 // Current download progress
238 auto* progressGroup = new QGroupBox("Current Download");
239 auto* progressLayout = new QVBoxLayout(progressGroup);
240
241 downloadStatusLabel_ = new QLabel("No download in progress");
242 progressLayout->addWidget(downloadStatusLabel_);
243
244 currentProgress_ = new QProgressBar();
245 currentProgress_->setRange(0, 100);
246 currentProgress_->setValue(0);
247 progressLayout->addWidget(currentProgress_);
248
249 auto* progressBtnLayout = new QHBoxLayout();
250 progressBtnLayout->addStretch();
251 cancelDownloadBtn_ = new QPushButton("Cancel");
252 cancelDownloadBtn_->setEnabled(false);
253 progressBtnLayout->addWidget(cancelDownloadBtn_);
254 progressLayout->addLayout(progressBtnLayout);
255
256 layout->addWidget(progressGroup);
257
258 // Log output
259 auto* logGroup = new QGroupBox("Log");
260 auto* logLayout = new QVBoxLayout(logGroup);
261
262 logText_ = new QTextEdit();
263 logText_->setReadOnly(true);
264 logText_->setFont(QFont("monospace", 9));
265 logLayout->addWidget(logText_);
266
267 layout->addWidget(logGroup);
268}
269
270// ==============================================================================
271// Data Population
272// ==============================================================================
273
274void RunnerManagerDialog::populateInstalledRunners()
275{
276 installedList_->clear();
277
278 // Force refresh of system info
280 const auto& runners = SystemInfoService::instance().getInstalledRunners();
281
282 for (const auto& runner : runners)
283 {
284 auto* item = new QListWidgetItem();
285 item->setText(QString::fromStdString(runner.name));
286 item->setData(Qt::UserRole, QString::fromStdString(runner.path));
287 item->setData(Qt::UserRole + 1, QString::fromStdString(runner.type));
288 item->setData(Qt::UserRole + 2, QString::fromStdString(runner.version));
289
290 // Add type indicator
291 QString typeIcon;
292 if (runner.type == "proton-cachyos")
293 typeIcon = "[CachyOS] ";
294 else if (runner.type == "proton-ge")
295 typeIcon = "[GE] ";
296 else if (runner.type == "proton")
297 typeIcon = "[Proton] ";
298 else if (runner.type == "wine")
299 typeIcon = "[Wine] ";
300
301 item->setText(typeIcon + QString::fromStdString(runner.name));
302 installedList_->addItem(item);
303 }
304
305 appendLog(QString("Found %1 installed runner(s)").arg(runners.size()));
306}
307
308void RunnerManagerDialog::fetchAvailableRunners()
309{
310 refreshAvailableBtn_->setEnabled(false);
311 refreshAvailableBtn_->setText("Fetching...");
312 availableList_->clear();
313 availableRunners_.clear();
314
315 appendLog("Fetching available runners from GitHub...");
316
317 // Fetch GE-Proton releases
318 QFuture<QString> future = QtConcurrent::run(
319 []() -> QString
320 {
321 // Pulled out so clang-format doesn't reflow the URL into two
322 // adjacent string literals, which clang-tidy then flags as
323 // bugprone-suspicious-missing-comma (false positive — they're
324 // intentionally concatenated by the preprocessor).
325 static constexpr const char* kProtonGEReleasesUrl =
326 "https://api.github.com/repos/GloriousEggroll/proton-ge-custom/"
327 "releases?per_page=15";
328 QProcess proc;
329 proc.start("curl", {"-s", "-L", "--connect-timeout", "10", "--max-time", "30",
330 QString::fromUtf8(kProtonGEReleasesUrl)});
331 proc.waitForFinished(35000);
332
333 if (proc.exitCode() != 0)
334 {
335 return QString();
336 }
337 return QString::fromUtf8(proc.readAllStandardOutput());
338 });
339
340 fetchWatcher_->setFuture(future);
341}
342
343void RunnerManagerDialog::parseGitHubReleases(const QString& jsonData, const QString& source)
344{
345 if (jsonData.isEmpty())
346 {
347 appendLog("Failed to fetch releases from GitHub");
348 return;
349 }
350
351 QJsonDocument doc = QJsonDocument::fromJson(jsonData.toUtf8());
352 if (!doc.isArray())
353 {
354 appendLog("Invalid JSON response from GitHub");
355 return;
356 }
357
358 QJsonArray releases = doc.array();
359 int addedCount = 0;
360
361 for (const QJsonValue releaseVal : releases)
362 {
363 QJsonObject release = releaseVal.toObject();
364
365 AvailableRunner runner;
366 runner.name = release["tag_name"].toString();
367 runner.version = runner.name;
368 runner.type = "proton-ge";
369 runner.releaseNotes = release["body"].toString();
370 runner.isPrerelease = release["prerelease"].toBool();
371 runner.releaseDate = QDateTime::fromString(release["published_at"].toString(), Qt::ISODate);
372 runner.source = source;
373
374 // Find the .tar.gz asset
375 QJsonArray assets = release["assets"].toArray();
376 for (const QJsonValue assetVal : assets)
377 {
378 QJsonObject asset = assetVal.toObject();
379 QString assetName = asset["name"].toString();
380
381 if (assetName.endsWith(".tar.gz") && !assetName.contains("sha512"))
382 {
383 runner.downloadUrl = asset["browser_download_url"].toString();
384 runner.fileSizeBytes = asset["size"].toVariant().toLongLong();
385 break;
386 }
387 }
388
389 if (!runner.downloadUrl.isEmpty())
390 {
391 availableRunners_.append(runner);
392
393 auto* item = new QListWidgetItem();
394 QString label = runner.name;
395 if (runner.isPrerelease)
396 label += " (pre-release)";
397 label += QString(" - %1").arg(formatSize(runner.fileSizeBytes));
398
399 item->setText(label);
400 item->setData(Qt::UserRole, availableRunners_.size() - 1); // Index
401 item->setData(Qt::UserRole + 1, runner.type);
402 availableList_->addItem(item);
403 addedCount++;
404 }
405 }
406
407 appendLog(QString("Found %1 available GE-Proton release(s)").arg(addedCount));
408}
409
410// ==============================================================================
411// Slot Implementations
412// ==============================================================================
413
414void RunnerManagerDialog::onRefreshInstalled()
415{
416 appendLog("Refreshing installed runners...");
417 populateInstalledRunners();
418}
419
420void RunnerManagerDialog::onRefreshAvailable()
421{
422 fetchAvailableRunners();
423}
424
425void RunnerManagerDialog::onInstalledSelectionChanged()
426{
427 auto* item = installedList_->currentItem();
428 if (!item)
429 {
430 installedInfoLabel_->setText("Select a runner to see details");
431 removeBtn_->setEnabled(false);
432 return;
433 }
434
435 QString path = item->data(Qt::UserRole).toString();
436 QString type = item->data(Qt::UserRole + 1).toString();
437 QString version = item->data(Qt::UserRole + 2).toString();
438
439 QString info = QString("<b>Path:</b> %1<br><b>Type:</b> %2<br><b>Version:</b> %3")
440 .arg(path, type, version);
441 installedInfoLabel_->setText(info);
442
443 // Only allow removing user-installed runners (not Steam's)
444 bool canRemove = !path.contains("/Steam/steamapps/common/");
445 removeBtn_->setEnabled(canRemove);
446}
447
448void RunnerManagerDialog::onAvailableSelectionChanged()
449{
450 auto* item = availableList_->currentItem();
451 if (!item)
452 {
453 availableInfoLabel_->setText("Select a runner to download");
454 releaseNotesText_->clear();
455 downloadBtn_->setEnabled(false);
456 return;
457 }
458
459 int idx = item->data(Qt::UserRole).toInt();
460 if (idx < 0 || idx >= availableRunners_.size())
461 {
462 return;
463 }
464
465 const AvailableRunner& runner = availableRunners_[idx];
466
467 QString info = QString("<b>%1</b> - %2<br>Released: %3")
468 .arg(runner.name.toHtmlEscaped())
469 .arg(formatSize(runner.fileSizeBytes))
470 .arg(runner.releaseDate.toString("yyyy-MM-dd"));
471 availableInfoLabel_->setText(info);
472
473 releaseNotesText_->setMarkdown(runner.releaseNotes);
474 downloadBtn_->setEnabled(!isDownloading_);
475}
476
477void RunnerManagerDialog::onDownloadSelected()
478{
479 auto* item = availableList_->currentItem();
480 if (!item)
481 return;
482
483 int idx = item->data(Qt::UserRole).toInt();
484 if (idx < 0 || idx >= availableRunners_.size())
485 return;
486
487 startDownload(availableRunners_[idx]);
488}
489
490void RunnerManagerDialog::onRemoveSelected()
491{
492 auto* item = installedList_->currentItem();
493 if (!item)
494 return;
495
496 QString path = item->data(Qt::UserRole).toString();
497 QString name = item->text();
498
499 // Defense-in-depth (CWE-22): the path comes from a trusted scan of the
500 // runner install dirs, but before rm -rf'ing it, confirm it really is a
501 // runner directory — a direct child of a "compatibilitytools.d" folder — so
502 // a malformed/poisoned scan entry can never delete something outside the
503 // runner roots. Works across ~/.steam, ~/.local/share/Steam and Flatpak
504 // layouts without hardcoding a specific root.
505 {
506 std::error_code ec;
507 const std::filesystem::path canon =
508 std::filesystem::weakly_canonical(std::filesystem::path(path.toStdString()), ec);
509 if (ec || canon.empty() || canon.parent_path().filename() != "compatibilitytools.d")
510 {
511 QMessageBox::warning(
512 this, "Error",
513 "Refusing to remove: not a runner directory under compatibilitytools.d.");
514 return;
515 }
516 }
517
518 auto result = QMessageBox::question(
519 this, "Remove Runner",
520 QString("Remove runner '%1'?\n\nThis will delete:\n%2").arg(name, path),
521 QMessageBox::Yes | QMessageBox::No);
522
523 if (result != QMessageBox::Yes)
524 return;
525
526 QDir dir(path);
527 if (!dir.exists())
528 return;
529
530 appendLog(QString("Removing %1...").arg(path));
531
532 // A runner directory is hundreds of MB (up to ~1.5 GB); deleting it on the
533 // GUI thread (the old `rm -rf` + waitForFinished(30000)) froze the UI for
534 // seconds. Run it off-thread using the QtConcurrent + QPointer-guard +
535 // queued-completion pattern already used by startDownload() in this file.
536 // std::filesystem::remove_all handles symlinks safely (removes the link,
537 // not its target — matching the old `rm -rf` intent).
538 removeBtn_->setEnabled(false);
539 QPointer<RunnerManagerDialog> guard(this);
540 const std::string target = path.toStdString();
541 (void)QtConcurrent::run(
542 [guard, target]()
543 {
544 std::error_code ec;
545 std::filesystem::remove_all(target, ec);
546 const bool ok = !ec;
547 QMetaObject::invokeMethod(
548 guard,
549 [guard, ok]()
550 {
551 if (!guard)
552 return;
553 if (ok)
554 {
555 guard->appendLog("Runner removed successfully");
556 }
557 else
558 {
559 guard->appendLog("Failed to remove runner");
560 QMessageBox::warning(guard, "Error", "Failed to remove runner directory");
561 }
562 guard->populateInstalledRunners();
563 guard->removeBtn_->setEnabled(guard->installedList_->currentItem() != nullptr);
564 },
565 Qt::QueuedConnection);
566 });
567}
568
569// ==============================================================================
570// Download and Install
571// ==============================================================================
572
573void RunnerManagerDialog::startDownload(const AvailableRunner& runner)
574{
575 if (isDownloading_)
576 {
577 QMessageBox::information(this, "Download in Progress",
578 "Please wait for the current download to complete.");
579 return;
580 }
581
582 isDownloading_ = true;
583 downloadBtn_->setEnabled(false);
584 cancelDownloadBtn_->setEnabled(true);
585 tabWidget_->setCurrentIndex(2); // Switch to Downloads tab
586
587 QString installPath = getInstallPath();
588 // Use QFileInfo to extract just the base filename, preventing path traversal
589 // if the URL's last segment contains ".." or other directory components
590 QString fileName = QFileInfo(runner.downloadUrl.split('/').last()).fileName();
591 if (fileName.isEmpty() || fileName == "." || fileName == "..")
592 {
593 appendLog("Error: invalid filename in download URL");
594 isDownloading_ = false;
595 downloadBtn_->setEnabled(true);
596 cancelDownloadBtn_->setEnabled(false);
597 return;
598 }
599 currentDownloadPath_ = installPath + "/" + fileName;
600
601 downloadStatusLabel_->setText(QString("Downloading %1...").arg(runner.name));
602 currentProgress_->setValue(0);
603 appendLog(QString("Starting download: %1").arg(runner.downloadUrl));
604 appendLog(QString("Destination: %1").arg(currentDownloadPath_));
605
606 // Create install directory if needed
607 QDir().mkpath(installPath);
608
609 // Download using curl (matches codebase pattern)
610 // Capture currentDownloadPath_ by value to avoid accessing `this` in worker thread
611 QString downloadPath = currentDownloadPath_;
612
613 // Create the process on the main thread so cancelDownloadBtn_ can kill it.
614 downloadProcess_ = new QProcess(this);
615 connect(
616 cancelDownloadBtn_, &QPushButton::clicked, this,
617 [this]()
618 {
619 if (downloadProcess_ && downloadProcess_->state() != QProcess::NotRunning)
620 {
621 appendLog("Download cancelled by user.");
622 downloadProcess_->kill();
623 }
624 },
625 Qt::UniqueConnection);
626
627 QProcess* proc = downloadProcess_;
628 proc->start("curl", {"-L", "-o", downloadPath, "--progress-bar", runner.downloadUrl});
629
630 QPointer<RunnerManagerDialog> guard(this);
631 (void)QtConcurrent::run(
632 [guard, runner, installPath, downloadPath, proc]()
633 {
634 // Simple progress update (curl doesn't provide easy progress parsing)
635 while (proc->state() == QProcess::Running)
636 {
637 QThread::msleep(500);
638 // Update UI on main thread
639 QMetaObject::invokeMethod(
640 guard,
641 [guard]()
642 {
643 if (!guard)
644 return;
645 // Pulse progress bar for activity indication (cap at 95 to not
646 // show 100% until the download is actually confirmed done)
647 int val = guard->currentProgress_->value();
648 guard->currentProgress_->setValue(qMin(val + 5, 95));
649 },
650 Qt::QueuedConnection);
651 if (!guard)
652 return; // dialog closed — stop polling
653 }
654
655 proc->waitForFinished(-1);
656 bool success = (proc->exitCode() == 0 && proc->exitStatus() == QProcess::NormalExit);
657
658 QMetaObject::invokeMethod(
659 guard,
660 [guard, success, runner, installPath]()
661 {
662 if (!guard)
663 return;
664 if (success)
665 {
666 guard->appendLog("Download completed successfully");
667 guard->currentProgress_->setValue(100);
668 guard->downloadStatusLabel_->setText("Extracting...");
669
670 // Extract the archive
671 guard->installRunner(guard->currentDownloadPath_, runner.name);
672 }
673 else
674 {
675 guard->appendLog("Download failed");
676 guard->downloadStatusLabel_->setText("Download failed");
677 guard->isDownloading_ = false;
678 guard->downloadBtn_->setEnabled(true);
679 guard->cancelDownloadBtn_->setEnabled(false);
680 }
681 },
682 Qt::QueuedConnection);
683 });
684}
685
686void RunnerManagerDialog::installRunner(const QString& archivePath, const QString& runnerName)
687{
688 appendLog(QString("Extracting %1...").arg(archivePath));
689 downloadStatusLabel_->setText("Extracting...");
690
691 // Switch to indeterminate mode so the bar animates while tar runs (can be
692 // several minutes for large Proton builds) rather than freezing at 100%.
693 currentProgress_->setRange(0, 0);
694
695 QString installPath = getInstallPath();
696
697 QPointer<RunnerManagerDialog> guard(this);
698 (void)QtConcurrent::run(
699 [guard, archivePath, installPath, runnerName]()
700 {
701 QProcess proc;
702 proc.setWorkingDirectory(installPath);
703 // --no-absolute-filenames and --strip-leading-slashes prevent archive
704 // entries from writing outside the working directory
705 proc.start("tar",
706 {"-xzf", archivePath, "--no-absolute-filenames", "--strip-leading-slashes"});
707 proc.waitForFinished(300000); // 5 minute timeout for large archives
708
709 bool success = (proc.exitCode() == 0);
710
711 QMetaObject::invokeMethod(
712 guard,
713 [guard, success, archivePath, runnerName]()
714 {
715 if (!guard)
716 return;
717 if (success)
718 {
719 guard->appendLog("Extraction completed successfully");
720
721 // Clean up archive
722 QFile::remove(archivePath);
723 guard->appendLog("Cleaned up archive file");
724
725 guard->downloadStatusLabel_->setText(
726 QString("Installed %1").arg(runnerName));
727 guard->appendLog(
728 QString("Runner %1 installed successfully!").arg(runnerName));
729
730 // Refresh installed list
731 guard->populateInstalledRunners();
732 }
733 else
734 {
735 guard->appendLog("Extraction failed");
736 guard->downloadStatusLabel_->setText("Installation failed");
737 }
738
739 guard->isDownloading_ = false;
740 guard->downloadBtn_->setEnabled(true);
741 guard->cancelDownloadBtn_->setEnabled(false);
742 // Restore determinate range before setting final value.
743 guard->currentProgress_->setRange(0, 100);
744 guard->currentProgress_->setValue(success ? 100 : 0);
745 },
746 Qt::QueuedConnection);
747 });
748}
749
750// ==============================================================================
751// Helper Methods
752// ==============================================================================
753
754QString RunnerManagerDialog::getInstallPath() const
755{
756 // Default to Steam compatibility tools directory
757 QString steamPath = QDir::homePath() + "/.steam/root/compatibilitytools.d";
758 if (QDir(steamPath).exists())
759 {
760 return steamPath;
761 }
762
763 // Fallback to alternate Steam path
764 steamPath = QDir::homePath() + "/.local/share/Steam/compatibilitytools.d";
765 QDir().mkpath(steamPath);
766 return steamPath;
767}
768
769QString RunnerManagerDialog::formatSize(qint64 bytes) const
770{
771 if (bytes < 1024)
772 return QString("%1 B").arg(bytes);
773 if (bytes < 1024 * 1024)
774 return QString("%1 KB").arg(bytes / 1024);
775 if (bytes < 1024 * 1024 * 1024)
776 return QString("%1 MB").arg(bytes / (1024 * 1024));
777 return QString("%1 GB").arg(static_cast<double>(bytes) / (1024.0 * 1024.0 * 1024.0), 0, 'f', 2);
778}
779
780void RunnerManagerDialog::appendLog(const QString& message)
781{
782 QString timestamp = QDateTime::currentDateTime().toString("hh:mm:ss");
783 logText_->append(QString("[%1] %2").arg(timestamp, message));
784 Logger::info("[RunnerManager] {}", message.toStdString());
785}
786
787// ==============================================================================
788// Theme Support
789// ==============================================================================
790
791void RunnerManagerDialog::applyTheme()
792{
793 const ThemeColors& c = themeManager_->colors();
794
795 setStyleSheet(
796 QString("QDialog { background-color: %1; }"
797 "QGroupBox { color: %2; border: 1px solid %3; border-radius: 4px; "
798 "margin-top: 8px; padding-top: 8px; }"
799 "QGroupBox::title { subcontrol-origin: margin; left: 10px; padding: 0 5px; }"
800 "QListWidget { background-color: %4; border: 1px solid %3; color: %2; }"
801 "QListWidget::item:selected { background-color: %5; }"
802 "QListWidget::item:alternate { background-color: %6; }"
803 "QTextEdit { background-color: %4; border: 1px solid %3; color: %2; }"
804 "QLabel { color: %2; }"
805 "QComboBox { background-color: %4; border: 1px solid %3; color: %2; padding: 4px; }"
806 "QPushButton { background-color: %7; color: %2; border: 1px solid %3; "
807 "padding: 6px 12px; border-radius: 4px; }"
808 "QPushButton:hover { background-color: %8; }"
809 "QPushButton:disabled { background-color: %4; color: %9; }"
810 "QProgressBar { background-color: %4; border: 1px solid %3; border-radius: 3px; }"
811 "QProgressBar::chunk { background-color: %10; border-radius: 2px; }")
812 .arg(c.windowBackground.name()) // 1
813 .arg(c.textPrimary.name()) // 2
814 .arg(c.border.name()) // 3
815 .arg(c.inputBackground.name()) // 4
816 .arg(c.accent.name()) // 5
817 .arg(c.cardBackground.name()) // 6
818 .arg(c.cardBackground.name()) // 7
819 .arg(c.hoverBackground.name()) // 8
820 .arg(c.textMuted.name()) // 9
821 .arg(c.success.name())); // 10
822
823 // Style the download button specially
824 if (downloadBtn_)
825 {
826 downloadBtn_->setStyleSheet(
827 QString("QPushButton { background-color: %1; color: %2; font-weight: bold; }"
828 "QPushButton:hover { background-color: %3; }"
829 "QPushButton:disabled { background-color: %4; color: %5; }")
830 .arg(c.success.name())
831 .arg(c.textOnAccent.name())
832 .arg(ThemeManager::lightenColor(c.success, 15).name())
833 .arg(c.inputBackground.name())
834 .arg(c.textMuted.name()));
835 }
836}
static void info(const std::string &message, Args &&... args)
Log info message (general information).
Definition logger.h:108
RunnerManagerDialog(QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
static SystemInfoService & instance()
Get singleton instance.
const std::vector< RunnerInfo > & getInstalledRunners()
Get all installed runners (Proton/Wine versions).
void refreshRunners()
Refresh only runner list (faster than full refresh).
void themeChanged()
Emitted when theme or accent color changes.
static QColor lightenColor(const QColor &color, int amount)
Lighten a color by increasing its lightness.
QColor inputBackground
QColor cardBackground
QColor textPrimary
QColor windowBackground
QColor textMuted
QColor hoverBackground
QColor textOnAccent