Commit ec0b4fe8 by patpat

修复拉取日志可能闪退的问题

parent ff4fa9c0
package com.bgycc.smartcanteen.action
import com.bgycc.smartcanteen.App
import com.bgycc.smartcanteen.BuildConfig
import com.bgycc.smartcanteen.server.http.MainHttpClient
import com.bgycc.smartcanteen.util.LogUtil
import com.blankj.utilcode.util.FileIOUtils
import com.blankj.utilcode.util.FileUtils
import com.blankj.utilcode.util.PathUtils
import com.blankj.utilcode.util.ZipUtils
......@@ -44,26 +41,28 @@ object LogAction : Action(ActionEnum.LOG_PULL.name) {
}
Thread {
state = State.STARTED
val logZipFile = File(PathUtils.getExternalAppCachePath(), "upload/log.zip")
val logUploadDir = File(PathUtils.getExternalAppCachePath(), "upload/log")
FileUtils.delete(logZipFile)
FileUtils.deleteDir(logUploadDir)
logUploadDir.mkdirs()
try {
state = State.STARTED
val logZipFile = File(PathUtils.getExternalAppCachePath(), "upload/log.zip")
val logUploadDir = File(PathUtils.getExternalAppCachePath(), "upload/log")
FileUtils.delete(logZipFile)
FileUtils.deleteDir(logUploadDir)
logUploadDir.mkdirs()
val logDir = when (type) {
"system" -> File(PathUtils.getExternalStoragePath(), "boot_log")
else -> File(PathUtils.getExternalAppCachePath(), "log")
}
FileUtils.listFilesInDir(logDir).forEach {
val date = Date(it.lastModified())
if (date >= startTime && date <= endTime) {
FileUtils.copyFile(it, File(logUploadDir, it.name))
val logDir = when (type) {
"system" -> File(PathUtils.getExternalStoragePath(), "boot_log")
else -> File(PathUtils.getExternalAppCachePath(), "log")
}
}
ZipUtils.zipFile(logUploadDir, logZipFile)
FileUtils.deleteDir(logUploadDir)
MainHttpClient.uploadLog(logZipFile, "$type${formatSrc.format(startTime)}${formatSrc.format(endTime)}${App.getDeviceSN()}.zip")
FileUtils.listFilesInDir(logDir)?.forEach {
val date = Date(it.lastModified())
if (date >= startTime && date <= endTime) {
FileUtils.copyFile(it, File(logUploadDir, it.name))
}
}
ZipUtils.zipFile(logUploadDir, logZipFile)
FileUtils.deleteDir(logUploadDir)
MainHttpClient.uploadLog(logZipFile, "$type${formatSrc.format(startTime)}${formatSrc.format(endTime)}${App.getDeviceSN()}.zip")
} catch (e: Exception) {}
state = State.INITED
}.start()
} catch (e: Exception) {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment