mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
优化
This commit is contained in:
parent
301d70c081
commit
6cd087be87
@ -41,6 +41,7 @@ import io.legado.app.utils.activityPendingIntent
|
|||||||
import io.legado.app.utils.cnCompare
|
import io.legado.app.utils.cnCompare
|
||||||
import io.legado.app.utils.createFolderIfNotExist
|
import io.legado.app.utils.createFolderIfNotExist
|
||||||
import io.legado.app.utils.isContentScheme
|
import io.legado.app.utils.isContentScheme
|
||||||
|
import io.legado.app.utils.outputStream
|
||||||
import io.legado.app.utils.postEvent
|
import io.legado.app.utils.postEvent
|
||||||
import io.legado.app.utils.readBytes
|
import io.legado.app.utils.readBytes
|
||||||
import io.legado.app.utils.readText
|
import io.legado.app.utils.readText
|
||||||
@ -230,9 +231,11 @@ class ExportBookService : BaseService() {
|
|||||||
DocumentUtils.delete(doc, filename)
|
DocumentUtils.delete(doc, filename)
|
||||||
val bookDoc = DocumentUtils.createFileIfNotExist(doc, filename)
|
val bookDoc = DocumentUtils.createFileIfNotExist(doc, filename)
|
||||||
?: throw NoStackTraceException("创建文档失败,请尝试重新设置导出文件夹")
|
?: throw NoStackTraceException("创建文档失败,请尝试重新设置导出文件夹")
|
||||||
|
val charset = Charset.forName(AppConfig.exportCharset)
|
||||||
contentResolver.openOutputStream(bookDoc.uri, "wa")?.use { bookOs ->
|
contentResolver.openOutputStream(bookDoc.uri, "wa")?.use { bookOs ->
|
||||||
|
BufferedOutputStream(bookOs, 64 * 1024).use { bos ->
|
||||||
getAllContents(book) { text, srcList ->
|
getAllContents(book) { text, srcList ->
|
||||||
bookOs.write(text.toByteArray(Charset.forName(AppConfig.exportCharset)))
|
bos.write(text.toByteArray(charset))
|
||||||
srcList?.forEach {
|
srcList?.forEach {
|
||||||
val vFile = BookHelp.getImage(book, it.src)
|
val vFile = BookHelp.getImage(book, it.src)
|
||||||
if (vFile.exists()) {
|
if (vFile.exists()) {
|
||||||
@ -249,6 +252,7 @@ class ExportBookService : BaseService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (AppConfig.exportToWebDav) {
|
if (AppConfig.exportToWebDav) {
|
||||||
// 导出到webdav
|
// 导出到webdav
|
||||||
AppWebDav.exportWebDav(bookDoc.uri, filename)
|
AppWebDav.exportWebDav(bookDoc.uri, filename)
|
||||||
@ -259,8 +263,11 @@ class ExportBookService : BaseService() {
|
|||||||
val filename = book.getExportFileName("txt")
|
val filename = book.getExportFileName("txt")
|
||||||
val bookPath = FileUtils.getPath(file, filename)
|
val bookPath = FileUtils.getPath(file, filename)
|
||||||
val bookFile = FileUtils.createFileWithReplace(bookPath)
|
val bookFile = FileUtils.createFileWithReplace(bookPath)
|
||||||
|
val charset = Charset.forName(AppConfig.exportCharset)
|
||||||
|
val bos = BufferedOutputStream(bookFile.outputStream(true), 64 * 1024)
|
||||||
|
bos.use {
|
||||||
getAllContents(book) { text, srcList ->
|
getAllContents(book) { text, srcList ->
|
||||||
bookFile.appendText(text, Charset.forName(AppConfig.exportCharset))
|
bos.write(text.toByteArray(charset))
|
||||||
srcList?.forEach {
|
srcList?.forEach {
|
||||||
val vFile = BookHelp.getImage(book, it.src)
|
val vFile = BookHelp.getImage(book, it.src)
|
||||||
if (vFile.exists()) {
|
if (vFile.exists()) {
|
||||||
@ -274,6 +281,7 @@ class ExportBookService : BaseService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (AppConfig.exportToWebDav) {
|
if (AppConfig.exportToWebDav) {
|
||||||
AppWebDav.exportWebDav(Uri.fromFile(bookFile), filename) // 导出到webdav
|
AppWebDav.exportWebDav(Uri.fromFile(bookFile), filename) // 导出到webdav
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ package io.legado.app.utils
|
|||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
|
||||||
fun File.getFile(vararg subDirFiles: String): File {
|
fun File.getFile(vararg subDirFiles: String): File {
|
||||||
val path = FileUtils.getPath(this, *subDirFiles)
|
val path = FileUtils.getPath(this, *subDirFiles)
|
||||||
@ -79,3 +80,7 @@ fun File.checkWrite(): Boolean {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun File.outputStream(append: Boolean = false): FileOutputStream {
|
||||||
|
return FileOutputStream(this, append)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user