From 0ff1dbd4e5e44da23b1d47d6b3eff4ea39c3bbff Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Thu, 22 Aug 2024 20:59:04 -0400 Subject: [PATCH] Bump libphysis, and check for disk space before updating the game This fixes a really easy situation to run into, updating the game without the space required. Now it should warn you before continuing into a terrible situation. --- external/libphysis | 2 +- launcher/include/patcher.h | 1 + launcher/src/patcher.cpp | 24 ++++++++++++++++++++++++ launcher/src/squareenixlogin.cpp | 2 ++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/external/libphysis b/external/libphysis index 1862f3a..8d68aee 160000 --- a/external/libphysis +++ b/external/libphysis @@ -1 +1 @@ -Subproject commit 1862f3a81f93178f55bda4ee7f88f3476f7f0062 +Subproject commit 8d68aeed9a8fc2d04ad258ee94e44001001f3b6e diff --git a/launcher/include/patcher.h b/launcher/include/patcher.h index c3bf046..e055f75 100644 --- a/launcher/include/patcher.h +++ b/launcher/include/patcher.h @@ -64,6 +64,7 @@ private: BootData *m_bootData = nullptr; GameData *m_gameData = nullptr; QStorageInfo m_patchesDirStorageInfo; + QStorageInfo m_baseDirStorageInfo; int m_remainingPatches = -1; diff --git a/launcher/src/patcher.cpp b/launcher/src/patcher.cpp index 3cde240..b166d55 100644 --- a/launcher/src/patcher.cpp +++ b/launcher/src/patcher.cpp @@ -55,6 +55,7 @@ QCoro::Task Patcher::patch(const physis_PatchList &patchList) co_return false; } + // First, let's check if we have enough space to even download the patches const qint64 neededSpace = patchList.patch_length - m_patchesDirStorageInfo.bytesAvailable(); if (neededSpace > 0) { KFormat format; @@ -63,6 +64,27 @@ QCoro::Task Patcher::patch(const physis_PatchList &patchList) co_return false; } + // If we do, we want to make sure we have enough space for all of the repositories we download + QMap repositorySizes; + for (int i = 0; i < patchList.num_entries; i++) { + // Record the largest byte size for the repository + const auto &patch = patchList.entries[i]; + const auto &key = Utility::repositoryFromPatchUrl(QLatin1String(patch.url)); + repositorySizes[key] = std::max(patch.size_on_disk, repositorySizes.value(Utility::repositoryFromPatchUrl(QLatin1String(patch.url)), 0)); + } + + int64_t requiredInstallSize = 0; + for (const auto &[_, value] : repositorySizes.asKeyValueRange()) { + requiredInstallSize += value; + } + const qint64 neededInstallSpace = requiredInstallSize - m_baseDirStorageInfo.bytesAvailable(); + if (neededInstallSpace > 0) { + KFormat format; + QString neededSpaceStr = format.formatByteSize(neededInstallSpace); + Q_EMIT m_launcher.miscError(i18n("There is not enough space available on disk to update the game. You need %1 of free space.", neededSpaceStr)); + co_return false; + } + Q_EMIT m_launcher.stageIndeterminate(); Q_EMIT m_launcher.stageChanged(i18n("Updating %1", getBaseString())); @@ -259,6 +281,8 @@ void Patcher::setupDirectories() m_patchesDir.setPath(dataDir.absoluteFilePath(QStringLiteral("patch"))); m_patchesDirStorageInfo = QStorageInfo(m_patchesDir); + + m_baseDirStorageInfo = QStorageInfo(m_baseDirectory); } QString Patcher::getBaseString() const diff --git a/launcher/src/squareenixlogin.cpp b/launcher/src/squareenixlogin.cpp index 7e74ad9..83dde2b 100644 --- a/launcher/src/squareenixlogin.cpp +++ b/launcher/src/squareenixlogin.cpp @@ -380,6 +380,8 @@ QCoro::Task SquareEnixLogin::registerSession() const QString body = QString::fromUtf8(reply->readAll()); if (!body.isEmpty()) { + qDebug(ASTRA_LOG) << "Game patch list:" << body; + m_patcher = new Patcher(m_launcher, m_info->profile->gamePath() + QStringLiteral("/game"), *m_info->profile->gameData(), this); std::string bodyStd = body.toStdString(); const bool hasPatched = co_await m_patcher->patch(physis_parse_patchlist(PatchListType::Game, bodyStd.c_str()));