修复重构loader后ftp模块的bug

pull/617/head
laoyuyu 5 years ago
parent c39bfbdd88
commit e14928e260
  1. 2
      Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  2. 3
      Aria/src/main/java/com/arialyy/aria/core/scheduler/TaskSchedulers.java
  3. 4
      HttpComponent/src/main/java/com/arialyy/aria/http/HttpFileInfoTask.java
  4. 2
      HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGInfoTask.java
  5. 4
      M3U8Component/src/main/java/com/arialyy/aria/m3u8/live/LiveStateManager.java
  6. 4
      M3U8Component/src/main/java/com/arialyy/aria/m3u8/vod/VodStateManager.java
  7. 4
      PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHelper.java
  8. 6
      PublicComponent/src/main/java/com/arialyy/aria/core/config/XMLReader.java
  9. 16
      PublicComponent/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
  10. 27
      PublicComponent/src/main/java/com/arialyy/aria/core/group/AbsGroupLoader.java
  11. 7
      PublicComponent/src/main/java/com/arialyy/aria/core/inf/IThreadStateManager.java
  12. 1
      PublicComponent/src/main/java/com/arialyy/aria/core/listener/BaseListener.java
  13. 16
      PublicComponent/src/main/java/com/arialyy/aria/core/listener/DownloadGroupListener.java
  14. 2
      PublicComponent/src/main/java/com/arialyy/aria/core/loader/AbsNormalTTBuilder.java
  15. 2
      PublicComponent/src/main/java/com/arialyy/aria/core/loader/IRecordHandler.java
  16. 22
      PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalLoader.java
  17. 20
      PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalThreadStateManager.java
  18. 3
      PublicComponent/src/main/java/com/arialyy/aria/core/loader/SubLoader.java
  19. 17
      PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTask.java
  20. 32
      PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java
  21. 2
      PublicComponent/src/main/java/com/arialyy/aria/util/RecordUtil.java
  22. 2
      app/src/main/java/com/arialyy/simple/DbTestActivity.java
  23. 2
      app/src/main/java/com/arialyy/simple/core/download/DownloadModule.java
  24. 11
      app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java
  25. 7
      app/src/main/java/com/arialyy/simple/core/download/FtpDownloadModule.java
  26. 2
      app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8LiveModule.java
  27. 2
      app/src/main/java/com/arialyy/simple/modlue/AnyRunnModule.java
  28. 2
      app/src/main/java/com/arialyy/simple/widget/SubStateLinearLayout.java

@ -311,7 +311,7 @@ public abstract class AbsTaskQueue<TASK extends AbsTask, TASK_WRAPPER extends Ab
task.start();
break;
case IEntity.STATE_CANCEL:
ALog.e(TAG, String.format("任务【%s】重试失败,原因:任务已删除", task.getTaskName()));
ALog.e(TAG, String.format("任务【%s】重试失败,原因:任务已删除", task.getTaskName()));
break;
case IEntity.STATE_COMPLETE:
ALog.e(TAG, String.format("任务【%s】重试失败,原因:已完成", task.getTaskName()));

