|
|
|
@ -66,7 +66,9 @@ private val localUriCache by lazy { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun Book.getLocalUri(): Uri { |
|
|
|
|
if (isLocal) { |
|
|
|
|
if (!isLocal) { |
|
|
|
|
throw NoStackTraceException("不是本地书籍") |
|
|
|
|
} |
|
|
|
|
var uri = localUriCache[bookUrl] |
|
|
|
|
if (uri != null) { |
|
|
|
|
return uri |
|
|
|
@ -84,13 +86,16 @@ fun Book.getLocalUri(): Uri { |
|
|
|
|
} |
|
|
|
|
//不同的设备书籍保存路径可能不一样, uri无效时尝试寻找当前保存路径下的文件 |
|
|
|
|
val defaultBookDir = AppConfig.defaultBookTreeUri |
|
|
|
|
if (defaultBookDir.isNullOrBlank()) { |
|
|
|
|
localUriCache[bookUrl] = uri |
|
|
|
|
return uri |
|
|
|
|
} |
|
|
|
|
val importBookDir = AppConfig.importBookPath |
|
|
|
|
|
|
|
|
|
// 查找书籍保存目录 |
|
|
|
|
if (!defaultBookDir.isNullOrBlank()) { |
|
|
|
|
val treeUri = Uri.parse(defaultBookDir) |
|
|
|
|
val treeFileDoc = FileDoc.fromUri(treeUri, true) |
|
|
|
|
val fileDoc = treeFileDoc.find(originName, 3) |
|
|
|
|
if (!treeFileDoc.exists()) { |
|
|
|
|
appCtx.toastOnUi("书籍保存目录失效,请重新设置!") |
|
|
|
|
} else { |
|
|
|
|
val fileDoc = treeFileDoc.find(originName, 5) |
|
|
|
|
if (fileDoc != null) { |
|
|
|
|
localUriCache[bookUrl] = fileDoc.uri |
|
|
|
|
//更新bookUrl 重启不用再找一遍 |
|
|
|
@ -98,10 +103,28 @@ fun Book.getLocalUri(): Uri { |
|
|
|
|
save() |
|
|
|
|
return fileDoc.uri |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 查找添加本地选择的目录 |
|
|
|
|
if (!importBookDir.isNullOrBlank()) { |
|
|
|
|
val treeUri = if (importBookDir.isUri()) { |
|
|
|
|
Uri.parse(importBookDir) |
|
|
|
|
} else { |
|
|
|
|
Uri.fromFile(File(importBookDir)) |
|
|
|
|
} |
|
|
|
|
val treeFileDoc = FileDoc.fromUri(treeUri, true) |
|
|
|
|
val fileDoc = treeFileDoc.find(originName, 5) |
|
|
|
|
if (fileDoc != null) { |
|
|
|
|
localUriCache[bookUrl] = fileDoc.uri |
|
|
|
|
bookUrl = fileDoc.toString() |
|
|
|
|
save() |
|
|
|
|
return fileDoc.uri |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
localUriCache[bookUrl] = uri |
|
|
|
|
return uri |
|
|
|
|
} |
|
|
|
|
throw NoStackTraceException("不是本地书籍") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun Book.cacheLocalUri(uri: Uri) { |
|
|
|
|