mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
fix(gog): check space for the extracted install before downloading an offline installer (#2419)
* fix(gog): bind every store root for installer extraction and log its error * 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. * fix(gog): keep the internal store root visible to installer extraction * 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. * fix(games): re-path saved folder binds that hold the internal store guest path * test(games): verify extractor binds after migrating a saved internal-guest bind * fix(gog): keep innoextract output in the log and leave the install failure message unchanged * fix(gog): count known installer part sizes in the free-space check when some part has no size
This commit is contained in:
1 parent
af1fe6c61c
commit
01dc415f10
10 files changed
+252
-30
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);
|
||||
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, null,
|
||||
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,16 @@ 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 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
|
||||
@@ -461,6 +462,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,42 @@ 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()))
|
||||
}
|
||||
|
||||
@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)
|
||||
|
||||
Reference in new issue
Block a user