@ -37,6 +37,7 @@ import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.core.task.ITask;
import com.arialyy.aria.core.task.UploadTask;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.NetUtils;
import java.util.Iterator;
import java.util.Map;
@ -47,7 +48,7 @@ import java.util.concurrent.ConcurrentHashMap;
* Created by lyy on 2017/6/4. 事件调度器用于处理任务状态的调度
*/
public class TaskSchedulers<TASK extends ITask> implements ISchedulers {
private final String TAG = "AbsSchedulers";
private final String TAG = CommonUtil.getClassName(getClass());
private static volatile TaskSchedulers INSTANCE;
private static FailureTaskHandler mFailureTaskHandler;

@ -85,7 +85,7 @@ public final class HttpFileInfoTask implements IInfoTask, Runnable {
} catch (IOException e) {
e.printStackTrace();
failDownload(new AriaIOException(TAG,
String.format("下载失败,filePath: %s, url: %s", mEntity.getDownloadPath(), mEntity.getUrl())),
String.format("下载失败,filePath: %s, url: %s", mEntity.getFilePath(), mEntity.getUrl())),
true);
} finally {
if (conn != null) {
@ -131,7 +131,7 @@ public final class HttpFileInfoTask implements IInfoTask, Runnable {
if (!FileUtil.checkMemorySpace(mEntity.getFilePath(), len)) {
failDownload(new TaskException(TAG,
String.format("下载失败,内存空间不足;filePath: %s, url: %s", mEntity.getDownloadPath(),
String.format("下载失败,内存空间不足;filePath: %s, url: %s", mEntity.getFilePath(),
mEntity.getUrl())), false);
return;
}

@ -132,7 +132,7 @@ public final class HttpDGInfoTask implements IInfoTask {
wrapper.getEntity().setFileSize(size);
wrapper.getEntity().update();
getLenComplete = true;
ALog.d(TAG, String.format("获取组合任务长度完成,组合任务总长度:%s,失败的任务数:%s", size, failCount));
ALog.d(TAG, String.format("获取组合任务长度完成,组合任务总长度:%s,失败的任务数:%s", size, failCount));
callback.onSucceed(wrapper.getKey(), new CompleteInfo());
notifyLock();
}

@ -144,6 +144,10 @@ final class LiveStateManager implements IThreadStateManager {
return mProgress;
}
@Override public void updateCurrentProgress(long currentProgress) {
mProgress = currentProgress;
}
@Override public void setLooper(TaskRecord taskRecord, Looper looper) {
mLooper = looper;
}

@ -247,6 +247,10 @@ public final class VodStateManager implements IThreadStateManager {
return progress;
}
@Override public void updateCurrentProgress(long currentProgress) {
progress = currentProgress;
}
private void printInfo(String tag) {
if (false) {
ALog.d(tag, String.format(

@ -21,6 +21,7 @@ import com.arialyy.aria.core.loader.IRecordHandler;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.BufferedRandomAccessFile;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.FileUtil;
import java.io.File;
import java.io.IOException;
@ -32,7 +33,7 @@ import java.io.IOException;
* @Date 2019-09-19
*/
public class RecordHelper {
private String TAG = "RecordHelper";
private String TAG = CommonUtil.getClassName(getClass());
private AbsTaskWrapper mWrapper;
protected TaskRecord mTaskRecord;
@ -166,6 +167,7 @@ public class RecordHelper {
tr.isComplete = false;
tr.endLocation = mWrapper.getEntity().getFileSize();
} else if (file.length() == mWrapper.getEntity().getFileSize()) {
ALog.d(TAG, "文件长度一致,线程完成");
tr.isComplete = true;
} else {
if (file.length() != tr.startLocation) {

@ -27,7 +27,7 @@ import org.xml.sax.helpers.DefaultHandler;
* Created by lyy on 2017/5/22. 读取配置文件
*/
public class XMLReader extends DefaultHandler {
private final String TAG = "XMLReader";
private final String TAG = CommonUtil.getClassName(this);
private DownloadConfig mDownloadConfig = Configuration.getInstance().downloadCfg;
private UploadConfig mUploadConfig = Configuration.getInstance().uploadCfg;
@ -62,13 +62,13 @@ public class XMLReader extends DefaultHandler {
String value = attributes.getValue("value");
switch (qName) {
case "getCreatedThreadNum": // 线程数
case "threadNum": // 线程数
int threadNum = checkInt(value) ? Integer.parseInt(value) : 3;
if (threadNum < 1) {
ALog.w(TAG, "下载线程数不能小于 1");
threadNum = 1;
}
setField("getCreatedThreadNum", threadNum, ConfigType.DOWNLOAD);
setField("threadNum", threadNum, ConfigType.DOWNLOAD);
break;
case "maxTaskNum": //最大任务书
int maxTaskNum = checkInt(value) ? Integer.parseInt(value) : 2;

@ -130,27 +130,11 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
this.groupHash = groupHash;
}
/**
* 后面会删除该方法请使用{@link #getFilePath()}
*/
@Deprecated
public String getDownloadPath() {
return downloadPath;
}
@Override
public String getFilePath() {
return downloadPath;
}
/**
* 后面会删除该方法请使用{@link #setFilePath(String)}
*/
@Deprecated
public DownloadEntity setDownloadPath(String downloadPath) {
return setFilePath(downloadPath);
}
public DownloadEntity setFilePath(String filePath) {
this.downloadPath = filePath;
return this;

@ -98,14 +98,14 @@ public abstract class AbsGroupLoader implements ILoaderVisitor, ILoader {
private void initState(Looper looper) {
mState = new GroupRunState(getWrapper().getKey(), mListener, mSubQueue);
for (DTaskWrapper wrapper : mGTWrapper.getSubTaskWrapper()) {
File subFile = new File(wrapper.getEntity().getFilePath());
long fileLen = checkFileExists(wrapper.getEntity().getFilePath());
if (wrapper.getEntity().getState() == IEntity.STATE_COMPLETE
&& subFile.exists()
&& subFile.length() == wrapper.getEntity().getFileSize()) {
&& fileLen != -1
&& fileLen == wrapper.getEntity().getFileSize()) {
mState.updateCompleteNum();
mCurrentLocation += wrapper.getEntity().getFileSize();
} else {
if (!subFile.exists()) {
if (fileLen == -1) {
wrapper.getEntity().setCurrentProgress(0);
}
wrapper.getEntity().setState(IEntity.STATE_POST_PRE);
@ -120,6 +120,25 @@ public abstract class AbsGroupLoader implements ILoaderVisitor, ILoader {
mScheduler = new Handler(looper, SimpleSchedulers.newInstance(mState, mGTWrapper.getKey()));
}
/**
* 检查文件是否存在需要检查普通任务和分块任务的
*
* @param filePath 文件路径
* @return 文件存在返回文件长度不存在返回-1
*/
private long checkFileExists(String filePath) {
File temp = new File(filePath);
if (temp.exists()) {
return temp.length();
}
File block = new File(String.format(IRecordHandler.SUB_PATH, filePath, 0));
if (block.exists()) {
return block.length();
} else {
return -1;
}
}
@Override public String getKey() {
return mGTWrapper.getKey();
}

@ -36,6 +36,7 @@ public interface IThreadStateManager extends ILoaderComponent {
String DATA_ERROR_INFO = "DATA_ERROR_INFO";
String DATA_THREAD_NAME = "DATA_THREAD_NAME";
String DATA_THREAD_LOCATION = "DATA_THREAD_LOCATION";
String DATA_ADD_LEN = "DATA_ADD_LEN"; // 增加的长度
/**
* 任务是否已经失败
@ -58,6 +59,12 @@ public interface IThreadStateManager extends ILoaderComponent {
*/
long getCurrentProgress();
/**
* 更新当前进度
* @param currentProgress 当前进度
*/
void updateCurrentProgress(long currentProgress);
/**
* 设置消息循环体
*/

@ -136,7 +136,6 @@ public abstract class BaseListener<ENTITY extends AbsEntity, TASK_WRAPPER extend
mEntity.setConvertSpeed(CommonUtil.formatFileSize(speed < 0 ? 0 : speed) + "/s");
}
mEntity.setSpeed(speed < 0 ? 0 : speed);
if (mTaskWrapper.getRequestType() != ITaskWrapper.M3U8_VOD) {
mEntity.setPercent((int) (mEntity.getFileSize() <= 0 ? 0
: mEntity.getCurrentProgress() * 100 / mEntity.getFileSize()));

@ -47,7 +47,7 @@ public class DownloadGroupListener
@Override
public void onSubPre(DownloadEntity subEntity) {
handleSpeed(subEntity, 0);
handleSubSpeed(subEntity, 0);
saveSubState(IEntity.STATE_PRE, subEntity);
sendInState2Target(ISchedulers.SUB_PRE, subEntity);
}
@ -59,7 +59,7 @@ public class DownloadGroupListener
@Override
public void onSubStart(DownloadEntity subEntity) {
handleSpeed(subEntity, 0);
handleSubSpeed(subEntity, 0);
saveSubState(IEntity.STATE_RUNNING, subEntity);
sendInState2Target(ISchedulers.SUB_START, subEntity);
}
@ -67,7 +67,7 @@ public class DownloadGroupListener
@Override
public void onSubStop(DownloadEntity subEntity, long stopLocation) {
subEntity.setCurrentProgress(stopLocation);
handleSpeed(subEntity, 0);
handleSubSpeed(subEntity, 0);
saveSubState(IEntity.STATE_STOP, subEntity);
saveCurrentLocation();
sendInState2Target(ISchedulers.SUB_STOP, subEntity);
@ -75,7 +75,7 @@ public class DownloadGroupListener
@Override
public void onSubComplete(DownloadEntity subEntity) {
handleSpeed(subEntity, 0);
handleSubSpeed(subEntity, 0);
saveSubState(IEntity.STATE_COMPLETE, subEntity);
saveCurrentLocation();
sendInState2Target(ISchedulers.SUB_COMPLETE, subEntity);
@ -83,7 +83,7 @@ public class DownloadGroupListener
@Override
public void onSubFail(DownloadEntity subEntity, BaseException e) {
handleSpeed(subEntity, 0);
handleSubSpeed(subEntity, 0);
saveSubState(IEntity.STATE_FAIL, subEntity);
saveCurrentLocation();
sendInState2Target(ISchedulers.SUB_FAIL, subEntity);
@ -95,7 +95,7 @@ public class DownloadGroupListener
@Override
public void onSubCancel(DownloadEntity subEntity) {
handleSpeed(subEntity, 0);
handleSubSpeed(subEntity, 0);
saveSubState(IEntity.STATE_CANCEL, subEntity);
saveCurrentLocation();
sendInState2Target(ISchedulers.SUB_CANCEL, subEntity);
@ -104,7 +104,7 @@ public class DownloadGroupListener
@Override
public void onSubRunning(DownloadEntity subEntity, long currentProgress) {
handleSpeed(subEntity, currentProgress);
handleSubSpeed(subEntity, currentProgress);
if (System.currentTimeMillis() - mLastSaveTime >= RUN_SAVE_INTERVAL) {
saveSubState(IEntity.STATE_RUNNING, subEntity);
mLastSaveTime = System.currentTimeMillis();
@ -112,7 +112,7 @@ public class DownloadGroupListener
sendInState2Target(ISchedulers.SUB_RUNNING, subEntity);
}
private void handleSpeed(DownloadEntity subEntity, long currentProgress) {
private void handleSubSpeed(DownloadEntity subEntity, long currentProgress) {
if (currentProgress == 0){
subEntity.setSpeed(0);
subEntity.setConvertSpeed("0kb/s");

@ -152,7 +152,7 @@ public abstract class AbsNormalTTBuilder implements IThreadTaskBuilder {
}
threadTasks.add(task);
}
if (currentProgress != 0 && currentProgress != getEntity().getCurrentProgress()) {
if (currentProgress != getEntity().getCurrentProgress()) {
ALog.d(TAG, String.format("进度修正,当前进度:%s", currentProgress));
getEntity().setCurrentProgress(currentProgress);
}

@ -37,7 +37,7 @@ public interface IRecordHandler extends ILoaderComponent {
long SUB_LEN = 1024 * 1024;
/**
* 分块文件路径
* 分块文件路径文件路径.线程id.part
*/
String SUB_PATH = "%s.%s.part";

@ -28,6 +28,7 @@ import com.arialyy.aria.core.manager.ThreadTaskManager;
import com.arialyy.aria.core.task.IThreadTask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.util.FileUtil;
import java.io.File;
/**
@ -71,17 +72,6 @@ public class NormalLoader extends AbsNormalLoader {
EventMsgUtil.getDefault().unRegister(this);
}
@Override protected void onPostPre() {
super.onPostPre();
if (getListener() instanceof IDLoadListener) {
((IDLoadListener) getListener()).onPostPre(getEntity().getFileSize());
}
File file = new File(getEntity().getFilePath());
if (file.getParentFile() != null && !file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
}
///**
// * 如果使用"Content-Disposition"中的文件名,需要更新{@link #mTempFile}的路径
// */
@ -105,11 +95,21 @@ public class NormalLoader extends AbsNormalLoader {
}
protected void startThreadTask() {
if (getListener() instanceof IDLoadListener) {
((IDLoadListener) getListener()).onPostPre(getEntity().getFileSize());
}
File file = new File(getEntity().getFilePath());
if (file.getParentFile() != null && !file.getParentFile().exists()) {
FileUtil.createDir(file.getPath());
}
mRecord = mRecordHandler.getRecord(getFileSize());
mStateManager.setLooper(mRecord, looper);
getTaskList().addAll(mTTBuilder.buildThreadTask(mRecord,
new Handler(looper, mStateManager.getHandlerCallback())));
startThreadNum = mTTBuilder.getCreatedThreadNum();
mStateManager.updateCurrentProgress(getEntity().getCurrentProgress());
if (mStateManager.getCurrentProgress() > 0) {
getListener().onResume(mStateManager.getCurrentProgress());
} else {

@ -61,11 +61,11 @@ public class NormalThreadStateManager implements IThreadStateManager {
mLooper = looper;
}
private void checkLooper(){
if (mTaskRecord == null){
private void checkLooper() {
if (mTaskRecord == null) {
throw new NullPointerException("任务记录为空");
}
if (mLooper == null){
if (mLooper == null) {
throw new NullPointerException("Looper为空");
}
}
@ -112,9 +112,12 @@ public class NormalThreadStateManager implements IThreadStateManager {
}
break;
case STATE_RUNNING:
if (msg.obj instanceof Long) {
mProgress += (long) msg.obj;
Bundle b = msg.getData();
if (b != null) {
long len = b.getLong(IThreadStateManager.DATA_ADD_LEN, 0);
mProgress += len;
}
break;
case STATE_UPDATE_PROGRESS:
if (msg.obj == null) {
@ -128,11 +131,8 @@ public class NormalThreadStateManager implements IThreadStateManager {
}
};
/**
* 不要使用handle更新启动线程的进度因为有延迟
*/
void updateProgress(long curProgress) {
mProgress = curProgress;
@Override public void updateCurrentProgress(long currentProgress) {
mProgress = currentProgress;
}
/**

@ -30,6 +30,7 @@ import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import java.io.File;
import java.util.List;
/**
@ -93,6 +94,8 @@ public final class SubLoader implements ILoader, ILoaderVisitor {
private void handlerTask() {
TaskRecord record = recordHandler.getRecord(wrapper.getEntity().getFileSize());
if (record.threadRecords != null
&& !TextUtils.isEmpty(record.filePath)
&& new File(record.filePath).exists()
&& !record.threadRecords.isEmpty()
&& record.threadRecords.get(0).isComplete) {
ALog.d(TAG, "子任务已完成,key:" + wrapper.getKey());

@ -64,7 +64,7 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver {
/**
* 当前线程的下去区间的进度
*/
private long mRangeProgress;
private long mRangeProgress, mLastRangeProgress;
private IThreadTaskAdapter mAdapter;
private ThreadRecord mRecord;
private String mThreadNmae;
@ -89,6 +89,7 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver {
isNotNetRetry = AriaConfig.getInstance().getAConfig().isNotNetRetry();
mRangeProgress = mRecord.startLocation;
mLastRangeProgress = mRangeProgress;
updateInterval = config.updateInterval;
}
@ -304,7 +305,7 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver {
}
@Override public synchronized void updateCompleteState() {
ALog.i(TAG, String.format("任务【%s】线程__%s__下载完毕", getTaskWrapper().getKey(), mRecord.threadId));
ALog.i(TAG, String.format("任务【%s】线程__%s__完成", getTaskWrapper().getKey(), mRecord.threadId));
writeConfig(true, mRecord.endLocation);
updateState(IThreadStateManager.STATE_COMPLETE, null);
}
@ -334,9 +335,11 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver {
msg.setData(b);
}
b.putString(IThreadStateManager.DATA_THREAD_NAME, getThreadName());
b.putLong(IThreadStateManager.DATA_ADD_LEN, mRangeProgress - mLastRangeProgress);
msg.what = IThreadStateManager.STATE_RUNNING;
msg.obj = mRangeProgress;
msg.sendToTarget();
mLastRangeProgress = mRangeProgress;
mLastSendProgressTime = System.currentTimeMillis();
}
@ -402,13 +405,13 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver {
if (mFailTimes < RETRY_NUM && needRetry && (NetUtils.isConnected(
AriaConfig.getInstance().getAPP())
|| isNotNetRetry) && !isBreak()) {
ALog.w(TAG, String.format("ts切片【%s】正在重试", getFileName()));
ALog.w(TAG, String.format("ts切片【%s】第%s重试", getFileName(), String.valueOf(mFailTimes)));
mFailTimes++;
FileUtil.deleteFile(mConfig.tempFile);
FileUtil.createFile(mConfig.tempFile);
ThreadTaskManager.getInstance().retryThread(this);
} else {
sendFailMsg(null, needRetry);
sendFailMsg(null, false);
}
}
@ -425,12 +428,12 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver {
}
if (mFailTimes < RETRY_NUM && needRetry && (NetUtils.isConnected(
AriaConfig.getInstance().getAPP()) || isNotNetRetry) && !isBreak()) {
ALog.w(TAG, String.format("分块【%s】正在重试", getFileName()));
ALog.w(TAG, String.format("分块【%s】第%s次重试", getFileName(), String.valueOf(mFailTimes)));
mFailTimes++;
handleBlockRecord();
ThreadTaskManager.getInstance().retryThread(this);
} else {
sendFailMsg(null, needRetry);
sendFailMsg(null, false);
}
}
@ -493,7 +496,7 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver {
* 将记录写入到配置文件
*
* @param isComplete 当前线程是否完成 {@code true}完成
* @param record 当前下载进度
* @param record 当前进度
*/
private void writeConfig(boolean isComplete, final long record) {
if (mRecord != null) {

@ -190,6 +190,27 @@ public class FileUtil {
return false;
}
/**
* 删除文件夹
*/
public static boolean deleteDir(File dirFile) {
// 如果dir对应的文件不存在,则退出
if (!dirFile.exists()) {
return false;
}
if (dirFile.isFile()) {
return dirFile.delete();
} else {
for (File file : dirFile.listFiles()) {
deleteDir(file);
}
}
return dirFile.delete();
}
/**
* 将对象写入文件
*
@ -275,9 +296,14 @@ public class FileUtil {
FileOutputStream fos = null;
FileChannel foc = null;
try {
if (file.exists() && file.isDirectory()) {
ALog.w(TAG, String.format("路径【%s】是文件夹,将删除该文件夹", targetPath));
FileUtil.deleteDir(file);
}
if (!file.exists()) {
file.createNewFile();
FileUtil.createFile(file);
}
fos = new FileOutputStream(targetPath);
foc = fos.getChannel();
List<FileInputStream> streams = new LinkedList<>();
@ -383,8 +409,8 @@ public class FileUtil {
*/
public static boolean checkMemorySpace(String path, long fileSize) {
File temp = new File(path);
if (!temp.exists()){
if (!temp.getParentFile().exists()){
if (!temp.exists()) {
if (!temp.getParentFile().exists()) {
FileUtil.createDir(temp.getParentFile().getPath());
}
path = temp.getParentFile().getPath();

@ -142,7 +142,7 @@ public class RecordUtil {
int type;
if (entity instanceof DownloadEntity) {
type = IRecordHandler.TYPE_DOWNLOAD;
filePath = ((DownloadEntity) entity).getDownloadPath();
filePath = entity.getFilePath();
} else if (entity instanceof UploadEntity) {
type = IRecordHandler.TYPE_UPLOAD;
filePath = entity.getFilePath();

@ -55,7 +55,7 @@ public class DbTestActivity extends BaseActivity<ActivityDbTestBinding> {
DownloadEntity entity = new DownloadEntity();
entity.setUrl(url);
entity.setFileName("ssssssssssssssssss");
entity.setDownloadPath(key);
entity.setFilePath(key);
DTaskWrapper dte = new DTaskWrapper(entity);

@ -129,7 +129,7 @@ public class DownloadModule extends BaseModule {
DownloadEntity entity = new DownloadEntity();
entity.setFileName(name);
entity.setUrl(downloadUrl);
entity.setDownloadPath(path);
entity.setFilePath(path);
return entity;
}
}

@ -28,6 +28,7 @@ import com.arialyy.aria.core.common.FtpOption;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.util.show.L;
import com.arialyy.frame.util.show.T;
@ -48,7 +49,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
private String mUrl, mFilePath;
private FtpDownloadModule mModule;
private long mTaskId;
private String user = "boamax\\update", passw = "2020&suzhou";
private String user = "lao", passw = "123456";
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
@ -124,7 +125,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
private FtpOption getFtpOption() {
FtpOption option = new FtpOption();
option.login(user, passw);
option.setServerIdentifier(FtpOption.FTPServerIdentifier.SYST_NT);
//option.setServerIdentifier(FtpOption.FTPServerIdentifier.SYST_NT);
//option.setConnectionMode(FtpConnectionMode.DATA_CONNECTION_MODE_ACTIVITY);
return option;
}
@ -145,7 +146,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
}
@Download.onTaskPre() protected void onTaskPre(DownloadTask task) {
L.d(TAG, "ftp task pre");
L.d(TAG, "ftp task pre, fileSize = " + task.getConvertFileSize());
getBinding().setFileSize(task.getConvertFileSize());
}
@ -154,6 +155,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
}
@Download.onTaskRunning() protected void running(DownloadTask task) {
ALog.d(TAG, "running, p = " + task.getPercent() + ", speed = " + task.getConvertSpeed());
getBinding().setProgress(task.getPercent());
getBinding().setSpeed(task.getConvertSpeed());
}
@ -165,6 +167,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
@Download.onTaskStop() void taskStop(DownloadTask task) {
L.d(TAG, "ftp task stop");
getBinding().setSpeed("");
getBinding().setStateStr(getString(R.string.resume));
}
@Download.onTaskCancel() void taskCancel(DownloadTask task) {
@ -174,12 +177,14 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
@Download.onTaskFail() void taskFail(DownloadTask task) {
L.d(TAG, "ftp task fail");
getBinding().setSpeed("");
getBinding().setStateStr(getString(R.string.resume));
}
@Download.onTaskComplete() void taskComplete(DownloadTask task) {
getBinding().setSpeed("");
getBinding().setProgress(100);
getBinding().setStateStr(getString(R.string.re_start));
Log.d(TAG, "md5 ==> " + CommonUtil.getFileMD5(new File(task.getFilePath())));
T.showShort(this, "文件:" + task.getEntity().getFileName() + ",下载完成");
}

@ -48,9 +48,8 @@ public class FtpDownloadModule extends BaseViewModule {
*/
LiveData<DownloadEntity> getFtpDownloadInfo(Context context) {
//String url = AppUtil.getConfigValue(context, FTP_URL_KEY, ftpDefUrl);
//String url = "ftp://9.9.9.72:2121/Cyberduck-6.9.4.30164.zip";
String url = "ftp://58.210.178.52:21/battery1.0.0.apk";
String filePath = AppUtil.getConfigValue(context, FTP_PATH_KEY, ftpDefPath);
//String filePath = AppUtil.getConfigValue(context, FTP_PATH_KEY, ftpDefPath);
String url = "ftp://9.9.9.72:2121/Cyberduck-6.9.4.30164.zip";
singDownloadInfo = Aria.download(context).getFirstDownloadEntity(url);
if (singDownloadInfo == null) {
@ -58,7 +57,7 @@ public class FtpDownloadModule extends BaseViewModule {
singDownloadInfo.setUrl(url);
String name = getFileName(ftpDefUrl);
singDownloadInfo.setFileName(name);
singDownloadInfo.setFilePath(filePath + name);
singDownloadInfo.setFilePath(ftpDefPath + name);
} else {
AppUtil.setConfigValue(context, FTP_PATH_KEY, singDownloadInfo.getFilePath());
AppUtil.setConfigValue(context, FTP_URL_KEY, singDownloadInfo.getUrl());

@ -55,7 +55,7 @@ public class M3U8LiveModule extends BaseViewModule {
singDownloadInfo.setFilePath(filePath);
singDownloadInfo.setFileName(temp.getName());
} else {
AppUtil.setConfigValue(context, M3U8_LIVE_PATH_KEY, singDownloadInfo.getDownloadPath());
AppUtil.setConfigValue(context, M3U8_LIVE_PATH_KEY, singDownloadInfo.getFilePath());
AppUtil.setConfigValue(context, M3U8_LIVE_URL_KEY, singDownloadInfo.getUrl());
}
liveData.postValue(singDownloadInfo);

@ -76,7 +76,7 @@ public class AnyRunnModule {
}
@Download.onTaskComplete void taskComplete(DownloadTask task) {
L.d(TAG, "path ==> " + task.getDownloadEntity().getDownloadPath());
L.d(TAG, "path ==> " + task.getDownloadEntity().getFilePath());
L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getFilePath())));
}

@ -74,7 +74,7 @@ public class SubStateLinearLayout extends LinearLayout implements View.OnClickLi
int i = 1;
for (DownloadEntity entity : datas) {
TextView view = createView(i - 1, entity);
mPosition.put(entity.getDownloadPath(), i);
mPosition.put(entity.getFilePath(), i);
addView(view, i);
i++;
}

Loading…
Cancel
Save