|
|
|
@ -54,6 +54,7 @@ object Backup { |
|
|
|
|
suspend fun backup(context: Context, path: String = legadoPath) { |
|
|
|
|
context.putPrefLong(PreferKey.lastBackup, System.currentTimeMillis()) |
|
|
|
|
withContext(IO) { |
|
|
|
|
synchronized(this@Backup) { |
|
|
|
|
writeListToJson(App.db.bookDao().all, "bookshelf.json", backupPath) |
|
|
|
|
writeListToJson(App.db.bookGroupDao().all, "bookGroup.json", backupPath) |
|
|
|
|
writeListToJson(App.db.bookSourceDao().all, "bookSource.json", backupPath) |
|
|
|
@ -86,6 +87,7 @@ object Backup { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun writeListToJson(list: List<Any>, fileName: String, path: String) { |
|
|
|
|
if (list.isNotEmpty()) { |
|
|
|
@ -96,6 +98,7 @@ object Backup { |
|
|
|
|
|
|
|
|
|
@Throws(java.lang.Exception::class) |
|
|
|
|
private fun copyBackup(context: Context, uri: Uri) { |
|
|
|
|
|
|
|
|
|
DocumentFile.fromTreeUri(context, uri)?.let { treeDoc -> |
|
|
|
|
for (fileName in backupFileNames) { |
|
|
|
|
val file = File(backupPath + File.separator + fileName) |
|
|
|
|