fix: a GOG install launches the game, not its config tool (#1644)

Blood Omen ships dxconfig.exe beside kain.exe and the shortcut pointed at
the config tool: pickExe kept the first .exe the folder listing returned
when no title match was found. Read the game's play task from GOG's own
goggame-<id>.info manifest first - a primary game task, or a primary
launcher task for launcher games, and the product's manifest ahead of any
other goggame-*.info - then the product's temp_executable; without either,
rank the folder's exes so a word of the title wins, config and tool names
lose, and depth then size break the remaining ties.

GOG's galaxy_*.exe support installer is not the game either. The Witcher:
Enhanced Edition ships galaxy_the_witcher_enhanced_edition_2.1.0.15.exe
beside launcher.exe, and its build metadata names that file as the
product's temp executable, so launching it starts a 32-bit installer that
stops at "Path not found" under ARM64 FEX - the same dialog as the setup
stub #1174 removed. Play tasks, the hint and the name search skip it.

Fixes #680
Fixes #694

Only a primary launcher task counts as a launch task: GOG files the
configuration tool beside a game as a non-primary launcher, so it now falls
through to the executable search instead of becoming the game.

The temp_executable hint is matched by basename with either separator and
must resolve inside the install folder, so a nested galaxy_*.exe is skipped
too and a hint cannot point outside the game.

GOG runs a task from the working directory it declares, and from the install
root when it declares none. That directory now reaches the sidecar and the
shortcut's Start In: a game in a subfolder (System/witcher.exe) starts where
GOG starts it instead of in System/, where it cannot find its Data folder.
This commit is contained in:
Moroni Granja authored and GitHub committed 2026-11-04 11:38:02 -05:00
1 parent d849e6ae0a
commit 0110dc3c0f
10 files changed
+625 -22

No files matched your search

@@ -18,12 +18,12 @@ import org.robolectric.annotation.Config
class AddedGamesStoreScanTest {
private val app get() = RuntimeEnvironment.getApplication()
private fun install(store: Store, id: String, title: String, exe: String, launcher: Boolean = false): File {
private fun install(store: Store, id: String, title: String, exe: String, launcher: Boolean = false, workdir: String? = null): File {
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
val folder = File(StoreInstallRoot.storeDir(StoreInstallRoot.installRoot(app), store), StoreInstallRoot.folderName(title, id))
File(folder, exe).apply { parentFile!!.mkdirs(); writeText("game") }
File(folder, "unins000.exe").writeText("uninstaller")
var sidecar = StoreGameSidecar(store, id, title, exe, args = if (launcher) listOf("-EpicPortal") else emptyList())
var sidecar = StoreGameSidecar(store, id, title, exe, workdir = workdir, args = if (launcher) listOf("-EpicPortal") else emptyList())
if (launcher) sidecar = StoreLaunch.writeLauncher(folder, sidecar)
sidecar.write(folder)
return folder
@@ -81,4 +81,39 @@ class AddedGamesStoreScanTest {
assertTrue(listing.contains(StoreLaunch.LAUNCHER))
assertTrue(listing.contains("\"store\":\"${Store.EPIC.id}\""))
}
// GOG runs a task from its declared working directory; the install root when it declares none.
@Test fun aTaskWorkingDirectoryBecomesTheShortcutsStartIn() {
val folder = install(Store.GOG, "1207658924", "Witcher Game", "System/witcher.exe", workdir = "System")
val game = AddedGames.scan(app).single { it.folder.absolutePath == folder.absolutePath }
assertTrue(game.guestDir.endsWith("/Witcher Game/System"))
}
@Test fun anEmptyTaskWorkingDirectoryIsTheGameFolder() {
val folder = install(Store.GOG, "1207658924", "Witcher Game", "System/witcher.exe", workdir = "")
val game = AddedGames.scan(app).single { it.folder.absolutePath == folder.absolutePath }
assertEquals("/root/Games/Stores/GOG/Witcher Game", game.guestDir)
}
@Test fun aSidecarWithoutATaskDirectoryStillStartsInTheExeFolder() {
val folder = install(Store.GOG, "7", "Old Game", "bin/old.exe")
val game = AddedGames.scan(app).single { it.folder.absolutePath == folder.absolutePath }
assertTrue(game.guestDir.endsWith("/Old Game/bin"))
}
// A picked exe that is not the store's own keeps its own folder, not the task directory.
@Test fun aPickedExeOnAGogGameStartsInItsOwnFolder() {
val folder = install(Store.GOG, "1207658924", "Witcher Game", "System/witcher.exe", workdir = "")
val tool = File(folder, "Tools/Editor.exe").apply { parentFile!!.mkdirs(); writeText("tool") }
AddedExes.put(app, AddedExes.Entry(folder.path, tool.path, picked = true))
val game = AddedGames.scan(app).single { it.folder.absolutePath == folder.absolutePath }
assertTrue(game.guestDir.endsWith("/Witcher Game/Tools"))
}
@Test fun pickingTheStoresOwnExeKeepsTheTaskDirectory() {
val folder = install(Store.GOG, "1207658924", "Witcher Game", "System/witcher.exe", workdir = "")
AddedExes.put(app, AddedExes.Entry(folder.path, File(folder, "System/witcher.exe").path, picked = true))
val game = AddedGames.scan(app).single { it.folder.absolutePath == folder.absolutePath }
assertEquals("/root/Games/Stores/GOG/Witcher Game", game.guestDir)
}
}
@@ -124,6 +124,25 @@ class StoreGameSidecarTest {
assertFalse(text.contains("DD_AUTH"))
}
@Test fun aWorkingDirectoryTravelsWithTheSidecar() {
val root = StoreGameSidecar(Store.GOG, "1207658924", "The Witcher", "System/witcher.exe", workdir = "")
assertTrue(root.toJson().has("workdir"))
assertEquals("", StoreGameSidecar.parse(root.toJson().toString())!!.workdir)
assertEquals("bin", StoreGameSidecar.parse(root.copy(workdir = "bin").toJson().toString())!!.workdir)
assertNull(StoreGameSidecar.parse(root.copy(workdir = null).toJson().toString())!!.workdir)
assertNull(StoreGameSidecar.parse("""{"store":"gog","id":"1","title":"T","exe":"game.exe"}""")!!.workdir)
assertNull(StoreGameSidecar.parse("""{"store":"gog","id":"1","title":"T","exe":"game.exe","workdir":"../x"}""")!!.workdir)
}
@Test fun theLauncherCdsIntoTheTaskWorkingDirectory() {
assertTrue(StoreLaunch.launcherText(sample.copy(exe = "System/witcher.exe", workdir = ""))
.contains("cd /d \"%~dp0\"\r\n"))
assertTrue(StoreLaunch.launcherText(sample.copy(exe = "bin/x64/game.exe", workdir = "bin/x64"))
.contains("cd /d \"%~dp0bin\\x64\"\r\n"))
assertTrue(StoreLaunch.launcherText(sample.copy(exe = "bin/game.exe", workdir = null))
.contains("cd /d \"%~dp0bin\"\r\n"))
}
@Test fun epicLauncherPrefersTheClientsArguments() {
val text = StoreLaunch.launcherText(sample.copy(exe = "Binaries/Win64/Celeste.exe"))
val lines = text.split("\r\n")
@@ -0,0 +1,339 @@
package com.droiddeck.launcher.stores.gog
import java.io.File
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class GogGameExeTest {
private fun withFolder(block: (File) -> Unit) {
val root = kotlin.io.path.createTempDirectory("gog-exe").toFile()
try {
block(root)
} finally {
root.deleteRecursively()
}
}
private fun File.exe(path: String, size: Int = 1024) {
val file = File(this, path)
file.parentFile?.mkdirs()
file.writeBytes(ByteArray(size))
}
// #680: Blood Omen installs dxconfig.exe next to kain.exe, and the config tool won.
@Test fun theGameExecutableWinsOverTheConfigToolInTheSameFolder() {
withFolder { root ->
root.exe("dxconfig.exe")
root.exe("kain.exe", 4096)
assertEquals("kain.exe", GogDownloadManager.pickExe(root, null, null, "Blood Omen: Legacy of Kain"))
}
}
@Test fun aConfigToolInTheGameFolderIsNeverTheFoundExecutable() {
withFolder { root ->
root.exe("dxconfig.exe")
root.exe("bin/kain.exe", 4096)
assertEquals("bin/kain.exe", GogDownloadManager.pickExe(root, null, null, "Blood Omen: Legacy of Kain"))
}
}
@Test fun theLauncherInTheGameRootLosesToTheGameExecutable() {
withFolder { root ->
root.exe("Launcher.exe")
root.exe("bin/witcher2.exe", 4096)
assertEquals(
"bin/witcher2.exe",
GogDownloadManager.pickExe(root, null, null, "The Witcher 2: Assassins of Kings Enhanced Edition"),
)
}
}
@Test fun theInstallerHintWinsOverTheSearch() {
withFolder { root ->
root.exe("dxconfig.exe")
root.exe("bin/game.exe", 4096)
assertEquals("bin/game.exe", GogDownloadManager.pickExe(root, null, "bin/game.exe", "Blood Omen: Legacy of Kain"))
}
}
@Test fun aFolderWithoutAGameExecutableYieldsNoPath() {
withFolder { root ->
root.exe("redist/vcredist_x64.exe")
assertEquals("", GogDownloadManager.pickExe(root, null, null, "Blood Omen: Legacy of Kain"))
}
}
@Test fun theManifestsGameTaskIsTheExecutable() {
withFolder { root ->
root.exe("dxconfig.exe")
root.exe("bin/omen.exe", 4096)
File(root, "goggame-1207659641.info").writeText(
"""{"gameId":"1207659641","playTasks":[
{"category":"tool","path":"dxconfig.exe","type":"FileTask"},
{"category":"game","isPrimary":true,"path":"bin\\omen.exe","type":"FileTask"},
{"category":"document","path":"manual.pdf","type":"FileTask"}
]}""",
)
assertEquals("bin/omen.exe", GogDownloadManager.pickExe(root, "1207659641", null, "Blood Omen: Legacy of Kain"))
}
}
@Test fun aManifestWithOnlyAToolTaskLeavesTheSearchInCharge() {
withFolder { root ->
root.exe("dxconfig.exe")
root.exe("kain.exe", 4096)
File(root, "goggame-1207659641.info")
.writeText("""{"playTasks":[{"category":"tool","path":"dxconfig.exe","type":"FileTask"}]}""")
assertEquals("kain.exe", GogDownloadManager.pickExe(root, null, null, "Blood Omen: Legacy of Kain"))
}
}
@Test fun aManifestPathOutsideTheGameFolderIsIgnored() {
withFolder { root ->
root.exe("kain.exe", 4096)
val outside = File(root.parentFile, "outside-${System.nanoTime()}.exe").apply { writeBytes(ByteArray(8)) }
try {
File(root, "goggame-1207659641.info").writeText(
"""{"playTasks":[{"category":"game","isPrimary":true,"path":"../${outside.name}","type":"FileTask"}]}""",
)
assertEquals("kain.exe", GogDownloadManager.pickExe(root, null, null, "Blood Omen: Legacy of Kain"))
} finally {
outside.delete()
}
}
}
@Test fun aPrimaryLauncherTaskIsTheGameOfLauncherGames() {
withFolder { root ->
root.exe("run.exe")
root.exe("game.exe", 4096)
File(root, "goggame-7.info").writeText(
"""{"playTasks":[
{"category":"launcher","isPrimary":true,"path":"run.exe","type":"FileTask"},
{"category":"game","path":"game.exe","type":"FileTask"}
]}""",
)
assertEquals("run.exe", GogDownloadManager.pickExe(root, "7", null, "Some Game"))
}
}
@Test fun aPrimaryGameTaskBeatsAPrimaryLauncherTask() {
withFolder { root ->
root.exe("run.exe")
root.exe("game.exe", 4096)
File(root, "goggame-7.info").writeText(
"""{"playTasks":[
{"category":"launcher","isPrimary":true,"path":"run.exe","type":"FileTask"},
{"category":"game","isPrimary":true,"path":"game.exe","type":"FileTask"}
]}""",
)
assertEquals("game.exe", GogDownloadManager.pickExe(root, "7", null, "Some Game"))
}
}
@Test fun theProductsOwnManifestDecidesOverADlcManifest() {
withFolder { root ->
root.exe("base.exe")
root.exe("dlc.exe", 4096)
File(root, "goggame-7.info")
.writeText("""{"playTasks":[{"category":"game","isPrimary":true,"path":"base.exe","type":"FileTask"}]}""")
File(root, "goggame-9.info")
.writeText("""{"playTasks":[{"category":"game","isPrimary":true,"path":"dlc.exe","type":"FileTask"}]}""")
assertEquals("base.exe", GogDownloadManager.pickExe(root, "7", null, "Some Game"))
}
}
@Test fun aDlcManifestSuppliesTheGameWhenTheProductsOwnHasNone() {
withFolder { root ->
root.exe("dxconfig.exe")
root.exe("dlc.exe", 4096)
File(root, "goggame-7.info")
.writeText("""{"playTasks":[{"category":"tool","path":"dxconfig.exe","type":"FileTask"}]}""")
File(root, "goggame-9.info")
.writeText("""{"playTasks":[{"category":"game","isPrimary":true,"path":"dlc.exe","type":"FileTask"}]}""")
assertEquals("dlc.exe", GogDownloadManager.pickExe(root, "7", null, "Some Game"))
}
}
@Test fun theManifestBeatsTheInstallerHint() {
withFolder { root ->
root.exe("dxconfig.exe")
root.exe("kain.exe", 4096)
File(root, "goggame-7.info")
.writeText("""{"playTasks":[{"category":"game","isPrimary":true,"path":"kain.exe","type":"FileTask"}]}""")
assertEquals(
"kain.exe",
GogDownloadManager.pickExe(root, "7", "dxconfig.exe", "Blood Omen: Legacy of Kain"),
)
}
}
// #694: the GOG build's temp executable is its Galaxy support installer, not the game.
@Test
fun theGalaxySupportInstallerIsNeverTheGame() {
withFolder { root ->
root.exe("galaxy_the_witcher_enhanced_edition_2.1.0.15.exe", 1_300_000)
root.exe("launcher.exe")
root.exe("register.exe")
root.exe("System/witcher.exe", 4096)
assertEquals(
"System/witcher.exe",
GogDownloadManager.pickExe(
root,
"1207658924",
"galaxy_the_witcher_enhanced_edition_2.1.0.15.exe",
"The Witcher: Enhanced Edition",
),
)
}
}
@Test
fun aManifestThatNamesTheGalaxySupportInstallerIsIgnored() {
withFolder { root ->
root.exe("galaxy_the_witcher_enhanced_edition_2.1.0.15.exe", 1_300_000)
root.exe("System/witcher.exe", 4096)
File(root, "goggame-1207658924.info").writeText(
"""{"playTasks":[{"category":"game","isPrimary":true,"path":"galaxy_the_witcher_enhanced_edition_2.1.0.15.exe","type":"FileTask"}]}""",
)
assertEquals(
"System/witcher.exe",
GogDownloadManager.pickExe(root, "1207658924", null, "The Witcher: Enhanced Edition"),
)
}
}
// GOG's own sample manifest files the Configuration Tool as a non-primary launcher task.
@Test
fun aNonPrimaryLauncherTaskIsNotTheGame() {
withFolder { root ->
root.exe("Config2_DX9.exe")
root.exe("ed6_win2_DX9.exe", 4096)
File(root, "goggame-1207658924.info").writeText(
"""{"playTasks":[
{"category":"launcher","name":"Configuration Tool","path":"Config2_DX9.exe","type":"FileTask"},
{"category":"game","path":"ed6_win2_DX9.exe","type":"FileTask"}
]}""",
)
assertEquals(
"ed6_win2_DX9.exe",
GogDownloadManager.pickExe(root, "1207658924", null, "The Legend of Heroes: Trails in the Sky SC"),
)
}
}
@Test
fun aLoneNonPrimaryLauncherLeavesTheSearchInCharge() {
withFolder { root ->
root.exe("Config2_DX9.exe")
root.exe("ed6_win2_DX9.exe", 4096)
File(root, "goggame-1207658924.info").writeText(
"""{"playTasks":[{"category":"launcher","path":"Config2_DX9.exe","type":"FileTask"}]}""",
)
assertEquals(
"ed6_win2_DX9.exe",
GogDownloadManager.pickExe(root, "1207658924", null, "The Legend of Heroes: Trails in the Sky SC"),
)
}
}
@Test
fun theSupportInstallerHintIsSkippedWhateverItsFolder() {
withFolder { root ->
root.exe("support/galaxy_setup.exe", 1_300_000)
root.exe("System/witcher.exe", 4096)
assertEquals(
"System/witcher.exe",
GogDownloadManager.pickExe(
root,
"1207658924",
"support/galaxy_setup.exe",
"The Witcher: Enhanced Edition",
),
)
assertEquals(
"System/witcher.exe",
GogDownloadManager.pickExe(
root,
"1207658924",
"support\\galaxy_setup.exe",
"The Witcher: Enhanced Edition",
),
)
}
}
@Test
fun anInstallerHintOutsideTheGameFolderIsIgnored() {
withFolder { root ->
root.exe("game.exe", 4096)
val outside = File(root.parentFile, "outside-${System.nanoTime()}.exe").apply { writeBytes(ByteArray(8)) }
try {
assertEquals(
"game.exe",
GogDownloadManager.pickExe(root, "7", "../${outside.name}", "Some Game"),
)
} finally {
outside.delete()
}
}
}
// GOG runs a task from the install root unless it declares a working directory.
@Test
fun aTaskWithoutAWorkingDirectoryRunsFromTheGameFolder() {
withFolder { root ->
root.exe("System/witcher.exe", 4096)
File(root, "goggame-1207658924.info").writeText(
"""{"playTasks":[{"category":"game","isPrimary":true,"path":"System\\witcher.exe","type":"FileTask"}]}""",
)
val task = GogDownloadManager.pickTask(root, "1207658924", null, "The Witcher: Enhanced Edition")
assertEquals("System/witcher.exe", task.path)
assertEquals("", task.workDir)
}
}
@Test
fun aDeclaredWorkingDirectoryIsKept() {
withFolder { root ->
root.exe("bin/x64/game.exe", 4096)
File(root, "goggame-7.info").writeText(
"""{"playTasks":[{"category":"game","isPrimary":true,"path":"bin\\x64\\game.exe","workingDir":"bin\\x64","type":"FileTask"}]}""",
)
val task = GogDownloadManager.pickTask(root, "7", null, "Some Game")
assertEquals("bin/x64/game.exe", task.path)
assertEquals("bin/x64", task.workDir)
}
}
@Test
fun aWorkingDirectoryThatLeavesTheGameFolderFallsBackToTheRoot() {
withFolder { root ->
root.exe("game.exe", 4096)
File(root, "goggame-7.info").writeText(
"""{"playTasks":[{"category":"game","isPrimary":true,"path":"game.exe","workingDir":"../other","type":"FileTask"}]}""",
)
assertEquals("", GogDownloadManager.pickTask(root, "7", null, "Some Game").workDir)
}
}
// GOG manifests use doubled separators (The Witcher 3: "bin//x64//witcher3.exe"); the sidecar
// parser rejects empty path components, so both values must be collapsed before they are stored.
@Test
fun duplicateSeparatorsInTaskValuesAreCollapsed() {
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)
}
}
}