From d7d081ffb1ecd86a46f687b0454ce3461ffbdeb4 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Thu, 12 Nov 2020 22:35:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8D=95=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=97=B6=EF=BC=8C=E6=96=87=E4=BB=B6=E5=B7=B2?= =?UTF-8?q?=E7=BB=8F=E5=AE=8C=E6=88=90=EF=BC=8C=E9=87=8D=E5=A4=8D=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E5=9B=9E=E8=B0=83=E4=B8=8B=E8=BD=BD=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20=E4=BF=AE=E5=A4=8D=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E9=87=8D=E6=96=B0=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=90=8C=E5=90=8D=E8=B7=AF=E5=BE=84=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=B2=A1=E6=9C=89=E8=A2=AB=E8=A2=AB=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DEV_LOG.md | 3 +++ .../aria/http/download/HttpDTTBuilderAdapter.java | 5 ++++- .../arialyy/aria/core/common/RecordHelper.java | 10 +++++----- .../core/loader/NormalThreadStateManager.java | 15 ++++++++++----- .../com/arialyy/aria/core/task/ThreadTask.java | 2 +- .../main/java/com/arialyy/aria/util/FileUtil.java | 2 ++ app/src/main/assets/aria_config.xml | 2 +- .../simple/core/download/HttpDownloadModule.java | 7 ++++--- .../simple/core/download/SingleTaskActivity.java | 2 +- 9 files changed, 31 insertions(+), 17 deletions(-) diff --git a/DEV_LOG.md b/DEV_LOG.md index c8099e8b..fa56660a 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,4 +1,7 @@ ## 开发日志 + + v_3.8.16 + - 修复单线程下载时,文件已经完成,重复下载回调下载失败的问题 + - 修复一个重新下载文件时,同名路径文件没有被被删除的问题 + v_3.8.15 (2020/11/9) - 修复不支持断点的连接下载失败问题,https://github.com/AriaLyy/Aria/issues/771 - 修复iv不存在时,索引文件异常的问题,https://github.com/AriaLyy/Aria/issues/780 diff --git a/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDTTBuilderAdapter.java b/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDTTBuilderAdapter.java index 53be6061..e4e3186e 100644 --- a/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDTTBuilderAdapter.java +++ b/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDTTBuilderAdapter.java @@ -35,10 +35,13 @@ final class HttpDTTBuilderAdapter extends AbsNormalTTBuilderAdapter { BufferedRandomAccessFile file = null; try { if (totalThreadNum > 1 && !record.isBlock) { - file = new BufferedRandomAccessFile(new File(getTempFile().getPath()), "rwd", 8192); + file = new BufferedRandomAccessFile(getTempFile().getPath(), "rwd", 8192); //设置文件长度 file.setLength(getEntity().getFileSize()); } + if (getTempFile().exists()) { + FileUtil.deleteFile(getTempFile()); + } return true; } catch (IOException e) { e.printStackTrace(); diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHelper.java b/PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHelper.java index bc4e81ff..8f2490a1 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHelper.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHelper.java @@ -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); } /** diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalThreadStateManager.java b/PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalThreadStateManager.java index 57853af7..6ef8a0eb 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalThreadStateManager.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalThreadStateManager.java @@ -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 partPath = new ArrayList<>(); diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTask.java b/PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTask.java index fc896aee..5b953e18 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTask.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTask.java @@ -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(); diff --git a/PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java b/PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java index d75410f3..a68c5989 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java @@ -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 subPaths) { + Log.d(TAG, "开始合并文件"); File file = new File(targetPath); FileOutputStream fos = null; FileChannel foc = null; diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml index 31b3265d..ed5bd5b3 100644 --- a/app/src/main/assets/aria_config.xml +++ b/app/src/main/assets/aria_config.xml @@ -44,7 +44,7 @@ 3、从3.4.1开始,如果线程数为1,文件初始化时将不再预占用对应长度的空间,下载多少byte,则占多大的空间; 对于采用多线程的任务或旧任务,依然采用原来的文件空间占用方式; --> - + diff --git a/app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java b/app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java index 89ad386b..b68dd6cb 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java +++ b/app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java @@ -51,10 +51,11 @@ public class HttpDownloadModule extends BaseViewModule { //String url = AppUtil.getConfigValue(context, HTTP_URL_KEY, defUrl); //String url = "http://fdfs.speedata.cn:9989/group1/M00/00/05/rBGFrl3fdAKAVJwfMtSa9R18wLU139.zip"; //String url = "http://9.9.9.28:8088/files/update.zip"; - //String url = "https://y.qq.com/download/import/QQMusic-import-1.2.1.zip"; - String url = "https://gitee.com/huang-junhua/iptv/raw/master/guonei.m3u8"; + String url = "https://y.qq.com/download/import/QQMusic-import-1.2.1.zip"; + //String url = "https://gitee.com/huang-junhua/iptv/raw/master/guonei.m3u8"; + //String url = "http://v.kjjl100.com/kz/zx/cj/2020cjswxdb/1.mp4"; //String url = "https://static.runoob.com/images/demo/demo2.jpg"; - String filePath = "/mnt/sdcard/xxx.m3u8"; + String filePath = "/mnt/sdcard/qq.zip"; singDownloadInfo = Aria.download(context).getFirstDownloadEntity(url); if (singDownloadInfo == null) { diff --git a/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java index 09f18bce..430e7ca5 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java @@ -266,7 +266,7 @@ public class SingleTaskActivity extends BaseActivity { if (task.getKey().equals(mUrl)) { Toast.makeText(SingleTaskActivity.this, getString(R.string.download_success), Toast.LENGTH_SHORT).show(); - //ALog.d(TAG, "文件md5: 9886e90f014d462b560dcec9c327bdb7"); + ALog.d(TAG, "文件md5: e088677570afe2e9f847cc8159b932dd"); ALog.d(TAG, "下载完成的文件md5: " + CommonUtil.getFileMD5(new File(task.getFilePath()))); getBinding().pl.setInfo(task.getEntity()); getBinding().pl.setProgress(100);