@ -62,7 +62,7 @@ fun Book.getLocalUri(): Uri {
defaultBookTreeUri ?: return originBookUri
val treeUri = Uri.parse(defaultBookTreeUri)
val treeFileDoc = FileDoc.fromUri(treeUri, true)
return treeFileDoc.find(originName)?.uri ?: originBookUri
return treeFileDoc.find(originName, 5)?.uri ?: originBookUri
}
throw NoStackTraceException("不是本地书籍")
@ -142,10 +142,29 @@ fun FileDoc.list(filter: FileDocFilter? = null): ArrayList<FileDoc>? {
return null
fun FileDoc.find(name: String): FileDoc? {
return list {
it.name == name
}?.firstOrNull()
/**
* 查找文档, 如果存在则返回文档,如果不存在返回空
* @param name 文件名
* @param depth 查找文件夹深度
*/
fun FileDoc.find(name: String, depth: Int = 0): FileDoc? {
val list = list()
list?.forEach {
if (it.name == name) {
return it
if (depth > 0) {
if (it.isDir) {
val fileDoc = it.find(name, depth - 1)
if (fileDoc != null) {
return fileDoc