Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a per-game option to delete the shader cache that has been created during the emulation #249

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions app/src/main/java/org/stratoemu/strato/AppDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
QuackingCanary marked this conversation as resolved.
Show resolved Hide resolved
35 changes: 34 additions & 1 deletion app/src/main/res/layout/app_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -185,5 +184,39 @@
app:iconGravity="textStart" />

</com.google.android.flexbox.FlexboxLayout>

<TextView
android:id="@+id/delete_pipeline_cache"
style="?attr/textAppearanceLabelLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/manage_shader_cache"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/flexboxSaves" />

<com.google.android.flexbox.FlexboxLayout
android:id="@+id/flexboxCache"
style="@style/ThemeOverlay.Material3.Button.IconButton.Filled.Tonal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:alignItems="center"
app:flexWrap="nowrap"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/delete_pipeline_cache"
app:layout_constraintVertical_bias="1">

<com.google.android.material.button.MaterialButton
android:id="@+id/cache_delete"
style="@style/Widget.Material3.Button.TonalButton.Icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/clear_shader_cache"
android:text="@string/clear_shader_cache"
app:icon="@drawable/ic_delete" />

</com.google.android.flexbox.FlexboxLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@
<string name="save_data_found">Save data found. What would you like to do?</string>
<string name="save_data_not_found">No save data found. What would you like to do?</string>
<string name="delete_save_confirmation_message">Are you sure you want to delete this save?</string>
<string name="delete_shader_cache_confirmation_message">Are you sure you want to delete all cached shaders?</string>
<string name="manage_shader_cache">Manage shader cache</string>
<string name="clear_shader_cache">Clear shader cache</string>
<string name="action_irreversible">This action is irreversible</string>
<string name="yes">Yes</string>
<string name="no">No</string>
Expand Down