pull/32/head
gedoor 6 years ago
parent d7fec4f35e
commit 1cc7799bd6
  1. 19
      app/src/main/java/io/legado/app/lib/webdav/WebDav.kt

@ -34,7 +34,6 @@ constructor(url: String) {
private var httpUrl: String? = null private var httpUrl: String? = null
var displayName: String? = null var displayName: String? = null
var createTime: Long = 0
var lastModified: Long = 0 var lastModified: Long = 0
var size: Long = 0 var size: Long = 0
var isDirectory = true var isDirectory = true
@ -110,7 +109,7 @@ constructor(url: String) {
val response = propFindResponse(ArrayList()) val response = propFindResponse(ArrayList())
var s = "" var s = ""
try { try {
if (response == null || !response.isSuccessful) { if (!response.isSuccessful) {
this.exists = false this.exists = false
return false return false
} }
@ -134,7 +133,6 @@ constructor(url: String) {
fun listFiles(propsList: ArrayList<String> = ArrayList()): List<WebDav> { fun listFiles(propsList: ArrayList<String> = ArrayList()): List<WebDav> {
val response = propFindResponse(propsList) val response = propFindResponse(propsList)
try { try {
assert(response != null)
if (response.isSuccessful) { if (response.isSuccessful) {
return parseDir(response.body()!!.string()) return parseDir(response.body()!!.string())
} }
@ -217,22 +215,13 @@ constructor(url: String) {
* @return 下载是否成功 * @return 下载是否成功
*/ */
fun download(savedPath: String, replaceExisting: Boolean): Boolean { fun download(savedPath: String, replaceExisting: Boolean): Boolean {
val file = File(savedPath) if (File(savedPath).exists()) {
if (file.exists()) { if (!replaceExisting) {
if (replaceExisting) {
file.delete()
} else {
return false return false
} }
} }
val inputS = inputStream ?: return false val inputS = inputStream ?: return false
try { File(savedPath).writeBytes(inputS.readBytes())
file.createNewFile()
file.writeBytes(inputS.readBytes())
return true
} catch (e: Exception) {
e.printStackTrace()
}
return false return false
} }

Loading…
Cancel
Save