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"
|
2025-03-17 18:44:36 -04:00
|
|
|
#include "profileconfig.h"
|
2023-10-08 18:02:02 -04:00
|
|
|
#include "utility.h"
|
2023-07-30 08:49:34 -04:00
|
|
|
|
2024-07-04 20:53:06 -04:00
|
|
|
const auto installerUrl = QStringLiteral("https://download.finalfantasyxiv.com/inst/ffxivsetup.exe");
|
2023-08-18 12:59:07 -04:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-04-01 14:54:41 -04:00
|
|
|
GameInstaller::GameInstaller(LauncherCore &launcher, Profile &profile, const QString &filePath, QObject *parent)
|
|
|
|
: GameInstaller(launcher, profile, parent)
|
2023-07-30 08:49:34 -04:00
|
|
|
{
|
2024-04-01 14:54:41 -04:00
|
|
|
m_localInstallerPath = filePath;
|
|
|
|
}
|
2022-03-16 18:39:13 -04:00
|
|
|
|
2024-04-01 14:54:41 -04:00
|
|
|
void GameInstaller::start()
|
|
|
|
{
|
|
|
|
if (m_localInstallerPath.isEmpty()) {
|
2024-07-04 20:53:06 -04:00
|
|
|
const auto request = QNetworkRequest(QUrl(installerUrl));
|
2024-04-01 14:54:41 -04:00
|
|
|
Utility::printRequest(QStringLiteral("GET"), request);
|
|
|
|
|
|
|
|
auto reply = m_launcher.mgr()->get(request);
|
|
|
|
|
|
|
|
QObject::connect(reply, &QNetworkReply::finished, [this, reply] {
|
|
|
|
if (reply->error() != QNetworkReply::NetworkError::NoError) {
|
|
|
|
Q_EMIT error(reply->errorString());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QDir dataDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
|
|
|
|
|
|
|
|
const QByteArray data = reply->readAll();
|
|
|
|
QCryptographicHash hash(QCryptographicHash::Sha256);
|
|
|
|
hash.addData(data);
|
|
|
|
|
|
|
|
if (hash.result() != installerSha256) {
|
|
|
|
Q_EMIT error(i18n("The installer failed the integrity check!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFile file(dataDir.absoluteFilePath(QStringLiteral("ffxivsetup.exe")));
|
|
|
|
file.open(QIODevice::WriteOnly);
|
|
|
|
file.write(data);
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
m_localInstallerPath = file.fileName();
|
|
|
|
installGame();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
installGame();
|
|
|
|
}
|
|
|
|
}
|
2023-08-18 12:59:07 -04:00
|
|
|
|
2024-04-01 14:54:41 -04:00
|
|
|
void GameInstaller::installGame()
|
|
|
|
{
|
2025-03-17 18:44:36 -04:00
|
|
|
const QDir installDirectory = m_profile.config()->gamePath();
|
2022-03-16 18:39:13 -04:00
|
|
|
|
2024-04-01 14:54:41 -04:00
|
|
|
const std::string installDirectoryStd = installDirectory.absolutePath().toStdString();
|
|
|
|
const std::string fileNameStd = m_localInstallerPath.toStdString();
|
2023-05-13 17:37:30 -04:00
|
|
|
|
2024-04-01 14:54:41 -04:00
|
|
|
physis_install_game(fileNameStd.c_str(), installDirectoryStd.c_str());
|
2022-03-16 18:39:13 -04:00
|
|
|
|
2024-04-01 14:54:41 -04:00
|
|
|
m_profile.readGameVersion();
|
2023-10-08 19:14:17 -04:00
|
|
|
|
2024-04-01 14:54:41 -04:00
|
|
|
Q_EMIT installFinished();
|
|
|
|
qInfo(ASTRA_LOG) << "Installed game in" << installDirectory;
|
2023-07-30 08:49:34 -04:00
|
|
|
}
|
2023-12-17 11:12:13 -05:00
|
|
|
|
2025-03-17 18:44:36 -04:00
|
|
|
#include "moc_gameinstaller.cpp"
|