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 5af68983..402b1846 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 @@ -170,9 +170,8 @@ public class CheckDGEntityUtil implements ICheckEntityUtil { if (!newName.equals(entity.getFileName())) { String oldPath = mEntity.getDirPath() + "/" + entity.getFileName(); String newPath = mEntity.getDirPath() + "/" + newName; - if (DbEntity.checkDataExist(DownloadEntity.class, "downloadPath=? or isComplete='true'", - newPath)) { - ALog.w(TAG, String.format("更新文件名失败,路径【%s】已存在或文件已下载", newPath)); + if (DbEntity.checkDataExist(DownloadEntity.class, "downloadPath=?", newPath)) { + ALog.w(TAG, String.format("更新文件名失败,路径【%s】被其它任务占用", newPath)); return; } 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 6d91f33f..741dd2d8 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 @@ -35,6 +35,7 @@ public class FtpBuilderTarget extends AbsBuilderTarget { mConfigHandler = new UNormalConfigHandler<>(this, -1); mConfigHandler.setFilePath(filePath); getTaskWrapper().setRequestType(ITaskWrapper.U_FTP); + getTaskWrapper().setNewTask(true); } /** diff --git a/DEV_LOG.md b/DEV_LOG.md index de37719f..fa4f7b3d 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,5 +1,8 @@ ## 开发日志 - + v_3.7.6 + + v_3.7.6 (2019/11/19) + - fix bug https://github.com/AriaLyy/Aria/issues/505 + - fix bug https://github.com/AriaLyy/Aria/issues/516 + - fix bug https://github.com/AriaLyy/Aria/issues/515 - 增加强制上传的api`forceUpload()` - 修复for循环上传文件出现的问题 - 移除创建任务的500ms间隔限制 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 e13a174e..29f1cdc7 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 @@ -60,6 +60,7 @@ class FtpUFileInfoThread extends AbsFtpInfoThread { @Override protected boolean onInterceptor(FTPClient client, FTPFile[] ftpFiles) { // 旧任务将不做处理,否则断点续传上传将失效 if (!mTaskWrapper.isNewTask()) { + ALog.d(TAG, "任务是旧任务,忽略该拦截器"); return true; } try { diff --git a/README.md b/README.md index a1adfe46..8b31e914 100644 --- a/README.md +++ b/README.md @@ -44,20 +44,20 @@ 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.5-blue)](https://github.com/AriaLyy/Aria) -[![Compiler](https://img.shields.io/badge/Compiler-3.7.5-blue)](https://github.com/AriaLyy/Aria) -[![FtpComponent](https://img.shields.io/badge/FtpComponent-3.7.5-orange)](https://github.com/AriaLyy/Aria) -[![M3U8Component](https://img.shields.io/badge/M3U8Component-3.7.5-orange)](https://github.com/AriaLyy/Aria) +[![Core](https://img.shields.io/badge/Core-3.7.6-blue)](https://github.com/AriaLyy/Aria) +[![Compiler](https://img.shields.io/badge/Compiler-3.7.6-blue)](https://github.com/AriaLyy/Aria) +[![FtpComponent](https://img.shields.io/badge/FtpComponent-3.7.6-orange)](https://github.com/AriaLyy/Aria) +[![M3U8Component](https://img.shields.io/badge/M3U8Component-3.7.6-orange)](https://github.com/AriaLyy/Aria) ```java -implementation 'com.arialyy.aria:core:3.7.5' -annotationProcessor 'com.arialyy.aria:compiler:3.7.5' -implementation 'com.arialyy.aria:ftpComponent:3.7.5' # 如果需要使用ftp,请增加该组件 -implementation 'com.arialyy.aria:m3u8Component:3.7.5' # 如果需要使用m3u8下载功能,请增加该组件 +implementation 'com.arialyy.aria:core:3.7.6' +annotationProcessor 'com.arialyy.aria:compiler:3.7.6' +implementation 'com.arialyy.aria:ftpComponent:3.7.6' # 如果需要使用ftp,请增加该组件 +implementation 'com.arialyy.aria:m3u8Component:3.7.6' # 如果需要使用m3u8下载功能,请增加该组件 ``` 如果出现android support依赖错误,请将 `compile 'com.arialyy.aria:core:'`替换为 ``` -api('com.arialyy.aria:aria-core:'){ +api('com.arialyy.aria:core:'){ exclude group: 'androidx.appcompat.app' } ``` @@ -65,7 +65,7 @@ api('com.arialyy.aria:aria-core:'){ __⚠️注意:3.5.4以下版本升级时,需要更新[配置文件](https://aria.laoyuyu.me/aria_doc/start/config.html)!!__ -__⚠️注意:3.7 以上版本已经适配了AndroidX__ +__⚠️注意:3.7 以上版本已经适配了AndroidX,如果是使用support库的,可使用[老版本](https://github.com/AriaLyy/Aria/tree/v3.6.6)__ *** ## 使用 @@ -137,11 +137,14 @@ protected void onCreate(Bundle savedInstanceState) { ### 版本日志 -+ v_3.7.5 (2019/11/10) - - fix bug https://github.com/AriaLyy/Aria/issues/500 - - fix bug https://github.com/AriaLyy/Aria/issues/508 - - fix bug https://github.com/AriaLyy/Aria/issues/503 - - 修复m3u8创建索引不成功的问题 + + v_3.7.6 (2019/11/19) + - fix bug https://github.com/AriaLyy/Aria/issues/505 + - fix bug https://github.com/AriaLyy/Aria/issues/516 + - fix bug https://github.com/AriaLyy/Aria/issues/515 + - 增加强制上传的api`forceUpload()` + - 修复for循环上传文件出现的问题 + - 移除创建任务的500ms间隔限制 + - 修复多线程读写时可能出现的`database is locked`的问题 [更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md) diff --git a/SFtpComponent/src/main/java/com/arialyy/aria/sftp/AbsSFtpFileInfoThread.java b/SFtpComponent/src/main/java/com/arialyy/aria/sftp/AbsSFtpFileInfoThread.java deleted file mode 100644 index 858cf640..00000000 --- a/SFtpComponent/src/main/java/com/arialyy/aria/sftp/AbsSFtpFileInfoThread.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.arialyy.aria.sftp; - -import com.arialyy.aria.core.inf.OnFileInfoCallback; -import com.arialyy.aria.core.wrapper.AbsTaskWrapper; -import com.jcraft.jsch.ChannelSftp; -import com.jcraft.jsch.JSchException; - -/** - * 获取sftp文件信息 - * - * @author lyy - */ -public class AbsSFtpFileInfoThread implements Runnable { - - private WP mWrapper; - private SFtpUtil mUtil; - private OnFileInfoCallback mCallback; - - public AbsSFtpFileInfoThread(SFtpUtil util, WP wrapper, OnFileInfoCallback callback) { - mWrapper = wrapper; - mUtil = util; - mCallback = callback; - } - - @Override public void run() { - startFlow(); - } - - private void startFlow() { - - } - - private ChannelSftp createChannel() { - ChannelSftp sftp = null; - try { - sftp = (ChannelSftp) mUtil.getSession().openChannel(SFtpUtil.CMD_TYPE_SFTP); - sftp.connect(); - } catch (JSchException e) { - e.printStackTrace(); - } - return sftp; - } -} diff --git a/SFtpComponent/src/main/java/com/arialyy/aria/sftp/BaseInfoThreadAdapter.java b/SFtpComponent/src/main/java/com/arialyy/aria/sftp/BaseInfoThreadAdapter.java new file mode 100644 index 00000000..53a939c3 --- /dev/null +++ b/SFtpComponent/src/main/java/com/arialyy/aria/sftp/BaseInfoThreadAdapter.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.sftp; + +import com.arialyy.aria.core.wrapper.AbsTaskWrapper; +import java.util.Vector; + +/** + * sftp文件信息适配器 + */ +public abstract class BaseInfoThreadAdapter { + + private WRAPPER mWrapper; + + public BaseInfoThreadAdapter(WRAPPER taskWrapper) { + mWrapper = taskWrapper; + } + + public WRAPPER getWrapper() { + return mWrapper; + } + + /** + * 处理文件 + * + * @return true 处理文件成功,false 处理文件失败,结束任务 + */ + protected abstract boolean handlerFile(Vector vector); +} diff --git a/SFtpComponent/src/main/java/com/arialyy/aria/sftp/AbsSFtpInfoThread.java b/SFtpComponent/src/main/java/com/arialyy/aria/sftp/SFtpInfoThread.java similarity index 53% rename from SFtpComponent/src/main/java/com/arialyy/aria/sftp/AbsSFtpInfoThread.java rename to SFtpComponent/src/main/java/com/arialyy/aria/sftp/SFtpInfoThread.java index 3ab60bf6..cf517381 100644 --- a/SFtpComponent/src/main/java/com/arialyy/aria/sftp/AbsSFtpInfoThread.java +++ b/SFtpComponent/src/main/java/com/arialyy/aria/sftp/SFtpInfoThread.java @@ -16,19 +16,25 @@ package com.arialyy.aria.sftp; import com.arialyy.aria.core.AriaConfig; -import com.arialyy.aria.core.common.AbsEntity; +import com.arialyy.aria.core.FtpUrlEntity; +import com.arialyy.aria.core.common.AbsNormalEntity; import com.arialyy.aria.core.inf.OnFileInfoCallback; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.wrapper.AbsTaskWrapper; import com.arialyy.aria.ftp.FtpTaskOption; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; +import com.jcraft.jsch.ChannelSftp; +import com.jcraft.jsch.JSchException; +import com.jcraft.jsch.SftpException; +import java.util.Vector; /** - * * https://cloud.tencent.com/developer/article/1354612 + * * @author lyy */ -public class AbsSFtpInfoThread> +public class SFtpInfoThread> implements Runnable { private final String TAG = CommonUtil.getClassName(getClass()); @@ -40,8 +46,12 @@ public class AbsSFtpInfoThread { + + DSFtpInfoThreadAdapter(DTaskWrapper taskWrapper) { + super(taskWrapper); + } + + @Override protected boolean handlerFile(Vector vector) { + return false; + } +} diff --git a/SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/SFtpDLoaderUtil.java b/SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/SFtpDLoaderUtil.java index 5b691cf9..8191cd7d 100644 --- a/SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/SFtpDLoaderUtil.java +++ b/SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/SFtpDLoaderUtil.java @@ -26,7 +26,7 @@ import com.arialyy.aria.core.loader.NormalLoader; import com.arialyy.aria.core.wrapper.AbsTaskWrapper; import com.arialyy.aria.exception.BaseException; import com.arialyy.aria.ftp.FtpTaskOption; -import com.arialyy.aria.sftp.AbsSFtpFileInfoThread; +import com.arialyy.aria.sftp.SFtpInfoThread; import com.arialyy.aria.sftp.SFtpUtil; /** @@ -57,15 +57,19 @@ public class SFtpDLoaderUtil extends AbsNormalLoaderUtil { } @Override protected Runnable createInfoThread() { - return new AbsSFtpFileInfoThread<>(mSftpUtil, (DTaskWrapper) getTaskWrapper(), new OnFileInfoCallback() { - @Override public void onComplete(String key, CompleteInfo info) { + DSFtpInfoThreadAdapter adapter = new DSFtpInfoThreadAdapter((DTaskWrapper) getTaskWrapper()); + SFtpInfoThread infoThread = new SFtpInfoThread<>(mSftpUtil, (DTaskWrapper) getTaskWrapper(), + new OnFileInfoCallback() { + @Override public void onComplete(String key, CompleteInfo info) { - } + } - @Override public void onFail(AbsEntity entity, BaseException e, boolean needRetry) { + @Override public void onFail(AbsEntity entity, BaseException e, boolean needRetry) { - mSftpUtil.logout(); - } - }); + } + }); + infoThread.setAdapter(adapter); + + return infoThread; } } 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 def2c8af..a1446e59 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 @@ -95,13 +95,13 @@ public class DownloadGroupActivity extends BaseActivity getUrls() { List urls = new ArrayList<>(); - String[] str = getContext().getResources().getStringArray(R.array.group_urls_1); - Collections.addAll(urls, str); + urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574141924275&di=a7ea1497a4a2528a45ce7103bf61adf4&imgtype=0&src=http%3A%2F%2Fg.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2Fc2cec3fdfc03924590b2a9b58d94a4c27d1e2500.jpg"); + urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574141924272&di=7861479e7cb3cea98d585eaf108f056f&imgtype=0&src=http%3A%2F%2Fd.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F562c11dfa9ec8a13c0741f5afd03918fa0ecc01a.jpg"); + //String[] str = getContext().getResources().getStringArray(R.array.group_urls_1); + //Collections.addAll(urls, str); return urls; } 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 5d8fc54c..2fb5db4e 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 @@ -28,6 +28,8 @@ import com.arialyy.annotations.Upload; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.common.FtpOption; import com.arialyy.aria.core.inf.IEntity; +import com.arialyy.aria.core.processor.FtpInterceptHandler; +import com.arialyy.aria.core.processor.IFtpUploadInterceptor; import com.arialyy.aria.core.task.UploadTask; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.util.ALog; @@ -114,26 +116,27 @@ public class FtpUploadActivity extends BaseActivity { public void onClick(View view) { switch (view.getId()) { case R.id.start: - //if (mTaskId == -1) { - // mTaskId = Aria.upload(this) - // .loadFtp(mFilePath) - // .setUploadUrl(mUrl) - // .option(getOption()) - // .create(); - // getBinding().setStateStr(getString(R.string.stop)); - // break; - //} - //if (Aria.upload(this).loadFtp(mTaskId).isRunning()) { - // Aria.upload(this).loadFtp(mTaskId).stop(); - // getBinding().setStateStr(getString(R.string.resume)); - //} else { - // Aria.upload(this) - // .loadFtp(mTaskId) - // .option(getOption()) - // .resume(); - // getBinding().setStateStr(getString(R.string.stop)); - //} - upload(); + if (mTaskId == -1) { + mTaskId = Aria.upload(this) + .loadFtp(mFilePath) + .setUploadUrl(mUrl) + .option(getOption()) + .forceUpload() + .create(); + getBinding().setStateStr(getString(R.string.stop)); + break; + } + if (Aria.upload(this).loadFtp(mTaskId).isRunning()) { + Aria.upload(this).loadFtp(mTaskId).stop(); + getBinding().setStateStr(getString(R.string.resume)); + } else { + Aria.upload(this) + .loadFtp(mTaskId) + .option(getOption()) + .resume(); + getBinding().setStateStr(getString(R.string.stop)); + } + //upload(); break; case R.id.cancel: Aria.upload(this).loadFtp(mTaskId).cancel(); @@ -168,6 +171,7 @@ public class FtpUploadActivity extends BaseActivity { private FtpOption getOption() { FtpOption option = new FtpOption(); option.login(user, pwd); + option.setUploadInterceptor(new FtpUploadInterceptor()); return option; } @@ -236,4 +240,13 @@ public class FtpUploadActivity extends BaseActivity { } } } + + private static class FtpUploadInterceptor implements IFtpUploadInterceptor { + @Override public FtpInterceptHandler onIntercept(UploadEntity entity, List fileList) { + FtpInterceptHandler.Builder builder = new FtpInterceptHandler.Builder(); + //builder.coverServerFile(); // 覆盖远端同名文件 + builder.resetFileName("test.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 e88d07cc..19042e5f 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 @@ -37,7 +37,7 @@ public class UploadModule extends BaseViewModule { LiveData getFtpInfo(Context context) { String url = AppUtil.getConfigValue(context, FTP_URL_KEY, "ftp://9.9.9.50:2121/aa/你好"); String filePath = AppUtil.getConfigValue(context, FTP_PATH_KEY, - Environment.getExternalStorageDirectory().getPath() + "/Download/PaNTFS15562.zip"); + Environment.getExternalStorageDirectory().getPath() + "/Download/Folx P58.zip"); UploadEntity entity = Aria.upload(context).getFirstUploadEntity(filePath); if (entity != null) { diff --git a/build.gradle b/build.gradle index 4ba0e57e..5d899125 100644 --- a/build.gradle +++ b/build.gradle @@ -44,8 +44,8 @@ task clean(type: Delete) { } ext { - versionCode = 375 - versionName = '3.7.5' + versionCode = 376 + versionName = '3.7.6' userOrg = 'arialyy' groupId = 'com.arialyy.aria' publishVersion = versionName