Merge remote-tracking branch 'origin/master'

This commit is contained in:
kunfei
2023-11-30 16:12:26 +08:00
3 changed files with 13 additions and 1 deletions
@@ -263,6 +263,8 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
val path = ACache.get().getAsString(exportBookPathKey) val path = ACache.get().getAsString(exportBookPathKey)
if (path.isNullOrEmpty()) { if (path.isNullOrEmpty()) {
selectExportFolder(position) selectExportFolder(position)
} else if (FileDoc.fromUri(path.parseToUri(), true).checkWrite() != true) {
selectExportFolder(position)
} else if (enableCustomExport()) {// 启用自定义导出 and 导出类型为Epub } else if (enableCustomExport()) {// 启用自定义导出 and 导出类型为Epub
configExportSection(path, position) configExportSection(path, position)
} else { } else {
@@ -274,7 +274,7 @@ class BackupConfigFragment : PreferenceFragment(),
if (backupPath.isContentScheme()) { if (backupPath.isContentScheme()) {
val uri = Uri.parse(backupPath) val uri = Uri.parse(backupPath)
val doc = DocumentFile.fromTreeUri(requireContext(), uri) val doc = DocumentFile.fromTreeUri(requireContext(), uri)
if (doc?.canWrite() == true) { if (doc?.checkWrite() == true) {
waitDialog.setText("备份中…") waitDialog.setText("备份中…")
waitDialog.setOnCancelListener { waitDialog.setOnCancelListener {
backupJob?.cancel() backupJob?.cancel()
@@ -287,6 +287,16 @@ fun FileDoc.delete() {
asDocumentFile()?.delete() asDocumentFile()?.delete()
} }
fun FileDoc.checkWrite(): Boolean? {
if (!isDir) {
throw NoStackTraceException("只能检查目录")
}
asFile()?.let {
return it.checkWrite()
}
return asDocumentFile()?.checkWrite()
}
/** /**
* DocumentFile 的 listFiles() 非常的慢,尽量不要使用 * DocumentFile 的 listFiles() 非常的慢,尽量不要使用
*/ */