pull/279/head
gedoor 4 years ago
parent 513e553721
commit 9b5c5f2a0d
  1. 3
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  2. 39
      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
object ReadBookConfig {
const val readConfigFileName = "readConfig.json"
private val configFilePath =
App.INSTANCE.filesDir.absolutePath + File.separator + readConfigFileName
private val configFilePath = FileUtils.getPath(App.INSTANCE.filesDir, readConfigFileName)
val configList: ArrayList<Config> = arrayListOf()
private val defaultConfigs by lazy {
val json = String(App.INSTANCE.assets.open(readConfigFileName).readBytes())

@ -33,6 +33,16 @@ object Restore {
}
val ignoreKeys = arrayOf("readConfig")
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 {
JsonPath.using(
@ -102,24 +112,27 @@ object Restore {
suspend fun restoreConfig(path: String = Backup.backupPath) {
withContext(IO) {
try {
val file =
FileUtils.createFileIfNotExist(path + File.separator + ReadBookConfig.readConfigFileName)
val configFile =
FileUtils.getFile(App.INSTANCE.filesDir, ReadBookConfig.readConfigFileName)
if (file.exists()) {
file.copyTo(configFile, true)
ReadBookConfig.upConfig()
if (!ignoreReadConfig) {
try {
val file =
FileUtils.createFileIfNotExist(path + File.separator + ReadBookConfig.readConfigFileName)
val configFile =
FileUtils.getFile(App.INSTANCE.filesDir, ReadBookConfig.readConfigFileName)
if (file.exists()) {
file.copyTo(configFile, true)
ReadBookConfig.upConfig()
}
} catch (e: Exception) {
e.printStackTrace()
}
} catch (e: Exception) {
e.printStackTrace()
}
Preferences.getSharedPreferences(App.INSTANCE, path, "config")?.all
?.let { map ->
val ignoreKeys = arrayOf(PreferKey.versionCode, PreferKey.defaultCover)
val edit = App.INSTANCE.defaultSharedPreferences.edit()
map.forEach {
if (!ignoreKeys.contains(it.key)) {
if (!ignorePrefKeys.contains(it.key)
&& !(readPrefKeys.contains(it.key) && ignoreReadConfig)
) {
when (val value = it.value) {
is Int -> edit.putInt(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() {
val json = GSON.toJson(ignoreConfig)
FileUtils.createFileIfNotExist(ignoreConfigPath).writeText(json)

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

Loading…
Cancel
Save