mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-26 00:06:02 +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
@@ -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