This commit is contained in:
@ -13,9 +13,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.arialyy.aria.core.upload;
|
||||
package com.arialyy.aria.core;
|
||||
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Set;
|
@ -207,10 +207,11 @@ public class DownloadGroupTarget
|
||||
if (!newName.equals(entity.getFileName())) {
|
||||
String oldPath = mEntity.getDirPath() + "/" + entity.getFileName();
|
||||
String newPath = mEntity.getDirPath() + "/" + newName;
|
||||
File file = new File(oldPath);
|
||||
if (file.exists()) {
|
||||
file.renameTo(new File(newPath));
|
||||
File oldFile = new File(oldPath);
|
||||
if (oldFile.exists()) {
|
||||
oldFile.renameTo(new File(newPath));
|
||||
}
|
||||
CommonUtil.renameDownloadConfig(oldFile.getName(), newName);
|
||||
DbEntity.exeSql(
|
||||
"UPDATE DownloadTaskEntity SET key='" + newPath + "' WHERE key='" + oldPath + "'");
|
||||
entity.setDownloadPath(newPath);
|
||||
|
@ -24,7 +24,7 @@ import com.arialyy.aria.core.command.normal.NormalCmdFactory;
|
||||
import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers;
|
||||
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
|
||||
import com.arialyy.aria.core.scheduler.ISchedulerListener;
|
||||
import com.arialyy.aria.core.upload.ProxyHelper;
|
||||
import com.arialyy.aria.core.ProxyHelper;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.CheckUtil;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
|
@ -21,6 +21,7 @@ import com.arialyy.aria.core.inf.AbsNormalTarget;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
@ -48,7 +49,7 @@ public class DownloadTarget
|
||||
if (mTaskEntity.entity == null) {
|
||||
mTaskEntity.entity = entity;
|
||||
}
|
||||
mEntity = entity;
|
||||
mEntity = mTaskEntity.entity;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -102,42 +103,32 @@ public class DownloadTarget
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置文件存储路径
|
||||
* 设置文件存储路径,如果需要修改新的文件名,修改路径便可。
|
||||
* 如:原文件路径 /mnt/sdcard/test.zip
|
||||
* 如果需要将test.zip改为game.zip,只需要重新设置文件路径为:/mnt/sdcard/game.zip
|
||||
*
|
||||
* @param downloadPath 路径必须为文件路径,不能为文件夹路径
|
||||
*/
|
||||
public DownloadTarget setDownloadPath(@NonNull String downloadPath) {
|
||||
if (TextUtils.isEmpty(downloadPath)) {
|
||||
throw new IllegalArgumentException("文件保持路径不能为null");
|
||||
}
|
||||
File file = new File(downloadPath);
|
||||
if (file.isDirectory()) {
|
||||
throw new IllegalArgumentException("文件不能为文件夹");
|
||||
}
|
||||
if (!downloadPath.equals(mEntity.getDownloadPath())) {
|
||||
File oldFile = new File(mEntity.getDownloadPath());
|
||||
File newFile = new File(downloadPath);
|
||||
if (TextUtils.isEmpty(mEntity.getDownloadPath()) || oldFile.renameTo(newFile)) {
|
||||
mEntity.setDownloadPath(downloadPath);
|
||||
mEntity.setFileName(file.getName());
|
||||
mEntity.setFileName(newFile.getName());
|
||||
mTaskEntity.key = downloadPath;
|
||||
mEntity.update();
|
||||
mTaskEntity.update();
|
||||
return this;
|
||||
CommonUtil.renameDownloadConfig(oldFile.getName(), newFile.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置文件名
|
||||
*
|
||||
* @deprecated {@link #setFileName(String)}
|
||||
*/
|
||||
@Deprecated public DownloadTarget setDownloadName(@NonNull String downloadName) {
|
||||
if (TextUtils.isEmpty(downloadName)) {
|
||||
throw new IllegalArgumentException("文件名不能为null");
|
||||
}
|
||||
mEntity.setFileName(downloadName);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置文件名
|
||||
*/
|
||||
public DownloadTarget setFileName(@NonNull String fileName) {
|
||||
if (TextUtils.isEmpty(fileName)) {
|
||||
throw new IllegalArgumentException("文件名不能为null");
|
||||
}
|
||||
mEntity.setFileName(fileName);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ package com.arialyy.aria.core.upload;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.ProxyHelper;
|
||||
import com.arialyy.aria.core.command.normal.NormalCmdFactory;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsReceiver;
|
||||
|
@ -82,14 +82,6 @@ public class UploadTarget extends AbsNormalTarget<UploadTarget, UploadEntity, Up
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置文件名
|
||||
*/
|
||||
public UploadTarget setFileName(String fileName) {
|
||||
mEntity.setFileName(fileName);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置上传文件类型
|
||||
*
|
||||
|
@ -44,8 +44,12 @@ import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import java.lang.reflect.GenericArrayType;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
@ -595,6 +599,65 @@ public class CommonUtil {
|
||||
return err.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重命名下载配置文件
|
||||
* 如果旧的配置文件名不存在,则使用新的配置文件名新创建一个文件,否则将旧的配置文件重命名为新的位置文件名。
|
||||
* 除了重命名配置文件名外,还会将文件中的记录重命名为新的记录,如果没有记录,则不做处理
|
||||
*
|
||||
* @param oldName 旧的下载文件名
|
||||
* @param newName 新的下载文件名
|
||||
*/
|
||||
public static void renameDownloadConfig(String oldName, String newName) {
|
||||
renameConfig(AriaManager.APP.getFilesDir().getPath() + AriaManager.DOWNLOAD_TEMP_DIR, oldName,
|
||||
newName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重命名上传配置文件
|
||||
* 如果旧的配置文件名不存在,则使用新的配置文件名新创建一个文件,否则将旧的配置文件重命名为新的位置文件名。
|
||||
* 除了重命名配置文件名外,还会将文件中的记录重命名为新的记录,如果没有记录,则不做处理
|
||||
*
|
||||
* @param oldName 旧的上传文件名
|
||||
* @param newName 新的上传文件名
|
||||
*/
|
||||
public static void renameUploadConfig(String oldName, String newName) {
|
||||
renameConfig(AriaManager.APP.getFilesDir().getPath() + AriaManager.UPLOAD_TEMP_DIR, oldName,
|
||||
newName);
|
||||
}
|
||||
|
||||
private static void renameConfig(String basePath, String oldName, String newName) {
|
||||
if (oldName.equals(newName)) return;
|
||||
File oldFile = new File(basePath + oldName + ".properties");
|
||||
File newFile = new File(basePath + newName + ".properties");
|
||||
if (!oldFile.exists()) {
|
||||
createFile(newFile.getPath());
|
||||
} else {
|
||||
Properties pro = CommonUtil.loadConfig(oldFile);
|
||||
if (!pro.isEmpty()) {
|
||||
Set<Object> keys = pro.keySet();
|
||||
Set<String> newKeys = new LinkedHashSet<>();
|
||||
Set<String> values = new LinkedHashSet<>();
|
||||
for (Object key : keys) {
|
||||
String oldKey = String.valueOf(key);
|
||||
if (oldKey.contains(oldName)) {
|
||||
values.add(pro.getProperty(oldKey));
|
||||
newKeys.add(oldKey.replace(oldName, newName));
|
||||
}
|
||||
}
|
||||
|
||||
pro.clear();
|
||||
Iterator<String> next = values.iterator();
|
||||
for (String key : newKeys) {
|
||||
pro.setProperty(key, next.next());
|
||||
}
|
||||
|
||||
CommonUtil.saveConfig(oldFile, pro);
|
||||
}
|
||||
|
||||
oldFile.renameTo(newFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取下载配置文件
|
||||
*/
|
||||
|
@ -20,7 +20,7 @@
|
||||
<connectTimeOut value="1000"/>
|
||||
|
||||
<!--设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒-->
|
||||
<iOTimeOut value="2000"/>
|
||||
<iOTimeOut value="200"/>
|
||||
|
||||
<!--设置写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢-->
|
||||
<buffSize value="8192"/>
|
||||
|
@ -56,7 +56,6 @@ public class SimpleNotification {
|
||||
public void start() {
|
||||
Aria.download(mContext)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadName("notification_test.apk")
|
||||
.setDownloadPath(
|
||||
Environment.getExternalStorageDirectory() + "/Download/消灭星星.apk")
|
||||
.start();
|
||||
|
@ -186,19 +186,25 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
String text = ((TextView) view).getText().toString();
|
||||
if (text.equals("重新开始?") || text.equals("开始")) {
|
||||
//String text = ((TextView) view).getText().toString();
|
||||
//if (text.equals("重新开始?") || text.equals("开始")) {
|
||||
// Aria.download(this)
|
||||
// .load(DOWNLOAD_URL)
|
||||
// .addHeader("groupName", "value")
|
||||
// .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
|
||||
// .setFileName("hehe.apk")
|
||||
// .start();
|
||||
//} else if (text.equals("恢复")) {
|
||||
// Aria.download(this).load(DOWNLOAD_URL).resume();
|
||||
//}
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.addHeader("groupName", "value")
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/gggg.apk")
|
||||
.start();
|
||||
} else if (text.equals("恢复")) {
|
||||
Aria.download(this).load(DOWNLOAD_URL).resume();
|
||||
}
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
Aria.download(this).load(DOWNLOAD_URL).stop();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
|
@ -43,12 +43,4 @@ public class GroupModule extends BaseModule {
|
||||
Collections.addAll(names, str);
|
||||
return names;
|
||||
}
|
||||
|
||||
//NormalList<String> convertPath(NormalList<String> urls){
|
||||
// NormalList<String> paths = new ArrayList<>();
|
||||
//
|
||||
// for (String url : urls){
|
||||
//
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
@ -68,7 +68,6 @@ final class FileListAdapter extends AbsRVAdapter<FileListEntity, FileListAdapter
|
||||
Toast.makeText(getContext(), "开始下载:" + item.name, Toast.LENGTH_SHORT).show();
|
||||
Aria.download(getContext())
|
||||
.load(item.downloadUrl)
|
||||
.setFileName(item.name)
|
||||
.setDownloadPath(item.downloadPath)
|
||||
.start();
|
||||
}
|
||||
|
Reference in New Issue
Block a user