From 8bb189570264b64eca88aa42d0b6dfc4bf73da2c Mon Sep 17 00:00:00 2001 From: MaxsTechReview Date: Tue, 24 Nov 2026 16:16:31 -0500 Subject: [PATCH] fix(gog): skip saves GOG Cloud marks deleted (#3025) * fix(gog): skip saves GOG Cloud marks deleted GOG keeps a deleted cloud save in the listing as an empty gzip object (hash aadd86936a80ee8a369579c3926f1b3c). The listing was read as plain names without hashes, so every deleted save was downloaded again as an empty file. Ask for the JSON listing, keep each object's hash, treat deletion markers as absent, and only send a marked save back once it changed locally. Local files are never removed. * docs: credit gogdl and Lutris for the GOG cloud deletion marker --- README.md | 2 +- .../droiddeck/launcher/stores/CloudPlan.kt | 3 +- .../droiddeck/launcher/stores/CloudSaves.kt | 16 +++++--- .../launcher/stores/CloudTransport.kt | 8 +++- .../launcher/stores/CloudPlanTest.kt | 9 +++++ .../launcher/stores/CloudSavesTest.kt | 38 ++++++++++++++++++- .../launcher/stores/GogCloudKeysTest.kt | 23 +++++++++++ 7 files changed, 89 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a1094c8d14..066136eab3 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ DroidDeck is [GPL-3.0](LICENSE). Steam and Proton belong to Valve Corporation. V
Stores -- Epic Games and GOG build on [Phobos](https://github.com/phobos665)'s adaptation of [Legendary](https://github.com/legendary-gl/legendary) and [gogdl](https://github.com/Heroic-Games-Launcher/heroic-gogdl). GOG install script registry entries are read the way [Heroic Games Launcher](https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher) (GPL-3.0) reads them. GOG cloud storage requests send the Galaxy communication-service User-Agent that gogdl and [Lutris](https://github.com/lutris/lutris) (GPL-3.0) send. +- Epic Games and GOG build on [Phobos](https://github.com/phobos665)'s adaptation of [Legendary](https://github.com/legendary-gl/legendary) and [gogdl](https://github.com/Heroic-Games-Launcher/heroic-gogdl). GOG install script registry entries are read the way [Heroic Games Launcher](https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher) (GPL-3.0) reads them. GOG cloud storage requests send the Galaxy communication-service User-Agent that gogdl and [Lutris](https://github.com/lutris/lutris) (GPL-3.0) send. Deleted GOG cloud saves are recognised by the empty-gzip deletion hash gogdl and Lutris skip. - Epic's official Linux launcher preview runs through FEX. That setup is outside Epic's listed Linux support. - The launcher's .deb gets the WebKitGTK and GTK 3 libraries it needs from unmodified [Debian](https://www.debian.org) 13 packages, following [@zooluis](https://github.com/zooluis)'s research in [#2268](https://github.com/Droid-Deck/DroidDeck/pull/2268). - Battle.net is by [@kayakyakr](https://github.com/kayakyakr). It runs Blizzard's own client in Proton (downloaded from Blizzard, not included) and shows key art from the [Battle.net Shop](https://shop.battle.net). Without Steam, its games see the pad as an Xbox 360 controller via `PROTON_SPOOF_STEAMINPUT_VIDPID` in [Proton](https://github.com/ValveSoftware/wine)'s `dlls/winebus.sys`. diff --git a/app/src/main/java/com/droiddeck/launcher/stores/CloudPlan.kt b/app/src/main/java/com/droiddeck/launcher/stores/CloudPlan.kt index d3c63b203a..940d1eee71 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/CloudPlan.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/CloudPlan.kt @@ -36,13 +36,14 @@ object CloudPlan { return Plan(transfer, conflicts, same) } - fun up(local: Map, remote: Map, baseline: Map?): Plan { + fun up(local: Map, remote: Map, baseline: Map?, deleted: Set = emptySet()): Plan { if (baseline == null) return Plan(emptyList(), emptyList(), emptyList(), refused = "no-baseline") val transfer = ArrayList(); val conflicts = ArrayList(); val same = ArrayList() for ((name, l) in local) { val r = remote[name] val b = baseline[name] when { + r == null && name in deleted && !localChanged(l, b) -> Unit r == null -> transfer += name same(l, r) -> same += name localChanged(l, b) && cloudChanged(r, b) -> conflicts += name diff --git a/app/src/main/java/com/droiddeck/launcher/stores/CloudSaves.kt b/app/src/main/java/com/droiddeck/launcher/stores/CloudSaves.kt index c2fd9890d5..5923cd6e44 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/CloudSaves.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/CloudSaves.kt @@ -430,17 +430,20 @@ object CloudSaves { internal fun md5(data: ByteArray): String = MessageDigest.getInstance("MD5").digest(data).joinToString("") { "%02x".format(it) } - private fun remote(cloud: CloudTransport, wanted: (String) -> Boolean): Map { + private class Listing(val live: Map, val deleted: Set) + + private fun remote(cloud: CloudTransport, wanted: (String) -> Boolean): Listing { val files = cloud.list() val pool = Executors.newFixedThreadPool(PARALLEL, com.droiddeck.launcher.stores.download.DownloadQueue.workerFactory("cloud")) for (f in files) if (wanted(f.name)) pool.execute { runCatching { cloud.details(f) } } pool.shutdown(); pool.awaitTermination(2, TimeUnit.MINUTES) - return files.associateBy { it.name } + val (gone, live) = files.partition(cloud::deleted) + return Listing(live.associateBy { it.name }, gone.mapTo(HashSet()) { it.name }) } internal fun downWith(context: Context, store: Store, id: String, dir: File, cloud: CloudTransport, force: Boolean, claim: () -> Boolean = { true }): Result { val files = localFiles(dir).filterKeys(cloud::wants) - val remote = remote(cloud) { it in files } + val remote = remote(cloud) { it in files }.live val local = files.mapValues { CloudPlan.Local(md5(it.value)) } val key = scope(store, id, dir) val base = baseline(context, store, key) @@ -498,9 +501,10 @@ object CloudSaves { val base = baseline(context, store, key) ?: return Result("skipped", 0, 0, "no-baseline") val files = localFiles(dir).filterKeys(cloud::wants).let { all -> if (cloud is UbisoftCloudTransport) all.filterValues(::markUbisoftSave) else all } if (files.isEmpty()) return Result("skipped", 0, 0, "nothing-local") - val remote = remote(cloud) { it in files } + val listing = remote(cloud) { it in files } + val remote = listing.live val local = files.mapValues { CloudPlan.Local(md5(it.value)) } - val planned = CloudPlan.up(local, remote.mapValues { CloudPlan.Remote(it.value.md5, it.value.modifiedMs) }, base) + val planned = CloudPlan.up(local, remote.mapValues { CloudPlan.Remote(it.value.md5, it.value.modifiedMs) }, base, listing.deleted) val alike = alike(cloud, planned.conflicts, local, remote) val plan = settled(planned, alike) val saved = savedConflicts(context, store, key).filter { it !in alike && it !in plan.same } @@ -547,7 +551,7 @@ object CloudSaves { send = send.filter { it in stamped } for ((name, t) in stamped) if (t > 0) files[name]?.setLastModified(t) } - val after = if (send.all { cloud.committed(it) != null }) emptyMap() else remote(cloud) { it in send && cloud.committed(it) == null } + val after = if (send.all { cloud.committed(it) != null }) emptyMap() else remote(cloud) { it in send && cloud.committed(it) == null }.live for (name in send) { val r = cloud.committed(name) ?: after[name] next[name] = CloudPlan.Entry(sentMd5.getValue(name), r?.md5, r?.modifiedMs ?: stamped[name] ?: -1L) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/CloudTransport.kt b/app/src/main/java/com/droiddeck/launcher/stores/CloudTransport.kt index 9e0ad99196..efb79d8543 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/CloudTransport.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/CloudTransport.kt @@ -31,6 +31,7 @@ interface CloudTransport { val contentDigests: Boolean get() = true fun committed(name: String): CloudFile? = null fun wants(name: String): Boolean = true + fun deleted(file: CloudFile): Boolean = false fun list(): List fun details(file: CloudFile) {} fun get(file: CloudFile): Pair @@ -252,6 +253,8 @@ private fun gzipFile(src: File, dst: File): GzipFile { } } +internal const val GOG_DELETED_MD5 = "aadd86936a80ee8a369579c3926f1b3c" + internal const val GOG_CLOUD_UA = "GOGGalaxyCommunicationService/2.0.13.27 (Windows_32bit) dont_sync_marker/true installation_source/gog" /** GOG Galaxy parses `X-Object-Meta-LocalLastModified`; objects without it fail as "invalid data". */ @@ -276,8 +279,11 @@ class GogCloud( private fun cloudKey(name: String) = key((prefix ?: "") + name) + override fun deleted(file: CloudFile): Boolean = file.md5.equals(GOG_DELETED_MD5, ignoreCase = true) + override fun list(): List { val c = open(base, "GET", token, ua) + c.setRequestProperty("Accept", "application/json") val code = c.responseCode if (code == 404) { c.disconnect(); return emptyList() } if (code !in 200..299) { @@ -300,7 +306,7 @@ class GogCloud( lm > 0 -> lm * 1000 iso > 0 -> iso else -> -1L - }) + }, o.optString("hash").trim().ifEmpty { null }) } } else { text.lines().map { it.trim() }.filter { it.isNotEmpty() }.map { CloudFile(it, -1L) } diff --git a/app/src/test/java/com/droiddeck/launcher/stores/CloudPlanTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/CloudPlanTest.kt index 1979bece2b..c2ef81ac04 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/CloudPlanTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/CloudPlanTest.kt @@ -48,6 +48,15 @@ class CloudPlanTest { assertEquals(listOf("s"), CloudPlan.up(mapOf("s" to Local("c")), mapOf("s" to Remote("c", 9000)), base).same) } + @Test fun aSaveDeletedInTheCloudGoesUpOnlyOnceItChangesLocally() { + val base = mapOf("s" to Entry("a", "a", 1000), "t" to Entry("x", "x", 1000)) + val gone = setOf("s") + val idle = CloudPlan.up(mapOf("s" to Local("a"), "t" to Local("y"), "n" to Local("new")), mapOf("t" to Remote("x", 1000)), base, gone) + assertEquals(setOf("t", "n"), idle.transfer.toSet()) + assertEquals(listOf("s"), CloudPlan.up(mapOf("s" to Local("b")), emptyMap(), base, gone).transfer) + assertEquals(listOf("s"), CloudPlan.up(mapOf("s" to Local("a")), emptyMap(), base).transfer) + } + @Test fun timesAloneDecideWhenTheServiceGivesNoHash() { val base = mapOf("s" to Entry("a", null, 1000)) assertEquals(listOf("s"), CloudPlan.down(mapOf("s" to Local("a")), mapOf("s" to Remote(null, 60_000)), base).transfer) diff --git a/app/src/test/java/com/droiddeck/launcher/stores/CloudSavesTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/CloudSavesTest.kt index f3944a8034..c2decf0879 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/CloudSavesTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/CloudSavesTest.kt @@ -25,7 +25,9 @@ class CloudSavesTest { val puts = ArrayList() var onGet: (CloudFile) -> Unit = {} var raceAfter = Int.MAX_VALUE - override fun list() = files.map { (k, v) -> CloudFile(k, v.second, CloudSaves.md5(v.first)) } + val gone = HashSet() + override fun deleted(file: CloudFile) = file.md5 == GOG_DELETED_MD5 + override fun list() = files.map { (k, v) -> CloudFile(k, v.second, CloudSaves.md5(v.first)) } + gone.map { CloudFile(it, 5000L, GOG_DELETED_MD5) } override fun get(file: CloudFile) = files.getValue(file.name).also { onGet(file) } override fun put(files: Map, modifiedMs: Map): Map { val sent = LinkedHashMap() @@ -40,6 +42,40 @@ class CloudSavesTest { private fun dir() = File(app.filesDir, "saves-${System.nanoTime()}").apply { mkdirs() } private val id get() = "g${System.nanoTime()}" + @Test fun savesTheCloudMarksDeletedAreNotDownloaded() { + val dir = dir() + val cloud = Memory().apply { + files["save1.ess"] = "kept".toByteArray() to 1000L + gone += listOf("save2.ess", "save3.ess", "save3.skse") + } + val r = CloudSaves.downWith(app, Store.GOG, id, dir, cloud, force = true) + assertEquals("ok", r.result); assertEquals(1, r.files) + assertEquals(listOf("save1.ess"), dir.list()!!.sorted()) + } + + @Test fun aLocalSaveTheCloudMarksDeletedIsLeftAlone() { + val dir = dir(); File(dir, "save2.ess").writeText("mine") + val cloud = Memory().apply { files["save1.ess"] = "kept".toByteArray() to 1000L; gone += "save2.ess" } + assertEquals("ok", CloudSaves.downWith(app, Store.GOG, id, dir, cloud, force = false).result) + assertEquals("mine", File(dir, "save2.ess").readText()) + assertEquals("kept", File(dir, "save1.ess").readText()) + } + + @Test fun anUnchangedSaveDeletedInTheCloudIsNotSentBackButANewerOneIs() { + val game = id; val dir = dir() + val cloud = Memory().apply { files["save1.ess"] = "a".toByteArray() to 1000L; files["save2.ess"] = "b".toByteArray() to 1000L } + assertEquals("ok", CloudSaves.downWith(app, Store.GOG, game, dir, cloud, force = false).result) + cloud.files.remove("save2.ess"); cloud.gone += "save2.ess" + val idle = CloudSaves.upWith(app, Store.GOG, game, dir, cloud, force = false) + assertEquals("up-to-date", idle.reason) + assertTrue(cloud.puts.isEmpty()) + File(dir, "save2.ess").writeText("b played again") + val r = CloudSaves.upWith(app, Store.GOG, game, dir, cloud, force = false) + assertEquals(listOf("save2.ess"), cloud.puts) + assertEquals("b played again", String(cloud.files.getValue("save2.ess").first)) + assertEquals(1, r.files) + } + @Test fun anUploadBeforeAnyDownloadIsRefused() { val dir = dir(); File(dir, "slot0.sav").writeText("fresh profile") val cloud = Memory().apply { files["slot0.sav"] = "real save".toByteArray() to 1000L } diff --git a/app/src/test/java/com/droiddeck/launcher/stores/GogCloudKeysTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/GogCloudKeysTest.kt index d6667e2a12..554948f49e 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/GogCloudKeysTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/GogCloudKeysTest.kt @@ -8,7 +8,12 @@ import org.junit.Assert.assertFalse import org.junit.Assert.assertNull import org.junit.Assert.assertTrue 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 GogCloudKeysTest { @Test fun defaultLocationIsStrippedLikeAnyNamedLocation() { val files = listOf(CloudFile("__default/savegame0.sav", 1L), CloudFile("saves/slot0.sav", 2L)) @@ -183,6 +188,24 @@ class GogCloudKeysTest { requests.forEach { assertEquals("Bearer token", it.headers["authorization"]) } } + @Test fun listAsksForJsonAndCarriesGalaxyDeletionMarks() { + val body = "[{\"name\":\"saves/save1.ess\",\"hash\":\"0123456789abcdef0123456789abcdef\",\"last_modified\":\"2026-11-17T22:58:55.038000+00:00\"}," + + "{\"name\":\"saves/save2.ess\",\"hash\":\"$GOG_DELETED_MD5\",\"last_modified\":\"2026-11-17T22:59:00+00:00\"}]" + lateinit var files: List + lateinit var cloud: GogCloud + val requests = serve(1, { "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: ${body.length}\r\nConnection: close\r\n\r\n$body" }) { url -> + cloud = GogCloud("user", "client", "token", "saves", url) + files = cloud.list() + } + assertEquals("application/json", requests.single().headers["accept"]) + assertEquals(listOf("save1.ess", "save2.ess"), files.map { it.name }) + assertEquals("0123456789abcdef0123456789abcdef", files[0].md5) + assertEquals(1_794_956_335_038L, files[0].modifiedMs) + assertFalse(cloud.deleted(files[0])) + assertTrue(cloud.deleted(files[1])) + assertFalse(cloud.deleted(CloudFile("save3.ess", 1L))) + } + @Test fun rejectedListKeepsTheServerErrorInTheDetail() { val body = "{\"error\":\"invalid_version\",\"error_description\":\"not supported with this version\"}" val failure = runCatching {