Skip to content
Permalink
Browse files

fix bug #100 #98

  • Loading branch information...
AriaLyy committed Aug 31, 2017
1 parent 219275b commit f9a65fe38bc587185fdb73ae12afe28886398e9d
@@ -29,12 +29,18 @@
import android.text.TextUtils;
import android.util.Log;
import android.widget.PopupWindow;
import com.arialyy.aria.core.command.ICmd;
import com.arialyy.aria.core.common.QueueMod;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadReceiver;
import com.arialyy.aria.core.command.ICmd;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.IReceiver;
import com.arialyy.aria.core.scheduler.AbsSchedulerListener;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.upload.UploadReceiver;
import com.arialyy.aria.core.upload.UploadTaskEntity;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.orm.DbUtil;
import com.arialyy.aria.util.CommonUtil;
import java.io.File;
@@ -184,6 +190,45 @@ UploadReceiver upload(Object obj) {
return (receiver instanceof UploadReceiver) ? (UploadReceiver) receiver : null;
}

/**
* 获取Aria下载错误日志
*
* @return 如果错误日志不存在则返回空,否则返回错误日志列表
*/
public List<ErrorEntity> getErrorLog() {
return DbEntity.findAllData(ErrorEntity.class);
}

/**
* 清楚错误日志
*/
public void cleanLog() {
DbEntity.clean(ErrorEntity.class);
}

/**
* 删除任务记录
*
* @param type 需要删除的任务类型,1、表示单任务下载。2、表示任务组下载。3、单任务上传
* @param key 下载为保存路径、任务组为任务组名、上传为上传文件路径
*/
public void delRecord(int type, String key) {
switch (type) {
case 1:
DbEntity.deleteData(DownloadEntity.class, "url=?", key);
DbEntity.deleteData(DownloadTaskEntity.class, "key=? and isGroupTask='false'", key);
break;
case 2:
DbEntity.deleteData(DownloadGroupEntity.class, "groupName=?", key);
DbEntity.deleteData(DownloadGroupTaskEntity.class, "key=?", key);
break;
case 3:
DbEntity.deleteData(UploadEntity.class, "filePath=?", key);
DbEntity.deleteData(UploadTaskEntity.class, "key=?", key);
break;
}
}

