fix bug https://github.com/AriaLyy/Aria/issues/505 增加上传任务强制上传的功能
This commit is contained in:
@@ -78,12 +78,6 @@ public class TaskRecord extends DbEntity {
|
||||
*/
|
||||
public boolean isBlock = false;
|
||||
|
||||
/**
|
||||
* 是否是使用虚拟文件下载的
|
||||
* {@code true}是,{@code false}不是
|
||||
*/
|
||||
public boolean isOpenDynamicFile = false;
|
||||
|
||||
/**
|
||||
* 线程类型
|
||||
* {@link #TYPE_HTTP_FTP}、{@link #TYPE_M3U8_VOD}
|
||||
|
||||
@@ -125,7 +125,6 @@ public class RecordHandler implements IRecordHandler {
|
||||
}
|
||||
mTaskWrapper.setNewTask(false);
|
||||
mTaskRecord = mAdapter.createTaskRecord(threadNum);
|
||||
mTaskRecord.isOpenDynamicFile = false;
|
||||
mTaskRecord.isBlock = false;
|
||||
File tempFile = new File(getFilePath());
|
||||
for (int i = 0; i < threadNum; i++) {
|
||||
|
||||
@@ -45,13 +45,13 @@ public class RecordHelper {
|
||||
/**
|
||||
* 处理非分块的,多线程任务
|
||||
*/
|
||||
public void handleMutilRecord() {
|
||||
public void handleMultiRecord() {
|
||||
// 默认线程分块长度
|
||||
long blockSize = mWrapper.getEntity().getFileSize() / mTaskRecord.threadRecords.size();
|
||||
File temp = new File(mTaskRecord.filePath);
|
||||
boolean fileExists = false;
|
||||
if (!temp.exists()) {
|
||||
BufferedRandomAccessFile tempFile = null;
|
||||
BufferedRandomAccessFile tempFile;
|
||||
try {
|
||||
tempFile = new BufferedRandomAccessFile(temp, "rw");
|
||||
tempFile.setLength(mWrapper.getEntity().getFileSize());
|
||||
@@ -145,10 +145,10 @@ public class RecordHelper {
|
||||
tr.startLocation = 0;
|
||||
tr.isComplete = false;
|
||||
tr.endLocation = mWrapper.getEntity().getFileSize();
|
||||
} else if (mTaskRecord.isOpenDynamicFile) {
|
||||
} else if (mTaskRecord.isBlock) {
|
||||
if (file.length() > mWrapper.getEntity().getFileSize()) {
|
||||
ALog.i(TAG, String.format("文件【%s】错误,任务重新开始", file.getPath()));
|
||||
file.delete();
|
||||
FileUtil.deleteFile(file);
|
||||
tr.startLocation = 0;
|
||||
tr.isComplete = false;
|
||||
tr.endLocation = mWrapper.getEntity().getFileSize();
|
||||
|
||||
@@ -35,8 +35,6 @@ public class SubThreadConfig {
|
||||
public ThreadRecord record;
|
||||
// 状态处理器
|
||||
public Handler stateHandler;
|
||||
// 动态文件
|
||||
public boolean isOpenDynamicFile;
|
||||
// m3u8切片索引
|
||||
public int peerIndex;
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.arialyy.aria.core.download;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.common.AbsGroupEntity;
|
||||
import com.arialyy.aria.core.wrapper.ITaskWrapper;
|
||||
import com.arialyy.aria.orm.annotation.Ignore;
|
||||
@@ -48,7 +49,12 @@ public class DownloadGroupEntity extends AbsGroupEntity {
|
||||
}
|
||||
|
||||
@Override public int getTaskType() {
|
||||
return getKey().startsWith("ftp") ? ITaskWrapper.D_FTP_DIR : ITaskWrapper.DG_HTTP;
|
||||
if (getSubEntities() == null || getSubEntities().isEmpty() || TextUtils.isEmpty(
|
||||
getSubEntities().get(0).getUrl())) {
|
||||
return ITaskWrapper.ERROR;
|
||||
}
|
||||
return getSubEntities().get(0).getUrl().startsWith("ftp") ? ITaskWrapper.D_FTP_DIR
|
||||
: ITaskWrapper.DG_HTTP;
|
||||
}
|
||||
|
||||
public DownloadGroupEntity() {
|
||||
|
||||
@@ -142,7 +142,6 @@ public class NormalLoader extends AbsLoader {
|
||||
String.format(IRecordHandler.SUB_PATH, mTempFile.getPath(), record.threadId))
|
||||
: mTempFile;
|
||||
config.isBlock = mRecord.isBlock;
|
||||
config.isOpenDynamicFile = mRecord.isOpenDynamicFile;
|
||||
config.startThreadNum = startNum;
|
||||
config.taskWrapper = mTaskWrapper;
|
||||
config.record = record;
|
||||
|
||||
@@ -463,8 +463,6 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver {
|
||||
if (mRecord != null) {
|
||||
mRecord.isComplete = isComplete;
|
||||
if (mConfig.isBlock) {
|
||||
mRecord.startLocation = record;
|
||||
} else if (mConfig.isOpenDynamicFile) {
|
||||
mRecord.startLocation = mConfig.tempFile.length();
|
||||
} else {
|
||||
if (0 < record && record < mRecord.endLocation) {
|
||||
|
||||
@@ -29,6 +29,11 @@ public class UTaskWrapper extends AbsTaskWrapper<UploadEntity> {
|
||||
*/
|
||||
private String tempUrl;
|
||||
|
||||
/**
|
||||
* 如果文件路径被其它任务占用,设置为true时,删除其它任务
|
||||
*/
|
||||
private boolean forceUpload = false;
|
||||
|
||||
public UTaskWrapper(UploadEntity entity) {
|
||||
super(entity);
|
||||
}
|
||||
@@ -48,6 +53,14 @@ public class UTaskWrapper extends AbsTaskWrapper<UploadEntity> {
|
||||
return getEntity().getKey();
|
||||
}
|
||||
|
||||
public boolean isForceUpload() {
|
||||
return forceUpload;
|
||||
}
|
||||
|
||||
public void setForceUpload(boolean forceUpload) {
|
||||
this.forceUpload = forceUpload;
|
||||
}
|
||||
|
||||
@Override public UploadConfig getConfig() {
|
||||
return Configuration.getInstance().uploadCfg;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.arialyy.aria.core.upload;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.common.AbsNormalEntity;
|
||||
import com.arialyy.aria.core.wrapper.ITaskWrapper;
|
||||
import com.arialyy.aria.orm.annotation.Primary;
|
||||
@@ -58,7 +59,10 @@ public class UploadEntity extends AbsNormalEntity implements Parcelable {
|
||||
}
|
||||
|
||||
@Override public int getTaskType() {
|
||||
return getUrl().startsWith("ftp") ? ITaskWrapper.D_FTP : ITaskWrapper.D_HTTP;
|
||||
if (TextUtils.isEmpty(getUrl())){
|
||||
return ITaskWrapper.ERROR;
|
||||
}
|
||||
return getUrl().startsWith("ftp") ? ITaskWrapper.U_FTP : ITaskWrapper.U_HTTP;
|
||||
}
|
||||
|
||||
public UploadEntity() {
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.arialyy.aria.core.event.ErrorEvent;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.inf.ITaskOption;
|
||||
import com.arialyy.aria.core.upload.UploadEntity;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.ComponentUtil;
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,7 +34,7 @@ class DBConfig {
|
||||
static boolean DEBUG = false;
|
||||
static Map<String, Class> mapping = new LinkedHashMap<>();
|
||||
static String DB_NAME;
|
||||
static int VERSION = 55;
|
||||
static int VERSION = 56;
|
||||
|
||||
/**
|
||||
* 是否将数据库保存在Sd卡,{@code true} 是
|
||||
|
||||
@@ -76,9 +76,6 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
// 需要使用如下语句:
|
||||
db.execSQL("PRAGMA foreign_keys=ON;");
|
||||
}
|
||||
if (DBConfig.DEBUG) {
|
||||
db.enableWriteAheadLogging();
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onCreate(SQLiteDatabase db) {
|
||||
@@ -139,6 +136,7 @@ final class SqlHelper extends SQLiteOpenHelper {
|
||||
SQLiteDatabase.CREATE_IF_NECESSARY);
|
||||
}
|
||||
}
|
||||
db.enableWriteAheadLogging();
|
||||
return db;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.arialyy.aria.util;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.inf.IRecordHandler;
|
||||
import com.arialyy.aria.core.upload.UploadEntity;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.List;
|
||||
@@ -37,7 +38,7 @@ public class CheckUtil {
|
||||
* @param filePath 文件保存路径
|
||||
* @return false 任务不再执行,true 任务继续执行
|
||||
*/
|
||||
public static boolean checkAndHandlePathConflicts(boolean isForceDownload, String filePath) {
|
||||
public static boolean checkDownloadPathConflicts(boolean isForceDownload, String filePath) {
|
||||
if (DbEntity.checkDataExist(DownloadEntity.class, "downloadPath=?", filePath)) {
|
||||
if (!isForceDownload) {
|
||||
ALog.e(TAG, String.format("下载失败,保存路径【%s】已经被其它任务占用,请设置其它保存路径", filePath));
|
||||
@@ -51,6 +52,27 @@ public class CheckUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查和处理路径冲突
|
||||
*
|
||||
* @param isForceUpload true,如果路径冲突,将删除其它任务的记录的
|
||||
* @param filePath 文件保存路径
|
||||
* @return false 任务不再执行,true 任务继续执行
|
||||
*/
|
||||
public static boolean checkUploadPathConflicts(boolean isForceUpload, String filePath) {
|
||||
if (DbEntity.checkDataExist(UploadEntity.class, "filePath=?", filePath)) {
|
||||
if (!isForceUpload) {
|
||||
ALog.e(TAG, String.format("上传失败,文件路径【%s】已经被其它任务占用,请设置其它保存路径", filePath));
|
||||
return false;
|
||||
} else {
|
||||
ALog.w(TAG, String.format("文件路径【%s】已经被其它任务占用,当前任务将覆盖该路径的文件", filePath));
|
||||
RecordUtil.delTaskRecord(filePath, IRecordHandler.TYPE_UPLOAD);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查成员类是否是静态和public
|
||||
*/
|
||||
|
||||
@@ -101,6 +101,9 @@ public class ComponentUtil {
|
||||
public <T extends IUtil> T buildUtil(AbsTaskWrapper wrapper, IEventListener listener) {
|
||||
int requestType = wrapper.getRequestType();
|
||||
String className = null;
|
||||
if (requestType == 1){
|
||||
throw new IllegalArgumentException("xxxx");
|
||||
}
|
||||
switch (requestType) {
|
||||
case ITaskWrapper.M3U8_LIVE:
|
||||
className = "com.arialyy.aria.m3u8.live.M3U8LiveUtil";
|
||||
|
||||
@@ -50,17 +50,7 @@ public class ErrorHelp {
|
||||
CommonUtil.getAppPath(AriaConfig.getInstance().getAPP()),
|
||||
getData("yyyy-MM-dd_HH_mm_ss"));
|
||||
|
||||
File log = new File(path);
|
||||
if (!log.getParentFile().exists()) {
|
||||
log.getParentFile().mkdirs();
|
||||
}
|
||||
if (!log.exists()) {
|
||||
try {
|
||||
log.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
FileUtil.createFile(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ public class RecordUtil {
|
||||
filePath = ((DownloadEntity) entity).getDownloadPath();
|
||||
} else if (entity instanceof UploadEntity) {
|
||||
type = IRecordHandler.TYPE_UPLOAD;
|
||||
filePath = ((UploadEntity) entity).getFilePath();
|
||||
filePath = entity.getFilePath();
|
||||
} else {
|
||||
ALog.w(TAG, "删除记录失败,未知类型");
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user