Skip to content
This repository was archived by the owner on Apr 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions app/src/main/java/net/rpcs3/ui/games/GamesScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,23 @@ fun GameItem(game: Game) {
leadingIcon = { Icon(Icons.Outlined.Delete, contentDescription = null) },
onClick = {
menuExpanded.value = false
val deleteProgress = ProgressRepository.create(context, "Deleting Game")
game.addProgress(GameProgress(deleteProgress, GameProgressType.Compile))
ProgressRepository.onProgressEvent(deleteProgress, -1, 0L)
val path = File(game.info.path)
if (path.exists()) {
GameRepository.remove(game)
path.deleteRecursively()
if (!FileUtil.deleteCache(context, game.info.path.substringAfterLast("/"))) {
AlertDialogQueue.showDialog(
title = "Unexpected Error",
message = "Failed to delete game cache",
confirmText = "Close",
dismissText = ""
)
FileUtil.deleteCache(context, game.info.path.substringAfterLast("/")) { success ->
if (!success) {
AlertDialogQueue.showDialog(
title = "Unexpected Error",
message = "Failed to delete game cache",
confirmText = "Close",
dismissText = ""
)
}
ProgressRepository.onProgressEvent(deleteProgress, 100, 100)
GameRepository.remove(game)
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/net/rpcs3/utils/FileUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import java.io.FileInputStream
import java.io.FileOutputStream
import java.io.IOException
import kotlin.concurrent.thread
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

private data class InstallableFolder(
val uri: Uri, val targetPath: String
Expand Down Expand Up @@ -215,8 +219,13 @@ object FileUtil {
return paths.size == 2 && "tree" == paths[0]
}

fun deleteCache(ctx: Context, gameId: String): Boolean {
return File(ctx.getExternalFilesDir(null)!!, "cache/cache/$gameId").deleteRecursively()
fun deleteCache(ctx: Context, gameId: String, onComplete: (Boolean) -> Unit) {
CoroutineScope(Dispatchers.IO).launch {
val result = File(ctx.getExternalFilesDir(null)!!, "cache/cache/$gameId").deleteRecursively()
withContext(Dispatchers.Main) {
onComplete(result)
}
}
}
}

Expand Down