mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 04:46:08 +00:00
fix: find GOG Galaxy SDK cloud saves when remote-config lists no locations (#970)
* fix: find GOG Galaxy SDK cloud saves when remote-config lists no locations cloudStorage.enabled with an empty locations list is Galaxy SDK IStorage under __default. DroidDeck treated that as no cloud. Use the SDK folder, strip/prefix the __default namespace, and inflate gzip bodies GOG stores on download. An empty cached template is fetched again so devices that already recorded "no cloud" recover. * fix: keep an empty GOG namespace, expire cached none, close gzip An explicit empty cloud_namespace is Auto Cloud and must not become __default just because the path template looks like Galaxy storage. A cached none is retried after a day so a later enablement is picked up. GZIPInputStream is closed after a compressed download. * fix: peel GOG cloud gzip only when the service or PUT compressor says so GET asks for identity encoding so the body is what GOG stored. A Content-Encoding of gzip is inflated once. Otherwise a gzip body is inflated only when it round-trips as GOG's PUT gzip (deflate 6, mtime 0), so a gzip-format save is not rewritten. * Reject corrupt GOG cloud downloads --------- Co-authored-by: xXJsonDeruloXx <danielhimebauch@gmail.com> Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
7 files changed
+245
-34
No files matched your search
@@ -47,4 +47,34 @@ class CloudSavePathsTest {
|
||||
File(profile, "AppData/Local/My-Game").mkdirs()
|
||||
assertEquals(File(profile, "AppData/Local/My-Game").path, CloudSavePaths.epic("{AppData}/MyGame", prefix, install, "acc", "app")!!.path)
|
||||
}
|
||||
|
||||
@Test fun gogGalaxySdkEmptyLocationsUseDefaultLocation() {
|
||||
val loc = CloudSavePaths.gogSaveFromRemote(true, emptyList(), "1")!!
|
||||
assertEquals(
|
||||
"%LocalAppData%/GOG.com/Galaxy/Applications/1/Storage/Shared/Files",
|
||||
loc.template,
|
||||
)
|
||||
assertEquals(CloudSavePaths.GOG_DEFAULT_NAMESPACE, loc.name)
|
||||
val dir = CloudSavePaths.gog(loc.template, prefix, install)
|
||||
assertEquals(
|
||||
File(profile, "AppData/Local/GOG.com/Galaxy/Applications/1/Storage/Shared/Files").path,
|
||||
dir!!.path,
|
||||
)
|
||||
}
|
||||
|
||||
@Test fun gogCloudDisabledOrUnknownClientIsNone() {
|
||||
assertNull(CloudSavePaths.gogSaveFromRemote(false, emptyList(), "1"))
|
||||
assertNull(CloudSavePaths.gogSaveFromRemote(true, emptyList(), ""))
|
||||
assertNull(CloudSavePaths.gogSaveFromRemote(true, listOf("saves" to ""), ""))
|
||||
}
|
||||
|
||||
@Test fun gogNamedLocationKeepsItsNameAndPreferSaves() {
|
||||
val loc = CloudSavePaths.gogSaveFromRemote(
|
||||
true,
|
||||
listOf("other" to "<?SAVED_GAMES?>/A", "Saves" to "<?APPLICATION_DATA_LOCAL_LOW?>/Hyperstrange/ELDERBORN"),
|
||||
"1",
|
||||
)!!
|
||||
assertEquals("<?APPLICATION_DATA_LOCAL_LOW?>/Hyperstrange/ELDERBORN", loc.template)
|
||||
assertEquals("Saves", loc.name)
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import java.io.File
|
||||
import java.util.concurrent.Executor
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
@@ -77,12 +78,22 @@ class CloudSavesTest {
|
||||
assertTrue(CloudSaves.dirty(app).contains(Store.GOG to gameId))
|
||||
CloudSaves.uploadAllDirty(app, "recovery", running = true)
|
||||
assertTrue(CloudSaves.dirty(app).contains(Store.GOG to gameId))
|
||||
com.droiddeck.launcher.stores.gog.GogPrefs.get(app).edit().putString("cloud_template_$gameId", "").apply()
|
||||
com.droiddeck.launcher.stores.gog.GogPrefs.get(app).edit()
|
||||
.putString("cloud_template_$gameId", "none")
|
||||
.putLong("cloud_template_at_$gameId", System.currentTimeMillis())
|
||||
.apply()
|
||||
assertEquals("no-cloud-saves", CloudSaves.uploadDirty(app, Store.GOG, gameId, "exit")!!.reason)
|
||||
assertTrue(CloudSaves.dirty(app).none { it.second == gameId })
|
||||
assertEquals(null, CloudSaves.uploadDirty(app, Store.GOG, gameId, "session-end"))
|
||||
}
|
||||
|
||||
@Test fun aNegativeCloudTemplateIsRetriedAfterADay() {
|
||||
val now = 1_000_000L
|
||||
assertTrue(CloudSaves.noneTemplateIsCurrent(now, now + 60_000L))
|
||||
assertFalse(CloudSaves.noneTemplateIsCurrent(now, now + CloudSaves.TEMPLATE_NONE_TTL_MS))
|
||||
assertFalse(CloudSaves.noneTemplateIsCurrent(0L, now))
|
||||
}
|
||||
|
||||
@Test fun aFirstLaunchWithoutAPrefixIsDeferredNotBlocked() {
|
||||
val deferred = ArrayList<Runnable>()
|
||||
val folder = File(StoreInstallRoot.storeDir(StoreInstallRoot.internalRoot(app), Store.GOG), "ELDERBORN").apply { mkdirs() }
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.droiddeck.launcher.stores
|
||||
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.util.zip.GZIPOutputStream
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class GogCloudKeysTest {
|
||||
@Test fun defaultLocationIsStrippedLikeAnyNamedLocation() {
|
||||
val files = listOf(CloudFile("__default/savegame0.sav", 1L), CloudFile("saves/slot0.sav", 2L))
|
||||
val (chosen, relative) = gogRelativeNames(files, "__default")
|
||||
assertEquals("__default", chosen)
|
||||
assertEquals(listOf("savegame0.sav"), relative.map { it.name })
|
||||
}
|
||||
|
||||
@Test fun gzipGogPutMatchesPythonGzipCompressLevel6Mtime0() {
|
||||
val raw = "savegame0".toByteArray()
|
||||
val expected = "1f8b08000000000000032b4e2c4b4d4fcc4d35000065fc333209000000".hex()
|
||||
assertArrayEquals(expected, gzipGogPut(raw))
|
||||
assertArrayEquals(raw, gunzip(expected))
|
||||
}
|
||||
|
||||
@Test fun contentEncodingGzipIsPeeledOnce() {
|
||||
val raw = "savegame0".toByteArray()
|
||||
val gz = ByteArrayOutputStream().also { GZIPOutputStream(it).use { z -> z.write(raw) } }.toByteArray()
|
||||
assertArrayEquals(raw, gogDecodeCloudBody(gz, "gzip"))
|
||||
assertArrayEquals(raw, gogDecodeCloudBody(raw, "gzip"))
|
||||
}
|
||||
|
||||
@Test fun corruptDeclaredGzipIsRejected() {
|
||||
val corrupt = gzipGogPut("savegame0".toByteArray()).dropLast(2).toByteArray()
|
||||
assertTrue(isGzip(corrupt))
|
||||
assertTrue(runCatching { gogDecodeCloudBody(corrupt, "gzip") }.isFailure)
|
||||
}
|
||||
|
||||
@Test fun isoDateHonorsOffsetAndFractionalSeconds() {
|
||||
val expected = java.time.Instant.parse("2024-01-02T01:04:05.123Z").toEpochMilli()
|
||||
assertEquals(expected, isoDate("2024-01-02T03:04:05.123+02:00"))
|
||||
assertEquals(expected, isoDate("2024-01-02T01:04:05.123"))
|
||||
}
|
||||
|
||||
@Test fun gogPutWrappedBodyWithoutEncodingIsPeeled() {
|
||||
val raw = "savegame0".toByteArray()
|
||||
assertArrayEquals(raw, gogDecodeCloudBody(gzipGogPut(raw), null))
|
||||
assertArrayEquals(raw, gogDecodeCloudBody(raw, null))
|
||||
}
|
||||
|
||||
@Test fun gzipThatIsTheSaveIsLeftIntact() {
|
||||
val raw = "savegame0".toByteArray()
|
||||
val gameGz = ByteArrayOutputStream().also { GZIPOutputStream(it).use { z -> z.write(raw) } }.toByteArray()
|
||||
assertTrue(isGzip(gameGz))
|
||||
assertFalse(gzipGogPut(raw).contentEquals(gameGz))
|
||||
assertArrayEquals(gameGz, gogDecodeCloudBody(gameGz, null))
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.hex() = chunked(2).map { it.toInt(16).toByte() }.toByteArray()
|
||||
Reference in new issue
Block a user