|
|
|
@ -14,10 +14,14 @@ 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.coroutine.Coroutine |
|
|
|
|
import io.legado.app.help.storage.Backup.defaultPath |
|
|
|
|
import io.legado.app.help.storage.Backup.legadoPath |
|
|
|
|
import io.legado.app.utils.* |
|
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
|
import kotlinx.coroutines.Dispatchers.Main |
|
|
|
|
import kotlinx.coroutines.GlobalScope |
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
|
import org.jetbrains.anko.defaultSharedPreferences |
|
|
|
|
import org.jetbrains.anko.doAsync |
|
|
|
|
import org.jetbrains.anko.toast |
|
|
|
@ -100,8 +104,8 @@ object Restore { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun importYueDuData(context: Context) { |
|
|
|
|
Coroutine.async { |
|
|
|
|
// 导入书架 |
|
|
|
|
GlobalScope.launch(IO) { |
|
|
|
|
try {// 导入书架 |
|
|
|
|
val shelfFile = FileHelp.getFile(defaultPath + File.separator + "myBookShelf.json") |
|
|
|
|
val books = mutableListOf<Book>() |
|
|
|
|
val items: List<Map<String, Any>> = jsonPath.parse(shelfFile.readText()).read("$") |
|
|
|
@ -141,16 +145,16 @@ object Restore { |
|
|
|
|
books.add(book) |
|
|
|
|
} |
|
|
|
|
App.db.bookDao().insert(*books.toTypedArray()) |
|
|
|
|
books |
|
|
|
|
}.onSuccess { |
|
|
|
|
context.toast("成功导入书籍${it?.size}") |
|
|
|
|
}.onError { |
|
|
|
|
context.toast("导入书籍失败\n${it.localizedMessage}") |
|
|
|
|
withContext(Main) { |
|
|
|
|
context.toast("成功导入书籍${books.size}") |
|
|
|
|
} |
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
context.toast("导入书籍失败\n${e.localizedMessage}") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Coroutine.async { |
|
|
|
|
// Book source |
|
|
|
|
val sourceFile = FileHelp.getFile(defaultPath + File.separator + "myBookSource.json") |
|
|
|
|
try {// Book source |
|
|
|
|
val sourceFile = |
|
|
|
|
FileHelp.getFile(defaultPath + File.separator + "myBookSource.json") |
|
|
|
|
val bookSources = mutableListOf<BookSource>() |
|
|
|
|
val items: List<Map<String, Any>> = jsonPath.parse(sourceFile.readText()).read("$") |
|
|
|
|
for (item in items) { |
|
|
|
@ -160,16 +164,16 @@ object Restore { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
App.db.bookSourceDao().insert(*bookSources.toTypedArray()) |
|
|
|
|
bookSources |
|
|
|
|
}.onSuccess { |
|
|
|
|
context.toast("成功导入书源${it?.size}") |
|
|
|
|
}.onError { |
|
|
|
|
context.toast("导入源失败\n${it.localizedMessage}") |
|
|
|
|
withContext(Main) { |
|
|
|
|
context.toast("成功导入书源${bookSources.size}") |
|
|
|
|
} |
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
context.toast("导入源失败\n${e.localizedMessage}") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Coroutine.async { |
|
|
|
|
// Replace rules |
|
|
|
|
val ruleFile = FileHelp.getFile(defaultPath + File.separator + "myBookReplaceRule.json") |
|
|
|
|
try {// Replace rules |
|
|
|
|
val ruleFile = |
|
|
|
|
FileHelp.getFile(defaultPath + File.separator + "myBookReplaceRule.json") |
|
|
|
|
val replaceRules = mutableListOf<ReplaceRule>() |
|
|
|
|
val items: List<Map<String, Any>> = jsonPath.parse(ruleFile.readText()).read("$") |
|
|
|
|
val existingRules = App.db.replaceRuleDao().all.map { it.pattern }.toSet() |
|
|
|
@ -188,12 +192,12 @@ object Restore { |
|
|
|
|
replaceRules.add(rule) |
|
|
|
|
} |
|
|
|
|
App.db.replaceRuleDao().insert(*replaceRules.toTypedArray()) |
|
|
|
|
replaceRules |
|
|
|
|
}.onSuccess { |
|
|
|
|
context.toast("成功导入替换规则${it?.size}") |
|
|
|
|
}.onError { |
|
|
|
|
context.toast("导入替换规则失败\n${it.localizedMessage}") |
|
|
|
|
withContext(Main) { |
|
|
|
|
context.toast("成功导入替换规则${replaceRules.size}") |
|
|
|
|
} |
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
context.toast("导入替换规则失败\n${e.localizedMessage}") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |