mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
fix(gog): bind every store root for installer extraction and log its error
This commit is contained in:
1 parent
40242fa082
commit
b33e01f495
6 files changed
+168
-27
No files matched your search
@@ -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<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;
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<String>()
|
||||
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<String> = listOf(PROGRAM, "--gog", "--silent", "-d", target, setup)
|
||||
|
||||
internal fun reason(lines: Iterable<String>): 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:") }
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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<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 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)"))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user