From 1cc7799bd6198f78d17d974723eaf124d276b274 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 25 May 2019 20:52:03 +0800 Subject: [PATCH] WebDav --- .../java/io/legado/app/lib/webdav/WebDav.kt | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt index a3f695171..a131c855f 100644 --- a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt +++ b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt @@ -34,7 +34,6 @@ constructor(url: String) { private var httpUrl: String? = null var displayName: String? = null - var createTime: Long = 0 var lastModified: Long = 0 var size: Long = 0 var isDirectory = true @@ -110,7 +109,7 @@ constructor(url: String) { val response = propFindResponse(ArrayList()) var s = "" try { - if (response == null || !response.isSuccessful) { + if (!response.isSuccessful) { this.exists = false return false } @@ -134,7 +133,6 @@ constructor(url: String) { fun listFiles(propsList: ArrayList = ArrayList()): List { val response = propFindResponse(propsList) try { - assert(response != null) if (response.isSuccessful) { return parseDir(response.body()!!.string()) } @@ -217,22 +215,13 @@ constructor(url: String) { * @return 下载是否成功 */ fun download(savedPath: String, replaceExisting: Boolean): Boolean { - val file = File(savedPath) - if (file.exists()) { - if (replaceExisting) { - file.delete() - } else { + if (File(savedPath).exists()) { + if (!replaceExisting) { return false } } val inputS = inputStream ?: return false - try { - file.createNewFile() - file.writeBytes(inputS.readBytes()) - return true - } catch (e: Exception) { - e.printStackTrace() - } + File(savedPath).writeBytes(inputS.readBytes()) return false }