From e8fb8879120b59a154a8bea4bcec4fcf45d5d2b7 Mon Sep 17 00:00:00 2001 From: fengyuecanzhu <1021300691@qq.com> Date: Fri, 1 Jul 2022 16:32:06 +0800 Subject: [PATCH] fix bug --- app/src/main/assets/updatelog.fy | 2 + .../xyz/fycz/myreader/application/App.java | 10 +- .../fycz/myreader/util/utils/OkHttpUtils.java | 29 +++- .../main/java/xyz/fycz/dynamic/AppLoadImpl.kt | 3 +- .../java/xyz/fycz/dynamic/fix/App243Fix.kt | 24 +-- .../java/xyz/fycz/dynamic/fix/App244Fix.kt | 14 +- .../java/xyz/fycz/dynamic/fix/App244Fix2.kt | 14 +- .../java/xyz/fycz/dynamic/fix/App246Fix.kt | 13 +- .../java/xyz/fycz/dynamic/fix/App246Fix2.kt | 13 +- .../java/xyz/fycz/dynamic/fix/App246Fix3.kt | 13 +- .../java/xyz/fycz/dynamic/fix/App246Fix4.kt | 13 +- .../java/xyz/fycz/dynamic/fix/App246Fix5.kt | 158 ++++++++++++++++++ .../java/xyz/fycz/dynamic/fix/AppFixHandle.kt | 18 +- .../xyz/fycz/dynamic/fix/AppSubSourceFix.kt | 19 +-- 14 files changed, 237 insertions(+), 106 deletions(-) create mode 100644 dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix5.kt diff --git a/app/src/main/assets/updatelog.fy b/app/src/main/assets/updatelog.fy index 6bfbe90..6b0ff4d 100644 --- a/app/src/main/assets/updatelog.fy +++ b/app/src/main/assets/updatelog.fy @@ -1,4 +1,6 @@ 1、修复阅读界面概率性闪退的问题 +2、关于界面新增插件加载结果 +3、修复书源订阅失败的问题 2022.05.28 风月读书v2.4.6 diff --git a/app/src/main/java/xyz/fycz/myreader/application/App.java b/app/src/main/java/xyz/fycz/myreader/application/App.java index 099676c..327601b 100644 --- a/app/src/main/java/xyz/fycz/myreader/application/App.java +++ b/app/src/main/java/xyz/fycz/myreader/application/App.java @@ -282,15 +282,9 @@ public class App extends Application { public static void checkVersionByServer(final AppCompatActivity activity, final boolean isManualCheck) { App.getApplication().newThread(() -> { try { - String url = "https://shimo.im/docs/cqkgjPRRydYYhQKt/read"; - if (debug) { - url = "https://shimo.im/docs/zfzpda7MUGskOC9v/read"; - } - String html = OkHttpUtils.getHtml(url); - Document doc = Jsoup.parse(html); - String content = doc.getElementsByClass("ql-editor").text(); + String content = OkHttpUtils.getUpdateInfo(); if (StringHelper.isEmpty(content)) { - content = OkHttpUtils.getUpdateInfo(); + content = OkHttpUtils.getBakUpdateInfo(); if (StringHelper.isEmpty(content)) { if (isManualCheck || NetworkUtils.isNetWorkAvailable()) { ToastUtils.showError("检查更新失败!"); diff --git a/app/src/main/java/xyz/fycz/myreader/util/utils/OkHttpUtils.java b/app/src/main/java/xyz/fycz/myreader/util/utils/OkHttpUtils.java index 82814bf..4f2675d 100644 --- a/app/src/main/java/xyz/fycz/myreader/util/utils/OkHttpUtils.java +++ b/app/src/main/java/xyz/fycz/myreader/util/utils/OkHttpUtils.java @@ -176,7 +176,7 @@ public class OkHttpUtils { return response.body().byteStream(); } - public static String getUpdateInfo() throws IOException, JSONException { + public static String getUpdateInfo() throws IOException { String key = "ryvwiq"; if (App.isDebug()) { key = "sgak2h"; @@ -197,17 +197,28 @@ public class OkHttpUtils { if (body == null) { return ""; } else { - String bodyStr = new String(body.bytes(), StandardCharsets.UTF_8); - JSONObject jsonObj = new JSONObject(bodyStr); - jsonObj = jsonObj.getJSONObject("data"); - String content = jsonObj.getString("content"); - Document doc = Jsoup.parse(content); - content = doc.text(); - Log.d("Http -> UpdateInfo", content); - return content; + try { + String bodyStr = new String(body.bytes(), StandardCharsets.UTF_8); + JSONObject jsonObj = new JSONObject(bodyStr); + jsonObj = jsonObj.getJSONObject("data"); + String content = jsonObj.getString("content"); + Document doc = Jsoup.parse(content); + content = doc.text(); + Log.d("Http -> UpdateInfo", content); + return content; + }catch (JSONException e){ + e.printStackTrace(); + return ""; + } } } + public static String getBakUpdateInfo() throws IOException { + return OkHttpUtils.getHtml("https://fyreader.coding.net/p/img/d/FYReader-Update/git/raw/master/" + + (App.isDebug() ? "debug" : "release") + + "/content.txt"); + } + public static Observable getStrResponse(AnalyzeUrl analyzeUrl) { return Observable.create(emitter -> { StringBuilder sb = new StringBuilder(); diff --git a/dynamic/src/main/java/xyz/fycz/dynamic/AppLoadImpl.kt b/dynamic/src/main/java/xyz/fycz/dynamic/AppLoadImpl.kt index afc6cbe..c6d183b 100644 --- a/dynamic/src/main/java/xyz/fycz/dynamic/AppLoadImpl.kt +++ b/dynamic/src/main/java/xyz/fycz/dynamic/AppLoadImpl.kt @@ -48,10 +48,11 @@ class AppLoadImpl : IAppLoader { App244Fix::class.java, App244Fix2::class.java, App246Fix::class.java, - //AppSubSourceFix::class.java, + AppSubSourceFix::class.java, App246Fix2::class.java, App246Fix3::class.java, App246Fix4::class.java, + App246Fix5::class.java, ) override fun onLoad(appParam: AppParam) { diff --git a/dynamic/src/main/java/xyz/fycz/dynamic/fix/App243Fix.kt b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App243Fix.kt index 57107ca..6fb85bc 100644 --- a/dynamic/src/main/java/xyz/fycz/dynamic/fix/App243Fix.kt +++ b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App243Fix.kt @@ -39,25 +39,11 @@ import xyz.fycz.myreader.util.utils.AdUtils class App243Fix : AppFixHandle { override fun onFix(key: String): BooleanArray { - var fx1 = false - var fx2 = false - try { - fixGetAllNoLocalSource() - fx1 = true - fixResult(key, "getAllNoLocalSource", true) - } catch (e: Exception) { - MapleUtils.log(e) - fixResult(key, "getAllNoLocalSource", false) - } - try { - fixAdTimeout() - fx2 = true - fixResult(key, "adTimeout", true) - } catch (e: Exception) { - MapleUtils.log(e) - fixResult(key, "adTimeout", false) - } - return booleanArrayOf(fx1, fx2) + return handleFix( + key, + "getAllNoLocalSource" to { fixGetAllNoLocalSource() }, + "adTimeout" to { fixAdTimeout() }, + ) } private fun getAllNoLocalSource(): List { diff --git a/dynamic/src/main/java/xyz/fycz/dynamic/fix/App244Fix.kt b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App244Fix.kt index 9fd3933..16471cf 100644 --- a/dynamic/src/main/java/xyz/fycz/dynamic/fix/App244Fix.kt +++ b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App244Fix.kt @@ -36,16 +36,10 @@ import java.io.* @AppFix([243, 244], ["修复书籍无法导出缓存的问题"], "2022-04-26") class App244Fix: AppFixHandle { override fun onFix(key: String): BooleanArray { - var fx = false - try { - fixUnionChapterCathe() - fx = true - fixResult(key, "unionChapterCathe", true) - } catch (e: Exception) { - MapleUtils.log(e) - fixResult(key, "unionChapterCathe", false) - } - return booleanArrayOf(fx) + return handleFix( + key, + "unionChapterCathe" to { fixUnionChapterCathe() }, + ) } private fun fixUnionChapterCathe() { diff --git a/dynamic/src/main/java/xyz/fycz/dynamic/fix/App244Fix2.kt b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App244Fix2.kt index 93c079d..3b06fac 100644 --- a/dynamic/src/main/java/xyz/fycz/dynamic/fix/App244Fix2.kt +++ b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App244Fix2.kt @@ -32,16 +32,10 @@ import xyz.fycz.myreader.webapi.crawler.base.ReadCrawler @AppFix([243, 244], ["修复搜索时当前分组不存在时无法搜索的问题"], "2022-05-11") class App244Fix2 : AppFixHandle{ override fun onFix(key: String): BooleanArray { - var fx = false - try { - fixGetEnableReadCrawlers() - fx = true - fixResult(key, "getEnableReadCrawlers", true) - } catch (e: Exception) { - MapleUtils.log(e) - fixResult(key, "getEnableReadCrawlers", false) - } - return booleanArrayOf(fx) + return handleFix( + key, + "getEnableReadCrawlers" to { fixGetEnableReadCrawlers() }, + ) } private fun fixGetEnableReadCrawlers() { diff --git a/dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix.kt b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix.kt index d46de62..67ae22e 100644 --- a/dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix.kt +++ b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix.kt @@ -43,15 +43,10 @@ import xyz.fycz.myreader.util.utils.ScreenUtils class App246Fix : AppFixHandle { override fun onFix(key: String): BooleanArray { - val result = try { - fxAdFile() - true - } catch (e: Exception) { - MapleUtils.log(e) - false - } - fixResult(key, "adFile", result) - return booleanArrayOf(result) + return handleFix( + key, + "adFile" to { fxAdFile() }, + ) } fun fxAdFile() { diff --git a/dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix2.kt b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix2.kt index 380d7cd..bdcbc89 100644 --- a/dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix2.kt +++ b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix2.kt @@ -30,15 +30,10 @@ import xyz.fycz.myreader.widget.page.PageView @AppFix([], ["修复阅读界面概率性闪退的问题"], "2022-06-23") class App246Fix2 : AppFixHandle { override fun onFix(key: String): BooleanArray { - val result = try { - fxPageView() - true - } catch (e: Exception) { - MapleUtils.log(e) - false - } - fixResult(key, "pageView", result) - return booleanArrayOf(result) + return handleFix( + key, + "pageView" to { fxPageView() }, + ) } private fun fxPageView() { diff --git a/dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix3.kt b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix3.kt index 21a658b..a23a4a3 100644 --- a/dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix3.kt +++ b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix3.kt @@ -51,15 +51,10 @@ import xyz.fycz.myreader.util.utils.fromJsonObject class App246Fix3 : AppFixHandle { override fun onFix(key: String): BooleanArray { - val result = try { - fxPluginView() - true - } catch (e: Exception) { - MapleUtils.log(e) - false - } - fixResult(key, "pluginView", result) - return booleanArrayOf(result) + return handleFix( + key, + "pluginView" to { fxPluginView() }, + ) } private fun fxPluginView() { diff --git a/dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix4.kt b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix4.kt index f22f3ee..c504c3f 100644 --- a/dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix4.kt +++ b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix4.kt @@ -31,15 +31,10 @@ import xyz.fycz.myreader.webapi.LanZouApi @AppFix([243, 244, 245, 246], ["修复书源订阅失败的问题"], "2022-06-30") class App246Fix4: AppFixHandle { override fun onFix(key: String): BooleanArray { - val result = try { - fxLanZouApi() - true - } catch (e: Exception) { - MapleUtils.log(e) - false - } - fixResult(key, "lanZouApi", result) - return booleanArrayOf(result) + return handleFix( + key, + "lanZouApi" to { fxLanZouApi() }, + ) } private fun fxLanZouApi() { diff --git a/dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix5.kt b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix5.kt new file mode 100644 index 0000000..eae6861 --- /dev/null +++ b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App246Fix5.kt @@ -0,0 +1,158 @@ +/* + * This file is part of FYReader. + * FYReader is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * FYReader is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with FYReader. If not, see . + * + * Copyright (C) 2020 - 2022 fengyuecanzhu + */ + +package xyz.fycz.dynamic.fix + +import android.util.Log +import androidx.appcompat.app.AppCompatActivity +import me.fycz.maple.MapleBridge +import me.fycz.maple.MapleUtils +import me.fycz.maple.MethodReplacement +import xyz.fycz.myreader.R +import xyz.fycz.myreader.application.App +import xyz.fycz.myreader.application.SysManager +import xyz.fycz.myreader.common.URLCONST +import xyz.fycz.myreader.util.SharedPreUtils +import xyz.fycz.myreader.util.ToastUtils +import xyz.fycz.myreader.util.help.StringHelper +import xyz.fycz.myreader.util.utils.NetworkUtils +import xyz.fycz.myreader.util.utils.OkHttpUtils +import java.io.IOException + +/** + * @author fengyue + * @date 2022/7/1 15:45 + */ +@AppFix([243, 244, 245, 246], ["修复检查更新失败的问题"], "2022-07-01") +class App246Fix5 : AppFixHandle { + override fun onFix(key: String): BooleanArray { + return handleFix( + key, + "checkUpdateUrl" to { fxCheckUpdateUrl() }, + ) + } + + fun fxCheckUpdateUrl() { + MapleUtils.findAndHookMethod( + App::class.java, + "checkVersionByServer", + AppCompatActivity::class.java, + Boolean::class.java, + object : MethodReplacement() { + override fun replaceHookedMethod(param: MapleBridge.MethodHookParam) { + checkUpdate(param.args[0] as AppCompatActivity, param.args[1] as Boolean) + } + } + ) + } + + fun checkUpdate(activity: AppCompatActivity, isManualCheck: Boolean) { + App.getApplication().newThread { + try { + var content = OkHttpUtils.getUpdateInfo() + if (StringHelper.isEmpty(content)) { + content = getBakUpdateInfo() + if (StringHelper.isEmpty(content)) { + if (isManualCheck || NetworkUtils.isNetWorkAvailable()) { + ToastUtils.showError("检查更新失败!") + } + return@newThread + } + } + val contents = content.split(";".toRegex()) + val newestVersion = contents[0].substring(contents[0].indexOf(":") + 1).toInt() + var isForceUpdate = contents[1].substring(contents[1].indexOf(":") + 1).toBoolean() + val downloadLink = + contents[2].substring(contents[2].indexOf(":") + 1).trim { it <= ' ' } + val updateContent = contents[3].substring(contents[3].indexOf(":") + 1) + + SharedPreUtils.getInstance().putString( + App.getmContext().getString(R.string.lanzousKeyStart), + contents[4].substring(contents[4].indexOf(":") + 1) + ) + val newSplashTime = contents[5].substring(contents[5].indexOf(":") + 1) + val oldSplashTime = SharedPreUtils.getInstance().getString("splashTime") + SharedPreUtils.getInstance() + .putBoolean("needUdSI", oldSplashTime != newSplashTime) + SharedPreUtils.getInstance().putString( + "splashTime", + contents[5].substring(contents[5].indexOf(":") + 1) + ) + SharedPreUtils.getInstance().putString( + "splashImageUrl", + contents[6].substring(contents[6].indexOf(":") + 1) + ) + SharedPreUtils.getInstance().putString( + "splashImageMD5", + contents[7].substring(contents[7].indexOf(":") + 1) + ) + val forceUpdateVersion = contents[8].substring(contents[8].indexOf(":") + 1).toInt() + SharedPreUtils.getInstance().putInt("forceUpdateVersion", forceUpdateVersion) + val domain = contents[9].substring(contents[9].indexOf(":") + 1) + SharedPreUtils.getInstance().putString("domain", domain) + val pluginConfigUrl = contents[10].substring(contents[10].indexOf(":") + 1) + SharedPreUtils.getInstance().putString("pluginConfigUrl", pluginConfigUrl) + val versionCode = App.getVersionCode() + isForceUpdate = isForceUpdate && forceUpdateVersion > versionCode + if (!StringHelper.isEmpty(downloadLink)) { + SharedPreUtils.getInstance() + .putString(App.getmContext().getString(R.string.downloadLink), downloadLink) + } else { + SharedPreUtils.getInstance().putString( + App.getmContext().getString(R.string.downloadLink), + URLCONST.APP_DIR_URL + ) + } + val updateContents = updateContent.split("/".toRegex()) + val s = StringBuilder() + updateContents.forEach { + s.append(it) + s.append("
") + } + Log.i("检查更新,最新版本", newestVersion.toString() + "") + if (newestVersion > versionCode) { + val setting = SysManager.getSetting() + if (isManualCheck || setting.newestVersionCode < newestVersion || isForceUpdate) { + setting.newestVersionCode = newestVersion + SysManager.saveSetting(setting) + App.getApplication().updateApp2( + activity, downloadLink, newestVersion, s.toString(), isForceUpdate + ) + } + } else if (isManualCheck) { + ToastUtils.showSuccess("已经是最新版本!") + } + } catch (e: Exception) { + e.printStackTrace() + Log.e("检查更新失败!", "" + e.localizedMessage) + if (isManualCheck || NetworkUtils.isNetWorkAvailable()) { + ToastUtils.showError("检查更新失败!") + } + } + } + } + + @Throws(IOException::class) + fun getBakUpdateInfo(): String { + return OkHttpUtils.getHtml( + "https://fyreader.coding.net/p/img/d/FYReader-Update/git/raw/master/" + + (if (App.isDebug()) "debug" else "release") + + "/content.txt" + ) + } +} \ No newline at end of file diff --git a/dynamic/src/main/java/xyz/fycz/dynamic/fix/AppFixHandle.kt b/dynamic/src/main/java/xyz/fycz/dynamic/fix/AppFixHandle.kt index 9672f0d..ec6db85 100644 --- a/dynamic/src/main/java/xyz/fycz/dynamic/fix/AppFixHandle.kt +++ b/dynamic/src/main/java/xyz/fycz/dynamic/fix/AppFixHandle.kt @@ -33,9 +33,25 @@ import xyz.fycz.myreader.util.utils.AdUtils * @date 2022/4/25 21:49 */ interface AppFixHandle { - + fun onFix(key: String): BooleanArray + fun handleFix(key: String, vararg fix: Pair Unit>): BooleanArray { + val results = mutableListOf() + fix.forEach { + val result = try { + it.second() + true + } catch (e: Exception) { + MapleUtils.log(e) + false + } + results.add(result) + fixResult(key, it.first, result) + } + return results.toBooleanArray() + } + fun fixResult(key: String, name: String, success: Boolean) { val res = if (success) "Success" else "Failed" if (!spu.getBoolean("$key-$name-$res", false)) { diff --git a/dynamic/src/main/java/xyz/fycz/dynamic/fix/AppSubSourceFix.kt b/dynamic/src/main/java/xyz/fycz/dynamic/fix/AppSubSourceFix.kt index 5a6734d..4ef41e9 100644 --- a/dynamic/src/main/java/xyz/fycz/dynamic/fix/AppSubSourceFix.kt +++ b/dynamic/src/main/java/xyz/fycz/dynamic/fix/AppSubSourceFix.kt @@ -29,17 +29,12 @@ import xyz.fycz.myreader.webapi.LanZouApi * @date 2022/6/21 18:30 */ @AppFix([], ["更新订阅书源链接,仅支持v2.4.3版本及以上版本"], "2022-06-21") -class AppSubSourceFix : AppFixHandle{ +class AppSubSourceFix : AppFixHandle { override fun onFix(key: String): BooleanArray { - val result = try { - fxSubSource() - true - } catch (e: Exception) { - MapleUtils.log(e) - false - } - fixResult(key, "subSource", result) - return booleanArrayOf(result) + return handleFix( + key, + "subSource" to { fxSubSource() }, + ) } private fun fxSubSource() { @@ -49,9 +44,9 @@ class AppSubSourceFix : AppFixHandle{ String::class.java, Int::class.java, String::class.java, - object : MethodHook(){ + object : MethodHook() { override fun beforeHookedMethod(param: MapleBridge.MethodHookParam) { - if (param.args[0] == URLCONST.SUB_SOURCE_URL){ + if (param.args[0] == URLCONST.SUB_SOURCE_URL) { param.args[0] = "https://fycz.lanzoum.com/b00pucrch" param.args[2] = "b0ox" }