2023-08-05 22:14:05 -04:00
|
|
|
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-03-16 18:39:13 -04:00
|
|
|
#include "gameinstaller.h"
|
|
|
|
|
2023-09-16 21:28:22 -04:00
|
|
|
#include <KLocalizedString>
|
2022-08-15 11:14:37 -04:00
|
|
|
#include <QFile>
|
2022-03-16 18:39:13 -04:00
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QStandardPaths>
|
2022-07-21 20:53:19 -04:00
|
|
|
#include <physis.hpp>
|
2022-03-16 18:39:13 -04:00
|
|
|
|
2023-10-08 18:02:02 -04:00
|
|
|
#include "astra_log.h"
|
2022-03-16 18:39:13 -04:00
|
|
|
#include "launchercore.h"
|
2023-07-30 08:49:34 -04:00
|
|
|
#include "profile.h"
|
2023-10-08 18:02:02 -04:00
|
|
|
#include "utility.h"
|
2023-07-30 08:49:34 -04:00
|
|
|
|
2023-08-18 12:59:07 -04:00
|
|
|
const QString installerUrl = QStringLiteral("https://download.finalfantasyxiv.com/inst/ffxivsetup.exe");
|
|
|
|
const QByteArray installerSha256 = QByteArray::fromHex("cf70bfaaf4f429794358ef84acbcbdc4193bee109fa1b6aea81bd4de038e500e");
|
|
|
|
|
2023-07-30 08:49:34 -04:00
|
|
|
GameInstaller::GameInstaller(LauncherCore &launcher, Profile &profile, QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_launcher(launcher)
|
|
|
|
, m_profile(profile)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameInstaller::installGame()
|
|
|
|
{
|
2023-08-18 12:59:07 -04:00
|
|
|
const QDir installDirectory = m_profile.gamePath();
|
2022-03-16 18:39:13 -04:00
|
|
|
|
2023-08-18 12:59:07 -04:00
|
|
|
QNetworkRequest request((QUrl(installerUrl)));
|
2022-03-16 18:39:13 -04:00
|
|
|
|
2023-10-11 13:34:43 -04:00
|
|
|
auto reply = m_launcher.mgr()->get(request);
|
2023-10-08 18:02:02 -04:00
|
|
|
Utility::printRequest(QStringLiteral("GET"), request);
|
|
|
|
|
2023-07-30 08:49:34 -04:00
|
|
|
QObject::connect(reply, &QNetworkReply::finished, [this, reply, installDirectory] {
|
2023-08-18 21:59:42 -04:00
|
|
|
if (reply->error() != QNetworkReply::NetworkError::NoError) {
|
2023-09-16 21:28:22 -04:00
|
|
|
Q_EMIT error(i18n("An error has occurred when downloading the installer.\n\n%1", reply->errorString()));
|
2023-08-18 21:59:42 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-18 12:59:07 -04:00
|
|
|
const QDir dataDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
|
|
|
|
|
|
|
|
const QByteArray data = reply->readAll();
|
|
|
|
QCryptographicHash hash(QCryptographicHash::Sha256);
|
|
|
|
hash.addData(data);
|
2022-03-16 18:39:13 -04:00
|
|
|
|
2023-08-18 12:59:07 -04:00
|
|
|
// TODO: turn into a proper error
|
|
|
|
Q_ASSERT(hash.result() == installerSha256);
|
|
|
|
|
2023-12-17 10:09:01 -05:00
|
|
|
QFile file(dataDir.absoluteFilePath(QStringLiteral("ffxivsetup.exe")));
|
2022-03-16 18:39:13 -04:00
|
|
|
file.open(QIODevice::WriteOnly);
|
2023-08-18 12:59:07 -04:00
|
|
|
file.write(data);
|
2022-03-16 18:39:13 -04:00
|
|
|
file.close();
|
|
|
|
|
2023-08-18 12:59:07 -04:00
|
|
|
const std::string installDirectoryStd = installDirectory.absolutePath().toStdString();
|
2023-05-13 17:37:30 -04:00
|
|
|
const std::string fileNameStd = file.fileName().toStdString();
|
|
|
|
|
|
|
|
physis_install_game(fileNameStd.c_str(), installDirectoryStd.c_str());
|
2022-03-16 18:39:13 -04:00
|
|
|
|
2023-10-08 19:14:17 -04:00
|
|
|
m_profile.readGameVersion();
|
|
|
|
|
2023-07-30 08:49:34 -04:00
|
|
|
Q_EMIT installFinished();
|
2023-10-08 18:02:02 -04:00
|
|
|
qInfo(ASTRA_LOG) << "Installed game in" << installDirectory;
|
2022-03-16 18:39:13 -04:00
|
|
|
});
|
2023-07-30 08:49:34 -04:00
|
|
|
}
|