diff --git a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java index 0d0c2f4a..b21910c6 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -282,7 +282,7 @@ import java.util.concurrent.ConcurrentHashMap; RecordUtil.delTaskRecord(key, IRecordHandler.TYPE_DOWNLOAD, removeFile, true); break; case 2: - RecordUtil.delGroupTaskRecord(key, removeFile); + RecordUtil.delGroupTaskRecordByHash(key, removeFile); break; case 3: RecordUtil.delTaskRecord(key, IRecordHandler.TYPE_UPLOAD); diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsBuilderTarget.java index 4ce228e3..16eb20c8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsBuilderTarget.java @@ -20,7 +20,7 @@ import com.arialyy.aria.core.common.controller.IStartFeature; import com.arialyy.aria.core.inf.AbsTarget; /** - * 处理第一次下载 + * 处理第一次创建的任务 */ public abstract class AbsBuilderTarget extends AbsTarget implements IStartFeature { @@ -42,6 +42,15 @@ public abstract class AbsBuilderTarget extends return (TARGET) this; } + /** + * 忽略文件占用,不管文件路径是否被其它任务占用,都执行上传\下载任务 + * 需要注意的是:如果文件被其它任务占用,并且还调用了该方法,将自动删除占用了该文件路径的任务 + */ + public TARGET ignoreFilePathOccupy() { + getController().ignoreFilePathOccupy(); + return (TARGET) this; + } + /** * 添加任务 * diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/controller/FeatureController.java b/Aria/src/main/java/com/arialyy/aria/core/common/controller/FeatureController.java index 1ceab180..875d2ad4 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/controller/FeatureController.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/controller/FeatureController.java @@ -98,6 +98,13 @@ public abstract class FeatureController { this.ignoreCheckPermissions = true; } + /** + * 强制执行任务,不管文件路径是否被占用 + */ + public void ignoreFilePathOccupy() { + mTaskWrapper.setIgnoreFilePathOccupy(true); + } + protected AbsTaskWrapper getTaskWrapper() { return mTaskWrapper; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java index c6eb5dcf..163af4ee 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java @@ -134,7 +134,7 @@ public class CheckDEntityUtil implements ICheckEntityUtil { //设置文件保存路径,如果新文件路径和旧文件路径不同,则修改路径 if (!filePath.equals(mEntity.getFilePath())) { // 检查路径冲突 - if (!CheckUtil.checkDownloadPathConflicts(mWrapper.isForceDownload(), filePath)) { + if (!CheckUtil.checkDPathConflicts(mWrapper.isIgnoreFilePathOccupy(), filePath)) { return false; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/CheckDGEntityUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/CheckDGEntityUtil.java index 402b1846..0e854888 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/CheckDGEntityUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/CheckDGEntityUtil.java @@ -16,12 +16,12 @@ package com.arialyy.aria.core.download; import android.text.TextUtils; -import com.arialyy.aria.core.common.ErrorCode; import com.arialyy.aria.core.common.RequestEnum; import com.arialyy.aria.core.inf.ICheckEntityUtil; import com.arialyy.aria.core.inf.IOptionConstant; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.ALog; +import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.RecordUtil; import java.io.File; @@ -70,10 +70,9 @@ public class CheckDGEntityUtil implements ICheckEntityUtil { return false; } - if ((mEntity.getDirPath() == null || !mEntity.getDirPath().equals(mWrapper.getDirPathTemp())) - && DbEntity.checkDataExist(DownloadGroupEntity.class, "dirPath=?", + // 检查路径冲突 + if (mWrapper.isNewTask() && !CheckUtil.checkDGPathConflicts(mWrapper.isIgnoreFilePathOccupy(), mWrapper.getDirPathTemp())) { - ALog.e(TAG, String.format("文件夹路径【%s】已被其它任务占用,请重新设置文件夹路径", mWrapper.getDirPathTemp())); return false; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java index cbb6c5e8..446a92e3 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java @@ -291,7 +291,7 @@ public class DownloadReceiver extends AbsReceiver { if (CheckUtil.checkDownloadUrlsIsEmpty(urls)) { return null; } - return DbDataHelper.getDGEntity(CommonUtil.getMd5Code(urls)); + return DbDataHelper.getDGEntityByHash(CommonUtil.getMd5Code(urls)); } /** @@ -304,7 +304,7 @@ public class DownloadReceiver extends AbsReceiver { if (!CheckUtil.checkUrl(url)) { return null; } - return DbDataHelper.getDGEntity(url); + return DbDataHelper.getDGEntityByHash(url); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/DNormalConfigHandler.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/DNormalConfigHandler.java index c5e24802..7f440895 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/DNormalConfigHandler.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/DNormalConfigHandler.java @@ -93,7 +93,7 @@ class DNormalConfigHandler implements IConfigHandler { } void setForceDownload(boolean forceDownload) { - getWrapper().setForceDownload(forceDownload); + getWrapper().setIgnoreFilePathOccupy(forceDownload); } void setUrl(String url) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpBuilderTarget.java index 6bb56047..047df49b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpBuilderTarget.java @@ -34,6 +34,7 @@ public class FtpBuilderTarget extends AbsBuilderTarget { mConfigHandler = new DNormalConfigHandler<>(this, -1); mConfigHandler.setUrl(url); getTaskWrapper().setRequestType(ITaskWrapper.D_FTP); + getTaskWrapper().setNewTask(true); } /** @@ -70,7 +71,9 @@ public class FtpBuilderTarget extends AbsBuilderTarget { * * @param filePath 路径必须为文件路径,不能为文件夹路径 * @param forceDownload {@code true}强制下载,不考虑文件路径是否被占用 + * @deprecated 使用 {@link #ignoreFilePathOccupy()} */ + @Deprecated @CheckResult(suggest = Suggest.TASK_CONTROLLER) public FtpBuilderTarget setFilePath(@NonNull String filePath, boolean forceDownload) { mConfigHandler.setTempFilePath(filePath); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirBuilderTarget.java index 3b6cad55..488f81a1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirBuilderTarget.java @@ -35,6 +35,7 @@ public class FtpDirBuilderTarget extends AbsBuilderTarget { this.url = url; mConfigHandler = new FtpDirConfigHandler<>(this, -1); getEntity().setGroupHash(url); + getTaskWrapper().setNewTask(true); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirNormalTarget.java index a6fae105..8ce740fe 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirNormalTarget.java @@ -32,6 +32,7 @@ public class FtpDirNormalTarget extends AbsNormalTarget { FtpDirNormalTarget(long taskId) { mConfigHandler = new FtpDirConfigHandler<>(this, taskId); + getTaskWrapper().setNewTask(false); } @Override public boolean isRunning() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpNormalTarget.java index 1513e408..c10f646b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpNormalTarget.java @@ -34,6 +34,7 @@ public class FtpNormalTarget extends AbsNormalTarget { FtpNormalTarget(long taskId) { mConfigHandler = new DNormalConfigHandler<>(this, taskId); getTaskWrapper().setRequestType(ITaskWrapper.D_FTP); + getTaskWrapper().setNewTask(false); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/GroupBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/GroupBuilderTarget.java index 2a93fd04..cbd7edae 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/GroupBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/GroupBuilderTarget.java @@ -34,8 +34,9 @@ public class GroupBuilderTarget extends AbsBuilderTarget { GroupBuilderTarget(List urls) { mConfigHandler = new HttpGroupConfigHandler<>(this, -1); - getTaskWrapper().setRequestType(ITaskWrapper.DG_HTTP); mConfigHandler.setGroupUrl(urls); + getTaskWrapper().setRequestType(ITaskWrapper.DG_HTTP); + getTaskWrapper().setNewTask(true); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/GroupNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/GroupNormalTarget.java index 5c3be712..00b4d8f6 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/GroupNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/GroupNormalTarget.java @@ -33,6 +33,7 @@ public class GroupNormalTarget extends AbsNormalTarget { GroupNormalTarget(long taskId) { mConfigHandler = new HttpGroupConfigHandler<>(this, taskId); getTaskWrapper().setRequestType(ITaskWrapper.DG_HTTP); + getTaskWrapper().setNewTask(false); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpBuilderTarget.java index eed6b2b3..ae3fd203 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpBuilderTarget.java @@ -22,12 +22,9 @@ import com.arialyy.aria.core.common.HttpOption; import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.m3u8.M3U8LiveOption; import com.arialyy.aria.core.download.m3u8.M3U8VodOption; -import com.arialyy.aria.core.inf.IOptionConstant; import com.arialyy.aria.core.inf.Suggest; -import com.arialyy.aria.core.processor.IHttpFileLenAdapter; import com.arialyy.aria.core.wrapper.AbsTaskWrapper; import com.arialyy.aria.core.wrapper.ITaskWrapper; -import com.arialyy.aria.util.CheckUtil; public class HttpBuilderTarget extends AbsBuilderTarget { @@ -35,13 +32,14 @@ public class HttpBuilderTarget extends AbsBuilderTarget { HttpBuilderTarget(String url) { mConfigHandler = new DNormalConfigHandler<>(this, -1); - getTaskWrapper().setRequestType(ITaskWrapper.D_HTTP); mConfigHandler.setUrl(url); + getTaskWrapper().setRequestType(ITaskWrapper.D_HTTP); + getTaskWrapper().setNewTask(true); } @CheckResult(suggest = Suggest.TASK_CONTROLLER) public HttpBuilderTarget m3u8VodOption(M3U8VodOption m3U8VodOption) { - if (m3U8VodOption == null){ + if (m3U8VodOption == null) { throw new NullPointerException("m3u8任务设置为空"); } getTaskWrapper().setRequestType(AbsTaskWrapper.M3U8_VOD); @@ -52,7 +50,7 @@ public class HttpBuilderTarget extends AbsBuilderTarget { @CheckResult(suggest = Suggest.TASK_CONTROLLER) public HttpBuilderTarget m3u8LiveOption(M3U8LiveOption m3U8LiveOption) { - if (m3U8LiveOption == null){ + if (m3U8LiveOption == null) { throw new NullPointerException("m3u8任务设置为空"); } getTaskWrapper().setRequestType(AbsTaskWrapper.M3U8_LIVE); @@ -92,7 +90,9 @@ public class HttpBuilderTarget extends AbsBuilderTarget { * * @param filePath 路径必须为文件路径,不能为文件夹路径 * @param forceDownload {@code true}强制下载,不考虑文件路径是否被占用 + * @deprecated 使用 {@link #ignoreFilePathOccupy()} */ + @Deprecated @CheckResult(suggest = Suggest.TASK_CONTROLLER) public HttpBuilderTarget setFilePath(@NonNull String filePath, boolean forceDownload) { mConfigHandler.setTempFilePath(filePath); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpNormalTarget.java index d17e9b3a..ea7800d0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpNormalTarget.java @@ -35,6 +35,7 @@ public class HttpNormalTarget extends AbsNormalTarget { HttpNormalTarget(long taskId) { mConfigHandler = new DNormalConfigHandler<>(this, taskId); getTaskWrapper().setRequestType(getTaskWrapper().getEntity().getTaskType()); + getTaskWrapper().setNewTask(false); } @CheckResult(suggest = Suggest.TASK_CONTROLLER) diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/M3U8NormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/M3U8NormalTarget.java index 2b530b85..63a8cfcd 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/M3U8NormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/M3U8NormalTarget.java @@ -27,6 +27,7 @@ public class M3U8NormalTarget extends AbsNormalTarget { M3U8NormalTarget(DTaskWrapper wrapper) { setTaskWrapper(wrapper); + getTaskWrapper().setNewTask(false); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/TcpBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/TcpBuilderTarget.java index 4b492cb0..314294d4 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/TcpBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/TcpBuilderTarget.java @@ -33,6 +33,7 @@ public class TcpBuilderTarget extends AbsBuilderTarget { TcpBuilderTarget(String ip, int port) { mConfigHandler = new DNormalConfigHandler<>(this, -1); getTaskWrapper().setRequestType(ITaskWrapper.D_TCP); + getTaskWrapper().setNewTask(true); } // ///** @@ -56,18 +57,4 @@ public class TcpBuilderTarget extends AbsBuilderTarget { return this; } - /** - * 设置文件存储路径,如果需要修改新的文件名,修改路径便可。 - * 如:原文件路径 /mnt/sdcard/test.zip - * 如果需要将test.zip改为game.zip,只需要重新设置文件路径为:/mnt/sdcard/game.zip - * - * @param filePath 路径必须为文件路径,不能为文件夹路径 - * @param forceDownload {@code true}强制下载,不考虑文件路径是否被占用 - */ - @CheckResult(suggest = Suggest.TASK_CONTROLLER) - public TcpBuilderTarget setFilePath(@NonNull String filePath, boolean forceDownload) { - mConfigHandler.setTempFilePath(filePath); - mConfigHandler.setForceDownload(forceDownload); - return this; - } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/CheckUEntityUtil.java b/Aria/src/main/java/com/arialyy/aria/core/upload/CheckUEntityUtil.java index c29c9efe..40e891f8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/CheckUEntityUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/CheckUEntityUtil.java @@ -58,9 +58,9 @@ public class CheckUEntityUtil implements ICheckEntityUtil { ALog.e(TAG, "上传失败,文件路径【" + filePath + "】不合法"); return false; } - - // 检查路径冲突 - if (!CheckUtil.checkUploadPathConflicts(mWrapper.isForceUpload(), filePath)) { + // 任务是新任务,并且路径冲突就不会继续执行 + if (mWrapper.isNewTask() && !CheckUtil.checkUPathConflicts( + mWrapper.isIgnoreFilePathOccupy(), filePath)) { return false; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpBuilderTarget.java index 741dd2d8..12546fd3 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpBuilderTarget.java @@ -52,9 +52,12 @@ public class FtpBuilderTarget extends AbsBuilderTarget { /** * 如果文件路径被其它任务占用,删除其它任务 + * + * @deprecated 使用 {@link #ignoreFilePathOccupy()} */ + @Deprecated public FtpBuilderTarget forceUpload() { - ((UTaskWrapper)getTaskWrapper()).setForceUpload(true); + getTaskWrapper().setIgnoreFilePathOccupy(true); return this; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpNormalTarget.java index e8353f9d..d093d8ad 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpNormalTarget.java @@ -33,6 +33,7 @@ public class FtpNormalTarget extends AbsNormalTarget { FtpNormalTarget(long taskId) { mConfigHandler = new UNormalConfigHandler<>(this, taskId); getTaskWrapper().setRequestType(ITaskWrapper.U_FTP); + getTaskWrapper().setNewTask(false); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpBuilderTarget.java index 8a72c40c..3e7e1fb5 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpBuilderTarget.java @@ -19,7 +19,6 @@ import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.AbsBuilderTarget; import com.arialyy.aria.core.common.HttpOption; import com.arialyy.aria.core.inf.Suggest; -import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.core.wrapper.AbsTaskWrapper; /** @@ -30,12 +29,12 @@ public class HttpBuilderTarget extends AbsBuilderTarget { private UNormalConfigHandler mConfigHandler; HttpBuilderTarget(String filePath) { - mConfigHandler = new UNormalConfigHandler<>(this, -1); mConfigHandler.setFilePath(filePath); //http暂时不支持断点上传 getTaskWrapper().setSupportBP(false); getTaskWrapper().setRequestType(AbsTaskWrapper.U_HTTP); + getTaskWrapper().setNewTask(true); } /** @@ -64,9 +63,12 @@ public class HttpBuilderTarget extends AbsBuilderTarget { /** * 如果文件路径被其它任务占用,删除其它任务 + * + * @deprecated 使用 {@link #ignoreFilePathOccupy()} */ + @Deprecated public HttpBuilderTarget forceUpload() { - ((UTaskWrapper) getTaskWrapper()).setForceUpload(true); + getTaskWrapper().setIgnoreFilePathOccupy(true); return this; } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpNormalTarget.java index 27a6e1fa..66136b04 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpNormalTarget.java @@ -33,6 +33,7 @@ public class HttpNormalTarget extends AbsNormalTarget { mConfigHandler = new UNormalConfigHandler<>(this, taskId); getTaskWrapper().setSupportBP(false); getTaskWrapper().setRequestType(AbsTaskWrapper.U_HTTP); + getTaskWrapper().setNewTask(false); } /** diff --git a/DEV_LOG.md b/DEV_LOG.md index be51081d..e000b3e9 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,10 +1,11 @@ ## 开发日志 - + v_3.7.10 + + v_3.7.10 (2019/12/3) - fix bug https://github.com/AriaLyy/Aria/issues/543#issuecomment-559733124 - fix bug https://github.com/AriaLyy/Aria/issues/542 - fix bug https://github.com/AriaLyy/Aria/issues/547 - 修复下载失败时,中断重试无效的问题 - 增加忽略权限检查的api,`ignoreCheckPermissions()` + - 增加通用的的忽略文件路径被占用的api,`isIgnoreFilePathOccupy()` + v_3.7.9 (2019/11/28) - fix bug https://github.com/AriaLyy/Aria/issues/537 + v_3.7.8 (2019/11/28) diff --git a/FtpComponent/src/main/java/com/arialyy/aria/ftp/FtpDirInfoThread.java b/FtpComponent/src/main/java/com/arialyy/aria/ftp/FtpDirInfoThread.java index 5bdb7614..7954d187 100644 --- a/FtpComponent/src/main/java/com/arialyy/aria/ftp/FtpDirInfoThread.java +++ b/FtpComponent/src/main/java/com/arialyy/aria/ftp/FtpDirInfoThread.java @@ -74,7 +74,7 @@ public class FtpDirInfoThread extends AbsFtpInfoThread { */ private String mTempFilePath; - /** - * {@code true}强制下载,不考虑文件路径是否被占用 - */ - private boolean forceDownload = false; - public DTaskWrapper(DownloadEntity entity) { super(entity); } @@ -124,12 +119,4 @@ public class DTaskWrapper extends AbsTaskWrapper { public void setTempFilePath(String mTempFilePath) { this.mTempFilePath = mTempFilePath; } - - public boolean isForceDownload() { - return forceDownload; - } - - public void setForceDownload(boolean forceDownload) { - this.forceDownload = forceDownload; - } } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/upload/UTaskWrapper.java b/PublicComponent/src/main/java/com/arialyy/aria/core/upload/UTaskWrapper.java index 5ab218d8..42e5d4c8 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/upload/UTaskWrapper.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/upload/UTaskWrapper.java @@ -29,11 +29,6 @@ public class UTaskWrapper extends AbsTaskWrapper { */ private String tempUrl; - /** - * 如果文件路径被其它任务占用,设置为true时,删除其它任务 - */ - private boolean forceUpload = false; - public UTaskWrapper(UploadEntity entity) { super(entity); } @@ -53,14 +48,6 @@ public class UTaskWrapper extends AbsTaskWrapper { return getEntity().getKey(); } - public boolean isForceUpload() { - return forceUpload; - } - - public void setForceUpload(boolean forceUpload) { - this.forceUpload = forceUpload; - } - @Override public UploadConfig getConfig() { return Configuration.getInstance().uploadCfg; } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/wrapper/AbsTaskWrapper.java b/PublicComponent/src/main/java/com/arialyy/aria/core/wrapper/AbsTaskWrapper.java index 3e489475..cf1a3fd7 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/wrapper/AbsTaskWrapper.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/wrapper/AbsTaskWrapper.java @@ -24,7 +24,6 @@ import com.arialyy.aria.core.event.ErrorEvent; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.ITaskOption; import com.arialyy.aria.core.upload.UploadEntity; -import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ComponentUtil; /** @@ -85,6 +84,19 @@ public abstract class AbsTaskWrapper */ private TaskOptionParams optionParams = new TaskOptionParams(); + /** + * {@code true}强制下载\上传,不考虑文件路径是否被占用 + */ + private boolean ignoreFilePathOccupy = false; + + public boolean isIgnoreFilePathOccupy() { + return ignoreFilePathOccupy; + } + + public void setIgnoreFilePathOccupy(boolean ignoreFilePathOccupy) { + this.ignoreFilePathOccupy = ignoreFilePathOccupy; + } + public void setTaskOption(ITaskOption option) { this.taskOption = option; } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/util/CheckUtil.java b/PublicComponent/src/main/java/com/arialyy/aria/util/CheckUtil.java index 7ba5a234..48bbb226 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/util/CheckUtil.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/util/CheckUtil.java @@ -18,6 +18,7 @@ package com.arialyy.aria.util; import android.text.TextUtils; import com.arialyy.aria.core.download.DownloadEntity; +import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.inf.IRecordHandler; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.orm.DbEntity; @@ -32,13 +33,13 @@ public class CheckUtil { private static final String TAG = "CheckUtil"; /** - * 检查和处理路径冲突 + * 检查和处理下载任务的路径冲突 * * @param isForceDownload true,如果路径冲突,将删除其它任务的记录的 * @param filePath 文件保存路径 * @return false 任务不再执行,true 任务继续执行 */ - public static boolean checkDownloadPathConflicts(boolean isForceDownload, String filePath) { + public static boolean checkDPathConflicts(boolean isForceDownload, String filePath) { if (DbEntity.checkDataExist(DownloadEntity.class, "downloadPath=?", filePath)) { if (!isForceDownload) { ALog.e(TAG, String.format("下载失败,保存路径【%s】已经被其它任务占用,请设置其它保存路径", filePath)); @@ -53,13 +54,13 @@ public class CheckUtil { } /** - * 检查和处理路径冲突 + * 检查和处理上传任务的路径冲突 * * @param isForceUpload true,如果路径冲突,将删除其它任务的记录的 * @param filePath 文件保存路径 * @return false 任务不再执行,true 任务继续执行 */ - public static boolean checkUploadPathConflicts(boolean isForceUpload, String filePath) { + public static boolean checkUPathConflicts(boolean isForceUpload, String filePath) { if (DbEntity.checkDataExist(UploadEntity.class, "filePath=?", filePath)) { if (!isForceUpload) { ALog.e(TAG, String.format("上传失败,文件路径【%s】已经被其它任务占用,请设置其它文件路径", filePath)); @@ -73,6 +74,27 @@ public class CheckUtil { return true; } + /** + * 检查和处理组合任务的路径冲突 + * + * @param isForceDownload true,如果路径冲突,将删除其它任务的记录的 + * @param dirPath 文件保存路径 + * @return false 任务不再执行,true 任务继续执行 + */ + public static boolean checkDGPathConflicts(boolean isForceDownload, String dirPath) { + if (DbEntity.checkDataExist(DownloadGroupEntity.class, "dirPath=?", dirPath)) { + if (!isForceDownload) { + ALog.e(TAG, String.format("下载失败,文件夹路径【%s】已经被其它任务占用,请设置其它文件路径", dirPath)); + return false; + } else { + ALog.w(TAG, String.format("文件夹路径【%s】已经被其它任务占用,当前任务将覆盖该路径", dirPath)); + RecordUtil.delGroupTaskRecordByPath(dirPath, false); + return true; + } + } + return true; + } + /** * 检查成员类是否是静态和public */ diff --git a/PublicComponent/src/main/java/com/arialyy/aria/util/DbDataHelper.java b/PublicComponent/src/main/java/com/arialyy/aria/util/DbDataHelper.java index d9382dd4..94776ad1 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/util/DbDataHelper.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/util/DbDataHelper.java @@ -52,7 +52,7 @@ public class DbDataHelper { * @param groupHash 组合任务Hash * @return 实体不存在,返回null */ - public static DownloadGroupEntity getDGEntity(String groupHash) { + public static DownloadGroupEntity getDGEntityByHash(String groupHash) { List wrapper = DbEntity.findRelationData(DGEntityWrapper.class, "DownloadGroupEntity.groupHash=?", groupHash); @@ -60,6 +60,20 @@ public class DbDataHelper { return wrapper == null || wrapper.size() == 0 ? null : wrapper.get(0).groupEntity; } + /** + * 获取组合任务实体、ftpDir任务实体 + * + * @param dirPath 组合任务Hash + * @return 实体不存在,返回null + */ + public static DownloadGroupEntity getDGEntityByPath(String dirPath) { + List wrapper = + DbEntity.findRelationData(DGEntityWrapper.class, "DownloadGroupEntity.dirPath=?", + dirPath); + + return wrapper == null || wrapper.size() == 0 ? null : wrapper.get(0).groupEntity; + } + /** * 获取组合任务实体、ftpDir任务实体 * diff --git a/PublicComponent/src/main/java/com/arialyy/aria/util/RecordUtil.java b/PublicComponent/src/main/java/com/arialyy/aria/util/RecordUtil.java index ceddf62c..dfc7ff7a 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/util/RecordUtil.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/util/RecordUtil.java @@ -42,12 +42,28 @@ public class RecordUtil { * @param removeFile {@code true} 无论任务是否完成,都会删除记录和文件; * {@code false} 如果任务已经完成,则只删除记录,不删除文件;任务未完成,记录和文件都会删除。 */ - public static void delGroupTaskRecord(String groupHash, boolean removeFile) { + public static void delGroupTaskRecordByHash(String groupHash, boolean removeFile) { if (TextUtils.isEmpty(groupHash)) { ALog.e(TAG, "删除下载任务组记录失败,groupHash为null"); return; } - DownloadGroupEntity groupEntity = DbDataHelper.getDGEntity(groupHash); + DownloadGroupEntity groupEntity = DbDataHelper.getDGEntityByHash(groupHash); + + delGroupTaskRecord(groupEntity, removeFile, true); + } + + /** + * 根据路径删除组合任务记录 + * + * @param removeFile {@code true} 无论任务是否完成,都会删除记录和文件; + * {@code false} 如果任务已经完成,则只删除记录,不删除文件;任务未完成,记录和文件都会删除。 + */ + public static void delGroupTaskRecordByPath(String dirPath, boolean removeFile) { + if (TextUtils.isEmpty(dirPath)) { + ALog.e(TAG, "删除下载任务组记录失败,组合任务路径为空"); + return; + } + DownloadGroupEntity groupEntity = DbDataHelper.getDGEntityByPath(dirPath); delGroupTaskRecord(groupEntity, removeFile, true); } diff --git a/README.md b/README.md index 20cbf846..05c0779b 100644 --- a/README.md +++ b/README.md @@ -44,16 +44,16 @@ Aria有以下特点: ## 引入库 [![license](http://img.shields.io/badge/license-Apache2.0-brightgreen.svg?style=flat)](https://github.com/AriaLyy/Aria/blob/master/LICENSE) -[![Core](https://img.shields.io/badge/Core-3.7.9-blue)](https://github.com/AriaLyy/Aria) -[![Compiler](https://img.shields.io/badge/Compiler-3.7.9-blue)](https://github.com/AriaLyy/Aria) -[![FtpComponent](https://img.shields.io/badge/FtpComponent-3.7.9-orange)](https://github.com/AriaLyy/Aria) -[![M3U8Component](https://img.shields.io/badge/M3U8Component-3.7.9-orange)](https://github.com/AriaLyy/Aria) +[![Core](https://img.shields.io/badge/Core-3.7.10-blue)](https://github.com/AriaLyy/Aria) +[![Compiler](https://img.shields.io/badge/Compiler-3.7.10-blue)](https://github.com/AriaLyy/Aria) +[![FtpComponent](https://img.shields.io/badge/FtpComponent-3.7.10-orange)](https://github.com/AriaLyy/Aria) +[![M3U8Component](https://img.shields.io/badge/M3U8Component-3.7.10-orange)](https://github.com/AriaLyy/Aria) ```java -implementation 'com.arialyy.aria:core:3.7.9' -annotationProcessor 'com.arialyy.aria:compiler:3.7.9' -implementation 'com.arialyy.aria:ftpComponent:3.7.9' # 如果需要使用ftp,请增加该组件 -implementation 'com.arialyy.aria:m3u8Component:3.7.9' # 如果需要使用m3u8下载功能,请增加该组件 +implementation 'com.arialyy.aria:core:3.7.10' +annotationProcessor 'com.arialyy.aria:compiler:3.7.10' +implementation 'com.arialyy.aria:ftpComponent:3.7.10' # 如果需要使用ftp,请增加该组件 +implementation 'com.arialyy.aria:m3u8Component:3.7.10' # 如果需要使用m3u8下载功能,请增加该组件 ``` 如果出现android support依赖错误,请将 `compile 'com.arialyy.aria:core:'`替换为 ``` @@ -137,8 +137,13 @@ protected void onCreate(Bundle savedInstanceState) { ### 版本日志 - + v_3.7.9 (2019/11/28) - - fix bug https://github.com/AriaLyy/Aria/issues/537 + + v_3.7.10 (2019/12/3) + - fix bug https://github.com/AriaLyy/Aria/issues/543#issuecomment-559733124 + - fix bug https://github.com/AriaLyy/Aria/issues/542 + - fix bug https://github.com/AriaLyy/Aria/issues/547 + - 修复下载失败时,中断重试无效的问题 + - 增加忽略权限检查的api,`ignoreCheckPermissions()` + - 增加通用的的忽略文件路径被占用的api,`isIgnoreFilePathOccupy()` [更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md) diff --git a/app/src/main/java/com/arialyy/simple/core/download/group/DownloadGroupActivity.java b/app/src/main/java/com/arialyy/simple/core/download/group/DownloadGroupActivity.java index a1446e59..998f1ed5 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/group/DownloadGroupActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/group/DownloadGroupActivity.java @@ -96,11 +96,11 @@ public class DownloadGroupActivity extends BaseActivity