diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 5a30aba70..7925fccf8 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -9,11 +9,7 @@ import io.legado.app.data.entities.ReplaceRule import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.localBook.LocalBook -import io.legado.app.utils.FileUtils -import io.legado.app.utils.MD5Utils -import io.legado.app.utils.externalFilesDir -import io.legado.app.utils.postEvent -import io.legado.app.utils.NetworkUtils +import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.withContext @@ -44,7 +40,7 @@ object BookHelp { fun clearCache() { FileUtils.deleteFile( - FileUtils.getPath(downloadDir, subDirs = *arrayOf(cacheFolderName)) + FileUtils.getPath(downloadDir, subDirs = arrayOf(cacheFolderName)) ) } @@ -73,7 +69,7 @@ object BookHelp { FileUtils.createFileIfNotExist( downloadDir, formatChapterName(bookChapter), - subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + subDirs = arrayOf(cacheFolderName, bookFolderName(book)) ).writeText(content) //保存图片 content.split("\n").forEach { @@ -95,24 +91,24 @@ object BookHelp { FileUtils.createFileIfNotExist( downloadDir, "${MD5Utils.md5Encode16(src)}${src.substringAfterLast(".").substringBefore(",")}", - subDirs = *arrayOf(cacheFolderName, bookFolderName(book), cacheImageFolderName) + subDirs = arrayOf(cacheFolderName, bookFolderName(book), cacheImageFolderName) ).writeBytes(it) } } fun getImage(book:Book, src:String): File { return FileUtils.getFile( - downloadDir, - "${MD5Utils.md5Encode16(src)}${src.substringAfterLast(".").substringBefore(",")}", - subDirs = *arrayOf(cacheFolderName, bookFolderName(book), cacheImageFolderName) - ) + downloadDir, + "${MD5Utils.md5Encode16(src)}${src.substringAfterLast(".").substringBefore(",")}", + subDirs = arrayOf(cacheFolderName, bookFolderName(book), cacheImageFolderName) + ) } fun getChapterFiles(book: Book): List { val fileNameList = arrayListOf() FileUtils.createFolderIfNotExist( downloadDir, - subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + subDirs = arrayOf(cacheFolderName, bookFolderName(book)) ).list()?.let { fileNameList.addAll(it) } @@ -126,7 +122,7 @@ object BookHelp { FileUtils.exists( downloadDir, formatChapterName(bookChapter), - subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + subDirs = arrayOf(cacheFolderName, bookFolderName(book)) ) } } @@ -138,7 +134,7 @@ object BookHelp { val file = FileUtils.getFile( downloadDir, formatChapterName(bookChapter), - subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + subDirs = arrayOf(cacheFolderName, bookFolderName(book)) ) if (file.exists()) { return file.readText() @@ -154,7 +150,7 @@ object BookHelp { FileUtils.createFileIfNotExist( downloadDir, formatChapterName(bookChapter), - subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + subDirs = arrayOf(cacheFolderName, bookFolderName(book)) ).delete() } } diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index 03ea7a84b..bb9a6327e 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -107,7 +107,7 @@ object Backup { DocumentUtils.createFileIfNotExist( treeDoc, fileName, - subDirs = *arrayOf("auto") + subDirs = arrayOf("auto") )?.writeBytes(context, file.readBytes()) } else { treeDoc.findFile(fileName)?.delete() diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index f78471fb9..c4bfb6ea6 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -248,7 +248,7 @@ class AnalyzeTxtFile { val rootFile = App.INSTANCE.getExternalFilesDir(null) ?: App.INSTANCE.externalCacheDir ?: App.INSTANCE.cacheDir - FileUtils.createFolderIfNotExist(rootFile, subDirs = *arrayOf(folderName)) + FileUtils.createFolderIfNotExist(rootFile, subDirs = arrayOf(folderName)) } fun getContent(book: Book, bookChapter: BookChapter): String { @@ -264,7 +264,7 @@ class AnalyzeTxtFile { private fun getBookFile(book: Book): File { if (book.bookUrl.isContentPath()) { val uri = Uri.parse(book.bookUrl) - val bookFile = FileUtils.getFile(cacheFolder, book.originName, subDirs = *arrayOf()) + val bookFile = FileUtils.getFile(cacheFolder, book.originName, subDirs = arrayOf()) if (!bookFile.exists()) { bookFile.createNewFile() DocumentUtils.readBytes(App.INSTANCE, uri)?.let { diff --git a/app/src/main/java/io/legado/app/utils/FileUtils.kt b/app/src/main/java/io/legado/app/utils/FileUtils.kt index d82f6bca0..047ab0cec 100644 --- a/app/src/main/java/io/legado/app/utils/FileUtils.kt +++ b/app/src/main/java/io/legado/app/utils/FileUtils.kt @@ -9,7 +9,7 @@ import java.io.IOException object FileUtils { fun exists(root: File, fileName: String, vararg subDirs: String): Boolean { - return getFile(root, fileName, subDirs = *subDirs).exists() + return getFile(root, fileName, subDirs = subDirs).exists() } fun createFileIfNotExist(root: File, fileName: String, vararg subDirs: String): File { @@ -18,7 +18,7 @@ object FileUtils { } fun createFolderIfNotExist(root: File, vararg subDirs: String): File { - val filePath = getPath(root, subDirs = *subDirs) + val filePath = getPath(root, subDirs = subDirs) return createFolderIfNotExist(filePath) } @@ -55,7 +55,7 @@ object FileUtils { } fun getDirFile(root: File, vararg subDirs: String): File { - val filePath = getPath(root, subDirs = *subDirs) + val filePath = getPath(root, subDirs = subDirs) return File(filePath) }