mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 13:05:47 +00:00
fix(gog): retry unreadable manifests, refresh the play task after updates, escape batch characters in arguments
This commit is contained in:
1 parent
a43f4d5ba6
commit
70ee78f6e2
5 files changed
+75
-7
No files matched your search
@@ -48,7 +48,7 @@ object StoreLaunch {
|
||||
if (sidecar.store != Store.ROCKSTAR) lines += "rem Written by DroidDeck for ${sidecar.store.label}: ${sidecar.title}. Steam's shortcut runs this file."
|
||||
lines += "cd /d \"%~dp0$dir\""
|
||||
for ((k, v) in sidecar.env) if (ENV_NAME.matches(k)) lines += "set \"$k=${v.replace("\"", "")}\""
|
||||
val args = sidecar.args.joinToString(" ") { if (sidecar.store == Store.ROCKSTAR) batchArg(it) else quoteArg(it) }
|
||||
val args = sidecar.args.joinToString(" ") { if (sidecar.store == Store.ROCKSTAR || it.any { c -> c in BATCH_META }) batchArg(it) else quoteArg(it) }
|
||||
val run = "\"%~dp0$exe\"" + (if (args.isNotEmpty()) " $args" else "")
|
||||
if (sidecar.store == Store.EPIC || sidecar.store == Store.UBISOFT) {
|
||||
lines += "set \"$ROOT_VAR=Z:\""
|
||||
@@ -105,6 +105,8 @@ object StoreLaunch {
|
||||
return lines.joinToString("\r\n") + "\r\n"
|
||||
}
|
||||
|
||||
private const val BATCH_META = "%^&|<>()\""
|
||||
|
||||
private val ENV_NAME = Regex("[A-Za-z_][A-Za-z0-9_]*")
|
||||
|
||||
private fun batchArg(arg: String): String {
|
||||
|
||||
@@ -24,11 +24,18 @@ import java.util.concurrent.atomic.AtomicBoolean
|
||||
object GogBackend : StoreBackend {
|
||||
const val PLAY_TASK_READ = "gogPlayTaskRead"
|
||||
|
||||
fun withPlayTask(folder: File, sidecar: StoreGameSidecar, replaceExe: Boolean): StoreGameSidecar {
|
||||
if (!runCatching { GogDownloadManager.manifestsReadable(folder) }.getOrDefault(false)) return sidecar.copy(extra = sidecar.extra - PLAY_TASK_READ)
|
||||
val task = runCatching { GogDownloadManager.declaredGameTask(folder, sidecar.id) }.getOrNull()?.takeIf { replaceExe || it.args.isNotEmpty() }
|
||||
val next = if (task != null) sidecar.copy(exe = task.path, workdir = task.workDir, args = task.args) else sidecar
|
||||
return next.copy(extra = next.extra + (PLAY_TASK_READ to "1"))
|
||||
}
|
||||
|
||||
fun adoptPlayTask(folder: File, sidecar: StoreGameSidecar): StoreGameSidecar {
|
||||
if (sidecar.store != Store.GOG || !sidecar.isInstalled || PLAY_TASK_READ in sidecar.extra) return sidecar
|
||||
val task = runCatching { GogDownloadManager.pickTask(folder, sidecar.id, null, sidecar.title) }.getOrNull()
|
||||
val next = if (task != null && task.args.isNotEmpty()) sidecar.copy(exe = task.path, workdir = task.workDir, args = task.args) else sidecar
|
||||
return runCatching { StoreLaunch.writeLauncher(folder, next.copy(extra = next.extra + (PLAY_TASK_READ to "1"))).also { it.write(folder) } }.getOrDefault(sidecar)
|
||||
val next = withPlayTask(folder, sidecar, replaceExe = false)
|
||||
if (PLAY_TASK_READ !in next.extra) return sidecar
|
||||
return runCatching { StoreLaunch.writeLauncher(folder, next).also { it.write(folder) } }.getOrDefault(sidecar)
|
||||
}
|
||||
|
||||
override val store: Store = Store.GOG
|
||||
|
||||
@@ -759,7 +759,7 @@ public final class GogDownloadManager {
|
||||
* one; any other {@code goggame-*.info} in the folder is only the fallback. Builds without a
|
||||
* manifest fall through to the hint and search below.
|
||||
*/
|
||||
private static GameTask declaredGameTask(File installPath, String gameId) {
|
||||
static GameTask declaredGameTask(File installPath, String gameId) {
|
||||
File own = gameId == null || gameId.isEmpty() ? null : new File(installPath, "goggame-" + gameId + ".info");
|
||||
if (own != null && !own.isFile()) own = null;
|
||||
List<File> others = new ArrayList<>();
|
||||
@@ -783,6 +783,20 @@ public final class GogDownloadManager {
|
||||
return best;
|
||||
}
|
||||
|
||||
static boolean manifestsReadable(File installPath) {
|
||||
File[] files = installPath.listFiles();
|
||||
if (files == null) return false;
|
||||
for (File f : files) {
|
||||
if (!f.isFile() || !f.getName().startsWith("goggame-") || !f.getName().endsWith(".info")) continue;
|
||||
try {
|
||||
new JSONObject(new String(Files.readAllBytes(f.toPath()), StandardCharsets.UTF_8));
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static final class GameTask {
|
||||
final String path;
|
||||
/** GOG's working directory for the task: "" is the install root, null when no task declared it. */
|
||||
|
||||
@@ -181,7 +181,7 @@ internal object GogMaintenance {
|
||||
}
|
||||
val sidecar = StoreGameSidecar.parse(journal.getJSONObject("sidecar").toString()) ?: error("The original GOG settings are missing")
|
||||
target.write(folder)
|
||||
StoreInstalls.complete(context, folder, sidecar.copy(installVersion = target.build, state = StoreGameSidecar.STATE_INSTALLED))
|
||||
StoreInstalls.complete(context, folder, GogBackend.withPlayTask(folder, sidecar.copy(installVersion = target.build, state = StoreGameSidecar.STATE_INSTALLED), replaceExe = true))
|
||||
check(GogFiles.journal(folder).delete()) { "Could not finish the GOG recovery record" }
|
||||
}
|
||||
}
|
||||
@@ -284,7 +284,7 @@ internal object GogMaintenance {
|
||||
val target = GogInstallRecord.read(folder)?.takeIf { proposal.operation == GogOperation.PATCH || proposal.operation == GogOperation.REFRESH && proposal.target.source != "depot" } ?: proposal.target
|
||||
check(target.verified) { "The patch completed, but its resulting version could not be verified. Inspect the game or use a full offline refresh." }
|
||||
target.write(folder)
|
||||
StoreInstalls.complete(app, folder, sidecar.copy(installVersion = target.build.ifBlank { target.version }, state = StoreGameSidecar.STATE_INSTALLED))
|
||||
StoreInstalls.complete(app, folder, GogBackend.withPlayTask(folder, sidecar.copy(installVersion = target.build.ifBlank { target.version }, state = StoreGameSidecar.STATE_INSTALLED), replaceExe = true))
|
||||
check(GogFiles.journal(folder).delete()) { "Could not finish the GOG recovery record" }
|
||||
runCatching { cleanCaches() }.onFailure { handle.log("gog: completed; could not remove expendable cache: ${it.message}") }
|
||||
checkedAt.remove(folder.path)
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.droiddeck.launcher.stores.Store
|
||||
import com.droiddeck.launcher.stores.StoreGameSidecar
|
||||
import com.droiddeck.launcher.stores.StoreLaunch
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
@@ -452,4 +453,48 @@ class GogGameExeTest {
|
||||
assertEquals("1", adopted.extra[GogBackend.PLAY_TASK_READ])
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anUnreadableManifestIsRetriedOnceItReadsAgain() {
|
||||
withFolder { root ->
|
||||
root.exe("RIVA.EXE", 65536)
|
||||
root.exe("dosbox/DOSBOX.EXE", 4096)
|
||||
val manifest = File(root, "goggame-1207658797.info")
|
||||
manifest.writeText(dosboxManifest.take(40))
|
||||
val stale = StoreGameSidecar(Store.GOG, "1207658797", "Realms of Arkania 3", "RIVA.EXE")
|
||||
stale.write(root)
|
||||
assertTrue(StoreLaunch.adopt(root, stale) === stale)
|
||||
assertFalse(GogBackend.PLAY_TASK_READ in StoreGameSidecar.read(root)!!.extra)
|
||||
manifest.writeText(dosboxManifest)
|
||||
val adopted = StoreLaunch.adopt(root, StoreGameSidecar.read(root)!!)
|
||||
assertEquals("dosbox/DOSBOX.EXE", adopted.exe)
|
||||
assertEquals("1", adopted.extra[GogBackend.PLAY_TASK_READ])
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anUpdatedBuildTakesItsNewPlayTask() {
|
||||
withFolder { root ->
|
||||
root.exe("bin/game.exe", 4096)
|
||||
root.exe("old.exe", 65536)
|
||||
File(root, "goggame-1.info").writeText("""{"playTasks":[{"category":"game","isPrimary":true,"path":"bin\\game.exe","arguments":"-a b","type":"FileTask"}]}""")
|
||||
val read = StoreGameSidecar(Store.GOG, "1", "Game", "old.exe", extra = mapOf(GogBackend.PLAY_TASK_READ to "1"))
|
||||
val updated = GogBackend.withPlayTask(root, read, replaceExe = true)
|
||||
assertEquals("bin/game.exe", updated.exe)
|
||||
assertEquals(listOf("-a", "b"), updated.args)
|
||||
File(root, "goggame-1.info").writeText("{")
|
||||
assertFalse(GogBackend.PLAY_TASK_READ in GogBackend.withPlayTask(root, read, replaceExe = true).extra)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun taskArgumentsWithBatchCharactersStayOneArgument() {
|
||||
withFolder { root ->
|
||||
root.exe("dosbox/DOSBOX.EXE", 4096)
|
||||
val sidecar = StoreGameSidecar(Store.GOG, "1", "Game", "dosbox/DOSBOX.EXE", args = listOf("-conf", "base&extra.conf", "-noconsole"))
|
||||
StoreLaunch.writeLauncher(root, sidecar)
|
||||
val text = File(root, StoreLaunch.LAUNCHER).readText()
|
||||
assertTrue(text.contains("-conf ^\"base^&extra.conf^\" -noconsole"))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user