This commit is contained in:
kunfei
2023-04-19 17:24:09 +08:00
parent faf597dabc
commit 5195833299
5 changed files with 67 additions and 19 deletions
@@ -129,14 +129,21 @@ object Backup {
ensureActive() ensureActive()
appCtx.getSharedPreferences(backupPath, "config")?.let { sp -> appCtx.getSharedPreferences(backupPath, "config")?.let { sp ->
val edit = sp.edit() val edit = sp.edit()
val aes = BackupAES()
appCtx.defaultSharedPreferences.all.forEach { (key, value) -> appCtx.defaultSharedPreferences.all.forEach { (key, value) ->
if (BackupConfig.keyIsNotIgnore(key)) { if (BackupConfig.keyIsNotIgnore(key)) {
when (value) { when (key) {
is Int -> edit.putInt(key, value) PreferKey.webDavPassword -> {
is Boolean -> edit.putBoolean(key, value) edit.putString(key, aes.encryptBase64(value.toString()))
is Long -> edit.putLong(key, value) }
is Float -> edit.putFloat(key, value)
is String -> edit.putString(key, value) else -> when (value) {
is Int -> edit.putInt(key, value)
is Boolean -> edit.putBoolean(key, value)
is Long -> edit.putLong(key, value)
is Float -> edit.putFloat(key, value)
is String -> edit.putString(key, value)
}
} }
} }
} }
@@ -0,0 +1,9 @@
package io.legado.app.help.storage
import cn.hutool.crypto.symmetric.AES
import io.legado.app.help.config.LocalConfig
import io.legado.app.utils.MD5Utils
class BackupAES : AES(
MD5Utils.md5Encode(LocalConfig.password).encodeToByteArray(0, 16)
)
@@ -45,10 +45,6 @@ object BackupConfig {
PreferKey.backupPath, PreferKey.backupPath,
PreferKey.defaultBookTreeUri, PreferKey.defaultBookTreeUri,
PreferKey.webDavDeviceName, PreferKey.webDavDeviceName,
// PreferKey.webDavUrl,
// PreferKey.webDavDir,
// PreferKey.webDavAccount,
// PreferKey.webDavPassword,
PreferKey.launcherIcon, PreferKey.launcherIcon,
PreferKey.bitmapCacheSize, PreferKey.bitmapCacheSize,
PreferKey.webServiceWakeLock, PreferKey.webServiceWakeLock,
@@ -10,7 +10,21 @@ import io.legado.app.constant.AppLog
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.* import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookGroup
import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.Bookmark
import io.legado.app.data.entities.DictRule
import io.legado.app.data.entities.HttpTTS
import io.legado.app.data.entities.KeyboardAssist
import io.legado.app.data.entities.ReadRecord
import io.legado.app.data.entities.ReplaceRule
import io.legado.app.data.entities.RssSource
import io.legado.app.data.entities.RssStar
import io.legado.app.data.entities.RuleSub
import io.legado.app.data.entities.SearchKeyword
import io.legado.app.data.entities.Server
import io.legado.app.data.entities.TxtTocRule
import io.legado.app.help.DirectLinkUpload import io.legado.app.help.DirectLinkUpload
import io.legado.app.help.LauncherIconHelp import io.legado.app.help.LauncherIconHelp
import io.legado.app.help.book.isLocal import io.legado.app.help.book.isLocal
@@ -19,8 +33,20 @@ import io.legado.app.help.config.LocalConfig
import io.legado.app.help.config.ReadBookConfig import io.legado.app.help.config.ReadBookConfig
import io.legado.app.help.config.ThemeConfig import io.legado.app.help.config.ThemeConfig
import io.legado.app.model.localBook.LocalBook import io.legado.app.model.localBook.LocalBook
import io.legado.app.utils.* import io.legado.app.utils.ACache
import io.legado.app.utils.FileUtils
import io.legado.app.utils.GSON
import io.legado.app.utils.compress.ZipUtils import io.legado.app.utils.compress.ZipUtils
import io.legado.app.utils.defaultSharedPreferences
import io.legado.app.utils.fromJsonArray
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.getPrefString
import io.legado.app.utils.getSharedPreferences
import io.legado.app.utils.isContentScheme
import io.legado.app.utils.openInputStream
import io.legado.app.utils.postEvent
import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
@@ -183,14 +209,21 @@ object Restore {
} }
appCtx.getSharedPreferences(path, "config")?.all?.let { map -> appCtx.getSharedPreferences(path, "config")?.all?.let { map ->
val edit = appCtx.defaultSharedPreferences.edit() val edit = appCtx.defaultSharedPreferences.edit()
val aes = BackupAES()
map.forEach { (key, value) -> map.forEach { (key, value) ->
if (BackupConfig.keyIsNotIgnore(key)) { if (BackupConfig.keyIsNotIgnore(key)) {
when (value) { when (key) {
is Int -> edit.putInt(key, value) PreferKey.webDavPassword -> {
is Boolean -> edit.putBoolean(key, value) edit.putString(key, aes.decryptStr(value.toString()))
is Long -> edit.putLong(key, value) }
is Float -> edit.putFloat(key, value)
is String -> edit.putString(key, value) else -> when (value) {
is Int -> edit.putInt(key, value)
is Boolean -> edit.putBoolean(key, value)
is Long -> edit.putLong(key, value)
is Float -> edit.putFloat(key, value)
is String -> edit.putString(key, value)
}
} }
} }
} }
@@ -19,6 +19,7 @@ import com.google.android.material.bottomnavigation.BottomNavigationView
import io.legado.app.BuildConfig import io.legado.app.BuildConfig
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppConst
import io.legado.app.constant.AppConst.appInfo import io.legado.app.constant.AppConst.appInfo
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
@@ -228,7 +229,9 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
okButton { okButton {
LocalConfig.password = editTextBinding.editView.text.toString() LocalConfig.password = editTextBinding.editView.text.toString()
} }
cancelButton() cancelButton {
LocalConfig.password = AppConst.androidId
}
} }
} }