优化代码

pull/352/head
gedoor 4 years ago
parent 13934582a4
commit 64bf4e0f04
  1. 2
      app/src/main/java/io/legado/app/help/BookHelp.kt
  2. 2
      app/src/main/java/io/legado/app/help/CrashHandler.kt
  3. 2
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  4. 5
      app/src/main/java/io/legado/app/utils/FileUtils.kt

@ -52,7 +52,7 @@ object BookHelp {
App.db.bookDao().all.forEach { App.db.bookDao().all.forEach {
bookFolderNames.add(it.getFolderName()) bookFolderNames.add(it.getFolderName())
} }
val file = FileUtils.getDirFile(downloadDir, cacheFolderName) val file = FileUtils.getFile(downloadDir, cacheFolderName)
file.listFiles()?.forEach { bookFile -> file.listFiles()?.forEach { bookFile ->
if (!bookFolderNames.contains(bookFile.name)) { if (!bookFolderNames.contains(bookFile.name)) {
FileUtils.deleteFile(bookFile.absolutePath) FileUtils.deleteFile(bookFile.absolutePath)

@ -142,7 +142,7 @@ class CrashHandler : Thread.UncaughtExceptionHandler {
val time = format.format(Date()) val time = format.format(Date())
val fileName = "crash-$time-$timestamp.log" val fileName = "crash-$time-$timestamp.log"
mContext?.externalCacheDir?.let { rootFile -> mContext?.externalCacheDir?.let { rootFile ->
FileUtils.getDirFile(rootFile, "crash").listFiles()?.forEach { FileUtils.getFile(rootFile, "crash").listFiles()?.forEach {
if (it.lastModified() < System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7)) { if (it.lastModified() < System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7)) {
it.delete() it.delete()
} }

@ -18,7 +18,7 @@ import java.util.concurrent.TimeUnit
object Backup { object Backup {
val backupPath: String by lazy { val backupPath: String by lazy {
FileUtils.getDirFile(App.INSTANCE.filesDir, "backup").absolutePath FileUtils.getFile(App.INSTANCE.filesDir, "backup").absolutePath
} }
val backupFileNames by lazy { val backupFileNames by lazy {

@ -54,11 +54,6 @@ object FileUtils {
return File(filePath) return File(filePath)
} }
fun getDirFile(root: File, vararg subDirs: String): File {
val filePath = getPath(root = root, *subDirs)
return File(filePath)
}
fun getPath(root: File, vararg subDirFiles: String): String { fun getPath(root: File, vararg subDirFiles: String): String {
val path = StringBuilder(root.absolutePath) val path = StringBuilder(root.absolutePath)
subDirFiles.forEach { subDirFiles.forEach {

Loading…
Cancel
Save