Compare commits

...
Author SHA1 Message Date
Kurt Himebauch 0b0b5e5ba2 fix(gog): count installer parts kept from a cancelled install as free space on retry 2026-11-16 02:50:23 +00:00
Kurt Himebauch 5926606f60 fix(gog): count known installer part sizes in the free-space check when some part has no size 2026-11-16 02:20:22 +00:00
Kurt Himebauch ac8412103a Merge branch 'main' into fix/gog-extract-exit-2 2026-11-15 10:59:45 -05:00
Kurt Himebauch e98b076734 fix(gog): keep innoextract output in the log and leave the install failure message unchanged 2026-11-11 20:23:02 +00:00
Kurt Himebauch 6c26aaaa8e test(games): verify extractor binds after migrating a saved internal-guest bind 2026-11-11 19:24:43 +00:00
Kurt Himebauch 6ce22a5b4a fix(games): re-path saved folder binds that hold the internal store guest path 2026-11-11 18:58:46 +00:00
Kurt Himebauch fe7cbc702d fix(games): never give an added folder the internal store guest path
An added folder named Stores was bound at /root/Games/Stores, over the
internal store install root. legacyRoots, used by bindFolder and the
games-folder migration, now gives such a folder a suffixed guest path,
so guestBinds mounts every added root again, matching guestPath and the
session binds.
2026-11-11 15:41:59 +00:00
Kurt Himebauch e939475200 fix(gog): keep the internal store root visible to installer extraction 2026-11-11 15:24:18 +00:00
Kurt Himebauch 57659b66d3 fix(gog): count the extracted size before downloading an offline installer
The installer fallback only checked free space for the download, so a
game that needs the download plus its extracted files failed after
every part was fetched, with innoextract's stream error. The failure
reason now drops innoextract's warnings and bug-report trailer.
2026-11-10 17:39:10 +00:00
Kurt Himebauch b33e01f495 fix(gog): bind every store root for installer extraction and log its error 2026-11-10 17:01:43 +00:00
10 changed files with 319 additions and 30 deletions

No files matched your search

