mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-20 19:57:45 +00:00
Simplify patcher strings
This commit is contained in:
parent
b7f278331a
commit
72f3cf2052
2 changed files with 43 additions and 35 deletions
|
@ -24,6 +24,7 @@ public:
|
|||
|
||||
private:
|
||||
void setupDirectories();
|
||||
QString getBaseString() const;
|
||||
|
||||
[[nodiscard]] bool isBoot() const
|
||||
{
|
||||
|
@ -35,6 +36,16 @@ private:
|
|||
QStringList hashes;
|
||||
long hashBlockSize;
|
||||
long length;
|
||||
bool isBoot;
|
||||
|
||||
QString getVersion() const
|
||||
{
|
||||
if (isBoot) {
|
||||
return QStringLiteral("ffxivboot - %1").arg(name);
|
||||
} else {
|
||||
return QStringLiteral("%1 - %2").arg(repository, name);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void processPatch(const QueuedPatch &patch);
|
||||
|
|
|
@ -44,13 +44,8 @@ QCoro::Task<> Patcher::patch(QNetworkAccessManager &mgr, const QString &patchLis
|
|||
co_return;
|
||||
}
|
||||
|
||||
if (isBoot()) {
|
||||
Q_EMIT m_launcher.stageIndeterminate();
|
||||
Q_EMIT m_launcher.stageChanged(i18n("Checking the FINAL FANTASY XIV Update/Launcher version."));
|
||||
} else {
|
||||
Q_EMIT m_launcher.stageIndeterminate();
|
||||
Q_EMIT m_launcher.stageChanged(i18n("Checking the FINAL FANTASY XIV Game version."));
|
||||
}
|
||||
Q_EMIT m_launcher.stageChanged(i18n("Checking the %1 version.", getBaseString()));
|
||||
|
||||
const QStringList parts = patchList.split("\r\n");
|
||||
|
||||
|
@ -65,14 +60,14 @@ QCoro::Task<> Patcher::patch(QNetworkAccessManager &mgr, const QString &patchLis
|
|||
const QStringList patchParts = parts[i].split(QLatin1Char('\t'));
|
||||
|
||||
const int length = patchParts[0].toInt();
|
||||
int ourIndex = patchIndex++;
|
||||
const int ourIndex = patchIndex++;
|
||||
|
||||
const QString version = patchParts[4];
|
||||
const QString &version = patchParts[4];
|
||||
const long hashBlockSize = patchParts.size() == 9 ? patchParts[6].toLong() : 0;
|
||||
|
||||
const QString name = version;
|
||||
const QString &name = version;
|
||||
const QStringList hashes = patchParts.size() == 9 ? (patchParts[7].split(QLatin1Char(','))) : QStringList();
|
||||
const QString url = patchParts[patchParts.size() == 9 ? 8 : 5];
|
||||
const QString &url = patchParts[patchParts.size() == 9 ? 8 : 5];
|
||||
const QString filename = QStringLiteral("%1.patch").arg(name);
|
||||
|
||||
auto url_parts = url.split(QLatin1Char('/'));
|
||||
|
@ -84,36 +79,27 @@ QCoro::Task<> Patcher::patch(QNetworkAccessManager &mgr, const QString &patchLis
|
|||
QDir().mkpath(repositoryDir.absolutePath());
|
||||
|
||||
const QString patchPath = repositoryDir.absoluteFilePath(filename);
|
||||
|
||||
const QueuedPatch patch{name, repository, version, patchPath, hashes, hashBlockSize, length, isBoot()};
|
||||
|
||||
patchQueue[ourIndex] = patch;
|
||||
|
||||
if (!QFile::exists(patchPath)) {
|
||||
auto patchReply = mgr.get(QNetworkRequest(url));
|
||||
|
||||
connect(patchReply, &QNetworkReply::downloadProgress, [this, repository, version, length](int received, int total) {
|
||||
Q_UNUSED(total)
|
||||
|
||||
if (isBoot()) {
|
||||
Q_EMIT m_launcher.stageChanged(i18n("Updating the FINAL FANTASY XIV Updater/Launcher version.\nDownloading ffxivboot - %1", version));
|
||||
} else {
|
||||
Q_EMIT m_launcher.stageChanged(i18n("Updating the FINAL FANTASY XIV Game version.\nDownloading %1 - %2", repository, version));
|
||||
}
|
||||
|
||||
Q_EMIT m_launcher.stageDeterminate(0, length, received);
|
||||
connect(patchReply, &QNetworkReply::downloadProgress, [this, patch](int received, int total) {
|
||||
Q_EMIT m_launcher.stageChanged(i18n("Updating %1.\nDownloading %2", getBaseString(), patch.getVersion()));
|
||||
Q_EMIT m_launcher.stageDeterminate(0, total, received);
|
||||
});
|
||||
|
||||
synchronizer.addFuture(QtFuture::connect(patchReply, &QNetworkReply::finished)
|
||||
.then([this, patchPath, patchReply, ourIndex, name, repository, version, hashes, hashBlockSize, length] {
|
||||
synchronizer.addFuture(QtFuture::connect(patchReply, &QNetworkReply::finished).then([patchPath, patchReply] {
|
||||
QFile file(patchPath);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write(patchReply->readAll());
|
||||
file.close();
|
||||
|
||||
patchQueue[ourIndex] = {name, repository, version, patchPath, hashes, hashBlockSize, length};
|
||||
}));
|
||||
} else {
|
||||
qDebug() << "Found existing patch: " << name;
|
||||
|
||||
patchQueue[ourIndex] = {name, repository, version, patchPath, hashes, hashBlockSize, length};
|
||||
|
||||
synchronizer.addFuture({});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,7 +110,9 @@ QCoro::Task<> Patcher::patch(QNetworkAccessManager &mgr, const QString &patchLis
|
|||
// This must happen synchronously
|
||||
size_t i = 0;
|
||||
for (const auto &patch : patchQueue) {
|
||||
Q_EMIT m_launcher.stageChanged(i18n("Updating %1.\nInstalling %2", getBaseString(), patch.getVersion()));
|
||||
Q_EMIT m_launcher.stageDeterminate(0, patchQueue.size(), i++);
|
||||
|
||||
processPatch(patch);
|
||||
}
|
||||
|
||||
|
@ -192,3 +180,12 @@ void Patcher::setupDirectories()
|
|||
|
||||
patchesDir.setPath(dataDir.absoluteFilePath(QStringLiteral("patches")));
|
||||
}
|
||||
|
||||
QString Patcher::getBaseString() const
|
||||
{
|
||||
if (isBoot()) {
|
||||
return i18n("FINAL FANTASY XIV Update/Launcher");
|
||||
} else {
|
||||
return i18n("FINAL FANTASY XIV Game");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue