修复单线程下载时,文件已经完成,重复下载回调下载失败的问题
修复一个重新下载文件时,同名路径文件没有被被删除的问题
This commit is contained in:
@@ -76,7 +76,7 @@ public class RecordHelper {
|
||||
tr.endLocation = endL;
|
||||
}
|
||||
}
|
||||
mWrapper.setNewTask(false);
|
||||
//mWrapper.setNewTask(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,8 +125,8 @@ public class RecordHelper {
|
||||
continue;
|
||||
}
|
||||
|
||||
long realLocation =
|
||||
tr.threadId * normalRectLen + blockFileLen; //正常情况下,该线程的startLocation的位置
|
||||
//正常情况下,该线程的startLocation的位置
|
||||
long realLocation = tr.threadId * normalRectLen + blockFileLen;
|
||||
/*
|
||||
* 检查记录文件
|
||||
*/
|
||||
@@ -147,7 +147,7 @@ public class RecordHelper {
|
||||
}
|
||||
}
|
||||
}
|
||||
mWrapper.setNewTask(false);
|
||||
//mWrapper.setNewTask(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,7 +190,7 @@ public class RecordHelper {
|
||||
tr.isComplete = false;
|
||||
}
|
||||
}
|
||||
mWrapper.setNewTask(false);
|
||||
//mWrapper.setNewTask(false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -105,16 +105,16 @@ public class NormalThreadStateManager implements IThreadStateManager {
|
||||
// mergerSFtp();
|
||||
// mListener.onComplete();
|
||||
//} else
|
||||
|
||||
if (mTaskRecord.isBlock) {
|
||||
if (mTaskRecord.isBlock || mTaskRecord.threadNum == 1) {
|
||||
if (mergeFile()) {
|
||||
mListener.onComplete();
|
||||
} else {
|
||||
mListener.onFail(false, null);
|
||||
}
|
||||
} else {
|
||||
mListener.onComplete();
|
||||
quitLooper();
|
||||
break;
|
||||
}
|
||||
mListener.onComplete();
|
||||
quitLooper();
|
||||
}
|
||||
break;
|
||||
@@ -248,8 +248,13 @@ public class NormalThreadStateManager implements IThreadStateManager {
|
||||
*/
|
||||
private boolean mergeFile() {
|
||||
if (mTaskRecord.threadNum == 1) {
|
||||
File targetFile = new File(mTaskRecord.filePath);
|
||||
if (targetFile.exists() && targetFile.length() == mTaskRecord.fileLength){
|
||||
return true;
|
||||
}
|
||||
FileUtil.deleteFile(targetFile);
|
||||
File partFile = new File(String.format(IRecordHandler.SUB_PATH, mTaskRecord.filePath, 0));
|
||||
return partFile.renameTo(new File(mTaskRecord.filePath));
|
||||
return partFile.renameTo(targetFile);
|
||||
}
|
||||
|
||||
List<String> partPath = new ArrayList<>();
|
||||
|
||||
@@ -310,7 +310,7 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver {
|
||||
}
|
||||
|
||||
@Override public synchronized void updateCompleteState() {
|
||||
ALog.i(TAG, String.format("任务【%s】线程__%s__完成", getTaskWrapper().getKey(), mRecord.threadId));
|
||||
ALog.i(TAG, String.format("任务【%s】线程__%s__完成, blockSize = %s", getTaskWrapper().getKey(), mRecord.threadId, mConfig.tempFile.length()));
|
||||
writeConfig(true, mRecord.endLocation);
|
||||
// 进度发送不是实时的,发送完成任务前,需要更新一次进度
|
||||
sendRunningState();
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.os.StatFs;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.os.storage.StorageVolume;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.AriaConfig;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@@ -322,6 +323,7 @@ public class FileUtil {
|
||||
* @return {@code true} 合并成功,{@code false}合并失败
|
||||
*/
|
||||
public static boolean mergeFile(String targetPath, List<String> subPaths) {
|
||||
Log.d(TAG, "开始合并文件");
|
||||
File file = new File(targetPath);
|
||||
FileOutputStream fos = null;
|
||||
FileChannel foc = null;
|
||||
|
||||
Reference in New Issue
Block a user