@@ -13,6 +13,7 @@ object GamesFolderMigration {
@Synchronized
fun run(context: Context) {
repathInternalGuest(context)
val dirs = SessionPrefs.addedGamesDirs(context)
if (dirs.isEmpty()) return
val roots = legacyRoots(SessionPrefs.gameFolderBinds(context).map { it.first } + dirs)
@@ -58,12 +59,30 @@ object GamesFolderMigration {
SessionPrefs.setGamesFoldersMigrated(context)
}
private fun repathInternalGuest(context: Context) {
val binds = SessionPrefs.gameFolderBinds(context)
if (binds.none { it.second == StoreInstallRoot.INTERNAL_GUEST }) return
val hosts = binds.map { it.first }
val roots = legacyRoots(hosts).associateBy { it.host.path }
val taken = binds.map { it.second }.filter { it != StoreInstallRoot.INTERNAL_GUEST }.toMutableSet()
SessionPrefs.setGameFolderBinds(context, binds.map { (host, guest) ->
if (guest != StoreInstallRoot.INTERNAL_GUEST) return@map host to guest
val base = roots.getValue(host).guest
var next = base
var n = 2
while (next in taken) next = "$base-${n++}"
taken.add(next)
host to next
})
}
internal fun legacyRoots(paths: List<String>): List<AddedGames.Root> {
val hosts = paths.distinct().map { File(it) }
val names = hosts.groupingBy { it.name.lowercase() }.eachCount()
return hosts.map { host ->
val name = host.name.ifEmpty { "games" }
val guestName = if ((names[name.lowercase()] ?: 0) > 1) name + "-" + "%08x".format(CRC32().apply { update(host.path.toByteArray()) }.value).take(4) else name
val clash = (names[name.lowercase()] ?: 0) > 1 || "${AddedGames.GUEST_DIR}/$name" == StoreInstallRoot.INTERNAL_GUEST
val guestName = if (clash) name + "-" + "%08x".format(CRC32().apply { update(host.path.toByteArray()) }.value).take(4) else name
AddedGames.Root(host, "${AddedGames.GUEST_DIR}/$guestName")
}
}
@@ -3,8 +3,10 @@ package com.droiddeck.launcher.stores
import android.content.Context
import android.os.StatFs
import android.os.storage.StorageManager
import com.droiddeck.launcher.frontend.AddedGames
import com.droiddeck.launcher.runtime.LinuxRuntime
import com.droiddeck.launcher.session.GameStorage
import com.droiddeck.launcher.session.SecondaryLibrary
import com.droiddeck.launcher.session.SessionPrefs
import java.io.File
import java.util.zip.CRC32
@@ -12,6 +14,7 @@ import java.util.zip.CRC32
object StoreInstallRoot {
const val SPACE_UNKNOWN = -1L
private const val INTERNAL = "root/Games/Stores"
const val INTERNAL_GUEST = "/$INTERNAL"
private const val ON_VOLUME = "Games"
const val GUEST_EXTERNAL = "/mnt/droiddeck-stores"
@@ -179,6 +182,24 @@ object StoreInstallRoot {
fun externalBindSpecsForXodus(context: Context): List<String> =
externalBindSpecs(externalRootsForXodus(context), LinuxRuntime.rootDir(context))
fun guestBinds(context: Context): List<String> {
val out = ArrayList<String>(externalBindSpecs(context))
val root = LinuxRuntime.rootDir(context)
GameStorage.effective(context)?.takeIf { File(it.path).isDirectory }?.let { library ->
val content = SecondaryLibrary.contentPath(File(library.path)).path
for (guest in SecondaryLibrary.CARD_GUESTS) {
File(root, guest.removePrefix("/")).mkdirs()
out += "$content:$guest"
}
}
for (folder in AddedGames.roots(context)) {
if (!folder.host.isDirectory || !folder.host.canRead()) continue
File(root, folder.guest.removePrefix("/")).mkdirs()
out += folder.host.path + ":" + folder.guest
}
return out
}
internal fun externalBindSpecs(roots: List<Pair<File, String>>, guestRoot: File): List<String> =
roots.mapNotNull { (host, guest) ->
if (!host.isDirectory || !host.canRead()) return@mapNotNull null
@@ -7,9 +7,7 @@ import com.droiddeck.launcher.R
import com.droiddeck.launcher.frontend.AddedGames
import com.droiddeck.launcher.runtime.BattleNet
import com.droiddeck.launcher.runtime.GuestCommand
import com.droiddeck.launcher.runtime.LinuxRuntime
import com.droiddeck.launcher.session.GameStorage
import com.droiddeck.launcher.session.SecondaryLibrary
import com.droiddeck.launcher.stores.CatalogItem
import com.droiddeck.launcher.stores.InstalledStoreGame
import com.droiddeck.launcher.stores.Store
@@ -75,22 +73,10 @@ object BattleNetInstall {
}
internal fun binds(context: Context): List<String> {
val out = ArrayList<String>(StoreInstallRoot.externalBindSpecs(context))
val root = LinuxRuntime.rootDir(context)
GameStorage.effective(context)?.let { library ->
if (!File(library.path).isDirectory) throw IllegalStateException(context.getString(R.string.game_sync_err_game_storage))
val content = SecondaryLibrary.contentPath(File(library.path)).path
for (guest in SecondaryLibrary.CARD_GUESTS) {
File(root, guest.removePrefix("/")).mkdirs()
out += "$content:$guest"
}
}
for (folder in AddedGames.roots(context)) {
if (!folder.host.isDirectory || !folder.host.canRead()) continue
File(root, folder.guest.removePrefix("/")).mkdirs()
out += folder.host.path + ":" + folder.guest
}
return out
return StoreInstallRoot.guestBinds(context)
}
internal fun run(context: Context, args: List<String>, cancelled: AtomicBoolean?, onLine: (String) -> Unit): Int =
@@ -4,7 +4,6 @@ import android.content.Context;
import android.util.Log;
import com.droiddeck.launcher.frontend.AddedGames;
import com.droiddeck.launcher.runtime.GuestCommand;
import com.droiddeck.launcher.stores.StoreLanguage;
import com.droiddeck.launcher.stores.StoreLog;
import com.droiddeck.launcher.stores.download.StoreDownloadTier;
@@ -271,11 +270,10 @@ public final class GogDownloadManager {
long planned = 0;
boolean sized = true;
for (InstallerPart part : parts) { planned += part.size; if (part.size <= 0) sized = false; }
if (sized) {
long usable = com.droiddeck.launcher.stores.StoreInstallRoot.availableBytes(installPath);
if (com.droiddeck.launcher.stores.StoreInstallRoot.insufficientSpace(planned, usable)) {
throw new InstallException("Not enough free space: need " + formatBytes(planned) + ", only " + formatBytes(usable) + " free");
}
long needed = installerBytesNeeded(knownPartBytes(parts), GogLibrary.INSTANCE.sizeOf(ctx, game.gameId));
long usable = com.droiddeck.launcher.stores.StoreInstallRoot.availableBytes(installPath) + reclaimableInstallerBytes(installPath, parts);
if (com.droiddeck.launcher.stores.StoreInstallRoot.insufficientSpace(needed, usable)) {
throw new InstallException("Not enough free space: need " + formatBytes(needed) + ", only " + formatBytes(usable) + " free");
}
long total = 0;
for (InstallerPart part : parts) {
@@ -327,10 +325,7 @@ public final class GogDownloadManager {
cb.onProgress("Extracting installer…", 95);
int rc;
try {
rc = GuestCommand.INSTANCE.run(ctx, Arrays.asList(
"/usr/local/bin/droiddeck-innoextract", "--gog", "--silent",
"-d", guestDir, guestSetup),
false, "gog-innoextract", null, null, false, cancelled,
rc = GogInnoextract.extract(ctx, guestSetup, guestDir, "gog-innoextract", cancelled,
line -> { cb.onLog("gog innoextract: " + line); return kotlin.Unit.INSTANCE; });
} catch (Exception e) {
throw new InstallException("The installer could not be extracted: " + e.getClass().getSimpleName());
@@ -339,6 +334,28 @@ public final class GogDownloadManager {
if (rc != 0) throw new InstallException("The installer could not be extracted (innoextract exit " + rc + ")");
}
static long knownPartBytes(List<InstallerPart> parts) {
long known = 0;
for (InstallerPart part : parts) if (part.size > 0) known += part.size;
return known;
}
static long reclaimableInstallerBytes(File installPath, List<InstallerPart> parts) {
long reclaimed = 0;
for (InstallerPart part : parts) {
try {
File existing = installerDestination(installPath, part.filename);
if (existing.isFile()) reclaimed += existing.length();
} catch (IOException ignored) {
}
}
return reclaimed;
}
static long installerBytesNeeded(long downloadBytes, long installedBytes) {
return Math.max(0, downloadBytes) + Math.max(0, installedBytes);
}
static final class InstallerPart {
final String url;
final String filename;
@@ -0,0 +1,17 @@
package com.droiddeck.launcher.stores.gog
import android.content.Context
import com.droiddeck.launcher.runtime.GuestCommand
import com.droiddeck.launcher.stores.StoreInstallRoot
import java.util.concurrent.atomic.AtomicBoolean
internal object GogInnoextract {
private const val PROGRAM = "/usr/local/bin/droiddeck-innoextract"
@JvmStatic
fun extract(context: Context, setup: String, target: String, logName: String, cancelled: AtomicBoolean, onLine: (String) -> Unit): Int =
GuestCommand.run(context, argv(setup, target), logName = logName,
extraBinds = StoreInstallRoot.guestBinds(context), cancelled = cancelled, onLine = onLine)
internal fun argv(setup: String, target: String): List<String> = listOf(PROGRAM, "--gog", "--silent", "-d", target, setup)
}
@@ -3,11 +3,9 @@ package com.droiddeck.launcher.stores.gog
import android.content.Context
import com.droiddeck.launcher.agent.AgentGuest
import com.droiddeck.launcher.frontend.AddedGames
import com.droiddeck.launcher.runtime.GuestCommand
import com.droiddeck.launcher.session.SessionService
import com.droiddeck.launcher.session.SessionState
import com.droiddeck.launcher.stores.StoreGameSidecar
import com.droiddeck.launcher.stores.StoreInstallRoot
import com.droiddeck.launcher.stores.download.DownloadQueue
import com.droiddeck.launcher.stores.download.DownloadStage
import org.json.JSONArray
@@ -71,8 +69,7 @@ internal object GogOffline {
val source = AddedGames.guestPath(context, installer) ?: error("The GOG installer is not visible to Linux")
val target = AddedGames.guestPath(context, extracted) ?: error("The GOG staging folder is not visible to Linux")
handle.stage(DownloadStage.INSTALL, "Extracting the full offline installer")
val rc = GuestCommand.run(context, listOf("/usr/local/bin/droiddeck-innoextract", "--gog", "--silent", "-d", target, source),
extraBinds = StoreInstallRoot.externalBindSpecs(context), cancelled = stop, logName = "gog-refresh", onLine = handle::log)
val rc = GogInnoextract.extract(context, source, target, "gog-refresh", stop, handle::log)
if (stop.get()) return
check(rc == 0) { "GOG installer extraction failed (exit $rc)" }
applyRefresh(proposal, extracted, handle, stop)
@@ -3,6 +3,7 @@ package com.droiddeck.launcher.frontend
import com.droiddeck.launcher.assumeFilePermissionsEnforced
import android.os.Environment
import com.droiddeck.launcher.session.SessionPrefs
import com.droiddeck.launcher.stores.StoreInstallRoot
import java.io.File
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
@@ -366,6 +367,15 @@ class AddedExesTest {
assertEquals("$clash-2", guests.last())
}
@Test fun aFolderNamedStoresIsNotBoundOverTheInternalStoreRoot() {
noGamesFolders()
val stores = File(tmp.newFolder("card"), "Stores").apply { exe(File(this, "One/One.exe")) }
val result = AddedGames.addFolder(app, stores)
val guest = SessionPrefs.gameFolderBinds(app).single().second
assertTrue(guest != StoreInstallRoot.INTERNAL_GUEST && guest.startsWith("${AddedGames.GUEST_DIR}/Stores-"))
assertEquals("$guest/One/One.exe", result.added.single().guestExe)
}
@Test fun aRemovedSingleExeGameStaysOffUntilPickedAgain() {
noGamesFolders()
val pick = onStorage("Download/Celeste/Celeste.exe")
@@ -3,6 +3,7 @@ package com.droiddeck.launcher.frontend
import com.droiddeck.launcher.session.GameStorage
import com.droiddeck.launcher.session.SessionPrefs
import com.droiddeck.launcher.stores.StoreGameSidecar
import com.droiddeck.launcher.stores.StoreInstallRoot
import java.io.File
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
@@ -182,6 +183,41 @@ class GamesFolderMigrationTest {
assertEquals(listOf(pc.path to AddedGames.GUEST_DIR + "/PC"), binds)
}
@Test fun aMigratedFolderNamedStoresDoesNotTakeTheInternalStoreGuest() {
val stores = File(tmp.newFolder("card"), "Stores").apply { exe(this, "One/One.exe") }
val pc = tmp.newFolder("PC").apply { exe(this, "Two/Two.exe") }
SessionPrefs.setAddedGamesDirs(app, listOf(stores.path, pc.path))
GamesFolderMigration.run(app)
val binds = SessionPrefs.gameFolderBinds(app).toMap()
assertTrue(binds.getValue(stores.path) != StoreInstallRoot.INTERNAL_GUEST)
assertEquals(AddedGames.GUEST_DIR + "/PC", binds.getValue(pc.path))
val games = AddedGames.scan(app).associateBy { it.name }
assertEquals(binds.getValue(stores.path) + "/One/One.exe", games.getValue("One").guestExe)
}
@Test fun aSavedBindAtTheInternalStoreGuestIsRepathed() {
val stores = File(tmp.newFolder("card"), "Stores").apply { exe(this, "One/One.exe") }
val pc = tmp.newFolder("PC").apply { exe(this, "Two/Two.exe") }
SessionPrefs.setGameFolderBinds(
app,
listOf(stores.path to StoreInstallRoot.INTERNAL_GUEST, pc.path to AddedGames.GUEST_DIR + "/PC"),
)
GamesFolderMigration.run(app)
val binds = SessionPrefs.gameFolderBinds(app).toMap()
assertTrue(binds.getValue(stores.path) != StoreInstallRoot.INTERNAL_GUEST)
assertTrue(binds.getValue(stores.path).startsWith("${AddedGames.GUEST_DIR}/Stores-"))
assertEquals(AddedGames.GUEST_DIR + "/PC", binds.getValue(pc.path))
assertTrue(binds.values.none { it == StoreInstallRoot.INTERNAL_GUEST })
assertEquals(binds.getValue(stores.path) + "/One/One.exe", AddedGames.guestPath(app, File(stores, "One/One.exe")))
val installer = File(stores, "GOG/Game/setup_1.exe").apply { parentFile?.mkdirs(); writeText("MZ") }
val guestInstaller = AddedGames.guestPath(app, installer)!!
val extractorBinds = StoreInstallRoot.guestBinds(app).map { it.substringBeforeLast(':') to it.substringAfterLast(':') }
val covering = extractorBinds.filter { (_, mount) -> guestInstaller.startsWith("$mount/") }.maxByOrNull { it.second.length }!!
assertEquals(installer.canonicalFile, File(covering.first + guestInstaller.removePrefix(covering.second)).canonicalFile)
val internalInstaller = "${StoreInstallRoot.INTERNAL_GUEST}/GOG/Game/setup_1.exe"
assertTrue(extractorBinds.none { (_, mount) -> internalInstaller == mount || internalInstaller.startsWith("$mount/") })
}
@Test fun twoFoldersOfOneNameKeepTheirOwnGuestPaths() {
val a = File(tmp.newFolder("a"), "Games").apply { mkdirs() }
val b = File(tmp.newFolder("b"), "Games").apply { mkdirs() }
@@ -0,0 +1,93 @@
package com.droiddeck.launcher.stores.gog
import com.droiddeck.launcher.frontend.AddedGames
import com.droiddeck.launcher.session.SecondaryLibrary
import com.droiddeck.launcher.session.SessionPrefs
import com.droiddeck.launcher.stores.StoreInstallRoot
import java.io.File
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class GogInnoextractTest {
private val app get() = RuntimeEnvironment.getApplication()
@Before @After fun resetStorage() {
SessionPrefs.setDefaultStorageFolder(app, "", "")
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
}
private fun installer(folder: File, names: List<String>) = names.map { File(folder, it).apply { parentFile?.mkdirs(); writeText("MZ") } }
private fun hostOf(guest: String, binds: List<String>): File? = binds
.map { it.substringBeforeLast(':') to it.substringAfterLast(':') }
.filter { (_, mount) -> guest == mount || guest.startsWith("$mount/") }
.maxByOrNull { it.second.length }
?.let { (host, mount) -> File(host + guest.removePrefix(mount)) }
private fun assertExtractorSeesEveryPart(folder: File, parts: List<String>) {
val files = installer(folder, parts)
val guestDir = AddedGames.guestPath(app, folder)
assertNotNull(guestDir)
val argv = GogInnoextract.argv("$guestDir/${parts.first()}", guestDir!!)
assertEquals("$guestDir/${parts.first()}", argv.last())
assertEquals(guestDir, argv[argv.indexOf("-d") + 1])
assertTrue(argv.contains("--gog"))
val binds = StoreInstallRoot.guestBinds(app)
assertEquals(folder.canonicalFile, hostOf(guestDir, binds)?.canonicalFile)
for (file in files) assertEquals(file.canonicalFile, hostOf("$guestDir/${file.name}", binds)?.canonicalFile)
assertNull(hostOf("$guestDir/${parts.first()}", emptyList()))
}
@Test fun singleFileAndMultiPartInstallersOnAChosenFolderAreVisibleToTheExtractor() {
val drive = File(app.filesDir, "usb/SSD").apply { mkdirs() }
SessionPrefs.setDefaultStorageFolder(app, drive.path, "SSD")
val single = File(drive, "Games/GOG/Single")
assertTrue(AddedGames.guestPath(app, single)!!.startsWith(StoreInstallRoot.GUEST_EXTERNAL + "/"))
assertExtractorSeesEveryPart(single, listOf("setup_1207658930.exe"))
assertExtractorSeesEveryPart(File(drive, "Games/GOG/Multi Part"), listOf("setup_1207658931.exe", "setup_1207658931-1.bin", "setup_1207658931-2.bin"))
}
@Test fun installersOnTheGameStorageCardAreVisibleToTheExtractor() {
val card = File(app.filesDir, "card/steam").apply { mkdirs() }
SessionPrefs.setGameStorage(app, card.path, "Card")
val folder = File(card, "Games/GOG/Multi Part")
assertTrue(SecondaryLibrary.CARD_GUESTS.any { AddedGames.guestPath(app, folder)!!.startsWith("$it/") })
assertExtractorSeesEveryPart(folder, listOf("setup_1207658932.exe", "setup_1207658932-1.bin"))
}
@Test fun anUnpluggedGameStorageCardDoesNotStopAnInternalExtraction() {
SessionPrefs.setGameStorage(app, File(app.filesDir, "unplugged/steam").path, "Card")
val folder = File(StoreInstallRoot.internalRoot(app), "GOG/Internal")
installer(folder, listOf("setup_1207658933.exe"))
val binds = StoreInstallRoot.guestBinds(app)
assertTrue(binds.none { bind -> SecondaryLibrary.CARD_GUESTS.any { bind.endsWith(":$it") } })
assertTrue(AddedGames.guestPath(app, folder)!!.startsWith("/root/Games/Stores/GOG/"))
}
@Test fun anAddedFolderNamedStoresIsMountedWithoutHidingTheInternalInstallRoot() {
val drive = File(app.filesDir, "usb/Stores").apply { mkdirs() }
AddedGames.bindFolder(app, drive)
val guest = AddedGames.guestPath(app, drive)!!
assertTrue(guest != StoreInstallRoot.INTERNAL_GUEST && !guest.startsWith(StoreInstallRoot.INTERNAL_GUEST + "/"))
SessionPrefs.setDefaultStorageFolder(app, drive.path, "Stores")
val chosen = File(drive, "Games/GOG/Chosen")
assertTrue(AddedGames.guestPath(app, chosen)!!.startsWith("$guest/"))
assertExtractorSeesEveryPart(chosen, listOf("setup_1207658934.exe", "setup_1207658934-1.bin"))
val internal = File(StoreInstallRoot.internalRoot(app), "GOG/Internal")
installer(internal, listOf("setup_1207658935.exe"))
val internalGuest = AddedGames.guestPath(app, internal)!!
assertTrue(internalGuest.startsWith(StoreInstallRoot.INTERNAL_GUEST + "/GOG/"))
assertNull(hostOf("$internalGuest/setup_1207658935.exe", StoreInstallRoot.guestBinds(app)))
}
}
@@ -1,10 +1,12 @@
package com.droiddeck.launcher.stores.gog
import com.droiddeck.launcher.stores.StoreInstallRoot
import java.io.File
import java.io.IOException
import java.nio.file.Files
import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertThrows
import org.junit.Assert.assertTrue
import org.junit.Test
@@ -83,6 +85,97 @@ class GogInstallerPartsTest {
}
}
private val gib = 1024L * 1024 * 1024
@Test fun anInstallerThatFitsOnlyBeforeExtractionIsRefusedBeforeItDownloads() {
val download = 1_048_576L + 17 * (7 * gib / 2)
val installed = 699 * gib / 10
val free = 944 * gib / 10
assertFalse(StoreInstallRoot.insufficientSpace(download, free))
val needed = GogDownloadManager.installerBytesNeeded(download, installed)
assertEquals(download + installed, needed)
assertTrue(StoreInstallRoot.insufficientSpace(needed, free))
}
@Test fun anInstallerThatFitsWithItsExtractedFilesIsAllowed() {
val download = 1_048_576L + 3_786_407_936L
assertFalse(StoreInstallRoot.insufficientSpace(GogDownloadManager.installerBytesNeeded(download, 6 * gib), 944 * gib / 10))
}
@Test fun anUnknownInstalledSizeKeepsTheDownloadOnlyCheck() {
val download = 1_048_576L + 3_786_407_936L
assertEquals(download, GogDownloadManager.installerBytesNeeded(download, 0L))
assertEquals(download, GogDownloadManager.installerBytesNeeded(download, -1L))
assertEquals(5 * gib, GogDownloadManager.installerBytesNeeded(0L, 5 * gib))
assertEquals(0L, GogDownloadManager.installerBytesNeeded(0L, -1L))
}
@Test fun aPartWithoutASizeStillCountsTheKnownBytesOfTheOthers() {
val parts = listOf(
GogDownloadManager.InstallerPart("u0", "setup.exe", 0L),
GogDownloadManager.InstallerPart("u1", "setup-1.bin", 60 * gib),
)
val needed = GogDownloadManager.installerBytesNeeded(GogDownloadManager.knownPartBytes(parts), 70 * gib)
assertEquals(130 * gib, needed)
assertTrue(StoreInstallRoot.insufficientSpace(needed, 95 * gib))
assertEquals(0L, GogDownloadManager.knownPartBytes(emptyList()))
}
private fun installDir(): File = Files.createTempDirectory("gog-parts").toFile()
@Test fun partsKeptFromACancelledInstallCountAsFreeSpaceOnRetry() {
val dir = installDir()
try {
File(dir, "setup.exe").writeBytes(ByteArray(1000))
File(dir, "setup-1.bin").writeBytes(ByteArray(500))
val parts = listOf(
GogDownloadManager.InstallerPart("u0", "setup.exe", 1000L),
GogDownloadManager.InstallerPart("u1", "setup-1.bin", 1000L),
)
val reclaimed = GogDownloadManager.reclaimableInstallerBytes(dir, parts)
assertEquals(1500L, reclaimed)
val needed = GogDownloadManager.installerBytesNeeded(GogDownloadManager.knownPartBytes(parts), 0L)
val free = 600L
assertTrue(StoreInstallRoot.insufficientSpace(needed, free))
assertFalse(StoreInstallRoot.insufficientSpace(needed, free + reclaimed))
} finally {
dir.deleteRecursively()
}
}
@Test fun aMissingPartOrADirectoryReclaimsNothing() {
val dir = installDir()
try {
File(dir, "folder.bin").mkdir()
val parts = listOf(
GogDownloadManager.InstallerPart("u0", "setup.exe", 1000L),
GogDownloadManager.InstallerPart("u1", "folder.bin", 1000L),
)
assertEquals(0L, GogDownloadManager.reclaimableInstallerBytes(dir, parts))
assertEquals(0L, GogDownloadManager.reclaimableInstallerBytes(dir, emptyList()))
} finally {
dir.deleteRecursively()
}
}
@Test fun aLinkedPartOrAnEscapingNameReclaimsNothing() {
val dir = installDir()
val outside = installDir()
try {
val target = File(outside, "big.bin").apply { writeBytes(ByteArray(4000)) }
Files.createSymbolicLink(File(dir, "setup.exe").toPath(), target.toPath())
File(dir.parentFile, "escape.bin").also { it.writeBytes(ByteArray(4000)); it.deleteOnExit() }
val parts = listOf(
GogDownloadManager.InstallerPart("u0", "setup.exe", 1000L),
GogDownloadManager.InstallerPart("u1", "../escape.bin", 1000L),
)
assertEquals(0L, GogDownloadManager.reclaimableInstallerBytes(dir, parts))
} finally {
dir.deleteRecursively()
outside.deleteRecursively()
}
}
@Test fun anotherPlatformOrNoDownloadsAddsNothing() {
assertEquals(0, GogDownloadManager.installerParts(downloads("""{"installers":[{"os":"linux","manualUrl":"https://example.invalid/x"}]}"""), "1").size)
assertEquals(0, GogDownloadManager.installerParts(downloads("{}"), "1").size)