From a069e577ba4f2ac2444ec85b2a70af4232ae63e3 Mon Sep 17 00:00:00 2001 From: Shamicen <84282253+Shamicen@users.noreply.github.com> Date: Sat, 16 Mar 2024 01:28:37 +0100 Subject: [PATCH] Change preferences containing passwords to appStateKeys (#1083) * Change preferences containing passwords to appStateKeys * Change versionCode to 65 * fix merge conflict and add instructions to get library back after migration --- app/src/main/java/exh/EXHMigrations.kt | 23 +++++++++++++++++++ .../core/security/SecurityPreferences.kt | 6 ++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/exh/EXHMigrations.kt b/app/src/main/java/exh/EXHMigrations.kt index 334618982..fe3e513cc 100644 --- a/app/src/main/java/exh/EXHMigrations.kt +++ b/app/src/main/java/exh/EXHMigrations.kt @@ -1,6 +1,7 @@ package exh import android.content.Context +import android.widget.Toast import androidx.core.content.edit import androidx.preference.PreferenceManager import eu.kanade.domain.base.BasePreferences @@ -20,6 +21,7 @@ import eu.kanade.tachiyomi.source.online.all.NHentai import eu.kanade.tachiyomi.ui.reader.setting.ReaderOrientation import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences import eu.kanade.tachiyomi.util.system.DeviceUtil +import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.workManager import exh.eh.EHentaiUpdateWorker import exh.log.xLogE @@ -655,6 +657,27 @@ object EXHMigrations { } } + if (oldVersion under 66) { + if (prefs.getBoolean(Preference.privateKey("encrypt_database"), false)) { + context.toast( + "Restart the app to load your encrypted library", + Toast.LENGTH_LONG + ) + } + + val appStatePrefsToReplace = listOf( + "__PRIVATE_sql_password", + "__PRIVATE_encrypt_database", + "__PRIVATE_cbz_password", + ) + + replacePreferences( + preferenceStore = preferenceStore, + filterPredicate = { it.key in appStatePrefsToReplace }, + newKey = { Preference.appStateKey(it.replace("__PRIVATE_", "").trim()) }, + ) + } + // if (oldVersion under 1) { } (1 is current release version) // do stuff here when releasing changed crap diff --git a/core/common/src/main/kotlin/eu/kanade/tachiyomi/core/security/SecurityPreferences.kt b/core/common/src/main/kotlin/eu/kanade/tachiyomi/core/security/SecurityPreferences.kt index aaab4a9d4..df266988d 100644 --- a/core/common/src/main/kotlin/eu/kanade/tachiyomi/core/security/SecurityPreferences.kt +++ b/core/common/src/main/kotlin/eu/kanade/tachiyomi/core/security/SecurityPreferences.kt @@ -24,9 +24,9 @@ class SecurityPreferences( fun authenticatorDays() = this.preferenceStore.getInt("biometric_days", 0x7F) - fun encryptDatabase() = this.preferenceStore.getBoolean(Preference.privateKey("encrypt_database"), false) + fun encryptDatabase() = this.preferenceStore.getBoolean(Preference.appStateKey("encrypt_database"), false) - fun sqlPassword() = this.preferenceStore.getString(Preference.privateKey("sql_password"), "") + fun sqlPassword() = this.preferenceStore.getString(Preference.appStateKey("sql_password"), "") fun passwordProtectDownloads() = preferenceStore.getBoolean( Preference.privateKey("password_protect_downloads"), @@ -35,7 +35,7 @@ class SecurityPreferences( fun encryptionType() = this.preferenceStore.getEnum("encryption_type", EncryptionType.AES_256) - fun cbzPassword() = this.preferenceStore.getString(Preference.privateKey("cbz_password"), "") + fun cbzPassword() = this.preferenceStore.getString(Preference.appStateKey("cbz_password"), "") // SY <-- /**