Actually delete the internal files when you delete a repo

This commit is contained in:
Blatzar 2022-10-07 14:53:51 +02:00
parent 4c4b6b1787
commit 9e66245066
2 changed files with 19 additions and 16 deletions

View file

@ -28,6 +28,7 @@ import com.lagradost.cloudstream3.APIHolder.removePluginMapping
import com.lagradost.cloudstream3.MainActivity.Companion.afterPluginsLoadedEvent import com.lagradost.cloudstream3.MainActivity.Companion.afterPluginsLoadedEvent
import com.lagradost.cloudstream3.mvvm.debugPrint import com.lagradost.cloudstream3.mvvm.debugPrint
import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
import com.lagradost.cloudstream3.plugins.RepositoryManager.PREBUILT_REPOSITORIES import com.lagradost.cloudstream3.plugins.RepositoryManager.PREBUILT_REPOSITORIES
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
import com.lagradost.cloudstream3.utils.Coroutines.main import com.lagradost.cloudstream3.utils.Coroutines.main
@ -123,6 +124,10 @@ object PluginManager {
val plugins = getPluginsOnline().filter { val plugins = getPluginsOnline().filter {
!it.filePath.contains(repositoryPath) !it.filePath.contains(repositoryPath)
} }
val file = File(repositoryPath)
normalSafeApiCall {
if (file.exists()) file.deleteRecursively()
}
setKey(PLUGINS_KEY, plugins) setKey(PLUGINS_KEY, plugins)
} }
} }
@ -178,7 +183,11 @@ object PluginManager {
val isDisabled = onlineData.second.status == PROVIDER_STATUS_DOWN val isDisabled = onlineData.second.status == PROVIDER_STATUS_DOWN
fun validOnlineData(context: Context): Boolean { fun validOnlineData(context: Context): Boolean {
return getPluginPath(context, savedData.internalName, onlineData.first).absolutePath == savedData.filePath return getPluginPath(
context,
savedData.internalName,
onlineData.first
).absolutePath == savedData.filePath
} }
} }
@ -484,18 +493,13 @@ object PluginManager {
} }
} }
/** suspend fun deletePlugin(file: File): Boolean {
* @param isFilePath will treat the pluginUrl as as the filepath instead of url val list = (getPluginsLocal() + getPluginsOnline()).filter { it.filePath == file.absolutePath }
* */
suspend fun deletePlugin(pluginIdentifier: String, isFilePath: Boolean): Boolean {
val data =
(if (isFilePath) (getPluginsLocal() + getPluginsOnline()).firstOrNull { it.filePath == pluginIdentifier }
else getPluginsOnline().firstOrNull { it.url == pluginIdentifier }) ?: return false
return try { return try {
if (File(data.filePath).delete()) { if (File(file.absolutePath).delete()) {
unloadPlugin(data.filePath) unloadPlugin(file.absolutePath)
deletePluginData(data) list.forEach { deletePluginData(it) }
return true return true
} }
false false

View file

@ -133,11 +133,10 @@ class PluginsViewModel : ViewModel() {
if (activity == null) return@ioSafe if (activity == null) return@ioSafe
val (repo, metadata) = plugin val (repo, metadata) = plugin
val (success, message) = if (isDownloaded(activity, plugin.second.internalName, plugin.first) || isLocal) { val file = getPluginPath(activity, plugin.second.internalName, plugin.first)
PluginManager.deletePlugin(
metadata.url, val (success, message) = if (file.exists() || isLocal) {
isLocal PluginManager.deletePlugin(file) to R.string.plugin_deleted
) to R.string.plugin_deleted
} else { } else {
PluginManager.downloadAndLoadPlugin( PluginManager.downloadAndLoadPlugin(
activity, activity,