From b33e01f49533ecd42da7ade3ebce03336eca4d35 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Tue, 10 Nov 2026 17:01:43 +0000 Subject: [PATCH] fix(gog): bind every store root for installer extraction and log its error --- .../launcher/stores/StoreInstallRoot.kt | 20 ++++ .../stores/battlenet/BattleNetInstall.kt | 16 +-- .../stores/gog/GogDownloadManager.java | 10 +- .../launcher/stores/gog/GogInnoextract.kt | 40 +++++++ .../launcher/stores/gog/GogOffline.kt | 7 +- .../launcher/stores/gog/GogInnoextractTest.kt | 102 ++++++++++++++++++ 6 files changed, 168 insertions(+), 27 deletions(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/stores/gog/GogInnoextract.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/stores/gog/GogInnoextractTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt index b3c3fc0795..31ef97385e 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt @@ -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 @@ -179,6 +181,24 @@ object StoreInstallRoot { fun externalBindSpecsForXodus(context: Context): List = externalBindSpecs(externalRootsForXodus(context), LinuxRuntime.rootDir(context)) + fun guestBinds(context: Context): List { + val out = ArrayList(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>, guestRoot: File): List = roots.mapNotNull { (host, guest) -> if (!host.isDirectory || !host.canRead()) return@mapNotNull null diff --git a/app/src/main/java/com/droiddeck/launcher/stores/battlenet/BattleNetInstall.kt b/app/src/main/java/com/droiddeck/launcher/stores/battlenet/BattleNetInstall.kt index fdd4db2495..8e016065e6 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/battlenet/BattleNetInstall.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/battlenet/BattleNetInstall.kt @@ -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 { - val out = ArrayList(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, cancelled: AtomicBoolean?, onLine: (String) -> Unit): Int = diff --git a/app/src/main/java/com/droiddeck/launcher/stores/gog/GogDownloadManager.java b/app/src/main/java/com/droiddeck/launcher/stores/gog/GogDownloadManager.java index a09629bc4c..588e880fd8 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/gog/GogDownloadManager.java +++ b/app/src/main/java/com/droiddeck/launcher/stores/gog/GogDownloadManager.java @@ -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; @@ -325,18 +324,15 @@ public final class GogDownloadManager { } String guestSetup = guestDir + "/" + setupName; cb.onProgress("Extracting installer…", 95); - int rc; + GogInnoextract.Result result; 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, + result = 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()); } if (cancelled.get()) return; - if (rc != 0) throw new InstallException("The installer could not be extracted (innoextract exit " + rc + ")"); + if (result.getExit() != 0) throw new InstallException(result.failure("The installer could not be extracted (innoextract exit " + result.getExit() + ")")); } static final class InstallerPart { diff --git a/app/src/main/java/com/droiddeck/launcher/stores/gog/GogInnoextract.kt b/app/src/main/java/com/droiddeck/launcher/stores/gog/GogInnoextract.kt new file mode 100644 index 0000000000..2a4c3a321d --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/stores/gog/GogInnoextract.kt @@ -0,0 +1,40 @@ +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" + private const val REASON_LINES = 3 + private const val REASON_CHARS = 400 + private val TREE = Regex("""^[\s├└│─]+""") + + class Result(val exit: Int, val reason: String) { + fun failure(message: String): String = if (reason.isEmpty()) message else "$message: $reason" + } + + @JvmStatic + fun extract(context: Context, setup: String, target: String, logName: String, cancelled: AtomicBoolean, onLine: (String) -> Unit): Result { + val details = ArrayDeque() + val exit = GuestCommand.run(context, argv(setup, target), logName = logName, + extraBinds = StoreInstallRoot.guestBinds(context), cancelled = cancelled) { line -> + onLine(line) + val kept = detail(line) + if (kept != null) { + details.addLast(kept) + if (details.size > REASON_LINES) details.removeFirst() + } + } + return Result(exit, if (exit == 0) "" else reason(details)) + } + + internal fun argv(setup: String, target: String): List = listOf(PROGRAM, "--gog", "--silent", "-d", target, setup) + + internal fun reason(lines: Iterable): String = + lines.mapNotNull(::detail).takeLast(REASON_LINES).joinToString(" ").take(REASON_CHARS) + + private fun detail(raw: String): String? = + raw.replace(TREE, "").trim().takeUnless { it.isEmpty() || it.startsWith("Warning:") } +} diff --git a/app/src/main/java/com/droiddeck/launcher/stores/gog/GogOffline.kt b/app/src/main/java/com/droiddeck/launcher/stores/gog/GogOffline.kt index 02ff54f26f..e7d5510bdd 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/gog/GogOffline.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/gog/GogOffline.kt @@ -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,10 +69,9 @@ 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 result = GogInnoextract.extract(context, source, target, "gog-refresh", stop, handle::log) if (stop.get()) return - check(rc == 0) { "GOG installer extraction failed (exit $rc)" } + check(result.exit == 0) { result.failure("GOG installer extraction failed (exit ${result.exit})") } applyRefresh(proposal, extracted, handle, stop) } diff --git a/app/src/test/java/com/droiddeck/launcher/stores/gog/GogInnoextractTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/gog/GogInnoextractTest.kt new file mode 100644 index 0000000000..8fd71ce246 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/stores/gog/GogInnoextractTest.kt @@ -0,0 +1,102 @@ +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) = names.map { File(folder, it).apply { parentFile?.mkdirs(); writeText("MZ") } } + + private fun hostOf(guest: String, binds: List): 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) { + 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 aFailedExtractionReportsTheExtractorsOwnError() { + val result = GogInnoextract.Result(2, GogInnoextract.reason(listOf( + "Warning: Unexpected setup data version: Inno Setup Setup Data (6.4.0)", + "Stream error while parsing setup headers!", + " ├─ detected setup version: 6.4.0", + " └─ error reason: iostream error", + "", + ))) + assertEquals( + "The installer could not be extracted (innoextract exit 2): Stream error while parsing setup headers! detected setup version: 6.4.0 error reason: iostream error", + result.failure("The installer could not be extracted (innoextract exit 2)"), + ) + } + + @Test fun theReasonKeepsTheLastErrorLinesAndStaysShort() { + val lines = (1..10).map { "Could not open file \"/mnt/droiddeck-stores/card/setup_$it.exe\"" } + assertEquals(lines.takeLast(3).joinToString(" "), GogInnoextract.reason(lines)) + assertEquals(400, GogInnoextract.reason(listOf("x".repeat(1000))).length) + } + + @Test fun anExtractionWithoutOutputKeepsTheExitMessage() { + val result = GogInnoextract.Result(2, GogInnoextract.reason(listOf("", "Warning: Unexpected setup data version"))) + assertEquals("GOG installer extraction failed (exit 2)", result.failure("GOG installer extraction failed (exit 2)")) + } +}