diff --git a/app/src/main/java/io/legado/app/lib/webdav/WebDavFile.kt b/app/src/main/java/io/legado/app/lib/webdav/WebDavFile.kt index b0ad187b7..fea46ea0b 100644 --- a/app/src/main/java/io/legado/app/lib/webdav/WebDavFile.kt +++ b/app/src/main/java/io/legado/app/lib/webdav/WebDavFile.kt @@ -12,4 +12,10 @@ class WebDavFile( val size: Long, val contentType: String, val lastModify: Long -) : WebDav(urlStr, authorization) \ No newline at end of file +) : WebDav(urlStr, authorization) { + + val isDir by lazy { + contentType == "httpd/unix-directory" + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/remote/manager/RemoteBookWebDav.kt b/app/src/main/java/io/legado/app/ui/book/remote/manager/RemoteBookWebDav.kt index 7990c3d73..70378138e 100644 --- a/app/src/main/java/io/legado/app/ui/book/remote/manager/RemoteBookWebDav.kt +++ b/app/src/main/java/io/legado/app/ui/book/remote/manager/RemoteBookWebDav.kt @@ -41,21 +41,15 @@ object RemoteBookWebDav : RemoteBookManager() { val remoteBooks = mutableListOf() AppWebDav.authorization?.let { //读取文件列表 - var remoteWebDavFileList: List? = null - kotlin.runCatching { - remoteWebDavFileList = WebDav(remoteBookUrl, it).listFiles() - } - //逆序文件排序 - remoteWebDavFileList = remoteWebDavFileList!!.reversed() + val remoteWebDavFileList: List = WebDav(remoteBookUrl, it).listFiles() //转化远程文件信息到本地对象 - remoteWebDavFileList!!.forEach { webDavFile -> + remoteWebDavFileList.forEach { webDavFile -> var webDavFileName = webDavFile.displayName var webDavUrlName = "${remoteBookUrl}${File.separator}${webDavFile.displayName}" - webDavFileName = URLDecoder.decode(webDavFileName,"utf-8") - webDavUrlName = URLDecoder.decode(webDavUrlName,"utf-8") - // 转码 - //val trueFileName = String(webDavFileName.toByteArray(Charset.forName("GBK")), Charset.forName("UTF-8")) - //val trueUrlName = String(webDavUrlName.toByteArray(Charset.forName("GBK")), Charset.forName("UTF-8")) + webDavFileName = URLDecoder.decode(webDavFileName, "utf-8") + webDavUrlName = URLDecoder.decode(webDavUrlName, "utf-8") + + webDavFile.isDir //分割后缀 val fileExtension = webDavFileName.substringAfterLast(".")