modify BlockManager.kt

v4
laoyuyu 2 years ago
parent a446db3946
commit 4a74e457d5
  1. 15
      Http/src/main/java/com/arialyy/aria/http/download/HttpDBlockInterceptor.kt

@ -16,6 +16,7 @@
package com.arialyy.aria.http.download package com.arialyy.aria.http.download
import com.arialyy.aria.core.DuaContext import com.arialyy.aria.core.DuaContext
import com.arialyy.aria.core.inf.IBlockManager
import com.arialyy.aria.core.task.BlockUtil import com.arialyy.aria.core.task.BlockUtil
import com.arialyy.aria.core.task.ITask import com.arialyy.aria.core.task.ITask
import com.arialyy.aria.core.task.ITaskInterceptor import com.arialyy.aria.core.task.ITaskInterceptor
@ -23,6 +24,7 @@ import com.arialyy.aria.core.task.TaskChain
import com.arialyy.aria.core.task.TaskResp import com.arialyy.aria.core.task.TaskResp
import com.arialyy.aria.orm.entity.TaskRecord import com.arialyy.aria.orm.entity.TaskRecord
import timber.log.Timber import timber.log.Timber
import java.io.File
/** /**
* block interceptor * block interceptor
@ -32,9 +34,11 @@ import timber.log.Timber
internal class HttpDBlockInterceptor : ITaskInterceptor { internal class HttpDBlockInterceptor : ITaskInterceptor {
private lateinit var task: ITask private lateinit var task: ITask
private lateinit var option: HttpDTaskOption private lateinit var option: HttpDTaskOption
private lateinit var blockManager: IBlockManager
override suspend fun interceptor(chain: TaskChain): TaskResp { override suspend fun interceptor(chain: TaskChain): TaskResp {
task = chain.getTask() task = chain.getTask()
blockManager = chain.blockManager
option = task.getTaskOption(HttpDTaskOption::class.java) option = task.getTaskOption(HttpDTaskOption::class.java)
if (task.taskState.fileSize < 0) { if (task.taskState.fileSize < 0) {
Timber.e("file size < 0") Timber.e("file size < 0")
@ -44,12 +48,10 @@ internal class HttpDBlockInterceptor : ITaskInterceptor {
// if task not support resume, don't save record // if task not support resume, don't save record
if (task.taskState.fileSize == 0L) { if (task.taskState.fileSize == 0L) {
chain.blockManager.setBlockNum(1) chain.blockManager.setBlockNum(1)
checkBlock()
return chain.proceed(chain.getTask()) return chain.proceed(chain.getTask())
} }
val blockNum = checkRecord() val blockNum = checkRecord()
chain.blockManager.setBlockNum(blockNum) chain.blockManager.setBlockNum(blockNum)
checkBlock()
return chain.proceed(chain.getTask()) return chain.proceed(chain.getTask())
} }
@ -77,13 +79,16 @@ internal class HttpDBlockInterceptor : ITaskInterceptor {
return taskRecord.blockNum return taskRecord.blockNum
} }
Timber.d("record existed") Timber.d("record existed")
checkBlock(recordWrapper.taskRecord)
return recordWrapper.taskRecord.blockNum return recordWrapper.taskRecord.blockNum
} }
/** /**ø
* if block already exist, upload progress * if block already exist, upload progress
*/ */
private fun checkBlock() { private fun checkBlock(record: TaskRecord) {
for (br in record.blockList) {
val block = File()
}
} }
} }
Loading…
Cancel
Save