kunfei %!s(int64=3) %!d(string=hai) anos
pai
achega
f74695f7f2

+ 22 - 9
app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt

@@ -242,9 +242,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
             val fileName = "${book.name} 作者:${book.author}"
             val fileName = "${book.name} 作者:${book.author}"
             book.downloadUrls!!.map {
             book.downloadUrls!!.map {
                 val mFileName = UrlUtil.getFileName(it) ?: fileName
                 val mFileName = UrlUtil.getFileName(it) ?: fileName
-                val isSupportedFile = AppPattern.bookFileRegex.matches(mFileName)
-                val isSupportDecompress = AppPattern.archiveFileRegex.matches(mFileName)
-                WebFile(it, mFileName, isSupportedFile, isSupportDecompress)
+                WebFile(it, mFileName)
             }
             }
         }.onError {
         }.onError {
             context.toastOnUi("LoadWebFileError\n${it.localizedMessage}")
             context.toastOnUi("LoadWebFileError\n${it.localizedMessage}")
@@ -259,10 +257,18 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
         execute {
         execute {
             waitDialogData.postValue(true)
             waitDialogData.postValue(true)
             if (webFile.isSupported) {
             if (webFile.isSupported) {
-                val book = LocalBook.importFileOnLine(webFile.url, webFile.name, bookSource)
+                val book = LocalBook.importFileOnLine(
+                    webFile.url,
+                    bookData.value!!.getExportFileName(webFile.suffix),
+                    bookSource
+                )
                 changeToLocalBook(book)
                 changeToLocalBook(book)
             } else {
             } else {
-                LocalBook.saveBookFile(webFile.url, webFile.name, bookSource)
+                LocalBook.saveBookFile(
+                    webFile.url,
+                    bookData.value!!.getExportFileName(webFile.suffix),
+                    bookSource
+                )
             }
             }
         }.onSuccess {
         }.onSuccess {
             @Suppress("unchecked_cast")
             @Suppress("unchecked_cast")
@@ -437,14 +443,21 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
     data class WebFile(
     data class WebFile(
         val url: String,
         val url: String,
         val name: String,
         val name: String,
-        // txt epub umd pdf等文件
-        val isSupported: Boolean,
-        // 压缩包形式的txt epub umd pdf文件
-        val isSupportDecompress: Boolean
     ) {
     ) {
+
         override fun toString(): String {
         override fun toString(): String {
             return name
             return name
         }
         }
+
+        // 后缀
+        val suffix: String = name.substringAfterLast(".")
+
+        // txt epub umd pdf等文件
+        val isSupported: Boolean = AppPattern.bookFileRegex.matches(name)
+
+        // 压缩包形式的txt epub umd pdf文件
+        val isSupportDecompress: Boolean = AppPattern.archiveFileRegex.matches(name)
+
     }
     }
 
 
 }
 }

+ 1 - 1
app/src/main/java/io/legado/app/utils/ArchiveUtils.kt

@@ -54,7 +54,7 @@ object ArchiveUtils {
         val name = archiveFileDoc.name
         val name = archiveFileDoc.name
         val workPathFileDoc = getCacheFolderFileDoc(name, path)
         val workPathFileDoc = getCacheFolderFileDoc(name, path)
         val workPath = workPathFileDoc.toString()
         val workPath = workPathFileDoc.toString()
-        return archiveFileDoc.uri.inputStream(appCtx).getOrThrow().use {
+        return archiveFileDoc.openInputStream().getOrThrow().use {
             when {
             when {
                 name.endsWith(".zip", ignoreCase = true) -> ZipUtils.unZipToPath(it, workPath)
                 name.endsWith(".zip", ignoreCase = true) -> ZipUtils.unZipToPath(it, workPath)
                 name.endsWith(".rar", ignoreCase = true) -> RarUtils.unRarToPath(it, workPath)
                 name.endsWith(".rar", ignoreCase = true) -> RarUtils.unRarToPath(it, workPath)

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

@@ -211,6 +211,10 @@ fun FileDoc.createFolderIfNotExist(
     }
     }
 }
 }
 
 
+fun FileDoc.openInputStream(): Result<InputStream> {
+    return uri.inputStream(appCtx)
+}
+
 fun FileDoc.exists(
 fun FileDoc.exists(
     fileName: String,
     fileName: String,
     vararg subDirs: String
     vararg subDirs: String