private IReceiver putReceiver(boolean isDownload, Object obj) {
final String key = getKey(isDownload, obj);
IReceiver receiver = mReceivers.get(key);
@@ -0,0 +1,77 @@
/*
* 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.core;

import com.arialyy.aria.orm.DbEntity;

/**
* Created by Aria.Lao on 2017/8/29.
* 错误实体
*/
public class ErrorEntity extends DbEntity {

/**
* 插入时间
*/
public long insertTime;

/**
* 错误信息
*/
public String err;

/**
* 任务名
*/
public String taskName;

/**
*任务类型
*/
public String taskType;

/**
* 提示
*/
public String msg;

/**
* 任务key
*/
public String key;

@Override public String toString() {
return "ErrorEntity{"
+ "insertTime="
+ insertTime
+ ", err='"
+ err
+ '\''
+ ", taskName='"
+ taskName
+ '\''
+ ", taskType='"
+ taskType
+ '\''
+ ", msg='"
+ msg
+ '\''
+ ", key='"
+ key
+ '\''
+ '}';
}
}
@@ -24,6 +24,7 @@
import com.arialyy.aria.core.inf.IEventListener;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.ErrorHelp;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
@@ -33,7 +34,7 @@

/**
* Created by lyy on 2017/1/18.
* 下载线程
* 任务线程
*/
public abstract class AbsThreadTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>>
implements Runnable {
@@ -59,6 +60,7 @@
*/
public static String SERVER_CHARSET = "ISO-8859-1";
private int mFailNum = 0;
private String mTaskType;
private Timer mFailTimer;

protected AbsThreadTask(StateConstance constance, IEventListener listener,
@@ -76,8 +78,11 @@ protected AbsThreadTask(StateConstance constance, IEventListener listener,
}
mBufSize = manager.getDownloadConfig().getBuffSize();
setMaxSpeed(AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMsxSpeed());
mTaskType = getTaskType();
}

protected abstract String getTaskType();

public void setMaxSpeed(double maxSpeed) {
if (-0.9999 < maxSpeed && maxSpeed < 0.00001) {
mSleepTime = 0;
@@ -93,7 +98,7 @@ private boolean filterVersion() {
}

/**
* 停止下载
* 停止任务
*/
public void stop() {
synchronized (AriaManager.LOCK) {
@@ -124,7 +129,7 @@ public void stop() {
}

/**
* 下载中
* 执行中
*/
protected void progress(long len) {
synchronized (AriaManager.LOCK) {
@@ -134,7 +139,7 @@ protected void progress(long len) {
}

/**
* 取消下载
* 取消任务
*/
public void cancel() {
synchronized (AriaManager.LOCK) {
@@ -185,6 +190,7 @@ protected void fail(long currentLocation, String msg, Exception ex) {
} else {
Log.e(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】执行失败");
mListener.onFail(true);
ErrorHelp.saveError(mTaskType, mEntity, "", CommonUtil.getPrintException(ex));
}
} catch (IOException e) {
e.printStackTrace();
@@ -27,6 +27,7 @@
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.BufferedRandomAccessFile;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.ErrorHelp;
import java.io.File;
import java.io.IOException;

@@ -103,11 +104,11 @@
return null;
}


private void failDownload(String errorMsg) {
closeTimer();
Log.e(TAG, errorMsg);
mConstance.isRunning = false;
mListener.onFail(false);
ErrorHelp.saveError("", mEntity, "", errorMsg);
}
}
@@ -18,6 +18,7 @@
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.util.ErrorHelp;
import java.util.Set;

/**
@@ -47,6 +48,7 @@ public FtpDirDownloadUtil(IDownloadGroupListener listener, DownloadGroupTaskEnti

@Override public void onFail(String url, String errorMsg) {
mListener.onFail(true);
ErrorHelp.saveError("FTP_DIR", mTaskEntity.getEntity(), "", errorMsg);
}
}).start();
}
@@ -148,4 +148,8 @@
}
}
}

@Override protected String getTaskType() {
return "FTP_DOWNLOAD";
}
}
@@ -126,4 +126,8 @@
}
}
}

@Override protected String getTaskType() {
return "HTTP_DOWNLOAD";
}
}
@@ -20,6 +20,7 @@
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.IDownloadListener;
import com.arialyy.aria.util.ErrorHelp;

/**
* Created by lyy on 2015/8/25.
@@ -83,6 +84,7 @@ public void setMaxSpeed(double maxSpeed) {

private void failDownload(String msg) {
mListener.onFail(true);
ErrorHelp.saveError("HTTP_DOWNLOAD", mTaskEntity.getEntity(), msg, "");
}

@Override public void run() {
@@ -45,6 +45,7 @@
super(constance, listener, info);
}


@Override public void run() {
FTPClient client = null;
OutputStream os = null;
@@ -181,4 +182,9 @@ private FTPClient createClient() throws IOException {
client.allocate(mBufSize);
return client;
}

@Override protected String getTaskType() {
return "FTP_UPLOAD";
}

}
@@ -202,4 +202,8 @@ private String finish(PrintWriter writer) throws IOException {
mOutputStream.close();
return response.toString();
}

@Override protected String getTaskType() {
return "HTTP_UPLOAD";
}
}
@@ -16,6 +16,7 @@
package com.arialyy.aria.orm;

import android.text.TextUtils;
import com.arialyy.aria.core.ErrorEntity;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
@@ -32,7 +33,7 @@
class DBConfig {
static Map<String, Class> mapping = new HashMap<>();
static String DB_NAME;
static int VERSION = 12;
static int VERSION = 13;

static {
if (TextUtils.isEmpty(DB_NAME)) {
@@ -50,5 +51,6 @@
mapping.put("DownloadGroupTaskEntity", DownloadGroupTaskEntity.class);
mapping.put("UploadEntity", UploadEntity.class);
mapping.put("UploadTaskEntity", UploadTaskEntity.class);
mapping.put("ErrorEntity", ErrorEntity.class);
}
}
@@ -36,6 +36,13 @@ protected DbEntity() {

}

/**
* 清空表数据
*/
public static <T extends DbEntity> void clean(Class<T> clazz) {
DbUtil.getInstance().clean(clazz);
}

/**
* 直接执行sql语句
*/
@@ -64,6 +64,18 @@ protected static DbUtil getInstance() {
return INSTANCE;
}

/**
* 清空表数据
*/
synchronized <T extends DbEntity> void clean(Class<T> clazz) {
checkDb();
String tableName = CommonUtil.getClassName(clazz);
if (tableExists(clazz)) {
String sql = "DELETE FROM " + tableName;
exeSql(sql);
}
}

/**
* 执行sql语句
*/
Oops, something went wrong.

0 comments on commit f9a65fe

Please sign in to comment.
You can’t perform that action at this time.