From bd1b3e7416f3a5bb90f364f0bf7693567286046c Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Thu, 29 Nov 2018 20:01:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/arialyy/aria/core/AriaManager.java | 11 +- .../com/arialyy/aria/core/ConfigHelper.java | 15 +- .../aria/core/download/BaseDListener.java | 8 +- .../aria/core/upload/BaseUListener.java | 11 +- .../com/arialyy/aria/util/CommonUtil.java | 110 ++++++- DEV_LOG.md | 1 + app/src/main/assets/aria_config.xml | 2 +- .../simple/download/SingleTaskActivity.java | 19 +- .../simple/upload/HttpUploadActivity.java | 2 +- .../com/arialyy/aria/core/Configuration.java | 309 +++++++----------- 10 files changed, 250 insertions(+), 238 deletions(-) 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 8adb564d..4dc826e0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -130,7 +130,7 @@ import org.xml.sax.SAXException; DownloadEntity.class, UploadEntity.class, DownloadGroupEntity.class, DownloadTaskEntity.class, UploadTaskEntity.class, DownloadGroupTaskEntity.class }; - String sql = "UPDATE %s SET state=2 WHERE state in (3,4,5,6)"; + String sql = "UPDATE %s SET state=2 WHERE state IN (3,4,5,6)"; for (Class clazz : clazzs) { String temp = String.format(sql, clazz.getSimpleName()); DbEntity.exeSql(temp); @@ -376,6 +376,10 @@ import org.xml.sax.SAXException; * 初始化配置文件 */ private void initConfig() { + mDConfig = Configuration.getInstance().downloadCfg; + mUConfig = Configuration.getInstance().uploadCfg; + mAConfig = Configuration.getInstance().appCfg; + File xmlFile = new File(APP.getFilesDir().getPath() + Configuration.XML_FILE); File tempDir = new File(APP.getFilesDir().getPath() + "/temp"); if (!xmlFile.exists()) { @@ -389,16 +393,13 @@ import org.xml.sax.SAXException; } CommonUtil.createFileFormInputStream(APP.getAssets().open("aria_config.xml"), file.getPath()); - if (!CommonUtil.checkMD5(md5Code, file)) { + if (!CommonUtil.checkMD5(md5Code, file) || !Configuration.getInstance().configExists()) { loadConfig(); } } catch (IOException e) { e.printStackTrace(); } } - mDConfig = Configuration.DownloadConfig.getInstance(); - mUConfig = Configuration.UploadConfig.getInstance(); - mAConfig = Configuration.AppConfig.getInstance(); if (tempDir.exists()) { File newDir = new File(APP.getFilesDir().getPath() + DOWNLOAD_TEMP_DIR); newDir.mkdirs(); 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 e8dda5b6..9c0d8ae5 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java @@ -22,15 +22,14 @@ import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; /** - * Created by lyy on 2017/5/22. - * 读取配置文件 + * Created by lyy on 2017/5/22. 读取配置文件 */ class ConfigHelper extends DefaultHandler { private final String TAG = "ConfigHelper"; - private Configuration.DownloadConfig mDownloadConfig = Configuration.DownloadConfig.getInstance(); - private Configuration.UploadConfig mUploadConfig = Configuration.UploadConfig.getInstance(); - private Configuration.AppConfig mAppConfig = Configuration.AppConfig.getInstance(); + private Configuration.DownloadConfig mDownloadConfig = Configuration.getInstance().downloadCfg; + private Configuration.UploadConfig mUploadConfig = Configuration.getInstance().uploadCfg; + private Configuration.AppConfig mAppConfig = Configuration.getInstance().appCfg; private @ConfigType int mType; @Override public void startDocument() throws SAXException { @@ -357,8 +356,8 @@ class ConfigHelper extends DefaultHandler { @Override public void endDocument() throws SAXException { super.endDocument(); - mDownloadConfig.saveAll(); - mUploadConfig.saveAll(); - mAppConfig.saveAll(); + mDownloadConfig.save(); + mUploadConfig.save(); + mAppConfig.save(); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java index ef997792..4c43b7c7 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java @@ -57,13 +57,7 @@ public class BaseDListener extends BaseListener - +