From f2a7c6b644f5928641789c4911d05a7a24f51aa0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 15 Feb 2020 15:27:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/storage/Backup.kt | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 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 cb7e596bf..d44d617b6 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 @@ -76,32 +76,35 @@ 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 doc = treeDoc.findFile(fileName) ?: treeDoc.createFile("", fileName) - doc?.let { - DocumentUtils.writeText( - context, - FileUtils.createFileIfNotExist(backupPath + File.separator + fileName).readText(), - doc.uri - ) + val file = File(backupPath + File.separator + fileName) + if (file.exists()) { + val doc = treeDoc.findFile(fileName) ?: treeDoc.createFile("", fileName) + doc?.let { + DocumentUtils.writeText( + context, + file.readText(), + doc.uri + ) + } } } } } - private fun copyBackup(file: File) { - try { - for (fileName in backupFileNames) { - FileUtils.createFileIfNotExist(backupPath + File.separator + fileName) - .copyTo( - FileUtils.createFileIfNotExist(file, fileName), - true - ) + @Throws(java.lang.Exception::class) + private fun copyBackup(rootFile: File) { + for (fileName in backupFileNames) { + val file = File(backupPath + File.separator + fileName) + if (file.exists()) { + file.copyTo( + FileUtils.createFileIfNotExist(rootFile, fileName), + true + ) } - } catch (e: Exception) { - e.printStackTrace() } } } \ No newline at end of file