pull/37/head
kunfei 5 years ago
parent 07845fab8c
commit 8ee85510c5
  1. 14
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  2. 11
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  3. 12
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  4. 14
      app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt

@ -19,8 +19,8 @@ import java.io.IOException
* 阅读界面配置
*/
object ReadBookConfig {
private const val fileName = "readConfig.json"
private val configList: ArrayList<Config> = arrayListOf<Config>()
const val readConfigFileName = "readConfig.json"
val configList: ArrayList<Config> = arrayListOf<Config>()
.apply {
upConfig(this)
}
@ -35,11 +35,12 @@ object ReadBookConfig {
}
fun upConfig(list: ArrayList<Config> = configList) {
val configFile = File(App.INSTANCE.filesDir.absolutePath + File.separator + fileName)
val configFile =
File(App.INSTANCE.filesDir.absolutePath + File.separator + readConfigFileName)
val json = if (configFile.exists()) {
String(configFile.readBytes())
} else {
String(App.INSTANCE.assets.open(fileName).readBytes())
String(App.INSTANCE.assets.open(readConfigFileName).readBytes())
}
try {
GSON.fromJsonArray<Config>(json)?.let {
@ -63,7 +64,8 @@ object ReadBookConfig {
fun save() {
GlobalScope.launch(IO) {
val json = GSON.toJson(configList)
val configFile = File(App.INSTANCE.filesDir.absolutePath + File.separator + fileName)
val configFile =
File(App.INSTANCE.filesDir.absolutePath + File.separator + readConfigFileName)
//获取流并存储
try {
BufferedWriter(FileWriter(configFile)).use { writer ->
@ -78,7 +80,7 @@ object ReadBookConfig {
fun reset() {
try {
val json = String(App.INSTANCE.assets.open(fileName).readBytes())
val json = String(App.INSTANCE.assets.open(readConfigFileName).readBytes())
GSON.fromJsonArray<Config>(json)?.let {
configList.clear()
configList.addAll(it)

@ -3,6 +3,7 @@ package io.legado.app.help.storage
import io.legado.app.App
import io.legado.app.R
import io.legado.app.help.FileHelp
import io.legado.app.help.ReadBookConfig
import io.legado.app.utils.FileUtils
import io.legado.app.utils.GSON
import org.jetbrains.anko.defaultSharedPreferences
@ -25,6 +26,7 @@ object Backup {
backupBookSource(path)
backupRssSource(path)
backupReplaceRule(path)
backupReadConfig(path)
backupPreference(path)
WebDavHelp.backUpWebDav(path)
uiThread {
@ -40,6 +42,8 @@ object Backup {
backupBookSource(path)
backupRssSource(path)
backupReplaceRule(path)
backupReadConfig(path)
backupPreference(path)
WebDavHelp.backUpWebDav(path)
}
}
@ -84,6 +88,13 @@ object Backup {
}
}
private fun backupReadConfig(path: String) {
GSON.toJson(ReadBookConfig.configList)?.let {
FileHelp.getFile(path + File.separator + ReadBookConfig.readConfigFileName)
.writeText(it)
}
}
private fun backupPreference(path: String) {
Preferences.getSharedPreferences(App.INSTANCE, path, "config")?.let { sp ->
val edit = sp.edit()

@ -13,6 +13,7 @@ import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.ReplaceRule
import io.legado.app.data.entities.RssSource
import io.legado.app.help.FileHelp
import io.legado.app.help.ReadBookConfig
import io.legado.app.help.storage.Backup.defaultPath
import io.legado.app.utils.*
import org.jetbrains.anko.defaultSharedPreferences
@ -68,6 +69,17 @@ object Restore {
} catch (e: Exception) {
e.printStackTrace()
}
try {
val file =
FileHelp.getFile(path + File.separator + ReadBookConfig.readConfigFileName)
val configFile =
File(App.INSTANCE.filesDir.absolutePath + File.separator + ReadBookConfig.readConfigFileName)
if (file.exists()) {
file.copyTo(configFile, true)
}
} catch (e: Exception) {
e.printStackTrace()
}
Preferences.getSharedPreferences(App.INSTANCE, path, "config")?.all?.map {
val edit = App.INSTANCE.defaultSharedPreferences.edit()
when (val value = it.value) {

@ -3,6 +3,7 @@ package io.legado.app.help.storage
import android.content.Context
import io.legado.app.App
import io.legado.app.help.FileHelp
import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.webdav.WebDav
import io.legado.app.lib.webdav.http.HttpAuth
import io.legado.app.utils.ZipUtils
@ -80,11 +81,14 @@ object WebDavHelp {
fun backUpWebDav(path: String) {
if (initWebDav()) {
val paths = arrayListOf<String>()
paths.add(path + File.separator + "bookshelf.json")
paths.add(path + File.separator + "bookSource.json")
paths.add(path + File.separator + "rssSource.json")
paths.add(path + File.separator + "replaceRule.json")
val paths = arrayListOf(
path + File.separator + "bookshelf.json",
path + File.separator + "bookSource.json",
path + File.separator + "rssSource.json",
path + File.separator + "replaceRule.json",
path + File.separator + "config.xml",
path + File.separator + ReadBookConfig.readConfigFileName
)
FileHelp.deleteFile(zipFilePath)
if (ZipUtils.zipFiles(paths, zipFilePath)) {
WebDav(getWebDavUrl() + "legado").makeAsDir()

Loading…
Cancel
Save