pull/279/head
gedoor 5 years ago
parent 513e553721
commit 9b5c5f2a0d
  1. 3
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  2. 19
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  3. 11
      app/src/main/java/io/legado/app/utils/FileUtils.kt

@ -19,8 +19,7 @@ import java.io.File
@Keep @Keep
object ReadBookConfig { object ReadBookConfig {
const val readConfigFileName = "readConfig.json" const val readConfigFileName = "readConfig.json"
private val configFilePath = private val configFilePath = FileUtils.getPath(App.INSTANCE.filesDir, readConfigFileName)
App.INSTANCE.filesDir.absolutePath + File.separator + readConfigFileName
val configList: ArrayList<Config> = arrayListOf() val configList: ArrayList<Config> = arrayListOf()
private val defaultConfigs by lazy { private val defaultConfigs by lazy {
val json = String(App.INSTANCE.assets.open(readConfigFileName).readBytes()) val json = String(App.INSTANCE.assets.open(readConfigFileName).readBytes())

@ -33,6 +33,16 @@ object Restore {
} }
val ignoreKeys = arrayOf("readConfig") val ignoreKeys = arrayOf("readConfig")
val ignoreTitle = arrayOf("阅读界面设置") val ignoreTitle = arrayOf("阅读界面设置")
private val ignorePrefKeys = arrayOf(PreferKey.versionCode, PreferKey.defaultCover)
private val readPrefKeys = arrayOf(
PreferKey.readStyleSelect,
PreferKey.shareLayout,
PreferKey.pageAnim,
PreferKey.hideStatusBar,
PreferKey.hideNavigationBar,
PreferKey.bodyIndent,
PreferKey.autoReadSpeed
)
val jsonPath: ParseContext by lazy { val jsonPath: ParseContext by lazy {
JsonPath.using( JsonPath.using(
@ -102,6 +112,7 @@ object Restore {
suspend fun restoreConfig(path: String = Backup.backupPath) { suspend fun restoreConfig(path: String = Backup.backupPath) {
withContext(IO) { withContext(IO) {
if (!ignoreReadConfig) {
try { try {
val file = val file =
FileUtils.createFileIfNotExist(path + File.separator + ReadBookConfig.readConfigFileName) FileUtils.createFileIfNotExist(path + File.separator + ReadBookConfig.readConfigFileName)
@ -114,12 +125,14 @@ object Restore {
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
} }
}
Preferences.getSharedPreferences(App.INSTANCE, path, "config")?.all Preferences.getSharedPreferences(App.INSTANCE, path, "config")?.all
?.let { map -> ?.let { map ->
val ignoreKeys = arrayOf(PreferKey.versionCode, PreferKey.defaultCover)
val edit = App.INSTANCE.defaultSharedPreferences.edit() val edit = App.INSTANCE.defaultSharedPreferences.edit()
map.forEach { map.forEach {
if (!ignoreKeys.contains(it.key)) { if (!ignorePrefKeys.contains(it.key)
&& !(readPrefKeys.contains(it.key) && ignoreReadConfig)
) {
when (val value = it.value) { when (val value = it.value) {
is Int -> edit.putInt(it.key, value) is Int -> edit.putInt(it.key, value)
is Boolean -> edit.putBoolean(it.key, value) is Boolean -> edit.putBoolean(it.key, value)
@ -153,6 +166,8 @@ object Restore {
} }
} }
val ignoreReadConfig: Boolean get() = ignoreConfig["readConfig"] == true
fun saveIgnoreConfig() { fun saveIgnoreConfig() {
val json = GSON.toJson(ignoreConfig) val json = GSON.toJson(ignoreConfig)
FileUtils.createFileIfNotExist(ignoreConfigPath).writeText(json) FileUtils.createFileIfNotExist(ignoreConfigPath).writeText(json)

@ -60,11 +60,14 @@ object FileUtils {
} }
fun getPath(root: File, fileName: String? = null, vararg subDirs: String): String { fun getPath(root: File, fileName: String? = null, vararg subDirs: String): String {
return if (fileName.isNullOrEmpty()) { val path = StringBuilder(root.absolutePath).append(File.separator)
root.absolutePath + File.separator + subDirs.joinToString(File.separator) subDirs.forEach {
} else { path.append(it).append(File.separator)
root.absolutePath + File.separator + subDirs.joinToString(File.separator) + File.separator + fileName
} }
if (!fileName.isNullOrEmpty()) {
path.append(fileName)
}
return path.toString()
} }
//递归删除文件夹下的数据 //递归删除文件夹下的数据

Loading…
Cancel
Save