2013-12-08 20:35:57 +00:00
|
|
|
#include "installationpage.hpp"
|
|
|
|
|
2023-12-02 07:15:54 +00:00
|
|
|
#include <QComboBox>
|
2014-01-24 21:25:22 +00:00
|
|
|
#include <QFileDialog>
|
2014-01-27 15:51:22 +00:00
|
|
|
#include <QMessageBox>
|
2022-06-16 19:29:55 +00:00
|
|
|
#include <QThread>
|
2013-12-13 12:38:49 +00:00
|
|
|
|
2013-12-08 21:58:29 +00:00
|
|
|
#include "mainwizard.hpp"
|
|
|
|
|
2022-04-17 16:28:14 +00:00
|
|
|
Wizard::InstallationPage::InstallationPage(QWidget* parent, Config::GameSettings& gameSettings)
|
|
|
|
: QWizardPage(parent)
|
|
|
|
, mGameSettings(gameSettings)
|
2013-12-08 20:35:57 +00:00
|
|
|
{
|
2014-04-18 11:17:37 +00:00
|
|
|
mWizard = qobject_cast<MainWizard*>(parent);
|
|
|
|
|
2013-12-08 20:35:57 +00:00
|
|
|
setupUi(this);
|
2013-12-26 17:02:34 +00:00
|
|
|
|
|
|
|
mFinished = false;
|
2013-12-25 17:52:34 +00:00
|
|
|
|
2022-07-17 12:24:27 +00:00
|
|
|
mThread = std::make_unique<QThread>();
|
2024-03-06 01:37:40 +00:00
|
|
|
mUnshield = std::make_unique<UnshieldWorker>(mGameSettings.value("morrowind-bsa-filesize").value.toLongLong());
|
2022-07-17 12:24:27 +00:00
|
|
|
mUnshield->moveToThread(mThread.get());
|
2014-01-01 21:46:29 +00:00
|
|
|
|
2022-08-19 00:25:47 +00:00
|
|
|
connect(mThread.get(), &QThread::started, mUnshield.get(), &UnshieldWorker::extract);
|
2014-01-01 21:46:29 +00:00
|
|
|
|
2022-08-19 00:25:47 +00:00
|
|
|
connect(mUnshield.get(), &UnshieldWorker::finished, mThread.get(), &QThread::quit);
|
2013-12-25 17:52:34 +00:00
|
|
|
|
2022-08-19 00:25:47 +00:00
|
|
|
connect(mUnshield.get(), &UnshieldWorker::finished, this, &InstallationPage::installationFinished,
|
|
|
|
Qt::QueuedConnection);
|
2013-12-25 17:52:34 +00:00
|
|
|
|
2022-08-19 00:25:47 +00:00
|
|
|
connect(mUnshield.get(), &UnshieldWorker::error, this, &InstallationPage::installationError, Qt::QueuedConnection);
|
2014-01-17 12:21:44 +00:00
|
|
|
|
2022-08-19 00:25:47 +00:00
|
|
|
connect(
|
|
|
|
mUnshield.get(), &UnshieldWorker::textChanged, installProgressLabel, &QLabel::setText, Qt::QueuedConnection);
|
2013-12-25 17:52:34 +00:00
|
|
|
|
2022-08-19 00:25:47 +00:00
|
|
|
connect(mUnshield.get(), &UnshieldWorker::textChanged, logTextEdit, &QPlainTextEdit::appendPlainText,
|
|
|
|
Qt::QueuedConnection);
|
2013-12-25 17:52:34 +00:00
|
|
|
|
2022-08-19 00:25:47 +00:00
|
|
|
connect(mUnshield.get(), &UnshieldWorker::textChanged, mWizard, &MainWizard::addLogText, Qt::QueuedConnection);
|
2014-03-30 20:58:50 +00:00
|
|
|
|
2022-08-19 00:25:47 +00:00
|
|
|
connect(mUnshield.get(), &UnshieldWorker::progressChanged, installProgressBar, &QProgressBar::setValue,
|
|
|
|
Qt::QueuedConnection);
|
2013-12-26 17:02:34 +00:00
|
|
|
|
2022-08-19 00:25:47 +00:00
|
|
|
connect(mUnshield.get(), &UnshieldWorker::requestFileDialog, this, &InstallationPage::showFileDialog,
|
|
|
|
Qt::QueuedConnection);
|
2022-04-17 16:28:14 +00:00
|
|
|
|
2022-08-19 00:25:47 +00:00
|
|
|
connect(mUnshield.get(), &UnshieldWorker::requestOldVersionDialog, this, &InstallationPage::showOldVersionDialog,
|
|
|
|
Qt::QueuedConnection);
|
2014-04-18 11:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Wizard::InstallationPage::~InstallationPage()
|
|
|
|
{
|
|
|
|
if (mThread->isRunning())
|
|
|
|
{
|
|
|
|
mUnshield->stopWorker();
|
2015-12-08 20:41:35 +00:00
|
|
|
mThread->quit();
|
2014-04-18 11:17:37 +00:00
|
|
|
mThread->wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wizard::InstallationPage::initializePage()
|
|
|
|
{
|
|
|
|
QString path(field(QLatin1String("installation.path")).toString());
|
|
|
|
QStringList components(field(QLatin1String("installation.components")).toStringList());
|
|
|
|
|
|
|
|
logTextEdit->appendPlainText(QString("Installing to %1").arg(path));
|
|
|
|
logTextEdit->appendPlainText(QString("Installing %1.").arg(components.join(", ")));
|
|
|
|
|
|
|
|
installProgressBar->setMinimum(0);
|
|
|
|
|
|
|
|
// Set the progressbar maximum to a multiple of 100
|
|
|
|
// That way installing all three components would yield 300%
|
|
|
|
// When one component is done the bar will be filled by 33%
|
|
|
|
|
2017-08-09 05:20:49 +00:00
|
|
|
if (field(QLatin1String("installation.retailDisc")).toBool() == true)
|
|
|
|
{
|
2014-04-18 11:17:37 +00:00
|
|
|
installProgressBar->setMaximum((components.count() * 100));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (components.contains(QLatin1String("Tribunal")) && !mWizard->mInstallations[path].hasTribunal)
|
|
|
|
installProgressBar->setMaximum(100);
|
|
|
|
|
|
|
|
if (components.contains(QLatin1String("Bloodmoon")) && !mWizard->mInstallations[path].hasBloodmoon)
|
|
|
|
installProgressBar->setMaximum(installProgressBar->maximum() + 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
startInstallation();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wizard::InstallationPage::startInstallation()
|
|
|
|
{
|
|
|
|
QStringList components(field(QLatin1String("installation.components")).toStringList());
|
|
|
|
QString path(field(QLatin1String("installation.path")).toString());
|
2014-01-24 21:25:22 +00:00
|
|
|
|
2017-08-09 05:20:49 +00:00
|
|
|
if (field(QLatin1String("installation.retailDisc")).toBool() == true)
|
2013-12-25 17:52:34 +00:00
|
|
|
{
|
|
|
|
// Always install Morrowind
|
2014-01-27 21:54:14 +00:00
|
|
|
mUnshield->setInstallComponent(Wizard::Component_Morrowind, true);
|
2013-12-25 17:52:34 +00:00
|
|
|
|
|
|
|
if (components.contains(QLatin1String("Tribunal")))
|
2014-01-27 21:54:14 +00:00
|
|
|
mUnshield->setInstallComponent(Wizard::Component_Tribunal, true);
|
2013-12-25 17:52:34 +00:00
|
|
|
|
|
|
|
if (components.contains(QLatin1String("Bloodmoon")))
|
2014-01-27 21:54:14 +00:00
|
|
|
mUnshield->setInstallComponent(Wizard::Component_Bloodmoon, true);
|
2013-12-25 17:52:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Morrowind should already be installed
|
2014-01-27 21:54:14 +00:00
|
|
|
mUnshield->setInstallComponent(Wizard::Component_Morrowind, false);
|
2013-12-25 17:52:34 +00:00
|
|
|
|
|
|
|
if (components.contains(QLatin1String("Tribunal")) && !mWizard->mInstallations[path].hasTribunal)
|
2014-01-27 21:54:14 +00:00
|
|
|
mUnshield->setInstallComponent(Wizard::Component_Tribunal, true);
|
2013-12-25 17:52:34 +00:00
|
|
|
|
|
|
|
if (components.contains(QLatin1String("Bloodmoon")) && !mWizard->mInstallations[path].hasBloodmoon)
|
2014-01-27 21:54:14 +00:00
|
|
|
mUnshield->setInstallComponent(Wizard::Component_Bloodmoon, true);
|
2013-12-25 17:52:34 +00:00
|
|
|
|
2013-12-26 17:02:34 +00:00
|
|
|
// Set the location of the Morrowind.ini to update
|
2014-04-17 00:15:06 +00:00
|
|
|
mUnshield->setIniPath(mWizard->mInstallations[path].iniPath);
|
2014-02-18 10:55:26 +00:00
|
|
|
mUnshield->setupSettings();
|
2013-12-26 17:02:34 +00:00
|
|
|
}
|
2013-12-25 17:52:34 +00:00
|
|
|
|
|
|
|
// Set the installation target path
|
2014-01-24 21:25:22 +00:00
|
|
|
mUnshield->setPath(path);
|
2013-12-25 17:52:34 +00:00
|
|
|
|
2013-12-26 17:02:34 +00:00
|
|
|
// Set the right codec to use for Morrowind.ini
|
2023-12-19 06:20:31 +00:00
|
|
|
QString language(field(QLatin1String("installation.language")).toString());
|
2013-12-26 17:02:34 +00:00
|
|
|
|
|
|
|
if (language == QLatin1String("Polish"))
|
|
|
|
{
|
2023-01-19 11:07:12 +00:00
|
|
|
mUnshield->setIniEncoding(ToUTF8::FromType::WINDOWS_1250);
|
2014-02-07 23:09:25 +00:00
|
|
|
}
|
|
|
|
else if (language == QLatin1String("Russian"))
|
|
|
|
{
|
2023-01-19 11:07:12 +00:00
|
|
|
mUnshield->setIniEncoding(ToUTF8::FromType::WINDOWS_1251);
|
2014-02-07 23:09:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-19 11:07:12 +00:00
|
|
|
mUnshield->setIniEncoding(ToUTF8::FromType::WINDOWS_1252);
|
2013-12-26 17:02:34 +00:00
|
|
|
}
|
|
|
|
|
2014-03-17 13:31:05 +00:00
|
|
|
mThread->start();
|
2014-01-24 21:25:22 +00:00
|
|
|
}
|
|
|
|
|
2014-01-27 21:54:14 +00:00
|
|
|
void Wizard::InstallationPage::showFileDialog(Wizard::Component component)
|
2014-01-24 21:25:22 +00:00
|
|
|
{
|
2014-01-28 12:27:09 +00:00
|
|
|
QString name;
|
|
|
|
switch (component)
|
|
|
|
{
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2014-01-28 12:27:09 +00:00
|
|
|
case Wizard::Component_Morrowind:
|
|
|
|
name = QLatin1String("Morrowind");
|
|
|
|
break;
|
|
|
|
case Wizard::Component_Tribunal:
|
|
|
|
name = QLatin1String("Tribunal");
|
|
|
|
break;
|
|
|
|
case Wizard::Component_Bloodmoon:
|
|
|
|
name = QLatin1String("Bloodmoon");
|
|
|
|
break;
|
|
|
|
}
|
2020-01-22 20:39:12 +00:00
|
|
|
logTextEdit->appendHtml(tr("<p>Attempting to install component %1.</p>").arg(name));
|
|
|
|
mWizard->addLogText(tr("Attempting to install component %1.").arg(name));
|
|
|
|
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setWindowTitle(tr("%1 Installation").arg(name));
|
|
|
|
msgBox.setIcon(QMessageBox::Information);
|
|
|
|
msgBox.setText(
|
|
|
|
QObject::tr("Select a valid %1 installation media.<br><b>Hint</b>: make sure that it contains at least one "
|
|
|
|
"<b>.cab</b> file.")
|
|
|
|
.arg(name));
|
|
|
|
msgBox.exec();
|
2014-01-28 12:27:09 +00:00
|
|
|
|
2014-03-16 21:09:20 +00:00
|
|
|
QString path
|
|
|
|
= QFileDialog::getExistingDirectory(this, tr("Select %1 installation media").arg(name), QDir::rootPath());
|
|
|
|
|
|
|
|
if (path.isEmpty())
|
|
|
|
{
|
2014-02-25 14:33:30 +00:00
|
|
|
logTextEdit->appendHtml(
|
2023-11-29 05:28:40 +00:00
|
|
|
tr("<p><br/><span style=\"color:red;\">"
|
|
|
|
"<b>Error: The installation was aborted by the user</b></span></p>"));
|
2014-03-30 20:58:50 +00:00
|
|
|
|
|
|
|
mWizard->addLogText(QLatin1String("Error: The installation was aborted by the user"));
|
2014-02-25 14:33:30 +00:00
|
|
|
mWizard->mError = true;
|
2014-03-17 13:31:05 +00:00
|
|
|
|
2014-02-25 14:33:30 +00:00
|
|
|
emit completeChanged();
|
2014-01-27 21:54:14 +00:00
|
|
|
return;
|
2014-01-24 21:25:22 +00:00
|
|
|
}
|
2014-01-27 21:54:14 +00:00
|
|
|
|
2014-03-16 21:09:20 +00:00
|
|
|
mUnshield->setDiskPath(path);
|
2013-12-25 17:52:34 +00:00
|
|
|
}
|
|
|
|
|
2022-04-17 16:28:14 +00:00
|
|
|
void Wizard::InstallationPage::showOldVersionDialog()
|
|
|
|
{
|
|
|
|
logTextEdit->appendHtml(tr("<p>Detected old version of component Morrowind.</p>"));
|
|
|
|
mWizard->addLogText(tr("Detected old version of component Morrowind."));
|
|
|
|
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setWindowTitle(tr("Morrowind Installation"));
|
|
|
|
msgBox.setIcon(QMessageBox::Information);
|
|
|
|
msgBox.setText(QObject::tr(
|
|
|
|
"There may be a more recent version of Morrowind available.<br><br>Do you wish to continue anyway?"));
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
|
|
|
msgBox.setDefaultButton(QMessageBox::No);
|
|
|
|
|
|
|
|
int ret = msgBox.exec();
|
|
|
|
if (ret == QMessageBox::No)
|
|
|
|
{
|
|
|
|
logTextEdit->appendHtml(
|
2023-11-29 05:28:40 +00:00
|
|
|
tr("<p><br/><span style=\"color:red;\">"
|
|
|
|
"<b>Error: The installation was aborted by the user</b></span></p>"));
|
2022-04-17 16:28:14 +00:00
|
|
|
|
|
|
|
mWizard->addLogText(QLatin1String("Error: The installation was aborted by the user"));
|
|
|
|
mWizard->mError = true;
|
|
|
|
|
|
|
|
emit completeChanged();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mUnshield->wakeAll();
|
|
|
|
}
|
|
|
|
|
2013-12-25 17:52:34 +00:00
|
|
|
void Wizard::InstallationPage::installationFinished()
|
|
|
|
{
|
2014-01-27 15:51:22 +00:00
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setWindowTitle(tr("Installation finished"));
|
|
|
|
msgBox.setIcon(QMessageBox::Information);
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
2014-12-22 09:45:34 +00:00
|
|
|
msgBox.setText(tr("Installation completed successfully!"));
|
2014-01-27 15:51:22 +00:00
|
|
|
|
|
|
|
msgBox.exec();
|
|
|
|
|
2013-12-25 17:52:34 +00:00
|
|
|
mFinished = true;
|
2013-12-26 17:02:34 +00:00
|
|
|
emit completeChanged();
|
2014-01-17 12:21:44 +00:00
|
|
|
}
|
|
|
|
|
2014-01-28 00:03:47 +00:00
|
|
|
void Wizard::InstallationPage::installationError(const QString& text, const QString& details)
|
2014-01-17 12:21:44 +00:00
|
|
|
{
|
2014-01-28 00:03:47 +00:00
|
|
|
installProgressLabel->setText(tr("Installation failed!"));
|
|
|
|
|
2023-11-29 05:28:40 +00:00
|
|
|
logTextEdit->appendHtml(tr("<p><br/><span style=\"color:red;\"><b>Error: %1</b></p>").arg(text));
|
|
|
|
logTextEdit->appendHtml(tr("<p><span style=\"color:red;\"><b>%1</b></p>").arg(details));
|
2014-01-28 00:03:47 +00:00
|
|
|
|
2014-03-30 20:58:50 +00:00
|
|
|
mWizard->addLogText(QLatin1String("Error: ") + text);
|
|
|
|
mWizard->addLogText(details);
|
|
|
|
|
|
|
|
mWizard->mError = true;
|
2014-01-28 00:03:47 +00:00
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setWindowTitle(tr("An error occurred"));
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
msgBox.setText(
|
2023-11-29 05:28:40 +00:00
|
|
|
tr("<html><head/><body><p><b>The Wizard has encountered an error</b></p>"
|
|
|
|
"<p>The error reported was:</p><p>%1</p>"
|
|
|
|
"<p>Press "Show Details..." for more information.</p></body></html>")
|
2014-01-28 00:03:47 +00:00
|
|
|
.arg(text));
|
|
|
|
|
|
|
|
msgBox.setDetailedText(details);
|
|
|
|
msgBox.exec();
|
|
|
|
|
|
|
|
emit completeChanged();
|
2013-12-25 17:52:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Wizard::InstallationPage::isComplete() const
|
|
|
|
{
|
2014-01-28 00:03:47 +00:00
|
|
|
if (!mWizard->mError)
|
|
|
|
{
|
|
|
|
return mFinished;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2013-12-25 17:52:34 +00:00
|
|
|
}
|
|
|
|
|
2013-12-08 21:58:29 +00:00
|
|
|
int Wizard::InstallationPage::nextId() const
|
|
|
|
{
|
2017-08-09 05:20:49 +00:00
|
|
|
if (field(QLatin1String("installation.retailDisc")).toBool() == true)
|
|
|
|
{
|
2014-01-28 00:03:47 +00:00
|
|
|
return MainWizard::Page_Conclusion;
|
2014-02-25 14:33:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!mWizard->mError)
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2014-02-25 14:33:30 +00:00
|
|
|
return MainWizard::Page_Import;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return MainWizard::Page_Conclusion;
|
|
|
|
}
|
2014-01-28 00:03:47 +00:00
|
|
|
}
|
2013-12-08 21:58:29 +00:00
|
|
|
}
|