From 2645bfeaea0a0e7d11e12ee6b7802799c0aecce0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 5 Jan 2020 21:54:09 +0800 Subject: [PATCH] up --- .../java/io/legado/app/help/storage/Backup.kt | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index a7fce4b21..462bc445a 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -15,7 +15,7 @@ import java.io.File object Backup { - val backupPath = App.INSTANCE.filesDir.absolutePath + File.separator + "backup" + private val backupPath = App.INSTANCE.filesDir.absolutePath + File.separator + "backup" val defaultPath by lazy { FileUtils.getSdCardPath() + File.separator + "YueDu" @@ -29,6 +29,18 @@ object Backup { legadoPath + File.separator + "Export" } + val backupFileNames by lazy { + arrayOf( + "bookshelf.json", + "bookGroup.json", + "bookSource.json", + "rssSource.json", + "replaceRule.json", + ReadBookConfig.readConfigFileName, + "config.xml" + ) + } + fun backup(context: Context, uri: Uri?) { App.db.bookDao().allBooks.let { if (it.isNotEmpty()) { @@ -81,21 +93,14 @@ object Backup { WebDavHelp.backUpWebDav(backupPath) if (uri != null) { copyBackup(context, uri) + } else { + copyBackup() } } private fun copyBackup(context: Context, uri: Uri) { DocumentFile.fromTreeUri(context, uri)?.let { treeDoc -> - val fileNames = arrayOf( - "bookshelf.json", - "bookGroup.json", - "bookSource.json", - "rssSource.json", - "replaceRule.json", - ReadBookConfig.readConfigFileName, - "config.xml" - ) - for (fileName in fileNames) { + for (fileName in backupFileNames) { treeDoc.createFile("text/plain", fileName)?.let { doc -> DocumentUtils.writeText( context, @@ -107,4 +112,10 @@ object Backup { } } + private fun copyBackup() { + for (fileName in backupFileNames) { + FileHelp.getFile(backupPath + File.separator + "bookshelf.json") + .copyTo(FileHelp.getFile(legadoPath + File.separator + "bookshelf.json")) + } + } } \ No newline at end of file