mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-01 02:25:40 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
291cc67537 |
No files matched your search
@@ -3182,10 +3182,10 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
|
||||
private fun removeGame(g: Library.SteamGame) {
|
||||
if (g.soundtrack) { removeSoundtrack(g); return }
|
||||
val folder = g.gameFiles ?: return
|
||||
val folder = g.gameFiles
|
||||
when (com.droiddeck.launcher.frontend.GameRemoval.kind(g)) {
|
||||
com.droiddeck.launcher.frontend.GameRemoval.Kind.LAUNCHER -> Unit
|
||||
com.droiddeck.launcher.frontend.GameRemoval.Kind.SHORTCUT -> removeAddedGame(folder.path, g.gameId, g.name)
|
||||
com.droiddeck.launcher.frontend.GameRemoval.Kind.SHORTCUT -> if (folder != null) removeAddedGame(folder.path, g.gameId, g.name)
|
||||
com.droiddeck.launcher.frontend.GameRemoval.Kind.STORE -> {
|
||||
val installed = com.droiddeck.launcher.frontend.GameRemoval.storeGame(g)
|
||||
if (installed != null) {
|
||||
@@ -3193,7 +3193,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
return
|
||||
}
|
||||
if (g.library == Library.ADDED) {
|
||||
removeAddedGame(folder.path, g.gameId, g.name)
|
||||
if (folder != null) removeAddedGame(folder.path, g.gameId, g.name)
|
||||
return
|
||||
}
|
||||
val target = com.droiddeck.launcher.frontend.GameRemoval.steamFiles(g) ?: return
|
||||
|
||||
@@ -16,10 +16,10 @@ object GameRemoval {
|
||||
else -> Kind.STORE
|
||||
}
|
||||
|
||||
class SteamFiles(val dir: File, val manifest: File, val partial: File?)
|
||||
class SteamFiles(val dir: File?, val manifest: File, val partial: File?)
|
||||
|
||||
fun steamFiles(game: Library.SteamGame): SteamFiles? {
|
||||
val dir = game.gameFiles ?: return null
|
||||
val dir = game.gameFiles ?: return leftover(game)
|
||||
val common = dir.parentFile ?: return null
|
||||
if (common.name != (if (game.soundtrack) "music" else "common")) return null
|
||||
val steamapps = common.parentFile ?: return null
|
||||
@@ -31,8 +31,10 @@ object GameRemoval {
|
||||
}
|
||||
|
||||
fun delete(target: SteamFiles): Boolean {
|
||||
StoreInstalls.deleteTree(target.dir)
|
||||
if (target.dir.exists()) return false
|
||||
target.dir?.let { dir ->
|
||||
StoreInstalls.deleteTree(dir)
|
||||
if (dir.exists()) return false
|
||||
}
|
||||
target.partial?.let { StoreInstalls.deleteTree(it) }
|
||||
target.manifest.delete()
|
||||
return !target.manifest.exists()
|
||||
@@ -47,6 +49,12 @@ object GameRemoval {
|
||||
return InstalledStoreGame(sidecar, folder)
|
||||
}
|
||||
|
||||
private fun leftover(game: Library.SteamGame): SteamFiles? {
|
||||
val manifest = game.manifest?.takeIf { it.isFile && declares(it, game.appId) } ?: return null
|
||||
val steamapps = manifest.parentFile ?: return null
|
||||
return SteamFiles(null, manifest, File(steamapps, "downloading/${game.appId}"))
|
||||
}
|
||||
|
||||
private fun declares(manifest: File, appId: Int): Boolean =
|
||||
runCatching { manifest.readText() }.getOrNull()?.let { Regex("\"appid\"\\s+\"$appId\"").containsMatchIn(it) } == true
|
||||
}
|
||||
@@ -20,9 +20,10 @@ object Library {
|
||||
val logo: File? = null,
|
||||
val installedAt: Long = 0L,
|
||||
val soundtrack: Boolean = false,
|
||||
val manifest: File? = null,
|
||||
) {
|
||||
fun withArt(art: File?, hero: File?, icon: File?, logo: File? = this.logo) =
|
||||
SteamGame(appId, name, art, library, gameId, hero, lastPlayed, gameFiles, protonPrefix, icon, source, storeId, logo, installedAt, soundtrack)
|
||||
SteamGame(appId, name, art, library, gameId, hero, lastPlayed, gameFiles, protonPrefix, icon, source, storeId, logo, installedAt, soundtrack, manifest)
|
||||
|
||||
val gameIdString: String get() = java.lang.Long.toUnsignedString(gameId)
|
||||
val launchKey: String get() = if (storeId != null) "$source:$storeId" else gameIdString
|
||||
@@ -167,6 +168,7 @@ object Library {
|
||||
protonPrefix = protonPrefix(context, appId.toLong(), library, roots),
|
||||
icon = images.icon(),
|
||||
logo = images.find(STEAM_LOGOS),
|
||||
manifest = manifest,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -886,7 +886,8 @@ internal fun RemoveButton(title: String, game: Library.SteamGame?, installed: In
|
||||
}
|
||||
val g = game ?: return
|
||||
val kind = GameRemoval.kind(g)
|
||||
if (kind == GameRemoval.Kind.LAUNCHER || g.gameFiles?.isDirectory != true) return
|
||||
val leftover = remember(g) { g.gameFiles == null && GameRemoval.steamFiles(g) != null }
|
||||
if (kind == GameRemoval.Kind.LAUNCHER || (g.gameFiles?.isDirectory != true && !leftover)) return
|
||||
var asking by remember(g.gameId) { mutableStateOf(false) }
|
||||
val shortcut = kind == GameRemoval.Kind.SHORTCUT
|
||||
val label = stringResource(if (shortcut) R.string.edit_remove else R.string.common_uninstall)
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.droiddeck.launcher.frontend
|
||||
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import java.io.File
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class GameRemovalTest {
|
||||
private val app get() = RuntimeEnvironment.getApplication()
|
||||
private lateinit var apps: File
|
||||
|
||||
@Before fun setUp() {
|
||||
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
|
||||
SessionPrefs.setSteamClientArch(app, "arm64")
|
||||
apps = File(SessionPrefs.steamRoot(app, "arm64"), "steamapps").apply { mkdirs() }
|
||||
}
|
||||
|
||||
private fun manifest(appId: Int, name: String, dir: String) =
|
||||
File(apps, "appmanifest_$appId.acf").apply {
|
||||
writeText("\"AppState\"\n{\n\t\"appid\"\t\t\"$appId\"\n\t\"name\"\t\t\"$name\"\n\t\"StateFlags\"\t\t\"4\"\n\t\"installdir\"\t\t\"$dir\"\n}\n")
|
||||
}
|
||||
|
||||
@Test fun aGameWhoseFilesWereDeletedCanStillBeRemoved() {
|
||||
val acf = manifest(17470, "Example", "Example")
|
||||
val partial = File(apps, "downloading/17470").apply { mkdirs() }
|
||||
File(partial, "chunk").writeText("x")
|
||||
val game = Library.steamGames(app, arch = "arm64").single()
|
||||
assertNull(game.gameFiles)
|
||||
|
||||
val target = requireNotNull(GameRemoval.steamFiles(game))
|
||||
assertNull(target.dir)
|
||||
assertEquals(acf, target.manifest)
|
||||
assertTrue(GameRemoval.delete(target))
|
||||
assertFalse(acf.exists())
|
||||
assertFalse(partial.exists())
|
||||
assertEquals(emptyList<Library.SteamGame>(), Library.steamGames(app, arch = "arm64"))
|
||||
}
|
||||
|
||||
@Test fun anInstalledGameStillRemovesItsFolder() {
|
||||
val acf = manifest(440, "Installed", "Installed")
|
||||
val folder = File(apps, "common/Installed").apply { mkdirs() }
|
||||
File(folder, "game.exe").writeText("x")
|
||||
val game = Library.steamGames(app, arch = "arm64").single()
|
||||
assertEquals(folder, game.gameFiles)
|
||||
|
||||
val target = requireNotNull(GameRemoval.steamFiles(game))
|
||||
assertEquals(folder, target.dir)
|
||||
assertTrue(GameRemoval.delete(target))
|
||||
assertFalse(folder.exists())
|
||||
assertFalse(acf.exists())
|
||||
}
|
||||
|
||||
@Test fun aRowWithoutFilesOrManifestOffersNoRemoval() {
|
||||
assertNull(GameRemoval.steamFiles(Library.SteamGame(17470, "Example", null, "steam")))
|
||||
val other = manifest(570, "Other", "Other")
|
||||
assertNull(GameRemoval.steamFiles(Library.SteamGame(17470, "Example", null, "steam", manifest = other)))
|
||||
assertTrue(other.exists())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user