mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
[skip ci] 优化
This commit is contained in:
parent
c48fdc5fbc
commit
d605d2f149
@ -290,28 +290,30 @@ object LocalBook {
|
||||
inputStream: InputStream,
|
||||
fileName: String
|
||||
): Uri {
|
||||
if (inputStream.isEmpty()) throw EmptyFileException("Unexpected empty inputStream")
|
||||
val defaultBookTreeUri = AppConfig.defaultBookTreeUri
|
||||
if (defaultBookTreeUri.isNullOrBlank()) throw NoStackTraceException("没有设置书籍保存位置!")
|
||||
val treeUri = Uri.parse(defaultBookTreeUri)
|
||||
return if (treeUri.isContentScheme()) {
|
||||
val treeDoc = DocumentFile.fromTreeUri(appCtx, treeUri)
|
||||
var doc = treeDoc!!.findFile(fileName)
|
||||
if (doc == null) {
|
||||
doc = treeDoc.createFile(FileUtils.getMimeType(fileName), fileName)
|
||||
?: throw SecurityException("请重新设置书籍保存位置\nPermission Denial")
|
||||
inputStream.use {
|
||||
if (it.isEmpty()) throw EmptyFileException("Unexpected empty inputStream")
|
||||
val defaultBookTreeUri = AppConfig.defaultBookTreeUri
|
||||
if (defaultBookTreeUri.isNullOrBlank()) throw NoStackTraceException("没有设置书籍保存位置!")
|
||||
val treeUri = Uri.parse(defaultBookTreeUri)
|
||||
return if (treeUri.isContentScheme()) {
|
||||
val treeDoc = DocumentFile.fromTreeUri(appCtx, treeUri)
|
||||
var doc = treeDoc!!.findFile(fileName)
|
||||
if (doc == null) {
|
||||
doc = treeDoc.createFile(FileUtils.getMimeType(fileName), fileName)
|
||||
?: throw SecurityException("请重新设置书籍保存位置\nPermission Denial")
|
||||
}
|
||||
appCtx.contentResolver.openOutputStream(doc.uri)!!.use { oStream ->
|
||||
it.copyTo(oStream)
|
||||
}
|
||||
doc.uri
|
||||
} else {
|
||||
val treeFile = File(treeUri.path!!)
|
||||
val file = treeFile.getFile(fileName)
|
||||
FileOutputStream(file).use { oStream ->
|
||||
it.copyTo(oStream)
|
||||
}
|
||||
Uri.fromFile(file)
|
||||
}
|
||||
appCtx.contentResolver.openOutputStream(doc.uri)!!.use { oStream ->
|
||||
inputStream.copyTo(oStream)
|
||||
}
|
||||
doc.uri
|
||||
} else {
|
||||
val treeFile = File(treeUri.path!!)
|
||||
val file = treeFile.getFile(fileName)
|
||||
FileOutputStream(file).use { oStream ->
|
||||
inputStream.copyTo(oStream)
|
||||
}
|
||||
Uri.fromFile(file)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,6 @@ import io.legado.app.data.entities.Book
|
||||
import io.legado.app.data.entities.BookChapter
|
||||
import io.legado.app.data.entities.BookSource
|
||||
import io.legado.app.exception.NoStackTraceException
|
||||
import io.legado.app.exception.EmptyFileException
|
||||
import io.legado.app.help.AppWebDav
|
||||
import io.legado.app.help.book.*
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
|
Loading…
Reference in New Issue
Block a user