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 3bf9bfef..a421deef 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 @@ -157,11 +157,11 @@ public class CheckDEntityUtil implements ICheckEntityUtil { File oldFile = new File(mEntity.getFilePath()); if (oldFile.exists()) { // 处理普通任务的重命名 - RecordUtil.modifyTaskRecord(oldFile.getPath(), newFile.getPath()); + RecordUtil.modifyTaskRecord(oldFile.getPath(), newFile.getPath(), mEntity.getTaskType()); ALog.i(TAG, String.format("将任务重命名为:%s", newFile.getName())); } else if (RecordUtil.blockTaskExists(oldFile.getPath())) { // 处理分块任务的重命名 - RecordUtil.modifyTaskRecord(oldFile.getPath(), newFile.getPath()); + RecordUtil.modifyTaskRecord(oldFile.getPath(), newFile.getPath(), mEntity.getTaskType()); ALog.i(TAG, String.format("将分块任务重命名为:%s", newFile.getName())); } } 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 1bf6b387..2834c5c3 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 @@ -179,7 +179,7 @@ public class CheckDGEntityUtil implements ICheckEntityUtil { return; } - RecordUtil.modifyTaskRecord(oldPath, newPath); + RecordUtil.modifyTaskRecord(oldPath, newPath, mEntity.getTaskType()); entity.setFilePath(newPath); entity.setFileName(newName); } 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 a67a8bb7..31106b59 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 @@ -31,6 +31,7 @@ public class FtpBuilderTarget extends AbsBuilderTarget { mConfigHandler = new DNormalConfigHandler<>(this, -1); mConfigHandler.setUrl(url); getTaskWrapper().setRequestType(ITaskWrapper.D_FTP); + getEntity().setTaskType(ITaskWrapper.D_FTP); getTaskWrapper().setNewTask(true); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirConfigHandler.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirConfigHandler.java index f731e41b..049001fd 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirConfigHandler.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirConfigHandler.java @@ -33,11 +33,12 @@ class FtpDirConfigHandler extends AbsGroupConfigHandle } private void init() { - getTaskWrapper().setRequestType(AbsTaskWrapper.D_FTP_DIR); + getTaskWrapper().setRequestType(ITaskWrapper.D_FTP_DIR); List wrappers = getTaskWrapper().getSubTaskWrapper(); if (!wrappers.isEmpty()) { for (DTaskWrapper subWrapper : wrappers) { subWrapper.setRequestType(ITaskWrapper.D_FTP); + subWrapper.getEntity().setTaskType(ITaskWrapper.D_FTP); } } } 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 534d98b0..10d07f42 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 @@ -18,6 +18,7 @@ package com.arialyy.aria.core.download.target; import com.arialyy.aria.core.common.AbsBuilderTarget; import com.arialyy.aria.core.common.HttpOption; import com.arialyy.aria.core.download.DTaskWrapper; +import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.m3u8.M3U8LiveOption; import com.arialyy.aria.core.download.m3u8.M3U8VodOption; import com.arialyy.aria.core.wrapper.AbsTaskWrapper; @@ -32,6 +33,7 @@ public class HttpBuilderTarget extends AbsBuilderTarget { mConfigHandler.setUrl(url); getTaskWrapper().setRequestType(ITaskWrapper.D_HTTP); getTaskWrapper().setNewTask(true); + ((DownloadEntity)getEntity()).setTaskType(ITaskWrapper.D_HTTP); } public HttpBuilderTarget m3u8VodOption(M3U8VodOption m3U8VodOption) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpGroupConfigHandler.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpGroupConfigHandler.java index 235ff97a..77249633 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpGroupConfigHandler.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpGroupConfigHandler.java @@ -18,6 +18,7 @@ package com.arialyy.aria.core.download.target; import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.inf.AbsTarget; +import com.arialyy.aria.core.wrapper.ITaskWrapper; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; @@ -58,6 +59,7 @@ class HttpGroupConfigHandler extends AbsGroupConfigHan List subEntities = DbDataHelper.createHttpSubTask(groupHash, mUrls); List wrappers = new ArrayList<>(); for (DownloadEntity subEntity : subEntities) { + subEntity.setTaskType(ITaskWrapper.D_HTTP); wrappers.add(new DTaskWrapper(subEntity)); } getEntity().setUrls(urls); 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 77b0a8ea..ab9d7212 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 @@ -16,6 +16,7 @@ package com.arialyy.aria.core.download.target; import com.arialyy.aria.core.common.AbsBuilderTarget; +import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.wrapper.ITaskWrapper; /** @@ -29,6 +30,7 @@ public class TcpBuilderTarget extends AbsBuilderTarget { TcpBuilderTarget(String ip, int port) { mConfigHandler = new DNormalConfigHandler<>(this, -1); getTaskWrapper().setRequestType(ITaskWrapper.D_TCP); + ((DownloadEntity) getEntity()).setTaskType(ITaskWrapper.D_TCP); getTaskWrapper().setNewTask(true); } // diff --git a/Aria/src/main/java/com/arialyy/aria/core/manager/DTaskWrapperFactory.java b/Aria/src/main/java/com/arialyy/aria/core/manager/DTaskWrapperFactory.java index c974d75c..16e6592d 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/manager/DTaskWrapperFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/manager/DTaskWrapperFactory.java @@ -20,6 +20,7 @@ import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IRecordHandler; +import com.arialyy.aria.core.wrapper.ITaskWrapper; import java.io.File; /** @@ -71,7 +72,7 @@ class DTaskWrapperFactory implements INormalTEFactory { mConfigHandler = new UNormalConfigHandler<>(this, -1); mConfigHandler.setFilePath(filePath); getTaskWrapper().setRequestType(ITaskWrapper.U_FTP); + ((UploadEntity)getEntity()).setTaskType(ITaskWrapper.U_FTP); getTaskWrapper().setNewTask(true); } 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 68145b56..4940a4c8 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 @@ -17,7 +17,8 @@ package com.arialyy.aria.core.upload.target; import com.arialyy.aria.core.common.AbsBuilderTarget; import com.arialyy.aria.core.common.HttpOption; -import com.arialyy.aria.core.wrapper.AbsTaskWrapper; +import com.arialyy.aria.core.upload.UploadEntity; +import com.arialyy.aria.core.wrapper.ITaskWrapper; /** * Created by lyy on 2017/2/28. @@ -31,7 +32,8 @@ public class HttpBuilderTarget extends AbsBuilderTarget { mConfigHandler.setFilePath(filePath); //http暂时不支持断点上传 getTaskWrapper().setSupportBP(false); - getTaskWrapper().setRequestType(AbsTaskWrapper.U_HTTP); + getTaskWrapper().setRequestType(ITaskWrapper.U_HTTP); + ((UploadEntity) getEntity()).setTaskType(ITaskWrapper.U_HTTP); getTaskWrapper().setNewTask(true); } diff --git a/DEV_LOG.md b/DEV_LOG.md index 85067cc1..bd29e876 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,13 +1,16 @@ ## 开发日志 - + v_3.8 + + v_3.8 (2019/12/17) - 移除androidx和support的依赖,现在无论是哪个版本的appcompat包都可以使用本框架 - 修复一个在xml中使用fragment导致的内存泄漏问题 - m3u8协议的key信息增加了`keyFormat`,`keyFormatVersion`字段 - - m3u8增加了`ignoreFailureTs`方法,忽略虾类失败的ts切片 + - m3u8增加了`ignoreFailureTs`方法,忽略下载失败的ts切片 - 修复在dialogFragment的`onCreateDialog()`注册导致的注解不生效问题 - 修复组合任务初始化失败时,无法删除的问题 - 修复`reStart()`后,无法停止的问题 - ftp增加主动模式,开启主动模式:https://aria.laoyuyu.me/aria_doc/api/ftp_params.html + - 修复ftp服务器无法响应`abor`命令导致的无法停止上传的问题 https://github.com/AriaLyy/Aria/issues/564 + - 修复ftp上传时,服务器有长度为0的文件导致上传失败的问题 + - 修复下载任务和上传任务的文件路径是同一个时,导致的记录混乱问题 - 优化提示 + v_3.7.10 (2019/12/3) - fix bug https://github.com/AriaLyy/Aria/issues/543#issuecomment-559733124 diff --git a/FtpComponent/src/main/java/com/arialyy/aria/ftp/AbsFtpInfoThread.java b/FtpComponent/src/main/java/com/arialyy/aria/ftp/AbsFtpInfoThread.java index cc74ee94..3fa81ac6 100644 --- a/FtpComponent/src/main/java/com/arialyy/aria/ftp/AbsFtpInfoThread.java +++ b/FtpComponent/src/main/java/com/arialyy/aria/ftp/AbsFtpInfoThread.java @@ -50,7 +50,7 @@ import javax.net.ssl.SSLContext; public abstract class AbsFtpInfoThread> implements Runnable { - private final String TAG = CommonUtil.getClassName(getClass()); + protected final String TAG = CommonUtil.getClassName(getClass()); protected ENTITY mEntity; protected TASK_WRAPPER mTaskWrapper; protected FtpTaskOption mTaskOption; @@ -123,7 +123,7 @@ public abstract class AbsFtpInfoThread 0){ + file.seek(getThreadRecord().startLocation); + } byte[] buffer = new byte[getTaskConfig().getBuffSize()]; int len; while (getThreadTask().isLive() && (len = is.read(buffer)) != -1) { diff --git a/FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpUFileInfoThread.java b/FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpUFileInfoThread.java index 29f1cdc7..af113b53 100644 --- a/FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpUFileInfoThread.java +++ b/FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpUFileInfoThread.java @@ -22,11 +22,11 @@ import com.arialyy.aria.core.TaskRecord; import com.arialyy.aria.core.ThreadRecord; import com.arialyy.aria.core.common.CompleteInfo; import com.arialyy.aria.core.inf.OnFileInfoCallback; +import com.arialyy.aria.core.processor.FtpInterceptHandler; +import com.arialyy.aria.core.processor.IFtpUploadInterceptor; import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.ftp.AbsFtpInfoThread; -import com.arialyy.aria.core.processor.FtpInterceptHandler; -import com.arialyy.aria.core.processor.IFtpUploadInterceptor; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.DbDataHelper; @@ -39,7 +39,6 @@ import java.util.List; * 单任务上传远程服务器文件信息 */ class FtpUFileInfoThread extends AbsFtpInfoThread { - private static final String TAG = "FtpUploadFileInfoThread"; static final int CODE_COMPLETE = 0xab1; private boolean isComplete = false; private String remotePath; @@ -59,10 +58,10 @@ class FtpUFileInfoThread extends AbsFtpInfoThread { @Override protected boolean onInterceptor(FTPClient client, FTPFile[] ftpFiles) { // 旧任务将不做处理,否则断点续传上传将失效 - if (!mTaskWrapper.isNewTask()) { - ALog.d(TAG, "任务是旧任务,忽略该拦截器"); - return true; - } + //if (!mTaskWrapper.isNewTask()) { + // ALog.d(TAG, "任务是旧任务,忽略该拦截器"); + // return true; + //} try { IFtpUploadInterceptor interceptor = mTaskOption.getUploadInterceptor(); if (interceptor != null) { @@ -78,7 +77,7 @@ class FtpUFileInfoThread extends AbsFtpInfoThread { FtpInterceptHandler interceptHandler = interceptor.onIntercept(mEntity, files); /* - 处理远端有同名文件的情况 + * 处理远端有同名文件的情况 */ if (files.contains(mEntity.getFileName())) { if (interceptHandler.isCoverServerFile()) { @@ -94,6 +93,7 @@ class FtpUFileInfoThread extends AbsFtpInfoThread { + "/" + interceptHandler.getNewFileName(); mTaskOption.setNewFileName(interceptHandler.getNewFileName()); + closeClient(client); run(); return false; @@ -123,6 +123,9 @@ class FtpUFileInfoThread extends AbsFtpInfoThread { if (ftpFile.getSize() == mEntity.getFileSize()) { isComplete = true; ALog.d(TAG, "FTP服务器上已存在该文件【" + ftpFile.getName() + "】"); + } else if (ftpFile.getSize() == 0) { + mTaskWrapper.setNewTask(true); + ALog.d(TAG, "FTP服务器上已存在该文件【" + ftpFile.getName() + "】,但文件长度为0,重新上传该文件"); } else { ALog.w(TAG, "FTP服务器已存在未完成的文件【" + ftpFile.getName() @@ -135,7 +138,8 @@ class FtpUFileInfoThread extends AbsFtpInfoThread { mTaskWrapper.setNewTask(false); // 修改记录 - TaskRecord record = DbDataHelper.getTaskRecord(mTaskWrapper.getKey()); + TaskRecord record = DbDataHelper.getTaskRecord(mTaskWrapper.getKey(), + mTaskWrapper.getEntity().getTaskType()); if (record == null) { record = new TaskRecord(); record.fileName = mEntity.getFileName(); diff --git a/FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpUThreadTaskAdapter.java b/FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpUThreadTaskAdapter.java index 891170ac..bd5e4bb7 100644 --- a/FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpUThreadTaskAdapter.java +++ b/FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpUThreadTaskAdapter.java @@ -34,6 +34,7 @@ import java.io.UnsupportedEncodingException; */ class FtpUThreadTaskAdapter extends BaseFtpThreadTaskAdapter { private String dir, remotePath; + private boolean storeFail = false; FtpUThreadTaskAdapter(SubThreadConfig config) { super(config); @@ -67,8 +68,7 @@ class FtpUThreadTaskAdapter extends BaseFtpThreadTaskAdapter { file = new BufferedRandomAccessFile(getThreadConfig().tempFile, "rwd", getTaskConfig().getBuffSize()); - if (getThreadRecord().startLocation != 0) { - //file.skipBytes((int) getThreadConfig().START_LOCATION); + if (getThreadRecord().startLocation > 0) { file.seek(getThreadRecord().startLocation); } boolean complete = upload(client, file); @@ -79,6 +79,7 @@ class FtpUThreadTaskAdapter extends BaseFtpThreadTaskAdapter { String.format("任务【%s】线程__%s__上传完毕", getEntity().getKey(), getThreadRecord().threadId)); complete(); } catch (IOException e) { + e.printStackTrace(); fail(new AriaIOException(TAG, String.format("上传失败,filePath: %s, uploadUrl: %s", getEntity().getFilePath(), getThreadConfig().url)), true); @@ -118,10 +119,11 @@ class FtpUThreadTaskAdapter extends BaseFtpThreadTaskAdapter { */ private boolean upload(final FTPClient client, final BufferedRandomAccessFile bis) throws IOException { - + final FtpFISAdapter fa = new FtpFISAdapter(bis); + storeFail = false; try { ALog.d(TAG, String.format("remotePath: %s", remotePath)); - client.storeFile(remotePath, new FtpFISAdapter(bis), new OnFtpInputStreamListener() { + client.storeFile(remotePath, fa, new OnFtpInputStreamListener() { boolean isStoped = false; @Override public void onFtpInputStream(FTPClient client, long totalBytesTransferred, @@ -137,23 +139,30 @@ class FtpUThreadTaskAdapter extends BaseFtpThreadTaskAdapter { progress(bytesTransferred); } catch (IOException e) { e.printStackTrace(); + storeFail = true; + try { + fa.close(); + } catch (IOException e1) { + e1.printStackTrace(); + } + closeClient(client); } } }); } catch (IOException e) { String msg = String.format("文件上传错误,错误码为:%s, msg:%s, filePath: %s", client.getReplyCode(), client.getReplyString(), getEntity().getFilePath()); - if (client.isConnected()) { - client.disconnect(); - } + closeClient(client); if (e.getMessage().contains("AriaIOException caught while copying")) { e.printStackTrace(); } else { - fail(new AriaIOException(TAG, msg, e), true); + fail(new AriaIOException(TAG, msg, e), !storeFail); } return false; } - + if (storeFail) { + return false; + } int reply = client.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { if (reply != FTPReply.TRANSFER_ABORTED) { @@ -161,9 +170,7 @@ class FtpUThreadTaskAdapter extends BaseFtpThreadTaskAdapter { String.format("文件上传错误,错误码为:%s, msg:%s, filePath: %s", reply, client.getReplyString(), getEntity().getFilePath())), false); } - if (client.isConnected()) { - client.disconnect(); - } + closeClient(client); return false; } return true; diff --git a/HttpComponent/src/main/java/com/arialyy/aria/http/HttpFileInfoThread.java b/HttpComponent/src/main/java/com/arialyy/aria/http/HttpFileInfoThread.java index d679eef4..9c7103e0 100644 --- a/HttpComponent/src/main/java/com/arialyy/aria/http/HttpFileInfoThread.java +++ b/HttpComponent/src/main/java/com/arialyy/aria/http/HttpFileInfoThread.java @@ -277,7 +277,7 @@ public class HttpFileInfoThread implements Runnable { } mEntity.setFileName(newName); mEntity.setFilePath(newPath); - RecordUtil.modifyTaskRecord(oldFile.getPath(), newPath); + RecordUtil.modifyTaskRecord(oldFile.getPath(), newPath, mEntity.getTaskType()); } /** diff --git a/HttpComponent/src/main/java/com/arialyy/aria/http/HttpRecordAdapter.java b/HttpComponent/src/main/java/com/arialyy/aria/http/HttpRecordAdapter.java index 21df6087..1dbba97b 100644 --- a/HttpComponent/src/main/java/com/arialyy/aria/http/HttpRecordAdapter.java +++ b/HttpComponent/src/main/java/com/arialyy/aria/http/HttpRecordAdapter.java @@ -67,7 +67,7 @@ public class HttpRecordAdapter extends AbsRecordHandlerAdapter { tr.startLocation = startL; tr.isComplete = false; - tr.threadType = TaskRecord.TYPE_HTTP_FTP; + tr.threadType = getEntity().getTaskType(); //最后一个线程的结束位置即为文件的总长度 if (threadId == (record.threadNum - 1)) { endL = getEntity().getFileSize(); @@ -91,7 +91,7 @@ public class HttpRecordAdapter extends AbsRecordHandlerAdapter { } else { record.isBlock = false; } - record.taskType = TaskRecord.TYPE_HTTP_FTP; + record.taskType = getEntity().getTaskType(); record.isGroupRecord = getEntity().isGroupChild(); if (record.isGroupRecord) { if (getEntity() instanceof DownloadEntity) { diff --git a/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDThreadTaskAdapter.java b/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDThreadTaskAdapter.java index 3f5ca877..45ea172a 100644 --- a/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDThreadTaskAdapter.java +++ b/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDThreadTaskAdapter.java @@ -112,7 +112,9 @@ final class HttpDThreadTaskAdapter extends BaseHttpThreadTaskAdapter { new BufferedRandomAccessFile(getThreadConfig().tempFile, "rwd", getTaskConfig().getBuffSize()); //设置每条线程写入文件的位置 - file.seek(getThreadRecord().startLocation); + if (getThreadRecord().startLocation > 0){ + file.seek(getThreadRecord().startLocation); + } readNormal(is, file); handleComplete(); } diff --git a/M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8RecordAdapter.java b/M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8RecordAdapter.java index 088f5f9d..17cc04e3 100644 --- a/M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8RecordAdapter.java +++ b/M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8RecordAdapter.java @@ -106,7 +106,7 @@ public class M3U8RecordAdapter extends AbsRecordHandlerAdapter { tr.threadId = threadId; tr.isComplete = false; tr.startLocation = 0; - tr.threadType = TaskRecord.TYPE_M3U8_VOD; + tr.threadType = getEntity().getTaskType(); tr.tsUrl = mOption.getUrls().get(threadId); return tr; } @@ -118,13 +118,7 @@ public class M3U8RecordAdapter extends AbsRecordHandlerAdapter { record.threadRecords = new ArrayList<>(); record.threadNum = threadNum; record.isBlock = true; - - int requestType = getWrapper().getRequestType(); - if (requestType == ITaskWrapper.M3U8_VOD) { - record.taskType = TaskRecord.TYPE_M3U8_VOD; - } else if (requestType == ITaskWrapper.M3U8_LIVE) { - record.taskType = TaskRecord.TYPE_M3U8_LIVE; - } + record.taskType = getEntity().getTaskType(); record.bandWidth = mOption.getBandWidth(); return record; } diff --git a/M3U8Component/src/main/java/com/arialyy/aria/m3u8/live/M3U8LiveLoader.java b/M3U8Component/src/main/java/com/arialyy/aria/m3u8/live/M3U8LiveLoader.java index 09d96c28..81af7931 100644 --- a/M3U8Component/src/main/java/com/arialyy/aria/m3u8/live/M3U8LiveLoader.java +++ b/M3U8Component/src/main/java/com/arialyy/aria/m3u8/live/M3U8LiveLoader.java @@ -169,7 +169,7 @@ public class M3U8LiveLoader extends BaseM3U8Loader { record.taskKey = mRecord.filePath; record.isComplete = false; record.tsUrl = tsUrl; - record.threadType = TaskRecord.TYPE_M3U8_LIVE; + record.threadType = getEntity().getTaskType(); record.threadId = indexId; mRecord.threadRecords.add(record); diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/TaskRecord.java b/PublicComponent/src/main/java/com/arialyy/aria/core/TaskRecord.java index 222c395b..75d3d92e 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/TaskRecord.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/TaskRecord.java @@ -15,6 +15,7 @@ */ package com.arialyy.aria.core; +import com.arialyy.aria.core.wrapper.ITaskWrapper; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.annotation.Ignore; import com.arialyy.aria.orm.annotation.NoNull; @@ -26,9 +27,9 @@ import java.util.List; * 任务上传或下载的任务记录 */ public class TaskRecord extends DbEntity { - public static final int TYPE_HTTP_FTP = 0; - public static final int TYPE_M3U8_VOD = 1; - public static final int TYPE_M3U8_LIVE = 2; + //public static final int TYPE_HTTP_FTP = 0; + //public static final int TYPE_M3U8_VOD = 1; + //public static final int TYPE_M3U8_LIVE = 2; @Ignore public List threadRecords; @@ -41,7 +42,6 @@ public class TaskRecord extends DbEntity { /** * 任务文件路径 */ - @Unique public String filePath; /** @@ -79,8 +79,8 @@ public class TaskRecord extends DbEntity { public boolean isBlock = false; /** - * 线程类型 - * {@link #TYPE_HTTP_FTP}、{@link #TYPE_M3U8_VOD} + * 任务类型 + * {@link ITaskWrapper} */ public int taskType = 0; diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/ThreadRecord.java b/PublicComponent/src/main/java/com/arialyy/aria/core/ThreadRecord.java index aca2b47f..546172d7 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/ThreadRecord.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/ThreadRecord.java @@ -15,6 +15,7 @@ */ package com.arialyy.aria.core; +import com.arialyy.aria.core.wrapper.ITaskWrapper; import com.arialyy.aria.orm.DbEntity; /** @@ -56,7 +57,7 @@ public class ThreadRecord extends DbEntity { /** * 线程类型 - * {@link TaskRecord#TYPE_HTTP_FTP}、{@link TaskRecord#TYPE_M3U8_VOD} + * {@link ITaskWrapper} */ public int threadType = 0; diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/common/AbsNormalEntity.java b/PublicComponent/src/main/java/com/arialyy/aria/core/common/AbsNormalEntity.java index d26bce47..015a0fcf 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/common/AbsNormalEntity.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/common/AbsNormalEntity.java @@ -17,6 +17,7 @@ package com.arialyy.aria.core.common; import android.os.Parcel; import android.os.Parcelable; +import com.arialyy.aria.core.wrapper.ITaskWrapper; import com.arialyy.aria.orm.annotation.Default; /** @@ -44,6 +45,20 @@ public abstract class AbsNormalEntity extends AbsEntity implements Parcelable { private boolean isRedirect = false; //是否重定向 private String redirectUrl; //重定向链接 + /** + * 任务类型 + * {@link ITaskWrapper} + */ + private int taskType; + + @Override public int getTaskType() { + return taskType; + } + + public void setTaskType(int taskType) { + this.taskType = taskType; + } + public String getUrl() { return url; } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHandler.java b/PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHandler.java index 4672a32a..dfe8f2d7 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHandler.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHandler.java @@ -71,9 +71,11 @@ public class RecordHandler implements IRecordHandler { convertDb(); } else { mAdapter.onPre(); - mTaskRecord = DbDataHelper.getTaskRecord(getFilePath()); + mTaskRecord = DbDataHelper.getTaskRecord(getFilePath(), mEntity.getTaskType()); if (mTaskRecord == null) { - FileUtil.createFile(getFilePath()); + if (!new File(getFilePath()).exists()){ + FileUtil.createFile(getFilePath()); + } initRecord(true); } else { File file = new File(mTaskRecord.filePath); diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java b/PublicComponent/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java index 01190f61..b6264596 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java @@ -78,22 +78,22 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable { return getUrl(); } - @Override public int getTaskType() { - int type; - if (TextUtils.isEmpty(getUrl())) { - type = ITaskWrapper.ERROR; - } else if (getUrl().startsWith("ftp")) { - type = ITaskWrapper.D_FTP; - } else { - M3U8Entity temp = getM3U8Entity(); - if (temp == null) { - type = ITaskWrapper.D_HTTP; - } else { - type = temp.isLive() ? ITaskWrapper.M3U8_LIVE : ITaskWrapper.M3U8_VOD; - } - } - return type; - } + //@Override public int getTaskType() { + // int type; + // if (TextUtils.isEmpty(getUrl())) { + // type = ITaskWrapper.ERROR; + // } else if (getUrl().startsWith("ftp")) { + // type = ITaskWrapper.D_FTP; + // } else { + // M3U8Entity temp = getM3U8Entity(); + // if (temp == null) { + // type = ITaskWrapper.D_HTTP; + // } else { + // type = temp.isLive() ? ITaskWrapper.M3U8_LIVE : ITaskWrapper.M3U8_VOD; + // } + // } + // return type; + //} public DownloadEntity() { } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/download/M3U8Entity.java b/PublicComponent/src/main/java/com/arialyy/aria/core/download/M3U8Entity.java index d024cb43..b534099b 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/download/M3U8Entity.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/download/M3U8Entity.java @@ -20,6 +20,7 @@ import android.os.Parcelable; import android.text.TextUtils; import com.arialyy.aria.core.TaskRecord; import com.arialyy.aria.core.ThreadRecord; +import com.arialyy.aria.core.wrapper.ITaskWrapper; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.annotation.Default; import com.arialyy.aria.util.ALog; @@ -153,7 +154,8 @@ public class M3U8Entity extends DbEntity implements Parcelable { return null; } List peers = new ArrayList<>(); - TaskRecord taskRecord = DbDataHelper.getTaskRecord(filePath); + TaskRecord taskRecord = DbDataHelper.getTaskRecord(filePath, + isLive ? ITaskWrapper.M3U8_LIVE : ITaskWrapper.M3U8_VOD); File cacheDir = new File(getCacheDir()); if ((taskRecord == null || taskRecord.threadRecords == null diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java b/PublicComponent/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java index 27db92a2..16f70083 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java @@ -17,9 +17,7 @@ package com.arialyy.aria.core.upload; import android.os.Parcel; import android.os.Parcelable; -import android.text.TextUtils; import com.arialyy.aria.core.common.AbsNormalEntity; -import com.arialyy.aria.core.wrapper.ITaskWrapper; import com.arialyy.aria.orm.annotation.Primary; /** @@ -58,12 +56,12 @@ public class UploadEntity extends AbsNormalEntity implements Parcelable { return filePath; } - @Override public int getTaskType() { - if (TextUtils.isEmpty(getUrl())){ - return ITaskWrapper.ERROR; - } - return getUrl().startsWith("ftp") ? ITaskWrapper.U_FTP : ITaskWrapper.U_HTTP; - } + //@Override public int getTaskType() { + // if (TextUtils.isEmpty(getUrl())){ + // return ITaskWrapper.ERROR; + // } + // return getUrl().startsWith("ftp") ? ITaskWrapper.U_FTP : ITaskWrapper.U_HTTP; + //} public UploadEntity() { } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/orm/AbsDelegate.java b/PublicComponent/src/main/java/com/arialyy/aria/orm/AbsDelegate.java index 72f19d55..132139f3 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/orm/AbsDelegate.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/orm/AbsDelegate.java @@ -28,16 +28,7 @@ import java.net.URLEncoder; abstract class AbsDelegate { static final String TAG = "AbsDelegate"; - /** - * URL编码字符串 - * - * @param str 原始字符串 - * @return 编码后的字符串 - */ - String encodeStr(String str) { - str = str.replaceAll("\\\\+", "%2B"); - return URLEncoder.encode(str); - } + /** * 检查list参数是否合法,list只能是{@code List} diff --git a/PublicComponent/src/main/java/com/arialyy/aria/orm/DBConfig.java b/PublicComponent/src/main/java/com/arialyy/aria/orm/DBConfig.java index 7ab0b3bc..641bd1f1 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/orm/DBConfig.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/orm/DBConfig.java @@ -34,7 +34,7 @@ class DBConfig { static boolean DEBUG = false; static Map> mapping = new LinkedHashMap<>(); static String DB_NAME; - static int VERSION = 56; + static int VERSION = 57; /** * 是否将数据库保存在Sd卡,{@code true} 是 diff --git a/PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateCommon.java b/PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateCommon.java index 27a01d3f..d0205bf8 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateCommon.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateCommon.java @@ -113,7 +113,7 @@ class DelegateCommon extends AbsDelegate { sql = sql.replace("?", "%s"); Object[] params = new String[expression.length - 1]; for (int i = 0, len = params.length; i < len; i++) { - params[i] = String.format("'%s'", encodeStr(expression[i + 1])); + params[i] = String.format("'%s'", SqlUtil.encodeStr(expression[i + 1])); } sql = String.format(sql, params); Cursor cursor = db.rawQuery(sql, null); diff --git a/PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateFind.java b/PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateFind.java index 6fdd6695..0e6a26e6 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateFind.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateFind.java @@ -205,7 +205,7 @@ class DelegateFind extends AbsDelegate { sql = sql.replace("?", "%s"); Object[] params = new String[expression.length - 1]; for (int i = 0, len = params.length; i < len; i++) { - params[i] = String.format("'%s'", encodeStr(expression[i + 1])); + params[i] = String.format("'%s'", SqlUtil.encodeStr(expression[i + 1])); } sql = String.format(sql, params); } else { @@ -421,7 +421,7 @@ class DelegateFind extends AbsDelegate { String[] temp = new String[selectionArgs.length]; int i = 0; for (String arg : selectionArgs) { - temp[i] = encodeStr(arg); + temp[i] = SqlUtil.encodeStr(arg); i++; } Cursor cursor = db.rawQuery(sql, temp); diff --git a/PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java b/PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java index 9835b250..00e32002 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java @@ -47,7 +47,7 @@ class DelegateUpdate extends AbsDelegate { sql = sql.replace("?", "%s"); Object[] params = new String[expression.length - 1]; for (int i = 0, len = params.length; i < len; i++) { - params[i] = String.format("'%s'", encodeStr(expression[i + 1])); + params[i] = String.format("'%s'", SqlUtil.encodeStr(expression[i + 1])); } sql = String.format(sql, params); db.execSQL(sql); @@ -166,7 +166,7 @@ class DelegateUpdate extends AbsDelegate { value = field.get(dbEntity).toString(); } } - values.put(field.getName(), encodeStr(value)); + values.put(field.getName(), SqlUtil.encodeStr(value)); } return values; } catch (IllegalAccessException e) { diff --git a/PublicComponent/src/main/java/com/arialyy/aria/orm/SqlHelper.java b/PublicComponent/src/main/java/com/arialyy/aria/orm/SqlHelper.java index 0344b32b..546a84c0 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/orm/SqlHelper.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/orm/SqlHelper.java @@ -21,6 +21,9 @@ import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.os.Build; +import android.text.TextUtils; +import com.arialyy.aria.core.download.M3U8Entity; +import com.arialyy.aria.core.wrapper.ITaskWrapper; import com.arialyy.aria.util.ALog; import java.io.File; import java.util.ArrayList; @@ -102,6 +105,10 @@ final class SqlHelper extends SQLiteOpenHelper { } else { handleDbUpdate(db, null); } + // 处理380版本TaskRecord 增加的记录类型判断 + if (newVersion == 57) { + addTaskRecordType(db); + } } } @@ -256,6 +263,79 @@ final class SqlHelper extends SQLiteOpenHelper { return temp; } + /** + * 给TaskRecord 增加任务类型 + */ + private void addTaskRecordType(SQLiteDatabase db) { + try { + db.beginTransaction(); + /* + * 增加下载实体的类型 + */ + String dSql = "SELECT downloadPath, url FROM DownloadEntity"; + Cursor c = db.rawQuery(dSql, null); + while (c.moveToNext()) { + int type; + String filePath = c.getString(0); + String url = c.getString(1); + if (url.startsWith("ftp") || url.startsWith("sftp")) { + type = ITaskWrapper.D_FTP; + } else { + if (mDelegate.tableExists(db, M3U8Entity.class)) { + Cursor m3u8c = db.rawQuery("SELECT isLive FROM M3U8Entity WHERE filePath=\"" + + SqlUtil.encodeStr(filePath) + + "\"", null); + if (m3u8c.moveToNext()) { + String temp = m3u8c.getString(0); + type = + (TextUtils.isEmpty(temp) ? false : Boolean.valueOf(temp)) ? ITaskWrapper.M3U8_LIVE + : ITaskWrapper.M3U8_VOD; + } else { + type = ITaskWrapper.D_HTTP; + } + m3u8c.close(); + } else { + type = ITaskWrapper.D_HTTP; + } + } + db.execSQL("UPDATE DownloadEntity SET taskType=? WHERE downloadPath=?", + new Object[] { type, filePath }); + db.execSQL("UPDATE TaskRecord SET taskType=? WHERE filePath=?", + new Object[] { type, filePath }); + db.execSQL("UPDATE ThreadRecord SET threadType=? WHERE taskKey=?", + new Object[] { type, filePath }); + } + c.close(); + + /* + * 增加上传实体的类型 + */ + String uSql = "SELECT filePath, url FROM UploadEntity"; + c = db.rawQuery(uSql, null); + while (c.moveToNext()) { + int type; + String filePath = c.getString(c.getColumnIndex("filePath")); + String url = c.getString(c.getColumnIndex("url")); + if (url.startsWith("ftp") || url.startsWith("sftp")) { + type = ITaskWrapper.D_FTP; + } else { + type = ITaskWrapper.D_HTTP; + } + db.execSQL("UPDATE UploadEntity SET taskType=? WHERE filePath=?", + new Object[] { type, filePath }); + db.execSQL("UPDATE TaskRecord SET taskType=? WHERE filePath=?", + new Object[] { type, filePath }); + db.execSQL("UPDATE ThreadRecord SET threadType=? WHERE taskKey=?", + new Object[] { type, filePath }); + } + c.close(); + + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + } + /** * 删除重复的repeat数据 */ diff --git a/PublicComponent/src/main/java/com/arialyy/aria/orm/SqlUtil.java b/PublicComponent/src/main/java/com/arialyy/aria/orm/SqlUtil.java index 0dea4c5d..c112784f 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/orm/SqlUtil.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/orm/SqlUtil.java @@ -29,6 +29,7 @@ import com.arialyy.aria.orm.annotation.Wrapper; import com.arialyy.aria.util.CommonUtil; import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -41,6 +42,17 @@ import java.util.Set; */ final class SqlUtil { + /** + * URL编码字符串 + * + * @param str 原始字符串 + * @return 编码后的字符串 + */ + static String encodeStr(String str) { + str = str.replaceAll("\\\\+", "%2B"); + return URLEncoder.encode(str); + } + /** * 获取主键字段名 */ 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 986cdfc5..d71c5003 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/util/CheckUtil.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/util/CheckUtil.java @@ -141,8 +141,15 @@ public class CheckUtil { */ public static void checkMemberClass(Class clazz) { int modifiers = clazz.getModifiers(); - if (!clazz.isMemberClass() || !Modifier.isStatic(modifiers) || Modifier.isPrivate(modifiers)) { - ALog.e(TAG, "为了防止内存泄漏,请使用静态的成员类(public static class xxx)或文件类(A.java)"); + //ALog.d(TAG, "isMemberClass = " + // + clazz.isMemberClass() + // + "; isStatic = " + // + Modifier.isStatic(modifiers) + // + "; isPrivate = " + // + Modifier.isPrivate(modifiers)); + if (!clazz.isMemberClass() || !Modifier.isStatic(modifiers)) { + ALog.e(TAG, String.format("为了防止内存泄漏,请使用静态的成员类(public static class %s)或文件类(%s.java)", + clazz.getSimpleName(), clazz.getSimpleName())); } } 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 94776ad1..93168562 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/util/DbDataHelper.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/util/DbDataHelper.java @@ -15,12 +15,13 @@ */ package com.arialyy.aria.util; -import com.arialyy.aria.core.wrapper.RecordWrapper; import com.arialyy.aria.core.TaskRecord; +import com.arialyy.aria.core.ThreadRecord; import com.arialyy.aria.core.download.DGEntityWrapper; import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadGroupEntity; +import com.arialyy.aria.core.wrapper.ITaskWrapper; import com.arialyy.aria.orm.DbEntity; import java.io.File; import java.util.ArrayList; @@ -35,15 +36,20 @@ public class DbDataHelper { * 获取任务记录 * * @param filePath 文件地址 + * @param taskType 任务类型{@link ITaskWrapper} * @return 没有记录返回null,有记录则返回任务记录 */ - public static TaskRecord getTaskRecord(String filePath) { - List record = - DbEntity.findRelationData(RecordWrapper.class, "TaskRecord.filePath=?", filePath); - if (record == null || record.size() == 0) { - return null; + public static TaskRecord getTaskRecord(String filePath, int taskType) { + TaskRecord taskRecord = + DbEntity.findFirst(TaskRecord.class, "filePath=? AND taskType=?", filePath, + String.valueOf(taskType)); + if (taskRecord != null) { + taskRecord.threadRecords = + DbEntity.findDatas(ThreadRecord.class, "taskKey=? AND threadType=?", filePath, + String.valueOf(taskType)); } - return record.get(0).taskRecord; + + return taskRecord; } /** 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 dfc7ff7a..08603eb2 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/util/RecordUtil.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/util/RecordUtil.java @@ -25,6 +25,7 @@ import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.download.M3U8Entity; import com.arialyy.aria.core.inf.IRecordHandler; import com.arialyy.aria.core.upload.UploadEntity; +import com.arialyy.aria.core.wrapper.ITaskWrapper; import com.arialyy.aria.core.wrapper.RecordWrapper; import com.arialyy.aria.orm.DbEntity; import java.io.File; @@ -187,7 +188,7 @@ public class RecordUtil { * @return true 为m3u8任务 */ private static boolean recordIsM3U8(int recordType) { - return recordType == TaskRecord.TYPE_M3U8_VOD || recordType == TaskRecord.TYPE_M3U8_LIVE; + return recordType == ITaskWrapper.M3U8_VOD || recordType == ITaskWrapper.M3U8_LIVE; } /** @@ -361,13 +362,14 @@ public class RecordUtil { * * @param oldPath 旧的文件路径 * @param newPath 新的文件路径 + * @param taskType 任务类型{@link ITaskWrapper} */ - public static void modifyTaskRecord(String oldPath, String newPath) { + public static void modifyTaskRecord(String oldPath, String newPath, int taskType) { if (oldPath.equals(newPath)) { ALog.w(TAG, "修改任务记录失败,新文件路径和旧文件路径一致"); return; } - TaskRecord record = DbDataHelper.getTaskRecord(oldPath); + TaskRecord record = DbDataHelper.getTaskRecord(oldPath, taskType); if (record == null) { if (new File(oldPath).exists()) { ALog.w(TAG, "修改任务记录失败,文件【" + oldPath + "】对应的任务记录不存在"); diff --git a/README.md b/README.md index 05c0779b..16f18028 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.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) +[![Core](https://img.shields.io/badge/Core-3.8-blue)](https://github.com/AriaLyy/Aria) +[![Compiler](https://img.shields.io/badge/Compiler-3.8-blue)](https://github.com/AriaLyy/Aria) +[![FtpComponent](https://img.shields.io/badge/FtpComponent-3.8-orange)](https://github.com/AriaLyy/Aria) +[![M3U8Component](https://img.shields.io/badge/M3U8Component-3.8-orange)](https://github.com/AriaLyy/Aria) ```java -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下载功能,请增加该组件 +implementation 'com.arialyy.aria:core:3.8' +annotationProcessor 'com.arialyy.aria:compiler:3.8' +implementation 'com.arialyy.aria:ftpComponent:3.8' # 如果需要使用ftp,请增加该组件 +implementation 'com.arialyy.aria:m3u8Component:3.8' # 如果需要使用m3u8下载功能,请增加该组件 ``` 如果出现android support依赖错误,请将 `compile 'com.arialyy.aria:core:'`替换为 ``` @@ -65,7 +65,7 @@ api('com.arialyy.aria:core:'){ __⚠️注意:3.5.4以下版本升级时,需要更新[配置文件](https://aria.laoyuyu.me/aria_doc/start/config.html)!!__ -__⚠️注意:3.7 以上版本已经适配了AndroidX,如果是使用support库的,可使用[老版本](https://github.com/AriaLyy/Aria/tree/v3.6.6)__ +__⚠️注意:3.8 以上版本已经适配了AndroidX和support库都可以使用 *** ## 使用 @@ -137,13 +137,19 @@ protected void onCreate(Bundle savedInstanceState) { ### 版本日志 - + 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.8 (2019/12/17) + - 移除androidx和support的依赖,现在无论是哪个版本的appcompat包都可以使用本框架 + - 修复一个在xml中使用fragment导致的内存泄漏问题 + - m3u8协议的key信息增加了`keyFormat`,`keyFormatVersion`字段 + - m3u8增加了`ignoreFailureTs`方法,忽略下载失败的ts切片 + - 修复在dialogFragment的`onCreateDialog()`注册导致的注解不生效问题 + - 修复组合任务初始化失败时,无法删除的问题 + - 修复`reStart()`后,无法停止的问题 + - ftp增加主动模式,开启主动模式:https://aria.laoyuyu.me/aria_doc/api/ftp_params.html + - 修复ftp服务器无法响应`abor`命令导致的无法停止上传的问题 https://github.com/AriaLyy/Aria/issues/564 + - 修复ftp上传时,服务器有长度为0的文件导致上传失败的问题 + - 修复下载任务和上传任务的文件路径是同一个时,导致的记录混乱问题 + - 优化提示 [更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md) diff --git a/app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java b/app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java index 2fb5db4e..ef2c856b 100644 --- a/app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java @@ -55,7 +55,8 @@ public class FtpUploadActivity extends BaseActivity { private String mUrl; private UploadModule mModule; private long mTaskId = -1; - private String user = "lao", pwd = "123456"; + private String user = "ftpuser", pwd = "ftpuser2020"; + //private String user = "lao", pwd = "123456"; @Override protected void init(Bundle savedInstanceState) { setTile("D_FTP 文件上传"); @@ -92,11 +93,11 @@ public class FtpUploadActivity extends BaseActivity { } private void setHelpCode() { - try { - getBinding().codeView.setSource(AppUtil.getHelpCode(this, "FtpUpload.java")); - } catch (IOException e) { - e.printStackTrace(); - } + //try { + // getBinding().codeView.setSource(AppUtil.getHelpCode(this, "FtpUpload.java")); + //} catch (IOException e) { + // e.printStackTrace(); + //} } @Override protected int setLayoutId() { @@ -245,7 +246,7 @@ public class FtpUploadActivity extends BaseActivity { @Override public FtpInterceptHandler onIntercept(UploadEntity entity, List fileList) { FtpInterceptHandler.Builder builder = new FtpInterceptHandler.Builder(); //builder.coverServerFile(); // 覆盖远端同名文件 - builder.resetFileName("test.zip"); //修改上传到远端服务器的文件名 + builder.resetFileName("test12.zip"); //修改上传到远端服务器的文件名 return builder.build(); } } diff --git a/app/src/main/java/com/arialyy/simple/core/upload/UploadModule.java b/app/src/main/java/com/arialyy/simple/core/upload/UploadModule.java index 59365c1b..6dcb68d7 100644 --- a/app/src/main/java/com/arialyy/simple/core/upload/UploadModule.java +++ b/app/src/main/java/com/arialyy/simple/core/upload/UploadModule.java @@ -35,9 +35,12 @@ public class UploadModule extends BaseViewModule { * 获取Ftp上传信息 */ LiveData getFtpInfo(Context context) { - String url = AppUtil.getConfigValue(context, FTP_URL_KEY, "ftp://9.9.9.72:2121/aab/你好"); - String filePath = AppUtil.getConfigValue(context, FTP_PATH_KEY, - Environment.getExternalStorageDirectory().getPath() + "/Download/AndroidAria.db"); + //String url = AppUtil.getConfigValue(context, FTP_URL_KEY, "ftp://9.9.9.72:2121/aab/你好"); + //String filePath = AppUtil.getConfigValue(context, FTP_PATH_KEY, + // Environment.getExternalStorageDirectory().getPath() + "/Download/AndroidAria.db"); + String url = "ftp://101.132.33.64:21/home/ftpuser/videopic/historymonitor/jobs/test"; + //String url = "ftp://9.9.9.72:2121/aab/你好"; + String filePath = "/mnt/sdcard/QQMusic-import-1.2.1.zip"; UploadEntity entity = Aria.upload(context).getFirstUploadEntity(filePath); if (entity != null) { diff --git a/app/src/main/res/layout/activity_ftp_upload.xml b/app/src/main/res/layout/activity_ftp_upload.xml index 174e9ab4..e71cacb0 100644 --- a/app/src/main/res/layout/activity_ftp_upload.xml +++ b/app/src/main/res/layout/activity_ftp_upload.xml @@ -72,11 +72,11 @@ /> - + + + + + diff --git a/build.gradle b/build.gradle index 42116f03..c5910ecb 100644 --- a/build.gradle +++ b/build.gradle @@ -45,7 +45,7 @@ task clean(type: Delete) { ext { versionCode = 380 - versionName = '3.8_pre_1' + versionName = '3.8' userOrg = 'arialyy' groupId = 'com.arialyy.aria' publishVersion = versionName