Browse Source

Merge remote-tracking branch 'origin/master'

kunfei 2 years ago
parent
commit
2f7164da39

+ 2 - 0
app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt

@@ -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 {

+ 1 - 1
app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt

@@ -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()

+ 10 - 0
app/src/main/java/io/legado/app/utils/FileDocExtensions.kt

@@ -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() 非常的慢,尽量不要使用
  */
  */