From 11e8ce8f9279c64205d016c81b8f85425a8b2c09 Mon Sep 17 00:00:00 2001 From: Blatzar <46196380+Blatzar@users.noreply.github.com> Date: Mon, 15 Aug 2022 19:20:26 +0200 Subject: [PATCH] No backing up plugins --- .../cloudstream3/utils/BackupUtils.kt | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt index ea16a84d..2d641f25 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt @@ -13,7 +13,21 @@ import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.module.kotlin.readValue import com.lagradost.cloudstream3.CommonActivity.showToast import com.lagradost.cloudstream3.R +import com.lagradost.cloudstream3.apmap import com.lagradost.cloudstream3.mvvm.logError +import com.lagradost.cloudstream3.plugins.PLUGINS_KEY +import com.lagradost.cloudstream3.plugins.PLUGINS_KEY_LOCAL +import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.ANILIST_CACHED_LIST +import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.ANILIST_SHOULD_UPDATE_LIST +import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.ANILIST_TOKEN_KEY +import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.ANILIST_UNIXTIME_KEY +import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.ANILIST_USER_KEY +import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_CACHED_LIST +import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_REFRESH_TOKEN_KEY +import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_SHOULD_UPDATE_LIST +import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_TOKEN_KEY +import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_UNIXTIME_KEY +import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_USER_KEY import com.lagradost.cloudstream3.utils.DataStore.getDefaultSharedPrefs import com.lagradost.cloudstream3.utils.DataStore.getSharedPrefs import com.lagradost.cloudstream3.utils.DataStore.mapper @@ -29,6 +43,34 @@ import java.text.SimpleDateFormat import java.util.* object BackupUtils { + + /** + * No sensitive or breaking data in the backup + * */ + private val nonTransferableKeys = listOf( + // When sharing backup we do not want to transfer what is essentially the password + ANILIST_TOKEN_KEY, + ANILIST_CACHED_LIST, + ANILIST_SHOULD_UPDATE_LIST, + ANILIST_UNIXTIME_KEY, + ANILIST_USER_KEY, + MAL_TOKEN_KEY, + MAL_REFRESH_TOKEN_KEY, + MAL_SHOULD_UPDATE_LIST, + MAL_CACHED_LIST, + MAL_UNIXTIME_KEY, + MAL_USER_KEY, + + // The plugins themselves are not backed up + PLUGINS_KEY, + PLUGINS_KEY_LOCAL + ) + + /** false if blacklisted key */ + private fun String.isTransferable(): Boolean { + return !nonTransferableKeys.contains(this) + } + var restoreFileSelector: ActivityResultLauncher>? = null // Kinda hack, but I couldn't think of a better way @@ -54,8 +96,8 @@ object BackupUtils { val ext = "json" val displayName = "CS3_Backup_${date}" - val allData = getSharedPrefs().all - val allSettings = getDefaultSharedPrefs().all + val allData = getSharedPrefs().all.filter { it.key.isTransferable() } + val allSettings = getDefaultSharedPrefs().all.filter { it.key.isTransferable() } val allDataSorted = BackupVars( allData.filter { it.value is Boolean } as? Map, @@ -79,6 +121,7 @@ object BackupUtils { allDataSorted, allSettingsSorted ) + val steam = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && subDir?.isDownloadDir() == true) { val cr = this.contentResolver @@ -204,7 +247,7 @@ object BackupUtils { map: Map?, isEditingAppSettings: Boolean = false ) { - map?.forEach { + map?.filter { it.key.isTransferable() }?.forEach { setKeyRaw(it.key, it.value, isEditingAppSettings) } }