|
|
@ -1,13 +1,12 @@ |
|
|
|
package io.legado.app.help.storage |
|
|
|
package io.legado.app.help.storage |
|
|
|
|
|
|
|
|
|
|
|
import android.app.AlarmManager |
|
|
|
|
|
|
|
import android.app.PendingIntent |
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
import android.content.Context |
|
|
|
import android.net.Uri |
|
|
|
import android.net.Uri |
|
|
|
import androidx.documentfile.provider.DocumentFile |
|
|
|
import androidx.documentfile.provider.DocumentFile |
|
|
|
import io.legado.app.BuildConfig |
|
|
|
import io.legado.app.BuildConfig |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.constant.AppConst.androidId |
|
|
|
import io.legado.app.constant.AppConst.androidId |
|
|
|
|
|
|
|
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.* |
|
|
@ -21,9 +20,7 @@ import kotlinx.coroutines.Dispatchers.Main |
|
|
|
import kotlinx.coroutines.delay |
|
|
|
import kotlinx.coroutines.delay |
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import splitties.init.appCtx |
|
|
|
import splitties.init.appCtx |
|
|
|
import splitties.systemservices.alarmManager |
|
|
|
|
|
|
|
import java.io.File |
|
|
|
import java.io.File |
|
|
|
import kotlin.system.exitProcess |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
object Restore { |
|
|
|
object Restore { |
|
|
@ -54,6 +51,7 @@ object Restore { |
|
|
|
|
|
|
|
|
|
|
|
//默认忽略keys |
|
|
|
//默认忽略keys |
|
|
|
private val ignorePrefKeys = arrayOf( |
|
|
|
private val ignorePrefKeys = arrayOf( |
|
|
|
|
|
|
|
PreferKey.themeMode, |
|
|
|
PreferKey.defaultCover, |
|
|
|
PreferKey.defaultCover, |
|
|
|
PreferKey.defaultCoverDark |
|
|
|
PreferKey.defaultCoverDark |
|
|
|
) |
|
|
|
) |
|
|
@ -116,7 +114,8 @@ object Restore { |
|
|
|
fileToListT<BookSource>(path, "bookSource.json")?.let { |
|
|
|
fileToListT<BookSource>(path, "bookSource.json")?.let { |
|
|
|
appDb.bookSourceDao.insert(*it.toTypedArray()) |
|
|
|
appDb.bookSourceDao.insert(*it.toTypedArray()) |
|
|
|
} ?: run { |
|
|
|
} ?: run { |
|
|
|
val bookSourceFile = FileUtils.createFileIfNotExist(path + File.separator + "bookSource.json") |
|
|
|
val bookSourceFile = |
|
|
|
|
|
|
|
FileUtils.createFileIfNotExist(path + File.separator + "bookSource.json") |
|
|
|
val json = bookSourceFile.readText() |
|
|
|
val json = bookSourceFile.readText() |
|
|
|
ImportOldData.importOldSource(json) |
|
|
|
ImportOldData.importOldSource(json) |
|
|
|
} |
|
|
|
} |
|
|
@ -172,6 +171,7 @@ object Restore { |
|
|
|
e.printOnDebug() |
|
|
|
e.printOnDebug() |
|
|
|
} |
|
|
|
} |
|
|
|
if (!ignoreReadConfig) { |
|
|
|
if (!ignoreReadConfig) { |
|
|
|
|
|
|
|
//恢复阅读界面配置 |
|
|
|
try { |
|
|
|
try { |
|
|
|
val file = |
|
|
|
val file = |
|
|
|
FileUtils.createFileIfNotExist("$path${File.separator}${ReadBookConfig.configFileName}") |
|
|
|
FileUtils.createFileIfNotExist("$path${File.separator}${ReadBookConfig.configFileName}") |
|
|
@ -197,14 +197,14 @@ object Restore { |
|
|
|
} |
|
|
|
} |
|
|
|
Preferences.getSharedPreferences(appCtx, path, "config")?.all?.let { map -> |
|
|
|
Preferences.getSharedPreferences(appCtx, path, "config")?.all?.let { map -> |
|
|
|
val edit = appCtx.defaultSharedPreferences.edit() |
|
|
|
val edit = appCtx.defaultSharedPreferences.edit() |
|
|
|
map.forEach { |
|
|
|
map.forEach { (key, value) -> |
|
|
|
if (keyIsNotIgnore(it.key)) { |
|
|
|
if (keyIsNotIgnore(key)) { |
|
|
|
when (val value = it.value) { |
|
|
|
when (value) { |
|
|
|
is Int -> edit.putInt(it.key, value) |
|
|
|
is Int -> edit.putInt(key, value) |
|
|
|
is Boolean -> edit.putBoolean(it.key, value) |
|
|
|
is Boolean -> edit.putBoolean(key, value) |
|
|
|
is Long -> edit.putLong(it.key, value) |
|
|
|
is Long -> edit.putLong(key, value) |
|
|
|
is Float -> edit.putFloat(it.key, value) |
|
|
|
is Float -> edit.putFloat(key, value) |
|
|
|
is String -> edit.putString(it.key, value) |
|
|
|
is String -> edit.putString(key, value) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -224,12 +224,7 @@ object Restore { |
|
|
|
if (!BuildConfig.DEBUG) { |
|
|
|
if (!BuildConfig.DEBUG) { |
|
|
|
LauncherIconHelp.changeIcon(appCtx.getPrefString(PreferKey.launcherIcon)) |
|
|
|
LauncherIconHelp.changeIcon(appCtx.getPrefString(PreferKey.launcherIcon)) |
|
|
|
} |
|
|
|
} |
|
|
|
appCtx.packageManager.getLaunchIntentForPackage(appCtx.packageName)?.let { intent -> |
|
|
|
postEvent(EventBus.RECREATE, "") |
|
|
|
val restartIntent = |
|
|
|
|
|
|
|
PendingIntent.getActivity(appCtx, 0, intent, PendingIntent.FLAG_ONE_SHOT) |
|
|
|
|
|
|
|
alarmManager[AlarmManager.RTC, System.currentTimeMillis() + 300] = restartIntent |
|
|
|
|
|
|
|
exitProcess(0) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|