From cb695f02d4196b171e0507ff7cd44967728a8cb7 Mon Sep 17 00:00:00 2001 From: Adrien Bouillon Date: Mon, 26 Feb 2024 14:29:19 +0100 Subject: [PATCH] pipeline cache deletion fix --- .idea/migrations.xml | 10 ++++++ .../java/org/stratoemu/strato/AppDialog.kt | 21 +++++++++-- .../strato/utils/CacheManagementUtils.kt | 32 +++++++++++++++++ app/src/main/res/layout/app_dialog.xml | 35 ++++++++++++++++++- app/src/main/res/values/strings.xml | 3 ++ 5 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 .idea/migrations.xml create mode 100644 app/src/main/java/org/stratoemu/strato/utils/CacheManagementUtils.kt diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 000000000..f8051a6f9 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/java/org/stratoemu/strato/AppDialog.kt b/app/src/main/java/org/stratoemu/strato/AppDialog.kt index 49ec42c15..397967b29 100644 --- a/app/src/main/java/org/stratoemu/strato/AppDialog.kt +++ b/app/src/main/java/org/stratoemu/strato/AppDialog.kt @@ -25,8 +25,10 @@ import org.stratoemu.strato.data.AppItemTag import org.stratoemu.strato.databinding.AppDialogBinding import org.stratoemu.strato.loader.LoaderResult import org.stratoemu.strato.settings.SettingsActivity +import org.stratoemu.strato.utils.CacheManagementUtils import org.stratoemu.strato.utils.SaveManagementUtils import org.stratoemu.strato.utils.serializable +import java.io.File /** * This dialog is used to show extra game metadata and provide extra options such as pinning the game to the home screen @@ -127,14 +129,29 @@ class AppDialog : BottomSheetDialogFragment() { AlertDialog.Builder(requireContext()) .setTitle(getString(R.string.delete_save_confirmation_message)) .setMessage(getString(R.string.action_irreversible)) - .setNegativeButton(getString(R.string.no), null) - .setPositiveButton(getString(R.string.yes)) { _, _ -> + .setNegativeButton(getString(R.string.cancel), null) + .setPositiveButton(getString(android.R.string.ok)) { _, _ -> SaveManagementUtils.deleteSaveFile(item.titleId) binding.deleteSave.isEnabled = false binding.exportSave.isEnabled = false }.show() } + val cacheExists = CacheManagementUtils.pipelineCacheExists(item.titleId!!) + + binding.cacheDelete.isEnabled = cacheExists + binding.cacheDelete.setOnClickListener { + AlertDialog.Builder(requireContext()) + .setTitle(getString(R.string.delete_shader_cache_confirmation_message)) + .setMessage(getString(R.string.action_irreversible)) + .setNegativeButton(getString(R.string.cancel), null) + .setPositiveButton(getString(android.R.string.ok)) { _, _ -> + if(CacheManagementUtils.deleteCacheFile(item.titleId!!)) { + binding.cacheDelete.isEnabled = false + } + }.show() + } + binding.importSave.setOnClickListener { SaveManagementUtils.importSave(documentPicker) } diff --git a/app/src/main/java/org/stratoemu/strato/utils/CacheManagementUtils.kt b/app/src/main/java/org/stratoemu/strato/utils/CacheManagementUtils.kt new file mode 100644 index 000000000..1ff4839df --- /dev/null +++ b/app/src/main/java/org/stratoemu/strato/utils/CacheManagementUtils.kt @@ -0,0 +1,32 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * Copyright © 2024 Strato Team and Contributors (https://github.com/strato-emu/) + */ + +package org.stratoemu.strato.utils + +import org.stratoemu.strato.StratoApplication +import org.stratoemu.strato.getPublicFilesDir +import java.io.File + +class CacheManagementUtils { + + companion object { + private val cacheFolderRoot by lazy { "${StratoApplication.instance.getPublicFilesDir().canonicalPath}/graphics_pipeline_cache/" } + + fun pipelineCacheExists(titleId: String) : Boolean { + val cacheFolderPath = cacheFolderRoot + titleId + val cacheFolderPathExt = "$cacheFolderRoot$titleId.staging" + + return File(cacheFolderPath).exists() && File(cacheFolderPathExt).exists() + } + + /** + * Deletes the cache files for a given game. + */ + fun deleteCacheFile(titleId : String) : Boolean { + return File("${cacheFolderRoot}$titleId").delete() + && File("${cacheFolderRoot}$titleId.staging").delete() + } + } +} diff --git a/app/src/main/res/layout/app_dialog.xml b/app/src/main/res/layout/app_dialog.xml index 2715b005f..e6f9f5ab7 100644 --- a/app/src/main/res/layout/app_dialog.xml +++ b/app/src/main/res/layout/app_dialog.xml @@ -148,7 +148,6 @@ android:layout_marginTop="8dp" app:alignItems="center" app:flexWrap="nowrap" - app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/save_management" @@ -185,5 +184,39 @@ app:iconGravity="textStart" /> + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c8b866924..568ce04e2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -304,6 +304,9 @@ Save data found. What would you like to do? No save data found. What would you like to do? Are you sure you want to delete this save? + Are you sure you want to delete all cached shaders? + Manage shader cache + Clear shader cache This action is irreversible Yes No