diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java index eb5f9c99..203ee0a5 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java @@ -311,7 +311,7 @@ public abstract class AbsTaskQueue implements ISchedulers { - private final String TAG = "AbsSchedulers"; + private final String TAG = CommonUtil.getClassName(getClass()); private static volatile TaskSchedulers INSTANCE; private static FailureTaskHandler mFailureTaskHandler; diff --git a/HttpComponent/src/main/java/com/arialyy/aria/http/HttpFileInfoTask.java b/HttpComponent/src/main/java/com/arialyy/aria/http/HttpFileInfoTask.java index 24d9236f..29fd34ac 100644 --- a/HttpComponent/src/main/java/com/arialyy/aria/http/HttpFileInfoTask.java +++ b/HttpComponent/src/main/java/com/arialyy/aria/http/HttpFileInfoTask.java @@ -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; } diff --git a/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGInfoTask.java b/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGInfoTask.java index e93e9f1e..32f1308b 100644 --- a/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGInfoTask.java +++ b/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGInfoTask.java @@ -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(); } diff --git a/M3U8Component/src/main/java/com/arialyy/aria/m3u8/live/LiveStateManager.java b/M3U8Component/src/main/java/com/arialyy/aria/m3u8/live/LiveStateManager.java index 62b27892..ab7901c5 100644 --- a/M3U8Component/src/main/java/com/arialyy/aria/m3u8/live/LiveStateManager.java +++ b/M3U8Component/src/main/java/com/arialyy/aria/m3u8/live/LiveStateManager.java @@ -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; } diff --git a/M3U8Component/src/main/java/com/arialyy/aria/m3u8/vod/VodStateManager.java b/M3U8Component/src/main/java/com/arialyy/aria/m3u8/vod/VodStateManager.java index cbba8db3..2b880862 100644 --- a/M3U8Component/src/main/java/com/arialyy/aria/m3u8/vod/VodStateManager.java +++ b/M3U8Component/src/main/java/com/arialyy/aria/m3u8/vod/VodStateManager.java @@ -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( diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHelper.java b/PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHelper.java index 99de4cc3..9fe5c43a 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHelper.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHelper.java @@ -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) { diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/config/XMLReader.java b/PublicComponent/src/main/java/com/arialyy/aria/core/config/XMLReader.java index 49fcbba8..f4dfbd84 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/config/XMLReader.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/config/XMLReader.java @@ -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; diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java b/PublicComponent/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java index b6264596..19d67809 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java @@ -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; diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/group/AbsGroupLoader.java b/PublicComponent/src/main/java/com/arialyy/aria/core/group/AbsGroupLoader.java index e7e8705b..7bd3ff25 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/group/AbsGroupLoader.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/group/AbsGroupLoader.java @@ -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(); } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IThreadStateManager.java b/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IThreadStateManager.java index 5b3811a7..01be3a84 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IThreadStateManager.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IThreadStateManager.java @@ -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); + /** * 设置消息循环体 */ diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/listener/BaseListener.java b/PublicComponent/src/main/java/com/arialyy/aria/core/listener/BaseListener.java index 2dc40426..6f370cf2 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/listener/BaseListener.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/listener/BaseListener.java @@ -136,7 +136,6 @@ public abstract class BaseListener= 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"); diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/loader/AbsNormalTTBuilder.java b/PublicComponent/src/main/java/com/arialyy/aria/core/loader/AbsNormalTTBuilder.java index c7c8db5b..33d7eb86 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/loader/AbsNormalTTBuilder.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/loader/AbsNormalTTBuilder.java @@ -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); } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/loader/IRecordHandler.java b/PublicComponent/src/main/java/com/arialyy/aria/core/loader/IRecordHandler.java index c23c7385..7f88fc9c 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/loader/IRecordHandler.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/loader/IRecordHandler.java @@ -37,7 +37,7 @@ public interface IRecordHandler extends ILoaderComponent { long SUB_LEN = 1024 * 1024; /** - * 分块文件路径 + * 分块文件路径,文件路径.线程id.part */ String SUB_PATH = "%s.%s.part"; diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalLoader.java b/PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalLoader.java index aeda85c5..255beabc 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalLoader.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalLoader.java @@ -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 { diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalThreadStateManager.java b/PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalThreadStateManager.java index bff67ba7..0e4e5744 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalThreadStateManager.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalThreadStateManager.java @@ -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; } /** diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/loader/SubLoader.java b/PublicComponent/src/main/java/com/arialyy/aria/core/loader/SubLoader.java index 8a5f0379..5d162beb 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/loader/SubLoader.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/loader/SubLoader.java @@ -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()); diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTask.java b/PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTask.java index b34abaf0..8c36ae72 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTask.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTask.java @@ -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) { diff --git a/PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java b/PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java index b5c8bd26..00861103 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java @@ -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 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(); diff --git a/PublicComponent/src/main/java/com/arialyy/aria/util/RecordUtil.java b/PublicComponent/src/main/java/com/arialyy/aria/util/RecordUtil.java index 02d51649..3debb45f 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/util/RecordUtil.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/util/RecordUtil.java @@ -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(); diff --git a/app/src/main/java/com/arialyy/simple/DbTestActivity.java b/app/src/main/java/com/arialyy/simple/DbTestActivity.java index feb15785..8815192a 100644 --- a/app/src/main/java/com/arialyy/simple/DbTestActivity.java +++ b/app/src/main/java/com/arialyy/simple/DbTestActivity.java @@ -55,7 +55,7 @@ public class DbTestActivity extends BaseActivity { DownloadEntity entity = new DownloadEntity(); entity.setUrl(url); entity.setFileName("ssssssssssssssssss"); - entity.setDownloadPath(key); + entity.setFilePath(key); DTaskWrapper dte = new DTaskWrapper(entity); diff --git a/app/src/main/java/com/arialyy/simple/core/download/DownloadModule.java b/app/src/main/java/com/arialyy/simple/core/download/DownloadModule.java index 800ec4e3..4b87c0a8 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/DownloadModule.java +++ b/app/src/main/java/com/arialyy/simple/core/download/DownloadModule.java @@ -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; } } \ No newline at end of file diff --git a/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java b/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java index 6f8e28fa..c170446b 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java @@ -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 " + CommonUtil.getFileMD5(new File(task.getFilePath()))); T.showShort(this, "文件:" + task.getEntity().getFileName() + ",下载完成"); } diff --git a/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadModule.java b/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadModule.java index ec149ddd..3f78c8cd 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadModule.java +++ b/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadModule.java @@ -48,9 +48,8 @@ public class FtpDownloadModule extends BaseViewModule { */ LiveData 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()); diff --git a/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8LiveModule.java b/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8LiveModule.java index 899c39d3..5a86ca0c 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8LiveModule.java +++ b/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8LiveModule.java @@ -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); diff --git a/app/src/main/java/com/arialyy/simple/modlue/AnyRunnModule.java b/app/src/main/java/com/arialyy/simple/modlue/AnyRunnModule.java index 4ce216c8..8bc2331f 100644 --- a/app/src/main/java/com/arialyy/simple/modlue/AnyRunnModule.java +++ b/app/src/main/java/com/arialyy/simple/modlue/AnyRunnModule.java @@ -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()))); } diff --git a/app/src/main/java/com/arialyy/simple/widget/SubStateLinearLayout.java b/app/src/main/java/com/arialyy/simple/widget/SubStateLinearLayout.java index 0c42cfcc..9ee9644f 100644 --- a/app/src/main/java/com/arialyy/simple/widget/SubStateLinearLayout.java +++ b/app/src/main/java/com/arialyy/simple/widget/SubStateLinearLayout.java @@ -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++; }