18#include <QStandardPaths>
19#include <QStorageInfo>
25 : QDialog(parent), script_(script),
26 themeManager_(themeManager ? themeManager : &
ThemeManager::instance())
29 setWindowTitle(QString(
"Install %1").arg(QString::fromStdString(script.
gameName)));
32 populateScriptDetails();
36void LutrisInstallPreviewDialog::setupUI()
38 QVBoxLayout* mainLayout =
new QVBoxLayout(
this);
41 QLabel* headerLabel =
new QLabel(
this);
42 headerLabel->setText(QString(
"<h2>%1</h2><p>Installer: %2 (%3)</p>")
43 .arg(QString::fromStdString(script_.
gameName).toHtmlEscaped())
44 .arg(QString::fromStdString(script_.
installerSlug).toHtmlEscaped())
45 .arg(QString::fromStdString(script_.
runner).toHtmlEscaped()));
46 mainLayout->addWidget(headerLabel);
49 QTabWidget* tabs =
new QTabWidget(
this);
54 QWidget* configTab =
new QWidget();
55 QVBoxLayout* configLayout =
new QVBoxLayout(configTab);
58 QGroupBox* locationGroup =
new QGroupBox(
"Install Location", configTab);
59 QVBoxLayout* locationLayout =
new QVBoxLayout(locationGroup);
61 QHBoxLayout* installDirLayout =
new QHBoxLayout();
62 installDirEdit_ =
new QLineEdit(locationGroup);
66 QDir::homePath() +
"/Games/" +
67 QString::fromStdString(script_.
gameName).replace(QRegularExpression(
"[^a-zA-Z0-9_-]"),
"_");
68 installDirEdit_->setText(defaultDir);
69 installDirLayout->addWidget(installDirEdit_);
71 installDirBrowseBtn_ =
new QPushButton(
"Browse...", locationGroup);
72 connect(installDirBrowseBtn_, &QPushButton::clicked,
this,
73 &LutrisInstallPreviewDialog::onBrowseInstallDir);
74 installDirLayout->addWidget(installDirBrowseBtn_);
75 locationLayout->addLayout(installDirLayout);
77 diskSpaceLabel_ =
new QLabel(locationGroup);
78 locationLayout->addWidget(diskSpaceLabel_);
80 configLayout->addWidget(locationGroup);
83 wineGroup_ =
new QGroupBox(
"Wine Configuration", configTab);
84 QFormLayout* wineLayout =
new QFormLayout(wineGroup_);
87 QHBoxLayout* prefixLayout =
new QHBoxLayout();
88 winePrefixEdit_ =
new QLineEdit(wineGroup_);
89 QString defaultPrefix =
90 QDir::homePath() +
"/.wine-" +
91 QString::fromStdString(script_.
gameSlug).replace(QRegularExpression(
"[^a-zA-Z0-9_-]"),
"_");
92 winePrefixEdit_->setText(defaultPrefix);
93 prefixLayout->addWidget(winePrefixEdit_);
95 winePrefixBrowseBtn_ =
new QPushButton(
"Browse...", wineGroup_);
96 connect(winePrefixBrowseBtn_, &QPushButton::clicked,
this,
97 &LutrisInstallPreviewDialog::onBrowseWinePrefix);
98 prefixLayout->addWidget(winePrefixBrowseBtn_);
99 wineLayout->addRow(
"Wine Prefix:", prefixLayout);
102 wineVersionCombo_ =
new QComboBox(wineGroup_);
103 wineVersionCombo_->addItem(
"System Wine",
"system");
104 wineVersionCombo_->addItem(
"Proton (Steam)",
"proton");
105 wineVersionCombo_->addItem(
"Wine-GE",
"wine-ge");
106 wineVersionCombo_->addItem(
"Proton-GE",
"proton-ge");
107 wineLayout->addRow(
"Wine Version:", wineVersionCombo_);
110 QHBoxLayout* wineOptionsLayout =
new QHBoxLayout();
112 dxvkCheck_ =
new QCheckBox(
"DXVK", wineGroup_);
113 dxvkCheck_->setChecked(
true);
114 dxvkCheck_->setToolTip(
"Vulkan-based DirectX 9/10/11 translation layer");
115 wineOptionsLayout->addWidget(dxvkCheck_);
117 vkd3dCheck_ =
new QCheckBox(
"VKD3D", wineGroup_);
118 vkd3dCheck_->setChecked(
true);
119 vkd3dCheck_->setToolTip(
"Vulkan-based DirectX 12 translation layer");
120 wineOptionsLayout->addWidget(vkd3dCheck_);
122 esyncCheck_ =
new QCheckBox(
"Esync", wineGroup_);
123 esyncCheck_->setChecked(
true);
124 esyncCheck_->setToolTip(
"Eventfd-based synchronization (improves performance)");
125 wineOptionsLayout->addWidget(esyncCheck_);
127 fsyncCheck_ =
new QCheckBox(
"Fsync", wineGroup_);
128 fsyncCheck_->setChecked(
true);
129 fsyncCheck_->setToolTip(
"Futex-based synchronization (requires kernel support)");
130 wineOptionsLayout->addWidget(fsyncCheck_);
132 wineOptionsLayout->addStretch();
133 wineLayout->addRow(
"Options:", wineOptionsLayout);
135 configLayout->addWidget(wineGroup_);
138 wineGroup_->setVisible(script_.
runner ==
"wine");
140 configLayout->addStretch();
141 tabs->addTab(configTab,
"Configuration");
146 QWidget* filesTab =
new QWidget();
147 QVBoxLayout* filesLayout =
new QVBoxLayout(filesTab);
149 QLabel* filesInfoLabel =
new QLabel(
"The following files will be downloaded:", filesTab);
150 filesLayout->addWidget(filesInfoLabel);
152 filesTree_ =
new QTreeWidget(filesTab);
153 filesTree_->setHeaderLabels({
"File",
"URL",
"Size"});
154 filesTree_->setRootIsDecorated(
false);
155 filesTree_->header()->setStretchLastSection(
false);
156 filesTree_->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
157 filesTree_->header()->setSectionResizeMode(1, QHeaderView::Stretch);
158 filesTree_->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
159 filesLayout->addWidget(filesTree_);
161 totalDownloadLabel_ =
new QLabel(filesTab);
162 filesLayout->addWidget(totalDownloadLabel_);
164 tabs->addTab(filesTab,
"Files to Download");
169 QWidget* stepsTab =
new QWidget();
170 QVBoxLayout* stepsLayout =
new QVBoxLayout(stepsTab);
172 QLabel* stepsInfoLabel =
new QLabel(
"Installation steps that will be executed:", stepsTab);
173 stepsLayout->addWidget(stepsInfoLabel);
175 stepsTree_ =
new QTreeWidget(stepsTab);
176 stepsTree_->setHeaderLabels({
"#",
"Action",
"Details"});
177 stepsTree_->setRootIsDecorated(
false);
178 stepsTree_->header()->setStretchLastSection(
false);
179 stepsTree_->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
180 stepsTree_->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
181 stepsTree_->header()->setSectionResizeMode(2, QHeaderView::Stretch);
182 stepsLayout->addWidget(stepsTree_);
184 tabs->addTab(stepsTab,
"Installation Steps");
189 QWidget* detailsTab =
new QWidget();
190 QVBoxLayout* detailsLayout =
new QVBoxLayout(detailsTab);
192 QLabel* detailsInfoLabel =
new QLabel(
"Raw installer script details:", detailsTab);
193 detailsLayout->addWidget(detailsInfoLabel);
195 scriptDetailsText_ =
new QTextEdit(detailsTab);
196 scriptDetailsText_->setReadOnly(
true);
197 scriptDetailsText_->setFontFamily(
"monospace");
198 detailsLayout->addWidget(scriptDetailsText_);
200 tabs->addTab(detailsTab,
"Script Details");
202 mainLayout->addWidget(tabs, 1);
207 QHBoxLayout* buttonLayout =
new QHBoxLayout();
208 buttonLayout->addStretch();
210 installBtn_ =
new QPushButton(
"Install",
this);
211 installBtn_->setDefault(
true);
212 connect(installBtn_, &QPushButton::clicked,
this,
213 &LutrisInstallPreviewDialog::onInstallClicked);
214 buttonLayout->addWidget(installBtn_);
216 cancelBtn_ =
new QPushButton(
"Cancel",
this);
217 connect(cancelBtn_, &QPushButton::clicked,
this, &QDialog::reject);
218 buttonLayout->addWidget(cancelBtn_);
220 mainLayout->addLayout(buttonLayout);
223 connect(installDirEdit_, &QLineEdit::textChanged,
this,
224 &LutrisInstallPreviewDialog::onValidateConfig);
225 connect(winePrefixEdit_, &QLineEdit::textChanged,
this,
226 &LutrisInstallPreviewDialog::onValidateConfig);
229void LutrisInstallPreviewDialog::populateScriptDetails()
233 uint64_t totalSize = 0;
235 for (
const auto& file : script_.files)
237 QTreeWidgetItem* item =
new QTreeWidgetItem();
238 item->setText(0, QString::fromStdString(file.filename.empty() ? file.id : file.filename));
239 item->setText(1, QString::fromStdString(file.url));
240 item->setText(2, file.size > 0 ? formatSize(file.size) :
"Unknown");
241 item->setToolTip(1, QString::fromStdString(file.url));
242 filesTree_->addTopLevelItem(item);
243 totalSize += file.size;
246 if (script_.files.empty())
248 QTreeWidgetItem* item =
new QTreeWidgetItem();
249 item->setText(0,
"(No files to download)");
250 item->setForeground(0, themeManager_->colors().textSecondary);
251 filesTree_->addTopLevelItem(item);
252 totalDownloadLabel_->setText(
"No files to download");
256 totalDownloadLabel_->setText(QString(
"Total download size: %1 (%2 file(s))")
257 .arg(totalSize > 0 ? formatSize(totalSize) :
"Unknown")
258 .arg(script_.files.size()));
264 for (
const auto& step : script_.steps)
266 QTreeWidgetItem* item =
new QTreeWidgetItem();
267 item->setText(0, QString::number(stepNum++));
268 item->setText(1, QString::fromStdString(step.task));
269 item->setText(2, QString::fromStdString(step.description));
270 item->setToolTip(2, QString::fromStdString(step.description));
271 stepsTree_->addTopLevelItem(item);
274 if (script_.steps.empty())
276 QTreeWidgetItem* item =
new QTreeWidgetItem();
277 item->setText(0,
"-");
278 item->setText(1,
"(No steps)");
279 item->setForeground(1, themeManager_->colors().textSecondary);
280 stepsTree_->addTopLevelItem(item);
285 details += QString(
"Game: %1\n").arg(QString::fromStdString(script_.gameName));
286 details += QString(
"Slug: %1\n").arg(QString::fromStdString(script_.gameSlug));
287 details += QString(
"Installer: %1\n").arg(QString::fromStdString(script_.installerSlug));
288 details += QString(
"Runner: %1\n").arg(QString::fromStdString(script_.runner));
289 details += QString(
"\n");
291 if (!script_.executable.empty())
293 details += QString(
"Executable: %1\n").arg(QString::fromStdString(script_.executable));
295 if (!script_.workingDir.empty())
297 details += QString(
"Working Dir: %1\n").arg(QString::fromStdString(script_.workingDir));
299 if (!script_.arguments.empty())
301 details += QString(
"Arguments: %1\n").arg(QString::fromStdString(script_.arguments));
304 if (!script_.environmentVariables.empty())
306 details += QString(
"\nEnvironment Variables:\n");
307 for (
const auto& [key, value] : script_.environmentVariables)
309 details += QString(
" %1=%2\n")
310 .arg(QString::fromStdString(key))
311 .arg(QString::fromStdString(value));
315 if (script_.runner ==
"wine")
317 details += QString(
"\nWine Configuration:\n");
318 if (!script_.wineConfig.version.empty())
321 QString(
" Version: %1\n").arg(QString::fromStdString(script_.wineConfig.version));
323 details += QString(
" DXVK: %1\n").arg(script_.wineConfig.dxvk ?
"Yes" :
"No");
324 details += QString(
" VKD3D: %1\n").arg(script_.wineConfig.vkd3d ?
"Yes" :
"No");
325 details += QString(
" Esync: %1\n").arg(script_.wineConfig.esync ?
"Yes" :
"No");
326 details += QString(
" Fsync: %1\n").arg(script_.wineConfig.fsync ?
"Yes" :
"No");
329 scriptDetailsText_->setPlainText(details);
332 if (script_.runner ==
"wine")
334 dxvkCheck_->setChecked(script_.wineConfig.dxvk);
335 vkd3dCheck_->setChecked(script_.wineConfig.vkd3d);
336 esyncCheck_->setChecked(script_.wineConfig.esync);
337 fsyncCheck_->setChecked(script_.wineConfig.fsync);
340 updateDiskSpaceInfo();
343void LutrisInstallPreviewDialog::updateDiskSpaceInfo()
345 QString installDir = installDirEdit_->text();
346 if (installDir.isEmpty())
348 diskSpaceLabel_->setText(
"Please specify an install directory");
353 QDir dir(installDir);
354 while (!dir.exists() && !dir.isRoot())
359 QStorageInfo storage(dir.absolutePath());
360 if (storage.isValid())
362 QString available = formatSize(
static_cast<uint64_t
>(storage.bytesAvailable()));
363 QString total = formatSize(
static_cast<uint64_t
>(storage.bytesTotal()));
364 diskSpaceLabel_->setText(
365 QString(
"Available disk space: %1 / %2").arg(available).arg(total));
369 diskSpaceLabel_->setText(
"Unable to determine disk space");
373void LutrisInstallPreviewDialog::onBrowseInstallDir()
375 QString dir = QFileDialog::getExistingDirectory(
376 this,
"Select Install Directory",
377 installDirEdit_->text().isEmpty() ? QDir::homePath() : installDirEdit_->text());
381 installDirEdit_->setText(dir);
385void LutrisInstallPreviewDialog::onBrowseWinePrefix()
387 QString dir = QFileDialog::getExistingDirectory(
388 this,
"Select Wine Prefix Directory",
389 winePrefixEdit_->text().isEmpty() ? QDir::homePath() : winePrefixEdit_->text());
393 winePrefixEdit_->setText(dir);
397void LutrisInstallPreviewDialog::onInstallClicked()
400 QString installDir = installDirEdit_->text().trimmed();
401 if (installDir.isEmpty())
403 QMessageBox::warning(
this,
"Invalid Configuration",
"Please specify an install directory.");
407 if (script_.runner ==
"wine")
409 QString winePrefix = winePrefixEdit_->text().trimmed();
410 if (winePrefix.isEmpty())
412 QMessageBox::warning(
this,
"Invalid Configuration",
413 "Please specify a Wine prefix directory.");
421void LutrisInstallPreviewDialog::onValidateConfig()
423 updateDiskSpaceInfo();
427 if (installDirEdit_->text().trimmed().isEmpty())
432 if (script_.runner ==
"wine" && winePrefixEdit_->text().trimmed().isEmpty())
437 installBtn_->setEnabled(valid);
443 config.
installPath = installDirEdit_->text().toStdString();
448 QString wineVersion = wineVersionCombo_->currentData().toString();
454QString LutrisInstallPreviewDialog::formatSize(uint64_t bytes)
const
459 const char* units[] = {
"B",
"KB",
"MB",
"GB",
"TB"};
461 double size =
static_cast<double>(bytes);
463 while (size >= 1024.0 && unitIndex < 4)
471 return QString(
"%1 B").arg(
static_cast<int>(size));
475 return QString(
"%1 %2").arg(size, 0,
'f', 1).arg(units[unitIndex]);
LutrisInstallPreviewDialog(const LutrisInstallerScript &script, QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
InstallConfig getInstallConfig() const
std::string downloadCachePath
std::string winePrefixPath
std::string installerSlug