修复连接中有+导致的地址呗使用问题。

修复表重复创建导致的崩溃问题 https://github.com/AriaLyy/Aria/issues/264
pull/330/head
laoyuyu 7 years ago
parent ed8430e45c
commit 0a85477da3
  1. 20
      Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java
  2. 17
      Aria/src/main/java/com/arialyy/aria/orm/DelegateCommon.java
  3. 7
      Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java
  4. 10
      Aria/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java
  5. BIN
      app/libs/siteparser.aar
  6. 2
      app/src/main/java/com/arialyy/simple/download/HighestPriorityActivity.java
  7. 5
      app/src/main/java/com/arialyy/simple/test/AnyRunActivity.java
  8. 2
      app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java

@ -32,7 +32,7 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
/** /**
* 资源地址 * 资源地址
*/ */
protected String url; protected String url, newUrl;
/** /**
* 通过地址初始化target * 通过地址初始化target
@ -48,6 +48,24 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
} }
} }
/**
* 更新下载url
*
* @param newUrl 新的下载url
*/
public TARGET updateUrl(String newUrl) {
if (TextUtils.isEmpty(newUrl)) {
ALog.e(TAG, "下载url更新失败,newUrl为null");
return (TARGET) this;
}
if (url.equals(newUrl)) {
ALog.e(TAG, "下载url更新失败,新的下载url和旧的url一致");
return (TARGET) this;
}
this.newUrl = newUrl;
return (TARGET) this;
}
/** /**
* 将任务设置为最高优先级任务最高优先级任务有以下特点 * 将任务设置为最高优先级任务最高优先级任务有以下特点
* 1在下载队列中有且只有一个最高优先级任务 * 1在下载队列中有且只有一个最高优先级任务

@ -41,7 +41,7 @@ class DelegateCommon extends AbsDelegate {
*/ */
void dropTable(SQLiteDatabase db, String tableName) { void dropTable(SQLiteDatabase db, String tableName) {
db = checkDb(db); db = checkDb(db);
String deleteSQL = "DROP TABLE IF EXISTS ".concat(tableName); String deleteSQL = String.format("DROP TABLE IF EXISTS %s", tableName);
print(DROP_TABLE, deleteSQL); print(DROP_TABLE, deleteSQL);
//db.beginTransaction(); //db.beginTransaction();
db.execSQL(deleteSQL); db.execSQL(deleteSQL);
@ -75,12 +75,11 @@ class DelegateCommon extends AbsDelegate {
db = checkDb(db); db = checkDb(db);
Cursor cursor = null; Cursor cursor = null;
try { try {
StringBuilder sb = new StringBuilder(); String sql =
sb.append("SELECT COUNT(*) AS c FROM sqlite_master WHERE type='table' AND name='"); String.format("SELECT name FROM sqlite_master WHERE type='table' AND name='%s'",
sb.append(tableName); tableName);
sb.append("'"); print(TABLE_EXISTS, sql);
print(TABLE_EXISTS, sb.toString()); cursor = db.rawQuery(sql, null);
cursor = db.rawQuery(sb.toString(), null);
if (cursor != null && cursor.moveToNext()) { if (cursor != null && cursor.moveToNext()) {
int count = cursor.getInt(0); int count = cursor.getInt(0);
if (count > 0) { if (count > 0) {
@ -133,7 +132,7 @@ class DelegateCommon extends AbsDelegate {
//外键Map,在Sqlite3中foreign修饰的字段必须放在最后 //外键Map,在Sqlite3中foreign修饰的字段必须放在最后
final List<Field> foreignArray = new ArrayList<>(); final List<Field> foreignArray = new ArrayList<>();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("CREATE TABLE ") sb.append("CREATE TABLE IF NOT EXISTS ")
.append(CommonUtil.getClassName(clazz)) .append(CommonUtil.getClassName(clazz))
.append(" ("); .append(" (");
for (Field field : fields) { for (Field field : fields) {
@ -187,7 +186,7 @@ class DelegateCommon extends AbsDelegate {
} }
} }
if (SqlUtil.isUnique(field)){ if (SqlUtil.isUnique(field)) {
sb.append(" UNIQUE"); sb.append(" UNIQUE");
} }

@ -34,7 +34,6 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.WeakHashMap;
/** /**
* Created by laoyuyu on 2018/3/22. * Created by laoyuyu on 2018/3/22.
@ -441,18 +440,18 @@ class DelegateFind extends AbsDelegate {
field.setBoolean(entity, !temp.equalsIgnoreCase("false")); field.setBoolean(entity, !temp.equalsIgnoreCase("false"));
} }
} else if (type == java.util.Date.class || type == java.sql.Date.class) { } else if (type == java.util.Date.class || type == java.sql.Date.class) {
field.set(entity, new Date(cursor.getString(column))); field.set(entity, new Date(URLDecoder.decode(cursor.getString(column))));
} else if (type == byte[].class) { } else if (type == byte[].class) {
field.set(entity, cursor.getBlob(column)); field.set(entity, cursor.getBlob(column));
} else if (type == Map.class) { } else if (type == Map.class) {
String temp = cursor.getString(column); String temp = cursor.getString(column);
if (!TextUtils.isEmpty(temp)) { if (!TextUtils.isEmpty(temp)) {
field.set(entity, SqlUtil.str2Map(temp)); field.set(entity, SqlUtil.str2Map(URLDecoder.decode(temp)));
} }
} else if (type == List.class) { } else if (type == List.class) {
String value = cursor.getString(column); String value = cursor.getString(column);
if (!TextUtils.isEmpty(value)) { if (!TextUtils.isEmpty(value)) {
field.set(entity, SqlUtil.str2List(value, field)); field.set(entity, SqlUtil.str2List(URLDecoder.decode(value), field));
} }
} }
} }

@ -24,6 +24,7 @@ import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.net.URLEncoder;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -123,7 +124,7 @@ class DelegateUpdate extends AbsDelegate {
Object obj = field.get(dbEntity); Object obj = field.get(dbEntity);
value = obj == null ? "" : convertValue(obj.toString()); value = obj == null ? "" : convertValue(obj.toString());
} }
values.put(field.getName(), value); values.put(field.getName(), encodeStr(value));
} }
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
@ -165,7 +166,7 @@ class DelegateUpdate extends AbsDelegate {
value = convertValue(field.get(dbEntity).toString()); value = convertValue(field.get(dbEntity).toString());
} }
} }
values.put(field.getName(), value); values.put(field.getName(), encodeStr(value));
} }
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
@ -175,6 +176,11 @@ class DelegateUpdate extends AbsDelegate {
close(db); close(db);
} }
private String encodeStr(String str) {
str = str.replaceAll("\\\\+", "%2B");
return URLEncoder.encode(str);
}
/** /**
* {@code true}自动增长的主键和需要忽略的字段 * {@code true}自动增长的主键和需要忽略的字段
*/ */

Binary file not shown.

@ -82,7 +82,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
mStart.setText("恢复"); mStart.setText("恢复");
mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light)); mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
setBtState(true); setBtState(true);
} else if (target.isDownloading()) { } else if (target.isRunning()) {
setBtState(false); setBtState(false);
} }
mSize.setText(target.getConvertFileSize()); mSize.setText(target.getConvertFileSize());

@ -4,11 +4,13 @@ import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.simple.R; import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityTestBinding; import com.arialyy.simple.databinding.ActivityTestBinding;
import java.util.List;
/** /**
* Created by laoyuyu on 2018/4/13. * Created by laoyuyu on 2018/4/13.
@ -26,7 +28,8 @@ public class AnyRunActivity extends BaseActivity<ActivityTestBinding> {
//String URL = "https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe"; //String URL = "https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe";
//String URL = "ftp://192.168.29.140:21/download/SDK_Demo-release.apk"; //String URL = "ftp://192.168.29.140:21/download/SDK_Demo-release.apk";
//String URL = "ftp://z:z@dygod18.com:21211/[电影天堂www.dy2018.com]猩球崛起3:终极之战BD国英双语中英双字.mkv"; //String URL = "ftp://z:z@dygod18.com:21211/[电影天堂www.dy2018.com]猩球崛起3:终极之战BD国英双语中英双字.mkv";
private String URL = "https://www.bilibili.com/bangumi/play/ep77693"; //private String URL = "https://www.bilibili.com/bangumi/play/ep77693";
private String URL = "http://cn-hbsjz-cmcc-v-03.acgvideo.com/upgcxcode/63/82/5108263/5108263-1-80.flv?expires=1530178500&platform=pc&ssig=vr7gLl0duyqWqSMnIpzaDA&oi=3746029570&nfa=BpfiWF+i4mNW8KzjZFHzBQ==&dynamic=1&hfa=2030547937&hfb=Yjk5ZmZjM2M1YzY4ZjAwYTMzMTIzYmIyNWY4ODJkNWI=&trid=3476be01a9254115b15f8cc7198600fe&nfc=1";
@Override protected int setLayoutId() { @Override protected int setLayoutId() {
return R.layout.activity_test; return R.layout.activity_test;

@ -65,7 +65,7 @@ public class AnyRunnModule {
void start(String url) { void start(String url) {
mUrl = url; mUrl = url;
String path = Environment.getExternalStorageDirectory().getPath() + "/aaa.apk"; String path = Environment.getExternalStorageDirectory().getPath() + "/aaas.apk";
//File file = new File(path); //File file = new File(path);
//if (file.exists()) { //if (file.exists()) {
// file.delete(); // file.delete();

Loading…
Cancel
Save