pull/49/head
kunfei 5 years ago
parent f0daf7dc39
commit e64038e585
  1. 10
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  2. 13
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  3. 2
      app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt

@ -16,12 +16,16 @@ import java.io.File
object Backup { object Backup {
val defaultPath by lazy { val defaultPath by lazy {
FileUtils.getSdCardPath() + File.separator + "YueDu" + File.separator + "legadoBackUp" FileUtils.getSdCardPath() + File.separator + "YueDu"
}
val legadoPath by lazy {
defaultPath + File.separator + "legadoBackUp"
} }
fun backup() { fun backup() {
doAsync { doAsync {
val path = defaultPath val path = legadoPath
backupBookshelf(path) backupBookshelf(path)
backupBookSource(path) backupBookSource(path)
backupRssSource(path) backupRssSource(path)
@ -37,7 +41,7 @@ object Backup {
fun autoBackup() { fun autoBackup() {
doAsync { doAsync {
val path = defaultPath val path = legadoPath
backupBookshelf(path) backupBookshelf(path)
backupBookSource(path) backupBookSource(path)
backupRssSource(path) backupRssSource(path)

@ -16,6 +16,7 @@ import io.legado.app.help.FileHelp
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.storage.Backup.defaultPath import io.legado.app.help.storage.Backup.defaultPath
import io.legado.app.help.storage.Backup.legadoPath
import io.legado.app.utils.* import io.legado.app.utils.*
import org.jetbrains.anko.defaultSharedPreferences import org.jetbrains.anko.defaultSharedPreferences
import org.jetbrains.anko.doAsync import org.jetbrains.anko.doAsync
@ -32,7 +33,7 @@ object Restore {
) )
} }
fun restore(path: String = defaultPath) { fun restore(path: String = legadoPath) {
doAsync { doAsync {
try { try {
val file = FileHelp.getFile(path + File.separator + "bookshelf.json") val file = FileHelp.getFile(path + File.separator + "bookshelf.json")
@ -100,9 +101,8 @@ object Restore {
fun importYueDuData(context: Context) { fun importYueDuData(context: Context) {
Coroutine.async { Coroutine.async {
val file = File(FileUtils.getSdCardPath(), "YueDu")
// 导入书架 // 导入书架
val shelfFile = File(file, "myBookShelf.json") val shelfFile = FileHelp.getFile(defaultPath + File.separator + "myBookShelf.json")
val books = mutableListOf<Book>() val books = mutableListOf<Book>()
val items: List<Map<String, Any>> = jsonPath.parse(shelfFile.readText()).read("$") val items: List<Map<String, Any>> = jsonPath.parse(shelfFile.readText()).read("$")
val existingBooks = App.db.bookDao().allBookUrls.toSet() val existingBooks = App.db.bookDao().allBookUrls.toSet()
@ -150,8 +150,7 @@ object Restore {
Coroutine.async { Coroutine.async {
// Book source // Book source
val file = File(FileUtils.getSdCardPath(), "YueDu") val sourceFile = FileHelp.getFile(defaultPath + File.separator + "myBookSource.json")
val sourceFile = File(file, "myBookSource.json")
val bookSources = mutableListOf<BookSource>() val bookSources = mutableListOf<BookSource>()
val items: List<Map<String, Any>> = jsonPath.parse(sourceFile.readText()).read("$") val items: List<Map<String, Any>> = jsonPath.parse(sourceFile.readText()).read("$")
for (item in items) { for (item in items) {
@ -169,10 +168,8 @@ object Restore {
} }
Coroutine.async { Coroutine.async {
// Book source
val file = File(FileUtils.getSdCardPath(), "YueDu")
// Replace rules // Replace rules
val ruleFile = File(file, "myBookReplaceRule.json") val ruleFile = FileHelp.getFile(defaultPath + File.separator + "myBookReplaceRule.json")
val replaceRules = mutableListOf<ReplaceRule>() val replaceRules = mutableListOf<ReplaceRule>()
val items: List<Map<String, Any>> = jsonPath.parse(ruleFile.readText()).read("$") val items: List<Map<String, Any>> = jsonPath.parse(ruleFile.readText()).read("$")
val existingRules = App.db.replaceRuleDao().all.map { it.pattern }.toSet() val existingRules = App.db.replaceRuleDao().all.map { it.pattern }.toSet()

@ -73,7 +73,7 @@ object WebDavHelp {
getWebDavUrl()?.let { getWebDavUrl()?.let {
val file = WebDav(it + "legado/" + name) val file = WebDav(it + "legado/" + name)
file.downloadTo(zipFilePath, true) file.downloadTo(zipFilePath, true)
ZipUtils.unzipFile(zipFilePath, Backup.defaultPath) ZipUtils.unzipFile(zipFilePath, Backup.legadoPath)
Restore.restore() Restore.restore()
} }
} }

Loading…
Cancel
Save