23 #include "freedoomdialog.h" 25 #include "configuration/doomseekerconfig.h" 26 #include "fileutils.h" 27 #include "pathfinder/filesearchpath.h" 28 #include "pathfinder/pathfinder.h" 29 #include "pathfinder/wadpathfinder.h" 30 #include "ui_freedoomdialog.h" 34 #include <QMessageBox> 35 #include <wadseeker/entities/checksum.h> 36 #include <wadseeker/entities/modset.h> 37 #include <wadseeker/freedoom.h> 38 #include <wadseeker/modinstall.h> 40 DClass<FreedoomDialog> :
public Ui::FreedoomDialog
44 ModInstall *modInstall;
54 d->freedoom =
new Freedoom(
this);
55 this->connect(d->freedoom, SIGNAL(finished()), SLOT(applyFreedoomVersionInfo()));
57 d->modInstall =
new ModInstall(
this);
58 this->connect(d->modInstall, SIGNAL(finished()), SLOT(onModInstallFinished()));
59 this->connect(d->modInstall, SIGNAL(fileDownloadProgress(QString,qint64,qint64)),
60 SLOT(showFileDownloadProgress(QString,qint64,qint64)));
62 d->btnInstall->setEnabled(
false);
68 FreedoomDialog::~FreedoomDialog()
72 void FreedoomDialog::accept()
74 ModSet modSet = selectedModFiles();
77 QMessageBox::critical(
this, tr(
"Install Freedoom"),
78 tr(
"Select at least one file."));
82 showStatus(tr(
"Downloading & installing ..."));
83 d->targetDir = d->cboInstallPath->currentText();
84 d->modInstall->install(d->targetDir, modSet);
87 void FreedoomDialog::onModInstallFinished()
89 if (!d->modInstall->isError())
95 showError(d->modInstall->error());
98 void FreedoomDialog::updateConfig()
100 gConfig.doomseeker.enableFreedoomInstallation(d->targetDir);
101 gConfig.saveToFile();
104 void FreedoomDialog::fetchInfo()
108 showStatus(tr(
"Downloading Freedoom version info ..."));
109 d->freedoom->requestModSet();
112 void FreedoomDialog::resetProgressBar()
114 d->progressBar->setFormat(tr(
"Working ..."));
115 d->progressBar->show();
116 d->progressBar->setMaximum(0);
117 d->progressBar->setValue(0);
120 void FreedoomDialog::applyFreedoomVersionInfo()
122 if (!d->freedoom->isError())
123 showModInfo(d->freedoom->modSet());
125 showError(tr(
"Error: %1").arg(d->freedoom->error()));
128 void FreedoomDialog::showModInfo(
const ModSet &modSet)
131 d->workInProgressArea->hide();
133 d->wadsTable->setSortingEnabled(
false);
134 d->wadsTable->clearContents();
135 while (d->wadsTable->rowCount() > 0)
137 d->wadsTable->removeRow(d->wadsTable->rowCount() - 1);
139 for (
const ModFile &file : modSet.modFiles())
143 d->wadsTable->setSortingEnabled(
true);
144 d->btnInstall->setEnabled(
true);
147 void FreedoomDialog::insertModFile(
const ModFile &file)
151 QString location = pathFinder.find(file.fileName()).path();
153 QString status = tr(
"OK");
154 bool needsInstall =
false;
155 if (location.isEmpty())
158 status = tr(
"Missing");
162 QByteArray md5 = FileUtils::md5(location);
163 for (Checksum checksum : file.checksums())
165 if (md5 != checksum.hash() && checksum.algorithm() == QCryptographicHash::Md5)
167 status = tr(
"Different");
173 if (file.fileName().compare(
"freedm.wad", Qt::CaseInsensitive) == 0)
174 needsInstall =
false;
176 d->wadsTable->insertRow(d->wadsTable->rowCount());
177 int row = d->wadsTable->rowCount() - 1;
178 d->wadsTable->setItem(row, ColName,
new QTableWidgetItem(file.fileName()));
179 d->wadsTable->setItem(row, ColStatus,
new QTableWidgetItem(status));
181 auto checkBox =
new QCheckBox();
182 checkBox->setChecked(needsInstall);
183 d->wadsTable->setCellWidget(row, ColInstall, checkBox);
185 QString tooltip = tr(
"<p>File: %1<br>Version: %2<br>" 186 "Description: %3<br>Location: %4</p>")
187 .arg(file.name(), file.version(), file.description(), location);
189 for (
int col = 0; col < d->wadsTable->columnCount(); ++col)
191 QTableWidgetItem *item = d->wadsTable->item(row, col);
193 item->setToolTip(tooltip);
197 void FreedoomDialog::showError(
const QString &text)
199 d->btnRetry->setVisible(
true);
201 d->progressBar->hide();
204 void FreedoomDialog::showStatus(
const QString &text)
207 d->workInProgressArea->show();
208 d->btnInstall->setEnabled(
false);
209 d->lblWorkInProgress->setText(text);
212 ModSet FreedoomDialog::selectedModFiles()
const 215 for (
int row = 0; row < d->wadsTable->rowCount(); ++row)
217 auto checkbox =
static_cast<QCheckBox *
>(d->wadsTable->cellWidget(row, ColInstall));
218 if (checkbox->isChecked())
220 QString fileName = d->wadsTable->item(row, ColName)->text();
221 modSet.addModFile(d->freedoom->modSet().findFileName(fileName));
227 void FreedoomDialog::setupInstallPaths()
229 auto completer =
new QCompleter(
this);
230 completer->setModel(
new QDirModel(completer));
231 d->cboInstallPath->setCompleter(completer);
235 d->cboInstallPath->addItem(path.path());
237 d->cboInstallPath->setCurrentText(gConfig.wadseeker.targetDirectory);
240 void FreedoomDialog::setupWadsTable()
242 QHeaderView *header = d->wadsTable->horizontalHeader();
243 header->setSectionResizeMode(ColName, QHeaderView::Stretch);
244 header->setSectionResizeMode(ColStatus, QHeaderView::ResizeToContents);
245 header->setSectionResizeMode(ColInstall, QHeaderView::ResizeToContents);
246 d->wadsTable->setColumnWidth(ColName, 150);
249 void FreedoomDialog::showFileDownloadProgress(
const QString &file,
250 qint64 current, qint64 total)
252 d->progressBar->setFormat(tr(
"%1 %p%").arg(file));
253 d->progressBar->setMaximum(total);
254 d->progressBar->setValue(current);
Performs a case-insensitive (OS independent) file searches.
void setAllowAliases(bool allowed)
Can disable WAD aliasing for contexts where only specific WADs should be found.
Wrapper for PathFinder that specializes in findings WADs.