feat(ea, ubisoft): cloud saves and a kept Ubisoft Denuvo token (#2824)

* feat(ubisoft): keep Denuvo game tokens per account and product until the game invalidates them

* feat(ubisoft): sync cloud saves through Ubisoft's cloud save service

* fix(xbox): turning cloud saves off passes the offline mode the game save runtime reads

* fix(ubisoft): Ubisoft games list their shared prefix, so they get a saves and cloud tab

* feat(ea): sync cloud saves through EA's cloud sync service

* fix(ea): sync at EA launch and exit, keep one rule snapshot, and check the cloud copy under the write lock

* fix(ubisoft): exact slot versions, scoped save export, and a Denuvo cache bound to its account

* fix(ea): fresh rules per sync, checksums required, backup before restore, and sign-in shown on the saves tab

* fix(ubisoft): launch-time sync on the shared prefix, saves scoped to the game, and Denuvo bound to each launch's account

* fix(ea): back up only the saves a restore replaces, refuse truncated manifests, and need a master title id

* fix(ubisoft): treat a slot whose bytes changed since the last sync as a conflict before uploading over it

* fix(ea): one resolved save folder per sync, refuse case collisions, and walk each folder once

* fix(ubisoft): sync only identified slots, keep live saves and backups safe, and tie a pending eviction to its account

* fix(cloud): a forced download fetches every saved conflict and keeps the ones it could not write

* test(ea): keep the cloud save cases in EaTest

* fix(ubisoft): report only written slots, keep drift conflicts, read whole headers, and never rename a named eviction

* fix(ea): keep real save folders in the inventory, back up any restored file, refuse duplicate or malformed cloud listings

* fix(cloud): commit Ubisoft slots one at a time and stop on a newer cloud write, name skipped and blocked slots, keep unsent conflicts

* fix(ubisoft): acknowledge an invalidation only once its marker is published and never serve a kept token after it

* fix(cloud): a cloud request the launcher cannot write still starts the game and keeps the exit upload

* fix(cloud): scope Ubisoft sync state to the account and product, compare alike slots, keep committed progress, and name partial slots

* fix(ea): ask for sign-in after a rejected refresh, upload saves reached through folder aliases

* fix(cloud): a launch that stops waiting for the cloud download claims it back, so no save is written once the game starts

* fix(ubisoft): name the account in an invalidation marker and never hold the token lock across a pipe write

* fix(ea): only invalid_grant asks for sign-in again, and case collisions count only among synced saves

* test(epic): let the launcher's ask doubles take the claim flag

* fix(ea): apply save rules in their order, match bare patterns inside the save folder, and resolve LocalLow and install folders

* fix(ubisoft): stamp a fresh identifier into a new save that has none, so it can sync

* fix(ubisoft): answer a burn ticket request as unavailable instead of leaving the game waiting

* fix(cloud): read EA manifests with the XML parser, clear conflicts whose sides match, and bound the claim and stall tests
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-18 18:32:06 -05:00
1 parent 6ed281f78d
commit 123c431b8e
31 files changed
+1999 -132

No files matched your search

@@ -25,7 +25,7 @@ object GameSaves {
fun label(context: Context): String = context.getString(R.string.saves_layout_zip, app)
}
data class Game(val game: Library.SteamGame, val prefix: File?, val saves: List<SaveDir>) {
data class Game(val game: Library.SteamGame, val prefix: File?, val saves: List<SaveDir>, val root: String? = null) {
val launched get() = prefix?.let { File(it, "drive_c").isDirectory } == true
}
@@ -36,7 +36,28 @@ object GameSaves {
fun savesDir(): File = File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "DroidDeck/Saves")
private fun backupsDir(): File = File(savesDir(), "backups")
fun game(game: Library.SteamGame): Game = Game(game, game.protonPrefix, game.protonPrefix?.let { locate(it, game) } ?: emptyList())
fun game(context: Context, game: Library.SteamGame): Game {
val root = if (ubisoft(game)) ubisoftRoot(context, game) else null
val saves = game.protonPrefix?.let { prefix -> if (ubisoft(game)) root?.let { ubisoftSaves(prefix, it) }.orEmpty() else locate(prefix, game) }.orEmpty()
return Game(game, game.protonPrefix, saves, root)
}
fun saves(context: Context, prefix: File, game: Library.SteamGame): List<SaveDir> =
if (ubisoft(game)) ubisoftRoot(context, game)?.let { ubisoftSaves(prefix, it) }.orEmpty() else locate(prefix, game)
private fun ubisoftRoot(context: Context, game: Library.SteamGame): String? {
val product = game.gameFiles?.let { com.droiddeck.launcher.stores.StoreGameSidecar.read(it) }?.extra?.get("productId")?.toLongOrNull() ?: return null
val user = com.droiddeck.launcher.stores.ubisoft.UbisoftAuth.load(context)?.userId
if (user.isNullOrEmpty() || user.contains('/') || user.contains("..")) return null
return "Saved Games/Ubisoft/$user/$product"
}
private fun ubisoft(game: Library.SteamGame) = game.source == com.droiddeck.launcher.stores.Store.UBISOFT.id
private fun ubisoftSaves(prefix: File, rel: String): List<SaveDir> {
val files = File(profile(prefix), rel).walkTopDown().filter { it.isFile }.toList()
return if (files.isEmpty()) emptyList() else listOf(SaveDir(rel, files.size, files.sumOf { it.length() }))
}
private val SAVE_ROOTS = listOf("Documents/My Games", "Saved Games", "AppData/Roaming", "Documents", "AppData/Local", "AppData/LocalLow")
@@ -109,9 +130,11 @@ object GameSaves {
fun export(context: Context, game: Game, layout: Layout, dir: File): Pair<File, Int> {
val prefix = game.prefix ?: error(context.getString(R.string.saves_not_launched, game.game.name))
val roots = game.saves.map { it.relPath }
if (roots.isEmpty() && ubisoft(game.game)) error(context.getString(R.string.saves_none_found, game.game.name))
dir.mkdirs()
val out = File(dir, "${safe(game.game.name)}_${stamp()}.zip")
val count = zipProfile(profile(prefix), game.saves.map { it.relPath }.ifEmpty { null }, layout, out)
val count = zipProfile(profile(prefix), roots.ifEmpty { null }, layout, out)
if (count == 0) { out.delete(); error(context.getString(R.string.saves_none_found, game.game.name)) }
return out to count
}
@@ -142,12 +165,21 @@ object GameSaves {
if (!driveC.isDirectory) error(context.getString(R.string.saves_not_launched, game.game.name))
if (!looksLikeSaveZip(zip)) error(context.getString(R.string.saves_not_save_zip, zip.name))
val scoped = if (ubisoft(game.game)) game.root ?: error(context.getString(R.string.saves_none_found, game.game.name)) else null
if (scoped != null) {
val base = File(profile(prefix), scoped).canonicalFile
val eligible = ZipInputStream(BufferedInputStream(zip.inputStream())).use { zis ->
generateSequence { zis.nextEntry }.any { e -> !e.isDirectory && remap(e.name)?.let { File(driveC, it).canonicalFile.path.startsWith(base.path + File.separator) } == true }
}
if (!eligible) error(context.getString(R.string.saves_not_save_zip, zip.name))
}
backupsDir().mkdirs()
val backup = File(backupsDir(), "${safe(game.game.name)}_${stamp()}.zip")
val backedUp = zipProfile(profile(prefix), null, Layout.GAMEHUB, backup)
val backup = File(backupsDir(), "${safe(game.game.name)}_${stamp()}_${System.currentTimeMillis()}.zip")
val backedUp = if (scoped != null && File(profile(prefix), scoped).walkTopDown().none { it.isFile }) 0
else zipProfile(profile(prefix), scoped?.let(::listOf), Layout.GAMEHUB, backup)
if (backedUp == 0) backup.delete()
val base = driveC.canonicalFile
val base = (if (scoped != null) File(profile(prefix), scoped) else driveC).canonicalFile
var written = 0
ZipInputStream(BufferedInputStream(zip.inputStream())).use { zis ->
var e = zis.nextEntry
@@ -1484,6 +1484,8 @@ object SessionPrefs {
(id and 0xFFFFFFFFL) to key.removePrefix("addedAppId:")
}.toMap()
fun storeGameFolder(context: Context, key: String): String? = prefs(context).getString("storeFolder:$key", null)
fun followStoreGame(context: Context, key: String, folderPath: String, gone: (String) -> Boolean) = synchronized(addedGameLock) {
val p = prefs(context)
val previous = p.getString("storeFolder:$key", null)