From 88dfa7eedc7eaa0496691afc5784059c33ff4a53 Mon Sep 17 00:00:00 2001 From: e <511455842@qq.com> Date: Thu, 1 Feb 2018 20:06:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86ftp?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aria/build.gradle | 4 +- .../com/arialyy/aria/core/AriaManager.java | 2 - .../aria/core/common/AbsFtpInfoThread.java | 23 +++++++--- .../aria/core/common/AbsFtpThreadTask.java | 5 +- .../download/downloader/FtpThreadTask.java | 21 +++++++-- .../core/upload/uploader/FtpThreadTask.java | 25 ++++++++-- .../com/arialyy/aria/util/CommonUtil.java | 3 +- DEV_LOG.md | 2 +- README.md | 16 ++++--- .../simple/download/FtpDownloadActivity.java | 7 +-- .../simple/download/SingleTaskActivity.java | 46 +++++++++---------- 11 files changed, 99 insertions(+), 55 deletions(-) diff --git a/Aria/build.gradle b/Aria/build.gradle index 4d7ee364..f95e9d8f 100644 --- a/Aria/build.gradle +++ b/Aria/build.gradle @@ -23,8 +23,8 @@ dependencies { testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' compile project(':AriaAnnotations') - compile 'com.arialyy.aria:aria-ftp-plug:1.0.3' +// compile 'com.arialyy.aria:aria-ftp-plug:1.0.3' -// compile project(':AriaFtpPlug') + compile project(':AriaFtpPlug') } apply from: 'bintray-release.gradle' 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 e52c90c8..9f7316c5 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -69,8 +69,6 @@ import org.xml.sax.SAXException; public static final String DOWNLOAD_TEMP_DIR = "/Aria/temp/download/"; public static final String UPLOAD_TEMP_DIR = "/Aria/temp/upload/"; - - @SuppressLint("StaticFieldLeak") private static volatile AriaManager INSTANCE = null; private Map mReceivers = new ConcurrentHashMap<>(); public static Context APP; diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java index 18911a09..c118475e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java @@ -23,6 +23,7 @@ import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.Regular; +import java.io.File; import java.io.IOException; import java.net.InetAddress; import java.util.regex.Matcher; @@ -77,11 +78,18 @@ public abstract class AbsFtpInfoThread 0) { ALog.i(TAG, "路径【" + setRemotePath() + "】下的文件列表 ==================================="); for (FTPFile file : files1) { @@ -89,7 +97,7 @@ public abstract class AbsFtpInfoThread + "】"); client = createClient(); if (client == null) return; - client.setRestartOffset(mConfig.START_LOCATION); + if (mConfig.START_LOCATION > 0) { + client.setRestartOffset(mConfig.START_LOCATION); + } + //发送第二次指令时,还需要再做一次判断 + int reply = client.getReplyCode(); + if (reply == FTPReply.SYNTAX_ERROR_IN_ARGUMENTS) { + ALog.e(TAG, "FTP没有打开写权限,断点续传失败,将从0开始读文件"); + } else if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.COMMAND_OK) { + client.disconnect(); + fail(mChildCurrentLocation, "获取文件信息错误,错误码为:" + reply + ",msg:" + client.getReplyString(), + null); + return; + } String remotePath = new String(mTaskEntity.urlEntity.remotePath.getBytes(charSet), SERVER_CHARSET); is = client.retrieveFileStream(remotePath); - //发送第二次指令时,还需要再做一次判断 - int reply = client.getReplyCode(); + reply = client.getReplyCode(); if (!FTPReply.isPositivePreliminary(reply)) { client.disconnect(); - fail(mChildCurrentLocation, "获取文件信息错误,错误码为:" + reply, null); + fail(mChildCurrentLocation, "获取流失败,错误码为:" + reply + ",msg:" + client.getReplyString(), + null); return; } + file = new BufferedRandomAccessFile(mConfig.TEMP_FILE, "rwd", mBufSize); file.seek(mConfig.START_LOCATION); byte[] buffer = new byte[mBufSize]; diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java index ed15bed1..afc80187 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java @@ -61,9 +61,28 @@ class FtpThreadTask extends AbsFtpThreadTask { client = createClient(); if (client == null) return; initPath(); - client.makeDirectory(dir); - client.changeWorkingDirectory(dir); + if (client.makeDirectory(dir)) { + fail(mChildCurrentLocation, "创建文件夹失败", null); + return; + } + if (client.changeWorkingDirectory(dir)) { + fail(mChildCurrentLocation, "选择工作文件夹失败", null); + return; + } client.setRestartOffset(mConfig.START_LOCATION); + int reply = client.getReplyCode(); + if (reply == FTPReply.SYNTAX_ERROR_IN_ARGUMENTS) { + client.disconnect(); + fail(mChildCurrentLocation, + "上传失败,FTP没有打开写权限,错误码为:" + reply + ",msg:" + client.getReplyString(), null); + return; + } else if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.COMMAND_OK) { + client.disconnect(); + fail(mChildCurrentLocation, + "上传失败,FTP没有打开写权限,错误码为:" + reply + ",msg:" + client.getReplyString(), null); + return; + } + file = new BufferedRandomAccessFile(mConfig.TEMP_FILE, "rwd", mBufSize); if (mConfig.START_LOCATION != 0) { //file.skipBytes((int) mConfig.START_LOCATION); @@ -82,7 +101,7 @@ class FtpThreadTask extends AbsFtpThreadTask { STATE.isRunning = false; mListener.onComplete(); } - if (STATE.isFail()){ + if (STATE.isFail()) { STATE.isRunning = false; mListener.onFail(false); } diff --git a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java index 090f8cd0..ee215f6f 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -103,7 +103,8 @@ public class CommonUtil { entity.hostName = str; } entity.port = m.group(3); - entity.remotePath = TextUtils.isEmpty(m.group(4)) ? "/" : "/" + m.group(4); + //entity.remotePath = TextUtils.isEmpty(m.group(4)) ? "/" : "/" + m.group(4); + entity.remotePath = TextUtils.isEmpty(m.group(4)) ? "/" : m.group(4); } return entity; } diff --git a/DEV_LOG.md b/DEV_LOG.md index 35476cb2..1c40411b 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,5 +1,5 @@ ## 开发日志 - + v_3.3.12 + + v_3.3.13 - 添加`@Download.onWait、@Upload.onWait、@DownloadGroup.onWait`三个新注解,队列已经满了,继续创建新任务,任务处于等待中,将会执行被这三个注解标志的方法 - app被kill,但是还存在等待中的任务A;第二次重新启动,先创建一个新的任务B,Aria会自动把B放进等待队列中,这时再次创建任务A,会导致重复下载,进度错乱的问题;本版本已修复这个问题 + v_3.3.11 diff --git a/README.md b/README.md index 7b80914a..5227aad2 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,12 @@ Aria有以下特点: compile 'com.arialyy.aria:aria-core:3.3.13' annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.13' ``` +如果出现android support,请将 `compile 'com.arialyy.aria:aria-core:3.3.13'`替换为 +``` +compile('com.arialyy.aria:'){ + exclude group: 'com.android.support' +} +``` 如果你使用的是kotlin,请使用kotlin官方提供的方法配置apt,[kotlin kapt官方配置传送门](https://www.kotlincn.net/docs/reference/kapt.html) *** @@ -97,12 +103,10 @@ protected void onCreate(Bundle savedInstanceState) { ### [更多说明,见WIKI](https://github.com/AriaLyy/Aria/wiki) ### 版本日志 -+ v_3.3.11 - - 添加进度更新间隔api,在`aria_config.xml`配置``或在代码中调用 - `AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setUpdateInterval(3000)`便可以改变进度刷新间隔 - - 修复下载过程中kill进程可能出现的文件错误的问题 https://github.com/AriaLyy/Aria/issues/192 - - 修复http上传的空指针问题 https://github.com/AriaLyy/Aria/issues/193 - - 修复下载地址中含有`'`导致的崩溃问题 https://github.com/AriaLyy/Aria/issues/194 ++ v_3.3.13 + - 添加`@Download.onWait、@Upload.onWait、@DownloadGroup.onWait`三个新注解,队列已经满了,继续创建新任务,任务处于等待中,将会执行被这三个注解标志的方法 + - app被kill,但是还存在等待中的任务A;第二次重新启动,先创建一个新的任务B,Aria会自动把B放进等待队列中,这时再次创建任务A,会导致重复下载,进度错乱的问题;本版本已修复这个问题 + [更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md) diff --git a/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java b/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java index 1b4827e8..500995ae 100644 --- a/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java @@ -38,7 +38,8 @@ public class FtpDownloadActivity extends BaseActivity { //"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe"; //"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk"; //"http://sitcac.daxincf.cn/wp-content/uploads/swift_vido/01/element.mp4_1"; - //"http://120.25.196.56:8000/filereq?id=15692406294&ipncid=105635&client=android&filename=20170819185541.avi"; - //"http://down2.xiaoshuofuwuqi.com/d/file/filetxt/20170608/14/%BA%DA%CE%D7%CA%A6%E1%C8%C6%F0.txt"; - //"http://tinghuaapp.oss-cn-shanghai.aliyuncs.com/20170612201739607815"; - //"http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk"; - //"http://oqcpqqvuf.bkt.clouddn.com/ceshi.txt"; - //"http://down8.androidgame-store.com/201706122321/97967927DD4E53D9905ECAA7874C8128/new/game1/19/45319/com.neuralprisma-2.5.2.174-2000174_1494784835.apk?f=web_1"; - //不支持断点的链接 - //"http://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-"; - //"http://gdown.baidu.com/data/wisegame/0904344dee4a2d92/QQ_718.apk"; - //"http://qudao.5535.cn/one/game.html?game=531&cpsuser=xiaoeryu2"; - "https://bogoe-res.mytbz.com/tbzengsong/If You're Happy.mp3"; + //"http://120.25.196.56:8000/filereq?id=15692406294&ipncid=105635&client=android&filename=20170819185541.avi"; + //"http://down2.xiaoshuofuwuqi.com/d/file/filetxt/20170608/14/%BA%DA%CE%D7%CA%A6%E1%C8%C6%F0.txt"; + //"http://tinghuaapp.oss-cn-shanghai.aliyuncs.com/20170612201739607815"; + //"http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk"; + //"http://oqcpqqvuf.bkt.clouddn.com/ceshi.txt"; + //"http://down8.androidgame-store.com/201706122321/97967927DD4E53D9905ECAA7874C8128/new/game1/19/45319/com.neuralprisma-2.5.2.174-2000174_1494784835.apk?f=web_1"; + //不支持断点的链接 + //"http://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-"; + //"http://gdown.baidu.com/data/wisegame/0904344dee4a2d92/QQ_718.apk"; + //"http://qudao.5535.cn/one/game.html?game=531&cpsuser=xiaoeryu2"; + //"https://bogoe-res.mytbz.com/tbzengsong/If You're Happy.mp3"; + "http://ozr0ucjs5.bkt.clouddn.com/51_box-104_20180131202610.apk"; @Bind(R.id.start) Button mStart; @Bind(R.id.stop) Button mStop; @Bind(R.id.cancel) Button mCancel; @@ -122,7 +118,7 @@ public class SingleTaskActivity extends BaseActivity { return true; } - @Download.onWait void onWait(DownloadTask task){ + @Download.onWait void onWait(DownloadTask task) { Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName()); } @@ -177,12 +173,12 @@ public class SingleTaskActivity extends BaseActivity { mCancel.setEnabled(false); setBtState(true); getBinding().setSpeed(""); + L.d(TAG, "path ==> " + task.getDownloadEntity().getDownloadPath()); L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath()))); L.d(TAG, "data ==> " + Aria.download(this).getDownloadEntity(DOWNLOAD_URL)); } - @Download.onNoSupportBreakPoint - public void onNoSupportBreakPoint(DownloadTask task) { + @Download.onNoSupportBreakPoint public void onNoSupportBreakPoint(DownloadTask task) { T.showShort(SingleTaskActivity.this, "该下载链接不支持断点"); } @@ -221,12 +217,14 @@ public class SingleTaskActivity extends BaseActivity { } } - private void startD(){ + private void startD() { //Aria.get(this).setLogLevel(ALog.LOG_CLOSE); //Aria.download(this).load("aaaa.apk"); Map map = new HashMap<>(); - map.put("User-Agent", "Mozilla/5.0 (Linux; Android 4.4.4; Nexus 5 Build/KTU84P; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 Mobile MQQBrowser/6.2 TBS/043722 Safari/537.36"); - map.put("Cookie", "BAIDUID=DFC7EF42C60AD1ACF0BA94389AA67F13:FG=1; H_WISE_SIDS=121192_104493_114745_121434_119046_100098_120212_121140_118882_118858_118850_118820_118792_121254_121534_121214_117588_117242_117431_119974_120597_121043_121422_120943_121175_121272_117552_120482_121013_119962_119145_120851_120841_120034_121325_116407_121109_120654_110085_120708; PSINO=7; BDORZ=AE84CDB3A529C0F8A2B9DCDD1D18B695"); + map.put("User-Agent", + "Mozilla/5.0 (Linux; Android 4.4.4; Nexus 5 Build/KTU84P; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 Mobile MQQBrowser/6.2 TBS/043722 Safari/537.36"); + map.put("Cookie", + "BAIDUID=DFC7EF42C60AD1ACF0BA94389AA67F13:FG=1; H_WISE_SIDS=121192_104493_114745_121434_119046_100098_120212_121140_118882_118858_118850_118820_118792_121254_121534_121214_117588_117242_117431_119974_120597_121043_121422_120943_121175_121272_117552_120482_121013_119962_119145_120851_120841_120034_121325_116407_121109_120654_110085_120708; PSINO=7; BDORZ=AE84CDB3A529C0F8A2B9DCDD1D18B695"); Aria.download(SingleTaskActivity.this) .load(DOWNLOAD_URL) //.addHeader("groupName", "value") @@ -234,8 +232,8 @@ public class SingleTaskActivity extends BaseActivity { //.setRequestMode(RequestEnum.POST) .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1.apk") .resetState() - //.start(); - .add(); + .start(); + //.add(); } @Override protected void onDestroy() {