|
|
@ -14,10 +14,14 @@ import io.legado.app.data.entities.ReplaceRule |
|
|
|
import io.legado.app.data.entities.RssSource |
|
|
|
import io.legado.app.data.entities.RssSource |
|
|
|
import io.legado.app.help.FileHelp |
|
|
|
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.storage.Backup.defaultPath |
|
|
|
import io.legado.app.help.storage.Backup.defaultPath |
|
|
|
import io.legado.app.help.storage.Backup.legadoPath |
|
|
|
import io.legado.app.help.storage.Backup.legadoPath |
|
|
|
import io.legado.app.utils.* |
|
|
|
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.defaultSharedPreferences |
|
|
|
import org.jetbrains.anko.doAsync |
|
|
|
import org.jetbrains.anko.doAsync |
|
|
|
import org.jetbrains.anko.toast |
|
|
|
import org.jetbrains.anko.toast |
|
|
@ -100,100 +104,100 @@ object Restore { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun importYueDuData(context: Context) { |
|
|
|
fun importYueDuData(context: Context) { |
|
|
|
Coroutine.async { |
|
|
|
GlobalScope.launch(IO) { |
|
|
|
// 导入书架 |
|
|
|
try {// 导入书架 |
|
|
|
val shelfFile = FileHelp.getFile(defaultPath + File.separator + "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() |
|
|
|
for (item in items) { |
|
|
|
for (item in items) { |
|
|
|
val jsonItem = jsonPath.parse(item) |
|
|
|
val jsonItem = jsonPath.parse(item) |
|
|
|
val book = Book() |
|
|
|
val book = Book() |
|
|
|
book.bookUrl = jsonItem.readString("$.noteUrl") ?: "" |
|
|
|
book.bookUrl = jsonItem.readString("$.noteUrl") ?: "" |
|
|
|
if (book.bookUrl.isBlank()) continue |
|
|
|
if (book.bookUrl.isBlank()) continue |
|
|
|
book.name = jsonItem.readString("$.bookInfoBean.name") ?: "" |
|
|
|
book.name = jsonItem.readString("$.bookInfoBean.name") ?: "" |
|
|
|
if (book.bookUrl in existingBooks) { |
|
|
|
if (book.bookUrl in existingBooks) { |
|
|
|
Log.d(AppConst.APP_TAG, "Found existing book: ${book.name}") |
|
|
|
Log.d(AppConst.APP_TAG, "Found existing book: ${book.name}") |
|
|
|
continue |
|
|
|
continue |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
book.origin = jsonItem.readString("$.tag") ?: "" |
|
|
|
|
|
|
|
book.originName = jsonItem.readString("$.bookInfoBean.origin") ?: "" |
|
|
|
|
|
|
|
book.author = jsonItem.readString("$.bookInfoBean.author") ?: "" |
|
|
|
|
|
|
|
book.type = |
|
|
|
|
|
|
|
if (jsonItem.readString("$.bookInfoBean.bookSourceType") == "AUDIO") 1 else 0 |
|
|
|
|
|
|
|
book.tocUrl = jsonItem.readString("$.bookInfoBean.chapterUrl") ?: book.bookUrl |
|
|
|
|
|
|
|
book.coverUrl = jsonItem.readString("$.bookInfoBean.coverUrl") |
|
|
|
|
|
|
|
book.customCoverUrl = jsonItem.readString("$.customCoverPath") |
|
|
|
|
|
|
|
book.lastCheckTime = jsonItem.readLong("$.bookInfoBean.finalRefreshData") ?: 0 |
|
|
|
|
|
|
|
book.canUpdate = jsonItem.readBool("$.allowUpdate") == true |
|
|
|
|
|
|
|
book.totalChapterNum = jsonItem.readInt("$.chapterListSize") ?: 0 |
|
|
|
|
|
|
|
book.durChapterIndex = jsonItem.readInt("$.durChapter") ?: 0 |
|
|
|
|
|
|
|
book.durChapterTitle = jsonItem.readString("$.durChapterName") |
|
|
|
|
|
|
|
book.durChapterPos = jsonItem.readInt("$.durChapterPage") ?: 0 |
|
|
|
|
|
|
|
book.durChapterTime = jsonItem.readLong("$.finalDate") ?: 0 |
|
|
|
|
|
|
|
book.group = jsonItem.readInt("$.group") ?: 0 |
|
|
|
|
|
|
|
book.intro = jsonItem.readString("$.bookInfoBean.introduce") |
|
|
|
|
|
|
|
book.latestChapterTitle = jsonItem.readString("$.lastChapterName") |
|
|
|
|
|
|
|
book.lastCheckCount = jsonItem.readInt("$.newChapters") ?: 0 |
|
|
|
|
|
|
|
book.order = jsonItem.readInt("$.serialNumber") ?: 0 |
|
|
|
|
|
|
|
book.useReplaceRule = jsonItem.readBool("$.useReplaceRule") == true |
|
|
|
|
|
|
|
book.variable = jsonItem.readString("$.variable") |
|
|
|
|
|
|
|
books.add(book) |
|
|
|
} |
|
|
|
} |
|
|
|
book.origin = jsonItem.readString("$.tag") ?: "" |
|
|
|
App.db.bookDao().insert(*books.toTypedArray()) |
|
|
|
book.originName = jsonItem.readString("$.bookInfoBean.origin") ?: "" |
|
|
|
withContext(Main) { |
|
|
|
book.author = jsonItem.readString("$.bookInfoBean.author") ?: "" |
|
|
|
context.toast("成功导入书籍${books.size}") |
|
|
|
book.type = |
|
|
|
} |
|
|
|
if (jsonItem.readString("$.bookInfoBean.bookSourceType") == "AUDIO") 1 else 0 |
|
|
|
} catch (e: Exception) { |
|
|
|
book.tocUrl = jsonItem.readString("$.bookInfoBean.chapterUrl") ?: book.bookUrl |
|
|
|
context.toast("导入书籍失败\n${e.localizedMessage}") |
|
|
|
book.coverUrl = jsonItem.readString("$.bookInfoBean.coverUrl") |
|
|
|
|
|
|
|
book.customCoverUrl = jsonItem.readString("$.customCoverPath") |
|
|
|
|
|
|
|
book.lastCheckTime = jsonItem.readLong("$.bookInfoBean.finalRefreshData") ?: 0 |
|
|
|
|
|
|
|
book.canUpdate = jsonItem.readBool("$.allowUpdate") == true |
|
|
|
|
|
|
|
book.totalChapterNum = jsonItem.readInt("$.chapterListSize") ?: 0 |
|
|
|
|
|
|
|
book.durChapterIndex = jsonItem.readInt("$.durChapter") ?: 0 |
|
|
|
|
|
|
|
book.durChapterTitle = jsonItem.readString("$.durChapterName") |
|
|
|
|
|
|
|
book.durChapterPos = jsonItem.readInt("$.durChapterPage") ?: 0 |
|
|
|
|
|
|
|
book.durChapterTime = jsonItem.readLong("$.finalDate") ?: 0 |
|
|
|
|
|
|
|
book.group = jsonItem.readInt("$.group") ?: 0 |
|
|
|
|
|
|
|
book.intro = jsonItem.readString("$.bookInfoBean.introduce") |
|
|
|
|
|
|
|
book.latestChapterTitle = jsonItem.readString("$.lastChapterName") |
|
|
|
|
|
|
|
book.lastCheckCount = jsonItem.readInt("$.newChapters") ?: 0 |
|
|
|
|
|
|
|
book.order = jsonItem.readInt("$.serialNumber") ?: 0 |
|
|
|
|
|
|
|
book.useReplaceRule = jsonItem.readBool("$.useReplaceRule") == true |
|
|
|
|
|
|
|
book.variable = jsonItem.readString("$.variable") |
|
|
|
|
|
|
|
books.add(book) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
App.db.bookDao().insert(*books.toTypedArray()) |
|
|
|
|
|
|
|
books |
|
|
|
|
|
|
|
}.onSuccess { |
|
|
|
|
|
|
|
context.toast("成功导入书籍${it?.size}") |
|
|
|
|
|
|
|
}.onError { |
|
|
|
|
|
|
|
context.toast("导入书籍失败\n${it.localizedMessage}") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Coroutine.async { |
|
|
|
try {// Book source |
|
|
|
// Book source |
|
|
|
val sourceFile = |
|
|
|
val sourceFile = FileHelp.getFile(defaultPath + File.separator + "myBookSource.json") |
|
|
|
FileHelp.getFile(defaultPath + File.separator + "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) { |
|
|
|
val jsonItem = jsonPath.parse(item) |
|
|
|
val jsonItem = jsonPath.parse(item) |
|
|
|
OldRule.jsonToBookSource(jsonItem.jsonString())?.let { |
|
|
|
OldRule.jsonToBookSource(jsonItem.jsonString())?.let { |
|
|
|
bookSources.add(it) |
|
|
|
bookSources.add(it) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
App.db.bookSourceDao().insert(*bookSources.toTypedArray()) |
|
|
|
|
|
|
|
withContext(Main) { |
|
|
|
|
|
|
|
context.toast("成功导入书源${bookSources.size}") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
|
|
|
context.toast("导入源失败\n${e.localizedMessage}") |
|
|
|
} |
|
|
|
} |
|
|
|
App.db.bookSourceDao().insert(*bookSources.toTypedArray()) |
|
|
|
|
|
|
|
bookSources |
|
|
|
|
|
|
|
}.onSuccess { |
|
|
|
|
|
|
|
context.toast("成功导入书源${it?.size}") |
|
|
|
|
|
|
|
}.onError { |
|
|
|
|
|
|
|
context.toast("导入源失败\n${it.localizedMessage}") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Coroutine.async { |
|
|
|
try {// Replace rules |
|
|
|
// Replace rules |
|
|
|
val ruleFile = |
|
|
|
val ruleFile = FileHelp.getFile(defaultPath + File.separator + "myBookReplaceRule.json") |
|
|
|
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() |
|
|
|
for ((index: Int, item: Map<String, Any>) in items.withIndex()) { |
|
|
|
for ((index: Int, item: Map<String, Any>) in items.withIndex()) { |
|
|
|
val jsonItem = jsonPath.parse(item) |
|
|
|
val jsonItem = jsonPath.parse(item) |
|
|
|
val rule = ReplaceRule() |
|
|
|
val rule = ReplaceRule() |
|
|
|
rule.id = jsonItem.readLong("$.id") ?: System.currentTimeMillis().plus(index) |
|
|
|
rule.id = jsonItem.readLong("$.id") ?: System.currentTimeMillis().plus(index) |
|
|
|
rule.pattern = jsonItem.readString("$.regex") ?: "" |
|
|
|
rule.pattern = jsonItem.readString("$.regex") ?: "" |
|
|
|
if (rule.pattern.isEmpty() || rule.pattern in existingRules) continue |
|
|
|
if (rule.pattern.isEmpty() || rule.pattern in existingRules) continue |
|
|
|
rule.name = jsonItem.readString("$.replaceSummary") ?: "" |
|
|
|
rule.name = jsonItem.readString("$.replaceSummary") ?: "" |
|
|
|
rule.replacement = jsonItem.readString("$.replacement") ?: "" |
|
|
|
rule.replacement = jsonItem.readString("$.replacement") ?: "" |
|
|
|
rule.isRegex = jsonItem.readBool("$.isRegex") == true |
|
|
|
rule.isRegex = jsonItem.readBool("$.isRegex") == true |
|
|
|
rule.scope = jsonItem.readString("$.useTo") |
|
|
|
rule.scope = jsonItem.readString("$.useTo") |
|
|
|
rule.isEnabled = jsonItem.readBool("$.enable") == true |
|
|
|
rule.isEnabled = jsonItem.readBool("$.enable") == true |
|
|
|
rule.order = jsonItem.readInt("$.serialNumber") ?: index |
|
|
|
rule.order = jsonItem.readInt("$.serialNumber") ?: index |
|
|
|
replaceRules.add(rule) |
|
|
|
replaceRules.add(rule) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
App.db.replaceRuleDao().insert(*replaceRules.toTypedArray()) |
|
|
|
|
|
|
|
withContext(Main) { |
|
|
|
|
|
|
|
context.toast("成功导入替换规则${replaceRules.size}") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
|
|
|
context.toast("导入替换规则失败\n${e.localizedMessage}") |
|
|
|
} |
|
|
|
} |
|
|
|
App.db.replaceRuleDao().insert(*replaceRules.toTypedArray()) |
|
|
|
|
|
|
|
replaceRules |
|
|
|
|
|
|
|
}.onSuccess { |
|
|
|
|
|
|
|
context.toast("成功导入替换规则${it?.size}") |
|
|
|
|
|
|
|
}.onError { |
|
|
|
|
|
|
|
context.toast("导入替换规则失败\n${it.localizedMessage}") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |