This commit is contained in:
@@ -377,7 +377,7 @@ import org.xml.sax.SAXException;
|
|||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
String md5Code = CommonUtil.getFileMD5(xmlFile);
|
String md5Code = CommonUtil.getFileMD5(xmlFile);
|
||||||
File file = new File(APP.getFilesDir().getPath() + "temp.xml");
|
File file = new File(APP.getFilesDir().getPath() + "/temp.xml");
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ class ConfigHelper extends DefaultHandler {
|
|||||||
|
|
||||||
String value = attributes.getValue("value");
|
String value = attributes.getValue("value");
|
||||||
switch (qName) {
|
switch (qName) {
|
||||||
case "useVirtualFile":
|
case "openDynamicFile":
|
||||||
loadUseVirtualFile(value);
|
loadOpenDynamicFile(value);
|
||||||
break;
|
break;
|
||||||
case "threadNum":
|
case "threadNum":
|
||||||
loadThreadNum(value);
|
loadThreadNum(value);
|
||||||
@@ -117,9 +117,9 @@ class ConfigHelper extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadUseVirtualFile(String value) {
|
private void loadOpenDynamicFile(String value) {
|
||||||
if (isDownloadConfig) {
|
if (isDownloadConfig) {
|
||||||
mDownloadConfig.useVirtualFile = checkBoolean(value) ? Boolean.valueOf(value) : false;
|
mDownloadConfig.openDynamicFile = checkBoolean(value) ? Boolean.valueOf(value) : false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String mod;
|
String mod;
|
||||||
// TODO: 2018/4/12 配置文件不存在,是否会出现wait获取不到 ?
|
|
||||||
int maxTaskNum = mQueue.getMaxTaskNum();
|
int maxTaskNum = mQueue.getMaxTaskNum();
|
||||||
AriaManager manager = AriaManager.getInstance(AriaManager.APP);
|
AriaManager manager = AriaManager.getInstance(AriaManager.APP);
|
||||||
if (isDownloadCmd) {
|
if (isDownloadCmd) {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import com.arialyy.aria.core.inf.IEventListener;
|
|||||||
import com.arialyy.aria.orm.DbEntity;
|
import com.arialyy.aria.orm.DbEntity;
|
||||||
import com.arialyy.aria.util.ALog;
|
import com.arialyy.aria.util.ALog;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
|
import com.arialyy.aria.util.DbHelper;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -241,14 +242,11 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
|||||||
if (mConfigFile.exists()) {
|
if (mConfigFile.exists()) {
|
||||||
convertDb();
|
convertDb();
|
||||||
} else {
|
} else {
|
||||||
List<RecordWrapper> records =
|
mRecord = DbHelper.getTaskRecord(mTaskEntity.getKey());
|
||||||
DbEntity.findRelationData(RecordWrapper.class, "TaskRecord.filePath=?",
|
if (mRecord == null) {
|
||||||
mTaskEntity.getKey());
|
|
||||||
if (records == null || records.size() == 0) {
|
|
||||||
initRecord();
|
initRecord();
|
||||||
mTaskEntity.setNewTask(true);
|
mTaskEntity.setNewTask(true);
|
||||||
} else {
|
} else {
|
||||||
mRecord = records.get(0).taskRecord;
|
|
||||||
if (mRecord.threadRecords == null || mRecord.threadRecords.isEmpty()) {
|
if (mRecord.threadRecords == null || mRecord.threadRecords.isEmpty()) {
|
||||||
initRecord();
|
initRecord();
|
||||||
mTaskEntity.setNewTask(true);
|
mTaskEntity.setNewTask(true);
|
||||||
@@ -336,8 +334,8 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
|||||||
mRecord.filePath = mTaskEntity.getKey();
|
mRecord.filePath = mTaskEntity.getKey();
|
||||||
mRecord.threadRecords = new ArrayList<>();
|
mRecord.threadRecords = new ArrayList<>();
|
||||||
mRecord.isGroupRecord = mTaskEntity.getEntity().isGroupChild();
|
mRecord.isGroupRecord = mTaskEntity.getEntity().isGroupChild();
|
||||||
mRecord.isUseVirtualFile =
|
mRecord.isOpenDynamicFile =
|
||||||
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().isUseVirtualFile();
|
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().isOpenDynamicFile();
|
||||||
if (mRecord.isGroupRecord) {
|
if (mRecord.isGroupRecord) {
|
||||||
if (mTaskEntity.getEntity() instanceof DownloadEntity) {
|
if (mTaskEntity.getEntity() instanceof DownloadEntity) {
|
||||||
mRecord.dGroupName = ((DownloadEntity) mTaskEntity.getEntity()).getGroupName();
|
mRecord.dGroupName = ((DownloadEntity) mTaskEntity.getEntity()).getGroupName();
|
||||||
|
|||||||
@@ -16,12 +16,14 @@
|
|||||||
package com.arialyy.aria.core.common;
|
package com.arialyy.aria.core.common;
|
||||||
|
|
||||||
import com.arialyy.aria.core.AriaManager;
|
import com.arialyy.aria.core.AriaManager;
|
||||||
|
import com.arialyy.aria.util.ALog;
|
||||||
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static java.util.Collections.unmodifiableSet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Aria.Lao on 2017/7/10.
|
* Created by Aria.Lao on 2017/7/10.
|
||||||
* 代理参数获取
|
* 代理参数获取
|
||||||
@@ -45,8 +47,19 @@ public class ProxyHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
|
List<String> classes = CommonUtil.getClassName(AriaManager.APP, "com.arialyy.aria");
|
||||||
|
for (String className : classes) {
|
||||||
|
if (!className.startsWith("com.arialyy.aria.ProxyClassCounter")){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ALog.d("TAG", className);
|
||||||
|
count(className);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void count(String className) {
|
||||||
try {
|
try {
|
||||||
Class clazz = Class.forName("com.arialyy.aria.ProxyClassCounter");
|
Class clazz = Class.forName(className);
|
||||||
Method download = clazz.getMethod("getDownloadCounter");
|
Method download = clazz.getMethod("getDownloadCounter");
|
||||||
Method downloadGroup = clazz.getMethod("getDownloadGroupCounter");
|
Method downloadGroup = clazz.getMethod("getDownloadGroupCounter");
|
||||||
Method downloadGroupSub = clazz.getMethod("getDownloadGroupSubCounter");
|
Method downloadGroupSub = clazz.getMethod("getDownloadGroupSubCounter");
|
||||||
@@ -54,19 +67,31 @@ public class ProxyHelper {
|
|||||||
Object object = clazz.newInstance();
|
Object object = clazz.newInstance();
|
||||||
Object dc = download.invoke(object);
|
Object dc = download.invoke(object);
|
||||||
if (dc != null) {
|
if (dc != null) {
|
||||||
downloadCounter = unmodifiableSet((Set<String>) dc);
|
if (downloadCounter == null) {
|
||||||
|
downloadCounter = new HashSet<>();
|
||||||
|
}
|
||||||
|
downloadCounter.addAll((Set<String>) dc);
|
||||||
}
|
}
|
||||||
Object dgc = downloadGroup.invoke(object);
|
Object dgc = downloadGroup.invoke(object);
|
||||||
if (dgc != null) {
|
if (dgc != null) {
|
||||||
downloadGroupCounter = unmodifiableSet((Set<String>) dgc);
|
if (downloadGroupCounter == null) {
|
||||||
|
downloadGroupCounter = new HashSet<>();
|
||||||
|
}
|
||||||
|
downloadGroupCounter.addAll((Set<String>) dgc);
|
||||||
}
|
}
|
||||||
Object dgsc = downloadGroupSub.invoke(object);
|
Object dgsc = downloadGroupSub.invoke(object);
|
||||||
if (dgsc != null){
|
if (dgsc != null) {
|
||||||
downloadGroupSubCounter = unmodifiableSet((Set<? extends String>) dgsc);
|
if (downloadGroupSubCounter == null) {
|
||||||
|
downloadGroupSubCounter = new HashSet<>();
|
||||||
|
}
|
||||||
|
downloadGroupSubCounter.addAll((Set<String>) dgsc);
|
||||||
}
|
}
|
||||||
Object uc = upload.invoke(object);
|
Object uc = upload.invoke(object);
|
||||||
if (uc != null) {
|
if (uc != null) {
|
||||||
uploadCounter = unmodifiableSet((Set<String>) uc);
|
if (uploadCounter == null) {
|
||||||
|
uploadCounter = new HashSet<>();
|
||||||
|
}
|
||||||
|
uploadCounter.addAll((Set<String>) uc);
|
||||||
}
|
}
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -78,5 +78,5 @@ public class TaskRecord extends DbEntity {
|
|||||||
* 是否是使用虚拟文件下载的
|
* 是否是使用虚拟文件下载的
|
||||||
* {@code true}是,{@code false}不是
|
* {@code true}是,{@code false}不是
|
||||||
*/
|
*/
|
||||||
public boolean isUseVirtualFile = false;
|
public boolean isOpenDynamicFile = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,10 +150,9 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
|
|||||||
mEntity.setDownloadPath(filePath);
|
mEntity.setDownloadPath(filePath);
|
||||||
mEntity.setFileName(newFile.getName());
|
mEntity.setFileName(newFile.getName());
|
||||||
mTaskEntity.setKey(filePath);
|
mTaskEntity.setKey(filePath);
|
||||||
//mTaskEntity.update();
|
|
||||||
if (oldFile.exists()) {
|
if (oldFile.exists()) {
|
||||||
oldFile.renameTo(newFile);
|
oldFile.renameTo(newFile);
|
||||||
CommonUtil.renameDownloadConfig(oldFile.getName(), newFile.getName());
|
CommonUtil.modifyTaskRecord(oldFile.getPath(), newFile.getPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> {
|
|||||||
if (oldFile.exists()) {
|
if (oldFile.exists()) {
|
||||||
oldFile.renameTo(new File(newPath));
|
oldFile.renameTo(new File(newPath));
|
||||||
}
|
}
|
||||||
CommonUtil.renameDownloadConfig(oldFile.getName(), newName);
|
CommonUtil.modifyTaskRecord(oldFile.getPath(), newPath);
|
||||||
entity.setDownloadPath(newPath);
|
entity.setDownloadPath(newPath);
|
||||||
taskEntity.setKey(newPath);
|
taskEntity.setKey(newPath);
|
||||||
entity.setFileName(newName);
|
entity.setFileName(newName);
|
||||||
|
|||||||
@@ -73,6 +73,10 @@ public class DownloadTaskEntity extends AbsNormalTaskEntity<DownloadEntity> {
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public void setKey(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
@@ -109,7 +113,5 @@ public class DownloadTaskEntity extends AbsNormalTaskEntity<DownloadEntity> {
|
|||||||
isGroupTask = groupTask;
|
isGroupTask = groupTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKey(String key) {
|
|
||||||
this.key = key;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class Downloader extends AbsFileer<DownloadEntity, DownloadTaskEntity> {
|
|||||||
mEntity.getFileSize() <= SUB_LEN
|
mEntity.getFileSize() <= SUB_LEN
|
||||||
|| mTaskEntity.getRequestType() == AbsTaskEntity.D_FTP_DIR
|
|| mTaskEntity.getRequestType() == AbsTaskEntity.D_FTP_DIR
|
||||||
|| mTaskEntity.getRequestType() == AbsTaskEntity.DG_HTTP
|
|| mTaskEntity.getRequestType() == AbsTaskEntity.DG_HTTP
|
||||||
|| mRecord.isUseVirtualFile
|
|| mRecord.isOpenDynamicFile
|
||||||
? 1
|
? 1
|
||||||
: AriaManager.getInstance(mContext).getDownloadConfig().getThreadNum();
|
: AriaManager.getInstance(mContext).getDownloadConfig().getThreadNum();
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ class Downloader extends AbsFileer<DownloadEntity, DownloadTaskEntity> {
|
|||||||
try {
|
try {
|
||||||
file = new BufferedRandomAccessFile(new File(mTempFile.getPath()), "rwd", 8192);
|
file = new BufferedRandomAccessFile(new File(mTempFile.getPath()), "rwd", 8192);
|
||||||
//设置文件长度
|
//设置文件长度
|
||||||
file.setLength(mRecord.isUseVirtualFile ? 1 : mEntity.getFileSize());
|
file.setLength(mRecord.isOpenDynamicFile ? 1 : mEntity.getFileSize());
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
failDownload("下载失败【downloadUrl:"
|
failDownload("下载失败【downloadUrl:"
|
||||||
|
|||||||
@@ -35,6 +35,11 @@ import org.apache.commons.net.ftp.FTPReply;
|
|||||||
*/
|
*/
|
||||||
class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity> {
|
class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity> {
|
||||||
private final String TAG = "FtpThreadTask";
|
private final String TAG = "FtpThreadTask";
|
||||||
|
private boolean isOpenDynamicFile;
|
||||||
|
/**
|
||||||
|
* 2M的动态长度
|
||||||
|
*/
|
||||||
|
private final int LEN_INTERVAL = 1024 * 1024 * 2;
|
||||||
|
|
||||||
FtpThreadTask(StateConstance constance, IDownloadListener listener,
|
FtpThreadTask(StateConstance constance, IDownloadListener listener,
|
||||||
SubThreadConfig<DownloadTaskEntity> downloadInfo) {
|
SubThreadConfig<DownloadTaskEntity> downloadInfo) {
|
||||||
@@ -44,6 +49,7 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
|
|||||||
mReadTimeOut = manager.getDownloadConfig().getIOTimeOut();
|
mReadTimeOut = manager.getDownloadConfig().getIOTimeOut();
|
||||||
mBufSize = manager.getDownloadConfig().getBuffSize();
|
mBufSize = manager.getDownloadConfig().getBuffSize();
|
||||||
isNotNetRetry = manager.getDownloadConfig().isNotNetRetry();
|
isNotNetRetry = manager.getDownloadConfig().isNotNetRetry();
|
||||||
|
isOpenDynamicFile = STATE.TASK_RECORD.isOpenDynamicFile;
|
||||||
setMaxSpeed(manager.getDownloadConfig().getMaxSpeed());
|
setMaxSpeed(manager.getDownloadConfig().getMaxSpeed());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,6 +104,11 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (mSleepTime > 0) Thread.sleep(mSleepTime);
|
if (mSleepTime > 0) Thread.sleep(mSleepTime);
|
||||||
|
if (isOpenDynamicFile) {
|
||||||
|
file.setLength(
|
||||||
|
STATE.CURRENT_LOCATION + LEN_INTERVAL < mEntity.getFileSize() ? STATE.CURRENT_LOCATION
|
||||||
|
+ LEN_INTERVAL : mEntity.getFileSize());
|
||||||
|
}
|
||||||
if (mChildCurrentLocation + len >= mConfig.END_LOCATION) {
|
if (mChildCurrentLocation + len >= mConfig.END_LOCATION) {
|
||||||
len = (int) (mConfig.END_LOCATION - mChildCurrentLocation);
|
len = (int) (mConfig.END_LOCATION - mChildCurrentLocation);
|
||||||
file.write(buffer, 0, len);
|
file.write(buffer, 0, len);
|
||||||
|
|||||||
@@ -179,7 +179,6 @@ class HttpFileInfoThread implements Runnable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File oldFile = new File(mEntity.getDownloadPath());
|
File oldFile = new File(mEntity.getDownloadPath());
|
||||||
String oldName = oldFile.getName();
|
|
||||||
String newPath = oldFile.getParent() + "/" + newName;
|
String newPath = oldFile.getParent() + "/" + newName;
|
||||||
if (oldFile.exists()) {
|
if (oldFile.exists()) {
|
||||||
oldFile.renameTo(new File(newPath));
|
oldFile.renameTo(new File(newPath));
|
||||||
@@ -187,7 +186,6 @@ class HttpFileInfoThread implements Runnable {
|
|||||||
mEntity.setFileName(newName);
|
mEntity.setFileName(newName);
|
||||||
mEntity.setDownloadPath(newPath);
|
mEntity.setDownloadPath(newPath);
|
||||||
mTaskEntity.setKey(newPath);
|
mTaskEntity.setKey(newPath);
|
||||||
CommonUtil.renameDownloadConfig(oldName, newName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
|||||||
* 2M的动态长度
|
* 2M的动态长度
|
||||||
*/
|
*/
|
||||||
private final int LEN_INTERVAL = 1024 * 1024 * 2;
|
private final int LEN_INTERVAL = 1024 * 1024 * 2;
|
||||||
private boolean useVirtualFile = false;
|
private boolean isOpenDynamicFile;
|
||||||
|
|
||||||
HttpThreadTask(StateConstance constance, IDownloadListener listener,
|
HttpThreadTask(StateConstance constance, IDownloadListener listener,
|
||||||
SubThreadConfig<DownloadTaskEntity> downloadInfo) {
|
SubThreadConfig<DownloadTaskEntity> downloadInfo) {
|
||||||
@@ -52,7 +52,7 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
|||||||
mReadTimeOut = manager.getDownloadConfig().getIOTimeOut();
|
mReadTimeOut = manager.getDownloadConfig().getIOTimeOut();
|
||||||
mBufSize = manager.getDownloadConfig().getBuffSize();
|
mBufSize = manager.getDownloadConfig().getBuffSize();
|
||||||
isNotNetRetry = manager.getDownloadConfig().isNotNetRetry();
|
isNotNetRetry = manager.getDownloadConfig().isNotNetRetry();
|
||||||
useVirtualFile = STATE.TASK_RECORD.isUseVirtualFile;
|
isOpenDynamicFile = STATE.TASK_RECORD.isOpenDynamicFile;
|
||||||
setMaxSpeed(manager.getDownloadConfig().getMaxSpeed());
|
setMaxSpeed(manager.getDownloadConfig().getMaxSpeed());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
|||||||
if (mSleepTime > 0) {
|
if (mSleepTime > 0) {
|
||||||
Thread.sleep(mSleepTime);
|
Thread.sleep(mSleepTime);
|
||||||
}
|
}
|
||||||
if (useVirtualFile) {
|
if (isOpenDynamicFile) {
|
||||||
file.setLength(
|
file.setLength(
|
||||||
STATE.CURRENT_LOCATION + LEN_INTERVAL < mEntity.getFileSize() ? STATE.CURRENT_LOCATION
|
STATE.CURRENT_LOCATION + LEN_INTERVAL < mEntity.getFileSize() ? STATE.CURRENT_LOCATION
|
||||||
+ LEN_INTERVAL : mEntity.getFileSize());
|
+ LEN_INTERVAL : mEntity.getFileSize());
|
||||||
|
|||||||
@@ -137,6 +137,8 @@ public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity {
|
|||||||
|
|
||||||
public abstract String getKey();
|
public abstract String getKey();
|
||||||
|
|
||||||
|
public abstract void setKey(String key);
|
||||||
|
|
||||||
@Override public void update() {
|
@Override public void update() {
|
||||||
if (getEntity() != null) {
|
if (getEntity() != null) {
|
||||||
getEntity().update();
|
getEntity().update();
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ public class DownloadGroupTaskQueue
|
|||||||
&& mExecutePool.getTask(entity.getEntity().getKey()) == null) {
|
&& mExecutePool.getTask(entity.getEntity().getKey()) == null) {
|
||||||
task = (DownloadGroupTask) TaskFactory.getInstance()
|
task = (DownloadGroupTask) TaskFactory.getInstance()
|
||||||
.createTask(targetName, entity, DownloadGroupSchedulers.getInstance());
|
.createTask(targetName, entity, DownloadGroupSchedulers.getInstance());
|
||||||
entity.setKey(entity.getEntity().getGroupName());
|
|
||||||
mCachePool.putTask(task);
|
mCachePool.putTask(task);
|
||||||
} else {
|
} else {
|
||||||
ALog.w(TAG, "任务已存在");
|
ALog.w(TAG, "任务已存在");
|
||||||
|
|||||||
@@ -123,7 +123,6 @@ public class DownloadTaskQueue extends AbsTaskQueue<DownloadTask, DownloadTaskEn
|
|||||||
&& mExecutePool.getTask(entity.getEntity().getKey()) == null) {
|
&& mExecutePool.getTask(entity.getEntity().getKey()) == null) {
|
||||||
task = (DownloadTask) TaskFactory.getInstance()
|
task = (DownloadTask) TaskFactory.getInstance()
|
||||||
.createTask(target, entity, DownloadSchedulers.getInstance());
|
.createTask(target, entity, DownloadSchedulers.getInstance());
|
||||||
entity.setKey(entity.getEntity().getDownloadPath());
|
|
||||||
mCachePool.putTask(task);
|
mCachePool.putTask(task);
|
||||||
} else {
|
} else {
|
||||||
ALog.w(TAG, "任务已存在");
|
ALog.w(TAG, "任务已存在");
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UploadTaskEntity>
|
|||||||
&& mExecutePool.getTask(entity.getEntity().getKey()) == null) {
|
&& mExecutePool.getTask(entity.getEntity().getKey()) == null) {
|
||||||
task = (UploadTask) TaskFactory.getInstance()
|
task = (UploadTask) TaskFactory.getInstance()
|
||||||
.createTask(targetName, entity, UploadSchedulers.getInstance());
|
.createTask(targetName, entity, UploadSchedulers.getInstance());
|
||||||
entity.setKey(entity.getEntity().getFilePath());
|
|
||||||
mCachePool.putTask(task);
|
mCachePool.putTask(task);
|
||||||
} else {
|
} else {
|
||||||
ALog.w(TAG, "任务已存在");
|
ALog.w(TAG, "任务已存在");
|
||||||
|
|||||||
@@ -18,17 +18,18 @@ package com.arialyy.aria.core.upload.uploader;
|
|||||||
import com.arialyy.aria.core.common.AbsFtpInfoThread;
|
import com.arialyy.aria.core.common.AbsFtpInfoThread;
|
||||||
import com.arialyy.aria.core.common.CompleteInfo;
|
import com.arialyy.aria.core.common.CompleteInfo;
|
||||||
import com.arialyy.aria.core.common.OnFileInfoCallback;
|
import com.arialyy.aria.core.common.OnFileInfoCallback;
|
||||||
|
import com.arialyy.aria.core.common.TaskRecord;
|
||||||
|
import com.arialyy.aria.core.common.ThreadRecord;
|
||||||
import com.arialyy.aria.core.upload.UploadEntity;
|
import com.arialyy.aria.core.upload.UploadEntity;
|
||||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||||
import com.arialyy.aria.util.ALog;
|
import com.arialyy.aria.util.ALog;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.DbHelper;
|
||||||
import java.io.File;
|
import java.util.ArrayList;
|
||||||
import java.util.Properties;
|
|
||||||
import org.apache.commons.net.ftp.FTPFile;
|
import org.apache.commons.net.ftp.FTPFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Aria.Lao on 2017/9/26.
|
* Created by Aria.Lao on 2017/9/26.
|
||||||
* 单任务远程服务器文件信息
|
* 单任务上传远程服务器文件信息
|
||||||
*/
|
*/
|
||||||
class FtpFileInfoThread extends AbsFtpInfoThread<UploadEntity, UploadTaskEntity> {
|
class FtpFileInfoThread extends AbsFtpInfoThread<UploadEntity, UploadTaskEntity> {
|
||||||
private static final String TAG = "FtpUploadFtpFileInfoThread";
|
private static final String TAG = "FtpUploadFtpFileInfoThread";
|
||||||
@@ -67,16 +68,27 @@ class FtpFileInfoThread extends AbsFtpInfoThread<UploadEntity, UploadTaskEntity>
|
|||||||
+ "尝试从位置:"
|
+ "尝试从位置:"
|
||||||
+ (ftpFile.getSize() - 1)
|
+ (ftpFile.getSize() - 1)
|
||||||
+ "开始上传");
|
+ "开始上传");
|
||||||
File configFile = new File(CommonUtil.getFileConfigPath(false, mEntity.getFileName()));
|
|
||||||
Properties pro = CommonUtil.loadConfig(configFile);
|
|
||||||
String key = mEntity.getFileName() + "_record_" + 0;
|
|
||||||
mTaskEntity.setNewTask(false);
|
mTaskEntity.setNewTask(false);
|
||||||
long oldRecord = Long.parseLong(pro.getProperty(key, "0"));
|
|
||||||
if (oldRecord == 0 || oldRecord != ftpFile.getSize()) {
|
// 修改记录
|
||||||
//修改本地保存的停止地址为服务器上对应文件的大小
|
TaskRecord record = DbHelper.getTaskRecord(mTaskEntity.getKey());
|
||||||
pro.setProperty(key, (ftpFile.getSize() - 1) + "");
|
if (record == null) {
|
||||||
CommonUtil.saveConfig(configFile, pro);
|
record = new TaskRecord();
|
||||||
|
record.fileName = mEntity.getFileName();
|
||||||
|
record.filePath = mTaskEntity.getKey();
|
||||||
|
record.threadRecords = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
ThreadRecord threadRecord;
|
||||||
|
if (record.threadRecords == null || record.threadRecords.isEmpty()) {
|
||||||
|
threadRecord = new ThreadRecord();
|
||||||
|
threadRecord.key = record.filePath;
|
||||||
|
} else {
|
||||||
|
threadRecord = record.threadRecords.get(0);
|
||||||
|
}
|
||||||
|
//修改本地保存的停止地址为服务器上对应文件的大小
|
||||||
|
threadRecord.startLocation = ftpFile.getSize() - 1;
|
||||||
|
record.save();
|
||||||
|
threadRecord.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class DBConfig {
|
|||||||
/*adb pull /mnt/sdcard/Android/data/com.arialyy.simple/files/DB/AriaLyyDb d:/db*/
|
/*adb pull /mnt/sdcard/Android/data/com.arialyy.simple/files/DB/AriaLyyDb d:/db*/
|
||||||
static Map<String, Class> mapping = new HashMap<>();
|
static Map<String, Class> mapping = new HashMap<>();
|
||||||
static String DB_NAME;
|
static String DB_NAME;
|
||||||
static int VERSION = 32;
|
static int VERSION = 33;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否将数据库保存在Sd卡,{@code true} 是
|
* 是否将数据库保存在Sd卡,{@code true} 是
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import com.arialyy.aria.core.inf.AbsNormalEntity;
|
|||||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||||
import com.arialyy.aria.core.upload.UploadEntity;
|
import com.arialyy.aria.core.upload.UploadEntity;
|
||||||
import com.arialyy.aria.orm.DbEntity;
|
import com.arialyy.aria.orm.DbEntity;
|
||||||
|
import dalvik.system.DexFile;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@@ -57,9 +58,8 @@ import java.security.MessageDigest;
|
|||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Enumeration;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
@@ -74,6 +74,39 @@ import java.util.regex.Pattern;
|
|||||||
public class CommonUtil {
|
public class CommonUtil {
|
||||||
private static final String TAG = "CommonUtil";
|
private static final String TAG = "CommonUtil";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取某包下所有类
|
||||||
|
*
|
||||||
|
* @param packageName 包名
|
||||||
|
* @return 类的完整名称
|
||||||
|
*/
|
||||||
|
public static List<String> getClassName(Context context, String packageName) {
|
||||||
|
List<String> classNameList = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
String pPath = context.getPackageCodePath();
|
||||||
|
File dir = new File(pPath).getParentFile();
|
||||||
|
String dPath = dir.getPath();
|
||||||
|
for (String path : dir.list()) {
|
||||||
|
String fPath = dPath + "/" + path;
|
||||||
|
if (!fPath.endsWith(".apk")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ALog.d(TAG, fPath);
|
||||||
|
DexFile df = new DexFile(fPath);//通过DexFile查找当前的APK中可执行文件
|
||||||
|
Enumeration<String> enumeration = df.entries();//获取df中的元素 这里包含了所有可执行的类名 该类名包含了包名+类名的方式
|
||||||
|
while (enumeration.hasMoreElements()) {//遍历
|
||||||
|
String className = enumeration.nextElement();
|
||||||
|
if (className.contains(packageName)) {//在当前所有可执行的类里面查找包含有该包名的所有类
|
||||||
|
classNameList.add(className);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return classNameList;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 拦截window.location.replace数据
|
* 拦截window.location.replace数据
|
||||||
*
|
*
|
||||||
@@ -469,9 +502,10 @@ public class CommonUtil {
|
|||||||
public static void createFileFormInputStream(InputStream is, String path) {
|
public static void createFileFormInputStream(InputStream is, String path) {
|
||||||
try {
|
try {
|
||||||
FileOutputStream fos = new FileOutputStream(path);
|
FileOutputStream fos = new FileOutputStream(path);
|
||||||
byte[] buf = new byte[1376];
|
byte[] buf = new byte[1024];
|
||||||
while (is.read(buf) > 0) {
|
int len;
|
||||||
fos.write(buf, 0, buf.length);
|
while ((len = is.read(buf)) > 0) {
|
||||||
|
fos.write(buf, 0, len);
|
||||||
}
|
}
|
||||||
is.close();
|
is.close();
|
||||||
fos.flush();
|
fos.flush();
|
||||||
@@ -845,60 +879,28 @@ public class CommonUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重命名下载配置文件
|
* 更新任务记录
|
||||||
* 如果旧的配置文件名不存在,则使用新的配置文件名新创建一个文件,否则将旧的配置文件重命名为新的位置文件名。
|
|
||||||
* 除了重命名配置文件名外,还会将文件中的记录重命名为新的记录,如果没有记录,则不做处理
|
|
||||||
*
|
*
|
||||||
* @param oldName 旧的下载文件名
|
* @param oldPath 旧的文件路径
|
||||||
* @param newName 新的下载文件名
|
* @param newPath 新的文件路径
|
||||||
*/
|
*/
|
||||||
public static void renameDownloadConfig(String oldName, String newName) {
|
public static void modifyTaskRecord(String oldPath, String newPath) {
|
||||||
renameConfig(true, oldName, newName);
|
if (oldPath.equals(newPath)) {
|
||||||
}
|
ALog.w(TAG, "修改任务记录失败,新文件路径和旧文件路径一致");
|
||||||
|
return;
|
||||||
/**
|
|
||||||
* 重命名上传配置文件
|
|
||||||
* 如果旧的配置文件名不存在,则使用新的配置文件名新创建一个文件,否则将旧的配置文件重命名为新的位置文件名。
|
|
||||||
* 除了重命名配置文件名外,还会将文件中的记录重命名为新的记录,如果没有记录,则不做处理
|
|
||||||
*
|
|
||||||
* @param oldName 旧的上传文件名
|
|
||||||
* @param newName 新的上传文件名
|
|
||||||
*/
|
|
||||||
public static void renameUploadConfig(String oldName, String newName) {
|
|
||||||
renameConfig(false, oldName, newName);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void renameConfig(boolean isDownload, String oldName, String newName) {
|
|
||||||
if (oldName.equals(newName)) return;
|
|
||||||
File oldFile = new File(getFileConfigPath(isDownload, oldName));
|
|
||||||
File newFile = new File(getFileConfigPath(isDownload, oldName));
|
|
||||||
if (!oldFile.exists()) {
|
|
||||||
createFile(newFile.getPath());
|
|
||||||
} else {
|
|
||||||
Properties pro = CommonUtil.loadConfig(oldFile);
|
|
||||||
if (!pro.isEmpty()) {
|
|
||||||
Set<Object> keys = pro.keySet();
|
|
||||||
Set<String> newKeys = new LinkedHashSet<>();
|
|
||||||
Set<String> values = new LinkedHashSet<>();
|
|
||||||
for (Object key : keys) {
|
|
||||||
String oldKey = String.valueOf(key);
|
|
||||||
if (oldKey.contains(oldName)) {
|
|
||||||
values.add(pro.getProperty(oldKey));
|
|
||||||
newKeys.add(oldKey.replace(oldName, newName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pro.clear();
|
|
||||||
Iterator<String> next = values.iterator();
|
|
||||||
for (String key : newKeys) {
|
|
||||||
pro.setProperty(key, next.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
CommonUtil.saveConfig(oldFile, pro);
|
|
||||||
}
|
|
||||||
|
|
||||||
oldFile.renameTo(newFile);
|
|
||||||
}
|
}
|
||||||
|
File oldFile = new File(oldPath);
|
||||||
|
if (!oldFile.exists()) {
|
||||||
|
ALog.w(TAG, "修改任务记录失败,文件【" + oldPath + "】不存在");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TaskRecord record = DbHelper.getTaskRecord(oldPath);
|
||||||
|
if (record == null) {
|
||||||
|
ALog.w(TAG, "修改任务记录失败,文件【" + oldPath + "】对应的任务记录不存在");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
record.filePath = newPath;
|
||||||
|
record.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
42
Aria/src/main/java/com/arialyy/aria/util/DbHelper.java
Normal file
42
Aria/src/main/java/com/arialyy/aria/util/DbHelper.java
Normal file
@@ -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.util;
|
||||||
|
|
||||||
|
import com.arialyy.aria.core.common.RecordWrapper;
|
||||||
|
import com.arialyy.aria.core.common.TaskRecord;
|
||||||
|
import com.arialyy.aria.orm.DbEntity;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库帮助类
|
||||||
|
*/
|
||||||
|
public class DbHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取任务记录
|
||||||
|
*
|
||||||
|
* @param filePath 文件地址
|
||||||
|
* @return 没有记录返回null,有记录则返回任务记录
|
||||||
|
*/
|
||||||
|
public static TaskRecord getTaskRecord(String filePath) {
|
||||||
|
List<RecordWrapper> records =
|
||||||
|
DbEntity.findRelationData(RecordWrapper.class, "TaskRecord.filePath=?", filePath);
|
||||||
|
if (records == null || records.size() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return records.get(0).taskRecord;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,6 +27,7 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
import javax.annotation.processing.Filer;
|
import javax.annotation.processing.Filer;
|
||||||
import javax.lang.model.element.Modifier;
|
import javax.lang.model.element.Modifier;
|
||||||
|
|
||||||
@@ -49,7 +50,8 @@ final class CountFiler {
|
|||||||
void createCountFile() throws IOException {
|
void createCountFile() throws IOException {
|
||||||
Set<String> keys = mPbUtil.getListenerClass().keySet();
|
Set<String> keys = mPbUtil.getListenerClass().keySet();
|
||||||
if (keys.size() == 0) return;
|
if (keys.size() == 0) return;
|
||||||
TypeSpec.Builder builder = TypeSpec.classBuilder(ProxyConstance.PROXY_COUNTER_NAME)
|
TypeSpec.Builder builder = TypeSpec.classBuilder(
|
||||||
|
ProxyConstance.PROXY_COUNTER_NAME + UUID.randomUUID().toString().replace("-", ""))
|
||||||
.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||||
|
|
||||||
FieldSpec mappingField = FieldSpec.builder(
|
FieldSpec mappingField = FieldSpec.builder(
|
||||||
|
|||||||
@@ -15,8 +15,8 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme.NoActionBar">
|
android:theme="@style/AppTheme.NoActionBar">
|
||||||
<!--android:name=".test.TestGroupActivity"-->
|
<!--android:name=".test.TestGroupActivity"-->
|
||||||
<!--android:name=".test.TestActivity"-->
|
|
||||||
<!--android:name=".MainActivity"-->
|
<!--android:name=".MainActivity"-->
|
||||||
|
<!--android:name=".test.TestActivity"-->
|
||||||
<activity
|
<activity
|
||||||
android:name=".test.AnyRunActivity"
|
android:name=".test.AnyRunActivity"
|
||||||
android:label="@string/app_name">
|
android:label="@string/app_name">
|
||||||
|
|||||||
@@ -11,12 +11,12 @@
|
|||||||
|
|
||||||
<!--注意,修改该配置文件中的属性会覆盖代码中所设置的属性-->
|
<!--注意,修改该配置文件中的属性会覆盖代码中所设置的属性-->
|
||||||
<download>
|
<download>
|
||||||
<!--是否使用虚拟文件,使用虚拟文件初始化时将不占用磁盘空间,下载多少byte,占多少空间,效果见chrome的下载。-->
|
<!--是否开启动态文件,开启动态文件后初始化时将不占用磁盘空间,下载多少byte,占多少空间,效果见chrome的下载。-->
|
||||||
<!--注意:
|
<!--注意:
|
||||||
1、使用该功能,将自动关闭多线程下载;
|
1、使用该功能,将自动关闭多线程下载;
|
||||||
2、对于已经采用了多线程的任务,依然采用原来的下载方式;
|
2、对于已经采用了多线程的任务,依然采用原来的下载方式;
|
||||||
3、原本参数是true,任务没下载完成,就参数改为false,那么没下载完成的任务还是会按照参数修改前的方式下载;只有新任务才会根据参数调用不同的下载方式。-->
|
3、原本参数是true,任务没下载完成,就参数改为false,那么没下载完成的任务还是会按照参数修改前的方式下载;只有新任务才会根据参数调用不同的下载方式。-->
|
||||||
<useVirtualFile value="true"/>
|
<openDynamicFile value="false"/>
|
||||||
|
|
||||||
<!--断网的时候是否重试,true:断网也重试;false:断网不重试,直接走失败的回调-->
|
<!--断网的时候是否重试,true:断网也重试;false:断网不重试,直接走失败的回调-->
|
||||||
<notNetRetry value="true"/>
|
<notNetRetry value="true"/>
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
<threadNum value="3"/>
|
<threadNum value="3"/>
|
||||||
|
|
||||||
<!--设置下载队列最大任务数, 默认为2-->
|
<!--设置下载队列最大任务数, 默认为2-->
|
||||||
<maxTaskNum value="2"/>
|
<maxTaskNum value="20"/>
|
||||||
|
|
||||||
<!--设置下载失败,重试次数,默认为10-->
|
<!--设置下载失败,重试次数,默认为10-->
|
||||||
<reTryNum value="2"/>
|
<reTryNum value="2"/>
|
||||||
|
|||||||
@@ -3,12 +3,9 @@ package com.arialyy.simple.test;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import com.arialyy.aria.core.Aria;
|
import com.arialyy.aria.core.Aria;
|
||||||
import com.arialyy.aria.core.inf.AbsEntity;
|
|
||||||
import com.arialyy.aria.util.ALog;
|
|
||||||
import com.arialyy.simple.R;
|
import com.arialyy.simple.R;
|
||||||
import com.arialyy.simple.base.BaseActivity;
|
import com.arialyy.simple.base.BaseActivity;
|
||||||
import com.arialyy.simple.databinding.ActivityTestBinding;
|
import com.arialyy.simple.databinding.ActivityTestBinding;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by laoyuyu on 2018/4/13.
|
* Created by laoyuyu on 2018/4/13.
|
||||||
@@ -18,8 +15,9 @@ public class AnyRunActivity extends BaseActivity<ActivityTestBinding> {
|
|||||||
AnyRunnModule module;
|
AnyRunnModule module;
|
||||||
String[] urls;
|
String[] urls;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
String URL = "http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk";
|
//String URL = "http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk";
|
||||||
//String URL = "http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
|
//String URL = "http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
|
||||||
|
private final String URL = "ftp://192.168.29.140:21/download//AriaPrj.rar";
|
||||||
//String URL = "https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe";
|
//String URL = "https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe";
|
||||||
|
|
||||||
@Override protected int setLayoutId() {
|
@Override protected int setLayoutId() {
|
||||||
@@ -42,9 +40,12 @@ public class AnyRunActivity extends BaseActivity<ActivityTestBinding> {
|
|||||||
// module.start(urls[index]);
|
// module.start(urls[index]);
|
||||||
// index++;
|
// index++;
|
||||||
//}
|
//}
|
||||||
module.start(URL);
|
//for (int i = 0; i < 10; i++) {
|
||||||
List<AbsEntity> list = Aria.download(this).getTotalTaskList();
|
|
||||||
ALog.d(TAG, "size ==> " + list.size());
|
module.startFtp(URL);
|
||||||
|
//}
|
||||||
|
//List<AbsEntity> list = Aria.download(this).getTotalTaskList();
|
||||||
|
//ALog.d(TAG, "size ==> " + list.size());
|
||||||
break;
|
break;
|
||||||
case R.id.stop:
|
case R.id.stop:
|
||||||
//List<AbsEntity> list = Aria.download(this).getTotalTaskList();
|
//List<AbsEntity> list = Aria.download(this).getTotalTaskList();
|
||||||
|
|||||||
@@ -62,16 +62,58 @@ public class AnyRunnModule {
|
|||||||
L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath())));
|
L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void start(String url) {
|
void start(String url) {
|
||||||
mUrl = url;
|
mUrl = url;
|
||||||
Aria.download(this)
|
Aria.download(this)
|
||||||
.load(url)
|
.load(url)
|
||||||
.addHeader("Accept-Encoding", "gzip")
|
//.addHeader("Accept-Encoding", "gzip")
|
||||||
.setRequestMode(RequestEnum.GET)
|
.setRequestMode(RequestEnum.GET)
|
||||||
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg123456.apk")
|
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg123456.apk")
|
||||||
.resetState()
|
//.resetState()
|
||||||
.start();
|
.start();
|
||||||
|
//String[] urls = new String[] {
|
||||||
|
// "http://cdn-s1.touchfound.net/1526449199142_3617.png",
|
||||||
|
// "http://cdn-s1.touchfound.net/mtVmResources/1526287158571.zip",
|
||||||
|
// "http://cdn-s1.touchfound.net/1526450206960_2186.png",
|
||||||
|
// "http://cdn-s1.touchfound.net/1526449199025_1476.png"
|
||||||
|
//};
|
||||||
|
//for (int i = 0, len = urls.length; i < len; i++){
|
||||||
|
//
|
||||||
|
// Aria.download(this)
|
||||||
|
// .load(urls[i])
|
||||||
|
// //.addHeader("Accept-Encoding", "gzip")
|
||||||
|
// .setRequestMode(RequestEnum.GET)
|
||||||
|
// .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg123456.apk" + i)
|
||||||
|
// //.resetState()
|
||||||
|
// .start();
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
void startFtp(String url) {
|
||||||
|
mUrl = url;
|
||||||
|
Aria.download(this)
|
||||||
|
.loadFtp(url)
|
||||||
|
.login("lao", "123456")
|
||||||
|
//.addHeader("Accept-Encoding", "gzip")
|
||||||
|
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ftp_ggsg16.apk")
|
||||||
|
//.resetState()
|
||||||
|
.start();
|
||||||
|
//String[] urls = new String[] {
|
||||||
|
// "http://cdn-s1.touchfound.net/1526449199142_3617.png",
|
||||||
|
// "http://cdn-s1.touchfound.net/mtVmResources/1526287158571.zip",
|
||||||
|
// "http://cdn-s1.touchfound.net/1526450206960_2186.png",
|
||||||
|
// "http://cdn-s1.touchfound.net/1526449199025_1476.png"
|
||||||
|
//};
|
||||||
|
//for (int i = 0, len = urls.length; i < len; i++){
|
||||||
|
//
|
||||||
|
// Aria.download(this)
|
||||||
|
// .load(urls[i])
|
||||||
|
// //.addHeader("Accept-Encoding", "gzip")
|
||||||
|
// .setRequestMode(RequestEnum.GET)
|
||||||
|
// .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg123456.apk" + i)
|
||||||
|
// //.resetState()
|
||||||
|
// .start();
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop(String url) {
|
void stop(String url) {
|
||||||
|
|||||||
@@ -375,23 +375,23 @@ class Configuration {
|
|||||||
int maxSpeed = 0;
|
int maxSpeed = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否使用虚拟文件,使用虚拟文件初始化时将不占用磁盘空间,下载多少byte,占多少空间,效果见chrome的下载。
|
* 是否开启动态文件,开启动态文件后初始化时将不占用磁盘空间,下载多少byte,占多少空间,效果见chrome的下载
|
||||||
* 注意:
|
* 注意:
|
||||||
* 1、使用该功能,将自动关闭多线程下载;
|
* 1、使用该功能,将自动关闭多线程下载;
|
||||||
* 2、对于已经采用了多线程的任务,依然采用原来的下载方式;
|
* 2、对于已经采用了多线程的任务,依然采用原来的下载方式;
|
||||||
* 3、原本参数是true,任务没下载完成,就参数改为false,那么没下载完成的任务还是会按照参数修改前的方式下载,只有新任务才会根据参数调用不同的下载方式
|
* 3、原本参数是true,任务没下载完成,就参数改为false,那么没下载完成的任务还是会按照参数修改前的方式下载,只有新任务才会根据参数调用不同的下载方式
|
||||||
* {@code true}使用
|
* {@code true}使用
|
||||||
*/
|
*/
|
||||||
boolean useVirtualFile = true;
|
boolean openDynamicFile = true;
|
||||||
|
|
||||||
public DownloadConfig setuseVirtualFile(boolean useVirtualFile) {
|
public DownloadConfig setOpenDynamicFile(boolean openDynamicFile) {
|
||||||
this.useVirtualFile = useVirtualFile;
|
this.openDynamicFile = openDynamicFile;
|
||||||
saveKey("useVirtualFile", String.valueOf(useVirtualFile));
|
saveKey("openDynamicFile", String.valueOf(openDynamicFile));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUseVirtualFile() {
|
public boolean isOpenDynamicFile() {
|
||||||
return useVirtualFile;
|
return openDynamicFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DownloadConfig setMaxTaskNum(int maxTaskNum) {
|
public DownloadConfig setMaxTaskNum(int maxTaskNum) {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ task clean(type: Delete) {
|
|||||||
ext {
|
ext {
|
||||||
userOrg = 'arialyy'
|
userOrg = 'arialyy'
|
||||||
groupId = 'com.arialyy.aria'
|
groupId = 'com.arialyy.aria'
|
||||||
publishVersion = '3.4'
|
publishVersion = '3.4.1_dev_2'
|
||||||
// publishVersion = '1.0.3' //FTP插件
|
// publishVersion = '1.0.3' //FTP插件
|
||||||
repoName='maven'
|
repoName='maven'
|
||||||
desc = 'android 下载框架'
|
desc = 'android 下载框架'
|
||||||
|
|||||||
Reference in New Issue
Block a user