1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-05-18 15:17:46 +00:00
astra/launcher/src/gameinstaller.cpp

86 lines
2.6 KiB
C++
Raw Normal View History

// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
#include "gameinstaller.h"
2023-09-16 21:28:22 -04:00
#include <KLocalizedString>
2022-08-15 11:14:37 -04:00
#include <QFile>
#include <QNetworkReply>
#include <QStandardPaths>
#include <physis.hpp>
#include "astra_log.h"
#include "launchercore.h"
#include "profile.h"
#include "utility.h"
const auto installerUrl = QStringLiteral("https://download.finalfantasyxiv.com/inst/ffxivsetup.exe");
const QByteArray installerSha256 = QByteArray::fromHex("cf70bfaaf4f429794358ef84acbcbdc4193bee109fa1b6aea81bd4de038e500e");
GameInstaller::GameInstaller(LauncherCore &launcher, Profile &profile, QObject *parent)
: QObject(parent)
, m_launcher(launcher)
, m_profile(profile)
{
}
GameInstaller::GameInstaller(LauncherCore &launcher, Profile &profile, const QString &filePath, QObject *parent)
: GameInstaller(launcher, profile, parent)
{
m_localInstallerPath = filePath;
}
void GameInstaller::start()
{
if (m_localInstallerPath.isEmpty()) {
const auto request = QNetworkRequest(QUrl(installerUrl));
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();
}
}
void GameInstaller::installGame()
{
const QDir installDirectory = m_profile.gamePath();
const std::string installDirectoryStd = installDirectory.absolutePath().toStdString();
const std::string fileNameStd = m_localInstallerPath.toStdString();
physis_install_game(fileNameStd.c_str(), installDirectoryStd.c_str());
m_profile.readGameVersion();
2023-10-08 19:14:17 -04:00
Q_EMIT installFinished();
qInfo(ASTRA_LOG) << "Installed game in" << installDirectory;
}
#include "moc_gameinstaller.cpp"