diff --git a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java index 4b08afca..21b80459 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -92,6 +92,7 @@ import org.xml.sax.SAXException; private AppConfig mAConfig; private DGroupConfig mDGConfig; private Handler mAriaHandler; + private DelegateWrapper mDbWrapper; private AriaManager(Context context) { APP = context.getApplicationContext(); @@ -172,7 +173,7 @@ import org.xml.sax.SAXException; dbConfig.delete(); } } - DelegateWrapper.init(context.getApplicationContext()); + mDbWrapper = DelegateWrapper.init(context.getApplicationContext()); } private void initAria() { @@ -192,6 +193,9 @@ import org.xml.sax.SAXException; }; String sql = "UPDATE %s SET state=2 WHERE state IN (3,4,5,6)"; for (Class clazz : clazzs) { + if (!mDbWrapper.tableExists(clazz)) { + continue; + } String temp = String.format(sql, clazz.getSimpleName()); DbEntity.exeSql(temp); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java index 91495d32..98173f05 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java @@ -160,7 +160,6 @@ public abstract class AbsFileer - implements IDownloadGroupListener { + implements IDGroupListener { private GroupSendParams mSeedEntity; DownloadGroupListener(DownloadGroupTask task, Handler outHandler) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java index f9724e95..f0c4afd4 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java @@ -107,7 +107,7 @@ public class DownloadGroupTarget extends AbsDGTarget { /** * 如果无法获取到组合任务到总长度,请调用该方法, * 请注意: - * 1、如果组合任务到子任务数过多,请不要使用该标志位,否则Aria将需要消耗大量的时间获取组合任务的总长度。 + * 1、如果组合任务到子任务数过多,请不要使用该标志位,否则Aria将需要消耗大量的时间获取组合任务的总长度,直到获取完成组合任务总长度后才会执行下载。 * 2、如果你的知道组合任务的总长度,请使用{@link #setFileSize(long)}设置组合任务的长度。 * 3、由于网络或其它原因的存在,这种方式获取的组合任务大小有可能是不准确的。 */ diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java index 927eaabc..a1612209 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java @@ -20,9 +20,9 @@ import android.os.Looper; import android.text.TextUtils; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.common.IUtil; -import com.arialyy.aria.core.download.group.DownloadGroupUtil; +import com.arialyy.aria.core.download.group.DGroupUtil; import com.arialyy.aria.core.download.group.FtpDirDownloadUtil; -import com.arialyy.aria.core.download.group.IDownloadGroupListener; +import com.arialyy.aria.core.download.group.IDGroupListener; import com.arialyy.aria.core.inf.AbsGroupTask; import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.scheduler.ISchedulers; @@ -57,9 +57,9 @@ public class DownloadGroupTask extends AbsGroupTask { @Override protected synchronized IUtil createUtil() { switch (mTaskWrapper.getRequestType()) { case AbsTaskWrapper.D_HTTP: - return new DownloadGroupUtil((IDownloadGroupListener) mListener, mTaskWrapper); + return new DGroupUtil((IDGroupListener) mListener, mTaskWrapper); case AbsTaskWrapper.D_FTP_DIR: - return new FtpDirDownloadUtil((IDownloadGroupListener) mListener, mTaskWrapper); + return new FtpDirDownloadUtil((IDGroupListener) mListener, mTaskWrapper); } return null; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupUtil.java index 4a1f7874..4ae6ac2e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupUtil.java @@ -44,7 +44,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable { int HTTP_GROUP = 0xa2; private long mCurrentLocation = 0; - protected IDownloadGroupListener mListener; + protected IDGroupListener mListener; private ScheduledThreadPoolExecutor mTimer; private long mUpdateInterval; private boolean isStop = false, isCancel = false; @@ -55,7 +55,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable { DGTaskWrapper mGTWrapper; GroupRunState mState; - AbsGroupUtil(IDownloadGroupListener listener, DGTaskWrapper groupWrapper) { + AbsGroupUtil(IDGroupListener listener, DGTaskWrapper groupWrapper) { mListener = listener; mGTWrapper = groupWrapper; mUpdateInterval = Configuration.getInstance().downloadCfg.getUpdateInterval(); @@ -195,7 +195,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable { /** * onStop前的操作 * - * @return 返回{@code true},直接回调{@link IDownloadGroupListener#onStop(long)} + * @return 返回{@code true},直接回调{@link IDGroupListener#onStop(long)} */ protected boolean onPreStop() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/ChildDownloadListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/ChildDLoadListener.java similarity index 97% rename from Aria/src/main/java/com/arialyy/aria/core/download/group/ChildDownloadListener.java rename to Aria/src/main/java/com/arialyy/aria/core/download/group/ChildDLoadListener.java index 91c383ff..ad4d60e6 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/group/ChildDownloadListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/ChildDLoadListener.java @@ -26,7 +26,7 @@ import com.arialyy.aria.util.CommonUtil; /** * 子任务事件监听 */ -class ChildDownloadListener implements IDownloadListener { +class ChildDLoadListener implements IDownloadListener { private DownloadEntity subEntity; private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度 private long lastSaveTime; @@ -34,7 +34,7 @@ class ChildDownloadListener implements IDownloadListener { private Handler schedulers; private SubDLoadUtil loader; - ChildDownloadListener(Handler schedulers, SubDLoadUtil loader) { + ChildDLoadListener(Handler schedulers, SubDLoadUtil loader) { this.loader = loader; this.schedulers = schedulers; subEntity = loader.getEntity(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/DownloadGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/DGroupUtil.java similarity index 83% rename from Aria/src/main/java/com/arialyy/aria/core/download/group/DownloadGroupUtil.java rename to Aria/src/main/java/com/arialyy/aria/core/download/group/DGroupUtil.java index cfa518b9..0c124366 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/group/DownloadGroupUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/DGroupUtil.java @@ -25,11 +25,12 @@ import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.downloader.HttpFileInfoThread; import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.IEntity; -import com.arialyy.aria.core.inf.IHttpFileLenAdapter; import com.arialyy.aria.exception.AriaIOException; import com.arialyy.aria.exception.BaseException; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -37,13 +38,14 @@ import java.util.concurrent.Executors; * Created by AriaL on 2017/6/30. * 任务组下载工具 */ -public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { +public class DGroupUtil extends AbsGroupUtil implements IUtil { private static final String TAG = "DownloadGroupUtil"; private final Object LOCK = new Object(); private ExecutorService mPool = null; private boolean getLenComplete = false; + private List mTempWrapper = new ArrayList<>(); - public DownloadGroupUtil(IDownloadGroupListener listener, DGTaskWrapper taskWrapper) { + public DGroupUtil(IDGroupListener listener, DGTaskWrapper taskWrapper) { super(listener, taskWrapper); } @@ -101,18 +103,18 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { int failCount; @Override public void run() { - try { - Thread.sleep(2000); - } catch (InterruptedException e) { - e.printStackTrace(); - } for (DTaskWrapper dTaskWrapper : mGTWrapper.getSubTaskWrapper()) { cloneHeader(dTaskWrapper); mPool.submit(new HttpFileInfoThread(dTaskWrapper, new OnFileInfoCallback() { @Override public void onComplete(String url, CompleteInfo info) { - createAndStartSubLoader((DTaskWrapper) info.wrapper, false); + if (!mGTWrapper.isUnknownSize()) { + createAndStartSubLoader((DTaskWrapper) info.wrapper, false); + } else { + mTempWrapper.add((DTaskWrapper) info.wrapper); + } count++; checkGetSizeComplete(count, failCount); + ALog.d(TAG, "获取子任务信息完成"); } @Override public void onFail(AbsEntity entity, BaseException e, boolean needRetry) { @@ -122,6 +124,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { mListener.onSubFail((DownloadEntity) entity, new AriaIOException(TAG, String.format("子任务获取文件长度失败,url:%s", ((DownloadEntity) entity).getUrl()))); checkGetSizeComplete(count, failCount); + mState.countFailNum(entity.getKey()); } })); } @@ -133,6 +136,11 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { * 检查组合任务大小是否获取完成,获取完成后取消阻塞,并设置组合任务大小 */ private void checkGetSizeComplete(int count, int failCount) { + if (failCount == mGTWrapper.getSubTaskWrapper().size()) { + mListener.onFail(false, new AriaIOException(TAG, "获取子任务长度失败")); + notifyLock(); + return; + } if (count == mGTWrapper.getSubTaskWrapper().size()) { long size = 0; for (DTaskWrapper wrapper : mGTWrapper.getSubTaskWrapper()) { @@ -142,14 +150,18 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { mGTWrapper.getEntity().setFileSize(size); mGTWrapper.getEntity().update(); getLenComplete = true; - ALog.d(TAG, String.format("获取组合任务长度完成,len:%s", size)); - } else if (failCount == mGTWrapper.getSubTaskWrapper().size()) { - mListener.onFail(true, new AriaIOException(TAG, "获取子任务长度失败")); - } - IHttpFileLenAdapter lenAdapter = mGTWrapper.asHttp().getFileLenAdapter(); - if (lenAdapter != null && lenAdapter.getClass().isAnonymousClass()) { - mGTWrapper.asHttp().setFileLenAdapter(null); + ALog.d(TAG, String.format("获取组合任务长度完成,组合任务总长度:%s,失败的只任务数:%s", size, failCount)); + // 未知大小的组合任务,延迟下载 + if (mGTWrapper.isUnknownSize()) { + for (DTaskWrapper wrapper : mTempWrapper) { + createAndStartSubLoader(wrapper, false); + } + } + notifyLock(); } + } + + private void notifyLock() { synchronized (LOCK) { LOCK.notifyAll(); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirDownloadUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirDownloadUtil.java index c4500cab..7d1d54ba 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirDownloadUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirDownloadUtil.java @@ -30,7 +30,7 @@ import com.arialyy.aria.exception.BaseException; public class FtpDirDownloadUtil extends AbsGroupUtil { private String TAG = "FtpDirDownloadUtil"; - public FtpDirDownloadUtil(IDownloadGroupListener listener, DGTaskWrapper taskEntity) { + public FtpDirDownloadUtil(IDGroupListener listener, DGTaskWrapper taskEntity) { super(listener, taskEntity); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/GroupRunState.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/GroupRunState.java index 28131784..75616709 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/group/GroupRunState.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/GroupRunState.java @@ -51,7 +51,7 @@ class GroupRunState { /** * 组合任务监听 */ - IDownloadGroupListener listener; + IDGroupListener listener; /** * 子任务队列 @@ -71,7 +71,7 @@ class GroupRunState { private String mGroupHash; - GroupRunState(String groupHash, IDownloadGroupListener listener, int subSize, + GroupRunState(String groupHash, IDGroupListener listener, int subSize, SimpleSubQueue queue) { this.listener = listener; this.queue = queue; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/IDownloadGroupListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/IDGroupListener.java similarity index 96% rename from Aria/src/main/java/com/arialyy/aria/core/download/group/IDownloadGroupListener.java rename to Aria/src/main/java/com/arialyy/aria/core/download/group/IDGroupListener.java index 48aa2dc6..918c45f6 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/group/IDownloadGroupListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/IDGroupListener.java @@ -23,7 +23,7 @@ import com.arialyy.aria.exception.BaseException; * Created by Aria.Lao on 2017/7/20. * 下载任务组事件 */ -public interface IDownloadGroupListener extends IDownloadListener { +public interface IDGroupListener extends IDownloadListener { /** * 子任务预处理 diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/SimpleSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/SimpleSchedulers.java index bff34012..6e4643dd 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/group/SimpleSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/SimpleSchedulers.java @@ -79,7 +79,7 @@ class SimpleSchedulers implements ISchedulers { * 2、stopNum + failNum + completeNum + cacheNum == subSize,则认为组合任务停止 * 3、failNum == subSize,只有全部的子任务都失败了,才能任务组合任务失败 */ - private synchronized void handleFail(final SubDLoadUtil loader) { + private synchronized void handleFail(final SubDLoadUtil loaderUtil) { Configuration config = Configuration.getInstance(); long interval = config.dGroupCfg.getSubReTryInterval(); @@ -88,32 +88,34 @@ class SimpleSchedulers implements ISchedulers { final int reTryNum = num; if ((!NetUtils.isConnected(AriaManager.APP) && !isNotNetRetry) - || loader.getEntity().getFailNum() > reTryNum) { - mQueue.removeTaskFromExecQ(loader); - mGState.listener.onSubFail(loader.getEntity(), new TaskException(TAG, - String.format("任务组子任务【%s】下载失败,下载地址【%s】", loader.getEntity().getFileName(), - loader.getEntity().getUrl()))); - mGState.countFailNum(loader.getKey()); + || loaderUtil.getDownloader() == null // 如果获取不到文件信息,loader为空 + || loaderUtil.getEntity().getFailNum() > reTryNum) { + mQueue.removeTaskFromExecQ(loaderUtil); + mGState.listener.onSubFail(loaderUtil.getEntity(), new TaskException(TAG, + String.format("任务组子任务【%s】下载失败,下载地址【%s】", loaderUtil.getEntity().getFileName(), + loaderUtil.getEntity().getUrl()))); + mGState.countFailNum(loaderUtil.getKey()); if (mGState.getFailNum() == mGState.getSubSize() || mGState.getStopNum() + mGState.getFailNum() + mGState.getCompleteNum() == mGState.getSubSize()) { mQueue.clear(); mGState.isRunning = false; - mGState.listener.onFail(true, new TaskException(TAG, + mGState.listener.onFail(false, new TaskException(TAG, String.format("任务组【%s】下载失败", mGState.getGroupHash()))); } else { startNext(); } return; } - final ScheduledThreadPoolExecutor timer = new ScheduledThreadPoolExecutor(1); + // 如果获取不到文件信息,loader为空 + final ScheduledThreadPoolExecutor timer = new ScheduledThreadPoolExecutor(1); timer.schedule(new Runnable() { @Override public void run() { - AbsEntity entity = loader.getEntity(); + AbsEntity entity = loaderUtil.getEntity(); if (entity.getFailNum() <= reTryNum) { - ALog.d(TAG, String.format("任务【%s】开始重试", loader.getEntity().getFileName())); - loader.reStart(); + ALog.d(TAG, String.format("任务【%s】开始重试", loaderUtil.getEntity().getFileName())); + loaderUtil.reStart(); } else { startNext(); } @@ -159,7 +161,8 @@ class SimpleSchedulers implements ISchedulers { mGState.updateCompleteNum(); ALog.d(TAG, String.format("总任务数:%s,完成的任务数:%s,失败的任务数:%s,停止的任务数:%s", mGState.getSubSize(), mGState.getCompleteNum(), mGState.getFailNum(), mGState.getStopNum())); - if (mGState.getCompleteNum() == mGState.getSubSize()) { + if (mGState.getCompleteNum() + mGState.getFailNum() + mGState.getStopNum() + == mGState.getSubSize()) { if (mGState.getStopNum() == 0 && mGState.getFailNum() == 0) { mGState.listener.onComplete(); } else { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/SubDLoadUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/SubDLoadUtil.java index 27131b36..91ca46f1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/group/SubDLoadUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/SubDLoadUtil.java @@ -38,7 +38,7 @@ class SubDLoadUtil implements IUtil { private Downloader mDownloader; private DTaskWrapper mWrapper; private Handler mSchedulers; - private ChildDownloadListener mListener; + private ChildDLoadListener mListener; private boolean needGetInfo; /** @@ -49,7 +49,7 @@ class SubDLoadUtil implements IUtil { mWrapper = taskWrapper; mSchedulers = schedulers; this.needGetInfo = needGetInfo; - mListener = new ChildDownloadListener(mSchedulers, SubDLoadUtil.this); + mListener = new ChildDLoadListener(mSchedulers, SubDLoadUtil.this); } @Override public String getKey() { @@ -73,6 +73,10 @@ class SubDLoadUtil implements IUtil { } } + public Downloader getDownloader() { + return mDownloader; + } + @Override public long getFileSize() { return mDownloader == null ? -1 : mDownloader.getFileSize(); } @@ -112,7 +116,7 @@ class SubDLoadUtil implements IUtil { } @Override public void onFail(AbsEntity entity, BaseException e, boolean needRetry) { - mSchedulers.obtainMessage(ISchedulers.FAIL, SubDLoadUtil.this); + mSchedulers.obtainMessage(ISchedulers.FAIL, SubDLoadUtil.this).sendToTarget(); } })).start(); } else { diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java index 5046623d..c3386028 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java @@ -18,8 +18,10 @@ package com.arialyy.aria.core.inf; import android.os.Parcel; import android.os.Parcelable; import com.arialyy.aria.orm.DbEntity; +import com.arialyy.aria.orm.annotation.Default; import com.arialyy.aria.orm.annotation.Ignore; import java.io.Serializable; + /** * Created by AriaL on 2017/6/29. */ @@ -53,6 +55,7 @@ public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable, /** * 任务状态{@link IEntity} */ + @Default("3") private int state = STATE_WAIT; /** * 当前下载进度 @@ -68,6 +71,7 @@ public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable, */ private int percent; + @Default("false") private boolean isComplete = false; /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalEntity.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalEntity.java index 86e6ed12..52d531db 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalEntity.java @@ -17,6 +17,7 @@ package com.arialyy.aria.core.inf; import android.os.Parcel; import android.os.Parcelable; +import com.arialyy.aria.orm.annotation.Default; /** * Created by AriaL on 2017/6/3. @@ -36,8 +37,10 @@ public abstract class AbsNormalEntity extends AbsEntity implements Parcelable { /** * 是否是任务组里面的下载实体 */ + @Default("false") private boolean isGroupChild = false; + @Default("false") private boolean isRedirect = false; //是否重定向 private String redirectUrl; //重定向链接 diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DelegateWrapper.java b/Aria/src/main/java/com/arialyy/aria/orm/DelegateWrapper.java index 16b8466f..53ab959d 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DelegateWrapper.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DelegateWrapper.java @@ -40,12 +40,15 @@ public class DelegateWrapper { mDManager = DelegateManager.getInstance(); } - public static void init(Context context) { - synchronized (DelegateWrapper.class) { - if (INSTANCE == null) { - INSTANCE = new DelegateWrapper(context); + public static DelegateWrapper init(Context context) { + if (INSTANCE == null) { + synchronized (DelegateWrapper.class) { + if (INSTANCE == null) { + INSTANCE = new DelegateWrapper(context); + } } } + return INSTANCE; } static DelegateWrapper getInstance() { @@ -117,7 +120,7 @@ public class DelegateWrapper { /** * 更新多条数据 */ - void updateManyData(List dbEntitys) { + void updateManyData(List dbEntitys) { mDManager.getDelegate(DelegateUpdate.class).updateManyData(mDb, dbEntitys); } @@ -182,14 +185,14 @@ public class DelegateWrapper { /** * 插入多条数据 */ - void insertManyData(List dbEntitys) { + void insertManyData(List dbEntitys) { mDManager.getDelegate(DelegateUpdate.class).insertManyData(mDb, dbEntitys); } /** * 查找某张表是否存在 */ - boolean tableExists(Class clazz) { + public boolean tableExists(Class clazz) { return mDManager.getDelegate(DelegateCommon.class).tableExists(mDb, clazz); } diff --git a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java index 0a3d8519..5957d750 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java @@ -95,7 +95,7 @@ final class SqlHelper extends SQLiteOpenHelper { @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { if (oldVersion < newVersion) { if (oldVersion < 31) { - handle314AriaUpdate(db); + handleLowAriaUpdate(db); } else if (oldVersion < 45) { handle360AriaUpdate(db); } else if (oldVersion < 51) { @@ -203,7 +203,6 @@ final class SqlHelper extends SQLiteOpenHelper { String newParamStr = oldParamStr; // 处理字段名称改变 if (modifyColumns != null) { - //newParamStr = params.toString(); Map columnMap = modifyColumns.get(tableName); if (columnMap != null && !columnMap.isEmpty()) { Set keys = columnMap.keySet(); @@ -223,7 +222,7 @@ final class SqlHelper extends SQLiteOpenHelper { } //删除中介表 mDelegate.dropTable(db, tableName + "_temp"); - }else { + } else { mDelegate.createTable(db, clazz); } } @@ -289,9 +288,9 @@ final class SqlHelper extends SQLiteOpenHelper { } /** - * 处理3.4版本之前数据库迁移,主要是修改子表外键字段对应的值 + * 处理低版本的数据库迁移,主要是修改子表外键字段对应的值 */ - private void handle314AriaUpdate(SQLiteDatabase db) { + private void handleLowAriaUpdate(SQLiteDatabase db) { String[] taskTables = new String[] { "UploadTaskEntity", "DownloadTaskEntity", "DownloadGroupTaskEntity" }; for (String taskTable : taskTables) { @@ -305,6 +304,9 @@ final class SqlHelper extends SQLiteOpenHelper { String[] keys = new String[] { "downloadPath", "groupName" }; int i = 0; for (String tableName : tables) { + if (!mDelegate.tableExists(db, tableName)) { + continue; + } String pColumn = keys[i]; String nullSql = String.format("DELETE FROM %s WHERE %s='' OR %s IS NULL", tableName, pColumn, pColumn); @@ -323,10 +325,16 @@ final class SqlHelper extends SQLiteOpenHelper { } Map> modifyColumnMap = new HashMap<>(); - Map map = new HashMap<>(); - map.put("groupName", "groupHash"); - modifyColumnMap.put("DownloadEntity", map); - modifyColumnMap.put("DownloadGroupEntity", map); + Map dMap = new HashMap<>(); + dMap.put("groupName", "groupHash"); + // 处理数据库版本小于3的字段改变 + dMap.put("downloadUrl", "url"); + dMap.put("isDownloadComplete", "isComplete"); + modifyColumnMap.put("DownloadEntity", dMap); + + Map dGMap = new HashMap<>(); + dGMap.put("groupName", "groupHash"); + modifyColumnMap.put("DownloadGroupEntity", dGMap); Map> delColumnMap = new HashMap<>(); List dEntityDel = new ArrayList<>(); diff --git a/DEV_LOG.md b/DEV_LOG.md index 4d737def..9023c673 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -3,9 +3,12 @@ - fix bug https://github.com/AriaLyy/Aria/issues/403 - fix bug https://github.com/AriaLyy/Aria/issues/414 - fix bug https://github.com/AriaLyy/Aria/issues/406 + - fix bug https://github.com/AriaLyy/Aria/issues/407 + - fix bug https://github.com/AriaLyy/Aria/issues/416 + - fix bug https://github.com/AriaLyy/Aria/issues/420 + - fix bug https://github.com/AriaLyy/Aria/issues/422 - 新增ftp上传拦截器 https://github.com/AriaLyy/Aria/issues/402 - 重构线程任务模块 - - 修复一个低版本数据库升级的问题 https://github.com/AriaLyy/Aria/issues/407 - 新增m3u8协议的文件下载 - 修复拦截器可能出现的空指针问题 - 移除`DownloadGroupEntity`字段`groupHash`的主键约束,`DownloadEntity`字段`groupHash`的外键约束,`TaskRecord`字段`dGroupHash`的外键约束 @@ -14,7 +17,8 @@ - 优化网络连接状态获取的逻辑 - 修复配置文件的某些配置失效的问题 - 新增m3u8切片状态注解`@M3U8.onPeerStart`,`@M3U8.onPeerComplete`,`@M3U8.onPeerFail` - - 新增动态指定m3u8协议视频的下载功能(边下边播) + - 新增动态指定m3u8协议视频的下载功能(边下边播下载支持),[详情](https://aria.laoyuyu.me/aria_doc/download/m3u8_vod.html) + - 优化`unknownSize`的处理,https://github.com/AriaLyy/Aria/issues/419,需要注意,如果组合任务只任务数过多,将需要更多时间才能进入下载流程 + v_3.6.4 (2019/5/16) - 优化任务接收器的代码结构 - 修复`DbEntity.saveAll()`失败的问题 diff --git a/README.md b/README.md index 87f4806d..26d8d54e 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ Aria有以下特点: - 在配置文件中很容易就可以设置CA证书的信息 + 支持[多线程分块下载](https://aria.laoyuyu.me/aria_doc/start/config.html),能更有效的发挥机器IO性能 + 支持300、301、302重定向下载链接下载 + + 支持m3u8协议的文件下载[m3u8下载](https://aria.laoyuyu.me/aria_doc/download/m3u8.html) + + 支持m3u8边下边看的下载支持,[点击查看详情](https://aria.laoyuyu.me/aria_doc/download/m3u8_vod.html) + 下载支持文件长度动态增加,文件下载初始化时将不再占用过多的内存空间,见[动态长度配置](https://aria.laoyuyu.me/aria_doc/start/config.html#%E4%B8%8B%E8%BD%BD%E5%8A%A8%E6%80%81%E6%96%87%E4%BB%B6%E8%AF%B4%E6%98%8E) [怎样使用Aria?](#使用) @@ -36,14 +38,17 @@ Aria有以下特点: +* m3u8下载 + +![m3u8点播文件边下边看](https://github.com/AriaLyy/Aria/blob/master/img/m3u8VodDownload.gif) ## 引入库 [![Core](https://api.bintray.com/packages/arialyy/maven/AriaApi/images/download.svg)](https://bintray.com/arialyy/maven/AriaApi/_latestVersion) [![Compiler](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion) ```java -compile 'com.arialyy.aria:aria-core:3.6.4' -annotationProcessor 'com.arialyy.aria:aria-compiler:3.6.4' +compile 'com.arialyy.aria:aria-core:3.6.5' +annotationProcessor 'com.arialyy.aria:aria-compiler:3.6.5' ``` 如果出现android support依赖错误,请将 `compile 'com.arialyy.aria:aria-core:'`替换为 ``` @@ -113,36 +118,25 @@ protected void onCreate(Bundle savedInstanceState) { ### 版本日志 - + v_3.6.4 (2019/5/16) - - 优化任务接收器的代码结构 - - 修复`DbEntity.saveAll()`失败的问题 - - 修复分块任务重命名失败的问题 - - fix bug https://github.com/AriaLyy/Aria/issues/379 - - 移除`getDownloadTask(String url)`、`getGroupTask(List urls)`、`getFtpDirTask(String path)` - 等获取任务的api,如果你希望获取对应状态,请使用实体的状态判断,如:`getDownloadEntity()`、`getDownloadGroupEntity()` - `getFtpDirEntity()` - - fix bug https://github.com/AriaLyy/Aria/issues/388 - - 修复使用`Content-Disposition`的文件名时,第一次下载无法重命名文件的问题 - - 修复使用`Content-Disposition`的文件名时,多次重命名文件的问题 - - 组合任务新增`unknownSize()`,用于处理组合任务大小ø未知的情况,https://github.com/AriaLyy/Aria/issues/380 - - 优化`AbsThreadTask`代码 - - 新增文件长度处理功能 https://github.com/AriaLyy/Aria/issues/393 - ```java - .setFileLenAdapter(new IHttpFileLenAdapter() { - @Override public long handleFileLen(Map> headers) { - ... - // 处理header中的文件长度 - - return fileLen; - } - }) - ``` - - 修复组合任务多次回调`onStop`注解的问题 - - 优化`isRunning()`的逻辑,任务是否在执行的判断将更加准确 - - 修复多次重复快速点击`暂停、开始`时,任务有可能重复下载的问题 - - 修复组合任务中没有等待中的只任务实体保存失败的问题 - - 新增组合任务url重复检查 https://github.com/AriaLyy/Aria/issues/395 - - 初始化任务时,如果url、path有错误将会回调`@Download.onTaskFail`、`@Upload.onTaskFail`、`@DownGroup.onTaskFail` + + v_3.6.5 + - fix bug https://github.com/AriaLyy/Aria/issues/403 + - fix bug https://github.com/AriaLyy/Aria/issues/414 + - fix bug https://github.com/AriaLyy/Aria/issues/406 + - fix bug https://github.com/AriaLyy/Aria/issues/407 + - fix bug https://github.com/AriaLyy/Aria/issues/416 + - fix bug https://github.com/AriaLyy/Aria/issues/420 + - fix bug https://github.com/AriaLyy/Aria/issues/422 + - 新增ftp上传拦截器 https://github.com/AriaLyy/Aria/issues/402 + - 重构线程任务模块 + - 新增m3u8协议的文件下载 + - 修复拦截器可能出现的空指针问题 + - 移除`DownloadGroupEntity`字段`groupHash`的主键约束,`DownloadEntity`字段`groupHash`的外键约束,`TaskRecord`字段`dGroupHash`的外键约束 + - 优化关联查询的性能 + - 修复任务记录删除失败的问题 + - 优化网络连接状态获取的逻辑 + - 修复配置文件的某些配置失效的问题 + - 新增m3u8切片状态注解`@M3U8.onPeerStart`,`@M3U8.onPeerComplete`,`@M3U8.onPeerFail` + - 新增动态指定m3u8协议视频的下载功能(边下边播下载支持),[详情](https://aria.laoyuyu.me/aria_doc/download/m3u8_vod.html) [更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md) diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml index 0889a681..dab01a5e 100644 --- a/app/src/main/assets/aria_config.xml +++ b/app/src/main/assets/aria_config.xml @@ -22,7 +22,7 @@ - + + https://atom-installer.github.com/v1.13.0/AtomSetup.exe1 http://hzdown.muzhiwan.com/2017/09/05/com.mir.iphone.empire83jie.mzw_59ae6d5a3638d.apk diff --git a/build.gradle b/build.gradle index f9e91beb..1fac0216 100644 --- a/build.gradle +++ b/build.gradle @@ -43,7 +43,7 @@ task clean(type: Delete) { ext { userOrg = 'arialyy' groupId = 'com.arialyy.aria' - publishVersion = '3.6.5_beta_3' + publishVersion = '3.6.5' // publishVersion = '1.0.4' //FTP插件 repoName='maven' desc = 'android 下载框架' diff --git a/img/m3u8VodDownload.gif b/img/m3u8VodDownload.gif index 54cb73c6..e3430fe9 100644 Binary files a/img/m3u8VodDownload.gif and b/img/m3u8VodDownload.gif differ diff --git a/py/download.py b/py/download.py index a90dd755..b06e9d7b 100644 --- a/py/download.py +++ b/py/download.py @@ -1,4 +1,5 @@ # coding=utf-8 +#!/usr/bin/python3 import os from flask import Flask, send_from_directory, request @@ -12,8 +13,8 @@ def downloader(filename): 不支持断点的下载 """ data = request.values.get('key') - print data - dirpath = 'D:/test' + print(data) + dirpath = '/Users/aria/dev/ftp' return send_from_directory(dirpath, filename, as_attachment=True) # as_attachment=True 一定要写,不然会变成打开,而不是下载 @@ -24,7 +25,7 @@ def downloader1(): """ filename = request.values.get('filename') data = request.values.get('key') - print data + print(data) dirpath = 'D:/test' return send_from_directory(dirpath, filename, as_attachment=True) # as_attachment=True 一定要写,不然会变成打开,而不是下载