|
|
|
@ -37,7 +37,7 @@ object Restore { |
|
|
|
|
for (fileName in Backup.backupFileNames) { |
|
|
|
|
if (doc.name == fileName) { |
|
|
|
|
DocumentUtils.readText(context, doc.uri)?.let { |
|
|
|
|
FileUtils.getFile(Backup.backupPath + File.separator + fileName) |
|
|
|
|
FileUtils.createFileIfNotExist(Backup.backupPath + File.separator + fileName) |
|
|
|
|
.writeText(it) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -50,7 +50,7 @@ object Restore { |
|
|
|
|
suspend fun restore(path: String) { |
|
|
|
|
withContext(IO) { |
|
|
|
|
try { |
|
|
|
|
val file = FileUtils.getFile(path + File.separator + "bookshelf.json") |
|
|
|
|
val file = FileUtils.createFileIfNotExist(path + File.separator + "bookshelf.json") |
|
|
|
|
val json = file.readText() |
|
|
|
|
GSON.fromJsonArray<Book>(json)?.let { |
|
|
|
|
App.db.bookDao().insert(*it.toTypedArray()) |
|
|
|
@ -59,7 +59,7 @@ object Restore { |
|
|
|
|
e.printStackTrace() |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
val file = FileUtils.getFile(path + File.separator + "bookGroup.json") |
|
|
|
|
val file = FileUtils.createFileIfNotExist(path + File.separator + "bookGroup.json") |
|
|
|
|
val json = file.readText() |
|
|
|
|
GSON.fromJsonArray<BookGroup>(json)?.let { |
|
|
|
|
App.db.bookGroupDao().insert(*it.toTypedArray()) |
|
|
|
@ -68,7 +68,7 @@ object Restore { |
|
|
|
|
e.printStackTrace() |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
val file = FileUtils.getFile(path + File.separator + "bookSource.json") |
|
|
|
|
val file = FileUtils.createFileIfNotExist(path + File.separator + "bookSource.json") |
|
|
|
|
val json = file.readText() |
|
|
|
|
GSON.fromJsonArray<BookSource>(json)?.let { |
|
|
|
|
App.db.bookSourceDao().insert(*it.toTypedArray()) |
|
|
|
@ -77,7 +77,7 @@ object Restore { |
|
|
|
|
e.printStackTrace() |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
val file = FileUtils.getFile(path + File.separator + "rssSource.json") |
|
|
|
|
val file = FileUtils.createFileIfNotExist(path + File.separator + "rssSource.json") |
|
|
|
|
val json = file.readText() |
|
|
|
|
GSON.fromJsonArray<RssSource>(json)?.let { |
|
|
|
|
App.db.rssSourceDao().insert(*it.toTypedArray()) |
|
|
|
@ -86,7 +86,8 @@ object Restore { |
|
|
|
|
e.printStackTrace() |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
val file = FileUtils.getFile(path + File.separator + "replaceRule.json") |
|
|
|
|
val file = |
|
|
|
|
FileUtils.createFileIfNotExist(path + File.separator + "replaceRule.json") |
|
|
|
|
val json = file.readText() |
|
|
|
|
GSON.fromJsonArray<ReplaceRule>(json)?.let { |
|
|
|
|
App.db.replaceRuleDao().insert(*it.toTypedArray()) |
|
|
|
@ -96,7 +97,7 @@ object Restore { |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
val file = |
|
|
|
|
FileUtils.getFile(path + File.separator + ReadBookConfig.readConfigFileName) |
|
|
|
|
FileUtils.createFileIfNotExist(path + File.separator + ReadBookConfig.readConfigFileName) |
|
|
|
|
val configFile = |
|
|
|
|
File(App.INSTANCE.filesDir.absolutePath + File.separator + ReadBookConfig.readConfigFileName) |
|
|
|
|
if (file.exists()) { |
|
|
|
@ -125,7 +126,7 @@ object Restore { |
|
|
|
|
GlobalScope.launch(IO) { |
|
|
|
|
try {// 导入书架 |
|
|
|
|
val shelfFile = |
|
|
|
|
FileUtils.getFile(Backup.defaultPath + File.separator + "myBookShelf.json") |
|
|
|
|
FileUtils.createFileIfNotExist(Backup.defaultPath + File.separator + "myBookShelf.json") |
|
|
|
|
val json = shelfFile.readText() |
|
|
|
|
val importCount = importOldBookshelf(json) |
|
|
|
|
withContext(Main) { |
|
|
|
@ -139,7 +140,7 @@ object Restore { |
|
|
|
|
|
|
|
|
|
try {// Book source |
|
|
|
|
val sourceFile = |
|
|
|
|
FileUtils.getFile(Backup.defaultPath + File.separator + "myBookSource.json") |
|
|
|
|
FileUtils.createFileIfNotExist(Backup.defaultPath + File.separator + "myBookSource.json") |
|
|
|
|
val json = sourceFile.readText() |
|
|
|
|
val importCount = importOldSource(json) |
|
|
|
|
withContext(Main) { |
|
|
|
@ -153,7 +154,7 @@ object Restore { |
|
|
|
|
|
|
|
|
|
try {// Replace rules |
|
|
|
|
val ruleFile = |
|
|
|
|
FileUtils.getFile(Backup.defaultPath + File.separator + "myBookReplaceRule.json") |
|
|
|
|
FileUtils.createFileIfNotExist(Backup.defaultPath + File.separator + "myBookReplaceRule.json") |
|
|
|
|
val json = ruleFile.readText() |
|
|
|
|
val importCount = importOldReplaceRule(json) |
|
|
|
|
withContext(Main) { |
|
|
|
|