mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
feat: uninstall or remove a game from the Games page (#1190)
This commit is contained in:
1 parent
6090da0eb5
commit
2457f27cdf
37 files changed
+224
-3
No files matched your search
@@ -860,6 +860,7 @@ class MainActivity : ComponentActivity() {
|
||||
},
|
||||
onSteamGameArtChanged = { appId -> refreshSteamGameArt(appId) },
|
||||
onAddedGameRemoved = { folder, appId, name -> removeAddedGame(folder, appId, name) },
|
||||
onGameRemoved = { g -> removeGame(g) },
|
||||
onAddedGamesArt = { on -> SessionPrefs.setAddedGamesArt(this, on); addedGamesArt = on; if (on) refreshAddedGames() },
|
||||
onSgdbKey = { key ->
|
||||
Thread({
|
||||
@@ -1806,6 +1807,30 @@ class MainActivity : ComponentActivity() {
|
||||
}, "steam-art-update").start()
|
||||
}
|
||||
|
||||
private fun removeGame(g: Library.SteamGame) {
|
||||
val folder = g.gameFiles ?: return
|
||||
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.STORE -> {
|
||||
val installed = com.droiddeck.launcher.frontend.GameRemoval.storeGame(g)
|
||||
if (installed != null) {
|
||||
com.droiddeck.launcher.stores.StoresState.uninstall(this, installed) { refreshAddedGames(); refresh() }
|
||||
return
|
||||
}
|
||||
if (g.library == Library.ADDED) {
|
||||
removeAddedGame(folder.path, g.gameId, g.name)
|
||||
return
|
||||
}
|
||||
val target = com.droiddeck.launcher.frontend.GameRemoval.steamFiles(g) ?: return
|
||||
Thread({
|
||||
com.droiddeck.launcher.frontend.GameRemoval.delete(target)
|
||||
ui.post { refreshAddedGames(); refresh() }
|
||||
}, "game-remove").start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeAddedGame(folder: String, appId: Long?, name: String) {
|
||||
steamGames = steamGames.filterNot { it.library == Library.ADDED && it.gameFiles?.path == folder }
|
||||
Thread({ com.droiddeck.launcher.frontend.AddedGames.remove(this, java.io.File(folder), appId, name) }, "added-game-remove").start()
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.droiddeck.launcher.frontend
|
||||
|
||||
import com.droiddeck.launcher.stores.InstalledStoreGame
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import com.droiddeck.launcher.stores.StoreGameSidecar
|
||||
import com.droiddeck.launcher.stores.StoreInstalls
|
||||
import com.droiddeck.launcher.stores.StoresState
|
||||
import java.io.File
|
||||
|
||||
object GameRemoval {
|
||||
enum class Kind { STORE, SHORTCUT, LAUNCHER }
|
||||
|
||||
fun kind(game: Library.SteamGame): Kind = when {
|
||||
game.library == Library.EPIC_LAUNCHER -> Kind.LAUNCHER
|
||||
game.library == Library.ADDED && game.source == Library.ADDED -> Kind.SHORTCUT
|
||||
else -> Kind.STORE
|
||||
}
|
||||
|
||||
class SteamFiles(val dir: File, val manifest: File, val partial: File?)
|
||||
|
||||
fun steamFiles(game: Library.SteamGame): SteamFiles? {
|
||||
val dir = game.gameFiles ?: return null
|
||||
val common = dir.parentFile ?: return null
|
||||
if (common.name != "common") return null
|
||||
val steamapps = common.parentFile ?: return null
|
||||
if (steamapps.name != "steamapps") return null
|
||||
val manifest = File(steamapps, "appmanifest_${game.appId}.acf")
|
||||
if (!manifest.isFile) return null
|
||||
if (!declares(manifest, game.appId)) return null
|
||||
return SteamFiles(dir, manifest, File(steamapps, "downloading/${game.appId}"))
|
||||
}
|
||||
|
||||
fun delete(target: SteamFiles): Boolean {
|
||||
StoreInstalls.deleteTree(target.dir)
|
||||
if (target.dir.exists()) return false
|
||||
target.partial?.let { StoreInstalls.deleteTree(it) }
|
||||
target.manifest.delete()
|
||||
return !target.manifest.exists()
|
||||
}
|
||||
|
||||
fun storeGame(game: Library.SteamGame): InstalledStoreGame? {
|
||||
val folder = game.gameFiles ?: return null
|
||||
val store = Store.byId(game.source)
|
||||
val id = game.storeId
|
||||
if (store != null && id != null) StoresState.installedGame(store, id)?.let { return it }
|
||||
val sidecar = StoreGameSidecar.read(folder)?.takeIf { it.isInstalled } ?: return null
|
||||
return InstalledStoreGame(sidecar, folder)
|
||||
}
|
||||
|
||||
private fun declares(manifest: File, appId: Int): Boolean =
|
||||
runCatching { manifest.readText() }.getOrNull()?.let { Regex("\"appid\"\\s+\"$appId\"").containsMatchIn(it) } == true
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.runtime.key
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.BoxScope
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.foundation.layout.Row
|
||||
@@ -30,6 +31,7 @@ import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Delete
|
||||
import androidx.compose.material.icons.outlined.Edit
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
@@ -110,7 +112,7 @@ internal fun GamesPage(s: FrontEndState, a: FrontEndActions, selected: String, o
|
||||
if (onAdd != null) Rise(0) { GamesHeader(gameCount, s.steamGamesX64, onAdd, Modifier.padding(bottom = 10.dp)) }
|
||||
Rise(0) {
|
||||
Row(verticalAlignment = Alignment.Bottom) {
|
||||
GameHero(current, Modifier.weight(1f).heightIn(min = if (narrow) 190.dp else 250.dp)) {
|
||||
GameHero(current, Modifier.weight(1f).heightIn(min = if (narrow) 190.dp else 250.dp), corner = { GameRemoveButton(current, s, a) }) {
|
||||
GameHeroCopy(current, if (narrow) 28.sp else 38.sp)
|
||||
GameActions(current, s, a, onEdit, launch)
|
||||
}
|
||||
@@ -132,7 +134,7 @@ internal fun GamesPage(s: FrontEndState, a: FrontEndActions, selected: String, o
|
||||
modifier = Modifier.weight(1f).fillMaxHeight().verticalScroll(rememberScrollState())
|
||||
.padding(horizontal = if (narrow) 14.dp else 20.dp, vertical = 16.dp),
|
||||
) {
|
||||
GameHero(current, Modifier.fillMaxWidth().heightIn(min = if (narrow) 170.dp else 200.dp)) {
|
||||
GameHero(current, Modifier.fillMaxWidth().heightIn(min = if (narrow) 170.dp else 200.dp), corner = { GameRemoveButton(current, s, a) }) {
|
||||
GameHeroCopy(current, if (narrow) 24.sp else 32.sp)
|
||||
GameActions(current, s, a, onEdit, launch)
|
||||
}
|
||||
@@ -439,6 +441,47 @@ private fun GamesDialogs(a: FrontEndActions, games: List<Library.SteamGame>) {
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GameRemoveButton(g: Library.SteamGame, s: FrontEndState, a: FrontEndActions) {
|
||||
val kind = com.droiddeck.launcher.frontend.GameRemoval.kind(g)
|
||||
if (s.shortcutPicker || kind == com.droiddeck.launcher.frontend.GameRemoval.Kind.LAUNCHER) return
|
||||
if (g.gameFiles?.isDirectory != true) return
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val hot = rememberHot(src)
|
||||
var asking by remember(g.gameId) { androidx.compose.runtime.mutableStateOf(false) }
|
||||
val shortcut = kind == com.droiddeck.launcher.frontend.GameRemoval.Kind.SHORTCUT
|
||||
val label = stringResource(if (shortcut) R.string.edit_remove else R.string.common_uninstall)
|
||||
val title = if (shortcut) stringResource(R.string.games_remove_title, g.name) else stringResource(R.string.stores_uninstall_title, g.name)
|
||||
val body = when {
|
||||
shortcut -> stringResource(R.string.games_remove_body)
|
||||
g.library == Library.ADDED -> stringResource(R.string.stores_uninstall_body)
|
||||
else -> stringResource(R.string.games_uninstall_body)
|
||||
}
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier.paneItem("game:remove").downToFirstTile().size(44.dp).clip(Shape12)
|
||||
.background(if (hot) colors.error.copy(alpha = 0.22f) else Color.Black.copy(alpha = 0.34f))
|
||||
.glideBorder(hot, Shape12, colors.error, pal.line2)
|
||||
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = androidx.compose.ui.semantics.Role.Button) { asking = true }
|
||||
.controllerConfirm { asking = true }
|
||||
.semantics { contentDescription = label },
|
||||
) {
|
||||
androidx.compose.material3.Icon(
|
||||
Icons.Outlined.Delete, contentDescription = null,
|
||||
tint = if (hot) colors.error else Color.White, modifier = Modifier.size(18.dp),
|
||||
)
|
||||
}
|
||||
if (asking) ConfirmDialog(
|
||||
title = title,
|
||||
text = body,
|
||||
confirm = label,
|
||||
onConfirm = { a.onGameRemoved(g) },
|
||||
onDismiss = { asking = false },
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun EditGameButton(onClick: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
@@ -570,7 +613,7 @@ private fun libraryLabel(g: Library.SteamGame): String = when {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GameHero(g: Library.SteamGame, modifier: Modifier, content: @Composable ColumnScope.() -> Unit) {
|
||||
private fun GameHero(g: Library.SteamGame, modifier: Modifier, corner: @Composable BoxScope.() -> Unit = {}, content: @Composable ColumnScope.() -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
Box(modifier = modifier.clip(Shape16).background(artBrush(hueOf(g.name)))) {
|
||||
val image = g.hero ?: g.art.takeIf { g.library != Library.EPIC_LAUNCHER }
|
||||
@@ -593,5 +636,6 @@ private fun GameHero(g: Library.SteamGame, modifier: Modifier, content: @Composa
|
||||
modifier = Modifier.align(Alignment.BottomStart).padding(horizontal = 22.dp, vertical = 18.dp),
|
||||
content = content,
|
||||
)
|
||||
Box(Modifier.align(Alignment.TopEnd).padding(12.dp), content = corner)
|
||||
}
|
||||
}
|
||||
@@ -165,6 +165,7 @@ class FrontEndActions(
|
||||
val onAddedGamesChanged: (folders: List<String>) -> Unit = {},
|
||||
val onSteamGameArtChanged: (appId: Int) -> Unit = {},
|
||||
val onAddedGameRemoved: (folder: String, appId: Long?, name: String) -> Unit = { _, _, _ -> },
|
||||
val onGameRemoved: (Library.SteamGame) -> Unit = {},
|
||||
val onAddedGamesArt: (Boolean) -> Unit = {},
|
||||
val onSgdbKey: (String) -> Unit = {},
|
||||
val onStopGameFileSync: () -> Unit = {},
|
||||
|
||||
Reference in new issue
Block a user