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 639649eb..c57e6f01 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -26,6 +26,7 @@ import android.os.Build; import android.os.Bundle; import android.support.v4.app.Fragment; import android.text.TextUtils; +import android.util.Log; import android.widget.PopupWindow; import com.arialyy.aria.core.download.DownloadReceiver; import com.arialyy.aria.core.inf.ICmd; @@ -65,8 +66,8 @@ import org.xml.sax.SAXException; DbUtil.init(context.getApplicationContext()); APP = context.getApplicationContext(); regAppLifeCallback(context); - File dFile = new File(Configuration.DOWNLOAD_CONFIG_FILE); - File uFile = new File(Configuration.UPLOAD_CONFIG_FILE); + File dFile = new File(APP.getFilesDir().getPath() + Configuration.DOWNLOAD_CONFIG_FILE); + File uFile = new File(APP.getFilesDir().getPath() +Configuration.UPLOAD_CONFIG_FILE); if (!dFile.exists() || !uFile.exists()) { loadConfig(); } @@ -105,7 +106,7 @@ import org.xml.sax.SAXException; * 如果需要在代码中修改下载配置,请使用以下方法 * * @ //修改最大任务队列数 - * Aria.get(this).getDownloadConfig().setMaxTaskNum(3).save(); + * Aria.get(this).getDownloadConfig().setMaxTaskNum(3).saveAll(); * */ public Configuration.DownloadConfig getDownloadConfig() { @@ -116,7 +117,7 @@ import org.xml.sax.SAXException; * 如果需要在代码中修改下载配置,请使用以下方法 * * @ //修改最大任务队列数 - * Aria.get(this).getUploadConfig().setMaxTaskNum(3).save(); + * Aria.get(this).getUploadConfig().setMaxTaskNum(3).saveAll(); * */ public Configuration.UploadConfig getUploadConfig() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java b/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java index db5f37a9..dcb9cb68 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java @@ -215,7 +215,7 @@ public class ConfigHelper extends DefaultHandler { @Override public void endDocument() throws SAXException { super.endDocument(); - mDownloadConfig.save(); - mUploadConfig.save(); + mDownloadConfig.saveAll(); + mUploadConfig.saveAll(); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/Configuration.java b/Aria/src/main/java/com/arialyy/aria/core/Configuration.java index f7a1aef7..3ce98ac4 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/Configuration.java +++ b/Aria/src/main/java/com/arialyy/aria/core/Configuration.java @@ -15,6 +15,8 @@ */ package com.arialyy.aria.core; +import android.util.Log; +import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.ReflectionUtil; import java.io.File; @@ -35,6 +37,10 @@ class Configuration { * 通用配置 */ public static class BaseConfig { + /** + * 旧任务数 + */ + public static int oldMaxTaskNum = 2; /** * 是否发送任务广播,true,发送 @@ -63,6 +69,7 @@ class Configuration { public BaseConfig setOpenBreadCast(boolean openBreadCast) { isOpenBreadCast = openBreadCast; + saveKey("isOpenBreadCast", openBreadCast + ""); return this; } @@ -71,7 +78,10 @@ class Configuration { } public BaseConfig setMaxTaskNum(int maxTaskNum) { + oldMaxTaskNum = this.maxTaskNum; this.maxTaskNum = maxTaskNum; + saveKey("maxTaskNum", maxTaskNum + ""); + DownloadTaskQueue.getInstance().setDownloadNum(maxTaskNum); return this; } @@ -81,6 +91,7 @@ class Configuration { public BaseConfig setReTryNum(int reTryNum) { this.reTryNum = reTryNum; + saveKey("reTryNum", reTryNum + ""); return this; } @@ -90,6 +101,7 @@ class Configuration { public BaseConfig setReTryInterval(long reTryInterval) { this.reTryInterval = reTryInterval; + saveKey("reTryInterval", reTryInterval + ""); return this; } @@ -99,9 +111,25 @@ class Configuration { public BaseConfig setConnectTimeOut(long connectTimeOut) { this.connectTimeOut = connectTimeOut; + saveKey("connectTimeOut", connectTimeOut + ""); return this; } + /** + * 保存key + */ + void saveKey(String key, String value) { + boolean isDownload = this instanceof DownloadConfig; + File file = new File( + AriaManager.APP.getFilesDir().getPath() + (isDownload ? DOWNLOAD_CONFIG_FILE + : UPLOAD_CONFIG_FILE)); + if (file.exists()) { + Properties properties = CommonUtil.loadConfig(file); + properties.setProperty(key, value); + CommonUtil.saveConfig(file, properties); + } + } + /** * 加载配置 */ @@ -145,7 +173,7 @@ class Configuration { /** * 保存配置 */ - public void save() { + void saveAll() { List fields = ReflectionUtil.getAllFields(getClass()); boolean isDownload = this instanceof DownloadConfig; try { @@ -199,6 +227,7 @@ class Configuration { public DownloadConfig setiOTimeOut(long iOTimeOut) { this.iOTimeOut = iOTimeOut; + saveKey("iOTimeOut", iOTimeOut + ""); return this; } @@ -208,6 +237,7 @@ class Configuration { public DownloadConfig setBuffSize(int buffSize) { this.buffSize = buffSize; + saveKey("buffSize", buffSize + ""); return this; } @@ -217,6 +247,7 @@ class Configuration { public DownloadConfig setCaPath(String caPath) { this.caPath = caPath; + saveKey("caPath", caPath); return this; } @@ -226,6 +257,7 @@ class Configuration { public DownloadConfig setCaName(String caName) { this.caName = caName; + saveKey("caName", caName); return this; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java index 073621ef..210b835e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java @@ -122,7 +122,7 @@ public class DownloadTaskQueue @Override public void setDownloadNum(int downloadNum) { //原始长度 - int size = AriaManager.getInstance(AriaManager.APP).getUploadConfig().getMaxTaskNum(); + int size = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().oldMaxTaskNum; int diff = downloadNum - size; if (size == downloadNum) { Log.d(TAG, "设置的下载任务数和配置文件的下载任务数一直,跳过"); diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java index 7f05cbff..8469cb0f 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java @@ -66,11 +66,11 @@ public interface ITaskQueue implements IPool { private ArrayBlockingQueue mExecuteQueue; private Map mExecuteArray; private int mSize; - private boolean isDownload; public ExecutePool(boolean isDownload) { - this.isDownload = isDownload; if (isDownload) { mSize = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum(); } else { @@ -87,11 +85,6 @@ public class ExecutePool implements IPool { } mExecuteQueue = temp; mSize = downloadNum; - if (isDownload) { - AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setMaxTaskNum(downloadNum); - } else { - AriaManager.getInstance(AriaManager.APP).getUploadConfig().setMaxTaskNum(downloadNum); - } } catch (InterruptedException e) { e.printStackTrace(); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 510df605..c94a4aab 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,7 +25,7 @@ - http://g37.gdl.netease.com/onmyoji_netease_1.apk + https://g37.gdl.netease.com/onmyoji_netease_10_1.0.20.apk http://static.gaoshouyou.com/d/eb/f2/dfeba30541f209ab8a50d847fc1661ce.apk http://rs.0.gaoshouyou.com/d/51/46/58514d126c46b8a3f27fc8c7db3b09ec.apk http://rs.0.gaoshouyou.com/d/23/69/07238f952669727878d7a0e180534c8b.apk