fix(gog): launch the declared play task with its arguments

GOG manifest paths are case-insensitive Windows paths, so a task whose
file or working directory differs in case from the files on disk was
dropped for the name search. Resolve both case-insensitively and carry
the task's arguments through to the sidecar, so DOSBox tasks start with
their config files instead of the bare DOS exe.
This commit is contained in:
maxjivi05 committed 2026-12-01 15:43:34 -05:00
1 parent 9dfbc05933
commit 220e9d8344
4 files changed
+96 -3

No files matched your search

@@ -136,6 +136,7 @@ object GogBackend : StoreBackend {
val sidecar = StoreGameSidecar(
Store.GOG, game.gameId, game.title, exe = result.exeRelative.ifEmpty { "" },
workdir = result.workDir,
args = result.args,
installVersion = result.buildId, installedAt = System.currentTimeMillis(),
cover = item.tallImageUrl ?: item.imageUrl, hero = item.imageUrl,
logo = item.logoUrl ?: fetchLogo(game.gameId),
@@ -6,6 +6,7 @@ import android.util.Log;
import com.droiddeck.launcher.frontend.AddedGames;
import com.droiddeck.launcher.stores.StoreLanguage;
import com.droiddeck.launcher.stores.StoreLog;
import com.droiddeck.launcher.stores.ea.EaPaths;
import com.droiddeck.launcher.stores.download.StoreDownloadTier;
import org.json.JSONArray;
@@ -68,6 +69,7 @@ public final class GogDownloadManager {
public String language;
/** GOG's working directory for the exe: "" is the install root, null when no task declared it. */
public String workDir;
public List<String> args = new ArrayList<>();
Result(String exeRelative, String buildId, long bytes) { this.exeRelative = exeRelative; this.buildId = buildId; this.bytes = bytes; }
}
@@ -250,7 +252,7 @@ public final class GogDownloadManager {
writeFile(new File(installPath, MARKER), ("{\"gameId\":\"" + game.gameId + "\",\"generation\":1}").getBytes("UTF-8"));
GameTask task = pickTask(installPath, game.gameId, null, game.title);
out.result = new Result(task == null ? "" : task.path, "", planned);
if (task != null) out.result.workDir = task.workDir;
if (task != null) { out.result.workDir = task.workDir; out.result.args = task.args; }
return out;
} catch (Exception e) {
out.error = "exception: " + e.getClass().getSimpleName();
@@ -306,6 +308,7 @@ public final class GogDownloadManager {
GogMaintenance.captureOffline(game.gameId, installPath, downloads);
Result result = new Result(exe, "", total);
result.workDir = task.workDir;
result.args = task.args;
return result;
} catch (InstallerException e) {
throw e;
@@ -785,7 +788,9 @@ public final class GogDownloadManager {
/** GOG's working directory for the task: "" is the install root, null when no task declared it. */
final String workDir;
final int rank;
GameTask(String path, String workDir, int rank) { this.path = path; this.workDir = workDir; this.rank = rank; }
final List<String> args;
GameTask(String path, String workDir, int rank) { this(path, workDir, rank, Collections.<String>emptyList()); }
GameTask(String path, String workDir, int rank, List<String> args) { this.path = path; this.workDir = workDir; this.rank = rank; this.args = args; }
}
/** The task this manifest would be played from, or null when it names none that exists. */
@@ -806,9 +811,11 @@ public final class GogDownloadManager {
if (rank == 0 || (best != null && rank <= best.rank)) continue;
String path = task.optString("path", "").replace('\\', '/').replaceAll("/+", "/").replaceFirst("^(\\.?/)+", "");
if (path.isEmpty()) continue;
if (!new File(installPath, path).isFile()) path = EaPaths.INSTANCE.relativeOnDisk(installPath, path);
if (path == null) continue;
File exe = new File(installPath, path);
if (!exe.isFile() || gogSupportExe(exe.getName()) || !inside(installPath, exe)) continue;
best = new GameTask(path, taskWorkDir(installPath, task), rank);
best = new GameTask(path, taskWorkDir(installPath, task), rank, EaPaths.INSTANCE.splitArgs(task.optString("arguments", "")));
}
return best;
}
@@ -825,6 +832,10 @@ public final class GogDownloadManager {
while (dir.startsWith("./")) dir = dir.substring(2);
dir = dir.replaceAll("^/+", "").replaceAll("/+$", "");
if (dir.isEmpty() || dir.equals(".")) return "";
if (!new File(installPath, dir).isDirectory()) {
dir = EaPaths.INSTANCE.relativeOnDisk(installPath, dir);
if (dir == null) return "";
}
File folder = new File(installPath, dir);
return folder.isDirectory() && inside(installPath, folder) ? dir : "";
}
@@ -397,6 +397,7 @@ internal object GogMaintenance {
val task = GogDownloadManager.pickTask(folder, game.gameId, GogContent.tempExecutable(target.manifest), game.title)
val result = GogDownloadManager.Result(task?.path ?: "", build.id, disk)
result.workDir = task?.workDir
result.args = task?.args.orEmpty()
result.language = target.language
result.dependencies = target.manifest.optJSONArray("dependencies")?.strings().orEmpty()
result.dependenciesRead = true
@@ -1,7 +1,11 @@
package com.droiddeck.launcher.stores.gog
import java.io.File
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.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
@@ -336,4 +340,80 @@ class GogGameExeTest {
assertEquals("System", task.workDir)
}
}
private val dosboxManifest = """{"playTasks":[
{"category":"game","isPrimary":true,"path":"DOSBOX\\DOSBox.exe","workingDir":"DOSBOX","type":"FileTask",
"arguments":"-conf \"..\\dosboxRiva.conf\" -conf \"..\\dosboxRiva_single.conf\" -noconsole -c \"exit\""}]}"""
@Test
fun aCaseMismatchedDosboxTaskWinsOverTheDosExe() {
withFolder { root ->
root.exe("RIVA.EXE", 65536)
root.exe("dosbox/DOSBOX.EXE", 4096)
File(root, "goggame-1207658797.info").writeText(dosboxManifest)
val task = GogDownloadManager.pickTask(root, "1207658797", null, "Realms of Arkania 3")
assertEquals("dosbox/DOSBOX.EXE", task.path)
}
}
@Test
fun aTasksArgumentsAndWorkingDirectoryAreCarriedThrough() {
withFolder { root ->
root.exe("RIVA.EXE", 65536)
root.exe("dosbox/DOSBOX.EXE", 4096)
File(root, "goggame-1207658797.info").writeText(dosboxManifest)
val task = GogDownloadManager.pickTask(root, "1207658797", null, "Realms of Arkania 3")
assertEquals("dosbox", task.workDir)
assertEquals(
listOf("-conf", "..\\dosboxRiva.conf", "-conf", "..\\dosboxRiva_single.conf", "-noconsole", "-c", "exit"),
task.args,
)
}
}
@Test
fun aTasksArgumentsReachTheLauncherScript() {
withFolder { root ->
root.exe("dosbox/DOSBOX.EXE", 4096)
File(root, "goggame-1207658797.info").writeText(dosboxManifest)
val task = GogDownloadManager.pickTask(root, "1207658797", null, "Realms of Arkania 3")
val sidecar = StoreGameSidecar(Store.GOG, "1207658797", "Realms of Arkania 3", task.path, workdir = task.workDir, args = task.args)
val script = StoreLaunch.launcherText(sidecar)
assertTrue(script, script.contains("cd /d \"%~dp0dosbox\""))
assertTrue(script, script.contains("\"%~dp0dosbox\\DOSBOX.EXE\" -conf ..\\dosboxRiva.conf -conf ..\\dosboxRiva_single.conf -noconsole -c exit"))
}
}
@Test
fun anArgumentWithSpacesIsKeptAsOneArgument() {
withFolder { root ->
root.exe("game.exe", 4096)
File(root, "goggame-7.info").writeText(
"""{"playTasks":[{"category":"game","isPrimary":true,"path":"game.exe","arguments":"-cfg \"my config.ini\" -windowed"}]}""",
)
assertEquals(listOf("-cfg", "my config.ini", "-windowed"), GogDownloadManager.pickTask(root, "7", null, "Some Game").args)
}
}
@Test
fun aTaskWithoutArgumentsKeepsNoneAndItsExactCasePath() {
withFolder { root ->
root.exe("System/witcher.exe", 4096)
File(root, "goggame-1207658924.info").writeText(
"""{"playTasks":[{"category":"game","isPrimary":true,"path":"System\\witcher.exe","workingDir":"System","type":"FileTask"}]}""",
)
val task = GogDownloadManager.pickTask(root, "1207658924", null, "The Witcher: Enhanced Edition")
assertEquals("System/witcher.exe", task.path)
assertEquals("System", task.workDir)
assertEquals(emptyList<String>(), task.args)
}
}
@Test
fun aSearchedExecutableHasNoArguments() {
withFolder { root ->
root.exe("kain.exe", 4096)
assertEquals(emptyList<String>(), GogDownloadManager.pickTask(root, null, null, "Blood Omen: Legacy of Kain").args)
}
}
}