diff --git a/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseAdapter.java b/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseAdapter.java index 609e1a6..41b77c1 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseAdapter.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseAdapter.java @@ -230,9 +230,6 @@ public abstract class BookcaseAdapter extends RecyclerView.Adapter chapters = (ArrayList) mChapterService.findBookAllChapterByBookId(book.getId()); - BufferedReader br = null; - BufferedWriter bw = null; - bw = new BufferedWriter(new FileWriter(FileUtils.getFile(APPCONST.TXT_BOOK_DIR + book.getName() + ".txt"))); if (chapters.size() == 0) { return false; } @@ -240,12 +237,20 @@ public abstract class BookcaseAdapter extends RecyclerView.Adapter + if (App.getVersionCode() == version) { + val fix = it.newInstance() + val fixResult = fix.onFix(annotation.date) + if (!spu.getBoolean(annotation.date, false)) { + fixResult.forEachIndexed { i, b -> + sb.append("${index++}、${annotation.fixLog[i]}:${if (b) "成功" else "失败"}\n") + } + spu.edit().run { + putBoolean(annotation.date, true) + apply() + } + } + } } - val msg = "$key\n更新内容:\n1、修复软件无法打开的问题(超时时间为5s):$fx1\n" + - "2、修复DIY书源重复显示订阅书源的问题:$fx2" - announce("插件更新", msg, key) } + if (sb.lastIndexOf("\n") > 0) sb.substring(0, sb.length - 1) + announce("插件更新", "2022-04-25更新内容:\n$sb", "fix244") } private fun announce(title: String, msg: String, key: String) { @@ -93,15 +105,4 @@ class AppLoadImpl : IAppLoader { MapleUtils.log(e) } } - - private fun fixResult(key: String, name: String, success: Boolean) { - val res = if (success) "Success" else "Failed" - if (!spu.getBoolean("$key-$name-$res", false)) { - AdUtils.adRecord(name, "fx$res") - spu.edit().run { - putBoolean("$key-$name-$res", true) - apply() - } - } - } } \ No newline at end of file diff --git a/dynamic/src/main/java/xyz/fycz/dynamic/App243Fix.kt b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App243Fix.kt similarity index 78% rename from dynamic/src/main/java/xyz/fycz/dynamic/App243Fix.kt rename to dynamic/src/main/java/xyz/fycz/dynamic/fix/App243Fix.kt index 2b867d8..891d3cc 100644 --- a/dynamic/src/main/java/xyz/fycz/dynamic/App243Fix.kt +++ b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App243Fix.kt @@ -16,7 +16,7 @@ * Copyright (C) 2020 - 2022 fengyuecanzhu */ -package xyz.fycz.dynamic +package xyz.fycz.dynamic.fix import android.os.Handler import me.fycz.maple.MapleBridge @@ -35,7 +35,31 @@ import xyz.fycz.myreader.util.utils.AdUtils * @author fengyue * @date 2022/3/31 9:21 */ -object App243Fix { +@AppFix([243], ["修复软件无法打开的问题(超时时间为5s)", "修复DIY书源重复显示订阅书源的问题"], "2022-03-31") +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) + } + private fun getAllNoLocalSource(): List { return DbManager.getDaoSession().bookSourceDao.queryBuilder() .where(BookSourceDao.Properties.SourceEName.isNull) @@ -45,7 +69,7 @@ object App243Fix { } - fun fixGetAllNoLocalSource() { + private fun fixGetAllNoLocalSource() { MapleUtils.findAndHookMethod( BookSourceManager::class.java, "getAllNoLocalSource", @@ -67,7 +91,7 @@ object App243Fix { MapleUtils.callMethod(obj, "startNormal") SharedPreAdUtils.getInstance().putBoolean("adTimeOut", true) } else { - if (time > 5){ + if (time > 5) { MapleUtils.setIntField(obj, "timeOut", 5) } val handler = MapleUtils.getObjectField(obj, "handler") as Handler @@ -76,7 +100,7 @@ object App243Fix { } } - fun fixAdTimeout() { + private fun fixAdTimeout() { MapleUtils.findAndHookMethod( SplashActivity::class.java, "adTimeout", @@ -90,7 +114,7 @@ object App243Fix { MapleUtils.findAndHookMethod( SplashActivity::class.java, "countTodayAd", - object : MethodHook(){ + object : MethodHook() { override fun afterHookedMethod(param: MapleBridge.MethodHookParam) { SharedPreAdUtils.getInstance().putBoolean("adTimeOut", false) } @@ -99,9 +123,9 @@ object App243Fix { MapleUtils.findAndHookMethod( AdUtils::class.java, "backSplashAd", - object : MethodHook(){ + object : MethodHook() { override fun beforeHookedMethod(param: MapleBridge.MethodHookParam) { - if (SharedPreAdUtils.getInstance().getBoolean("adTimeOut")){ + if (SharedPreAdUtils.getInstance().getBoolean("adTimeOut")) { param.result = false } } diff --git a/dynamic/src/main/java/xyz/fycz/dynamic/fix/App244Fix.kt b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App244Fix.kt new file mode 100644 index 0000000..a403529 --- /dev/null +++ b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App244Fix.kt @@ -0,0 +1,105 @@ +/* + * 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.text.TextUtils +import me.fycz.maple.MapleBridge +import me.fycz.maple.MapleUtils +import me.fycz.maple.MethodReplacement +import xyz.fycz.myreader.common.APPCONST +import xyz.fycz.myreader.greendao.entity.Book +import xyz.fycz.myreader.greendao.entity.Chapter +import xyz.fycz.myreader.greendao.service.ChapterService +import xyz.fycz.myreader.ui.adapter.BookcaseAdapter +import xyz.fycz.myreader.util.utils.FileUtils +import java.io.* + +/** + * @author fengyue + * @date 2022/4/25 23:00 + */ +@AppFix([243, 244], ["修复书籍无法导出缓存的问题"], "2022-04-25") +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, "getAllNoLocalSource", false) + } + return booleanArrayOf(fx) + } + + private fun fixUnionChapterCathe() { + MapleUtils.findAndHookMethod( + BookcaseAdapter::class.java, + "unionChapterCathe", + Book::class.java, + object : MethodReplacement() { + override fun replaceHookedMethod(param: MapleBridge.MethodHookParam): Any { + return unionChapterCathe(param.args[0] as Book) + } + } + ) + } + + @Throws(IOException::class) + fun unionChapterCathe(book: Book): Boolean { + val chapters = ChapterService.getInstance().findBookAllChapterByBookId(book.id) as ArrayList + if (chapters.size == 0) { + return false + } + val bookFile = File(APPCONST.BOOK_CACHE_PATH + book.id) + if (!bookFile.exists()) { + return false + } + var br: BufferedReader? + val bw: BufferedWriter? + val filePath = + APPCONST.TXT_BOOK_DIR + book.name + (if (book.author.isNullOrEmpty()) "" else " 作者:" + book.author) + ".txt" + bw = BufferedWriter(FileWriter(FileUtils.getFile(filePath))) + bw.write("《${book.name}》") + if (!book.author.isNullOrEmpty()) { + bw.write("作者:${book.author}") + } + if (!book.desc.isNullOrEmpty()) { + bw.write("简介:${book.desc}") + } + bw.newLine() + for (chapter in chapters) { + if (ChapterService.isChapterCached(chapter)) { + bw.write("\t" + chapter.title) + bw.newLine() + br = BufferedReader(FileReader(ChapterService.getChapterFile(chapter))) + var line: String? + while (br.readLine().also { line = it } != null) { + bw.write(line) + bw.newLine() + } + br.close() + } + } + bw.flush() + bw.close() + return true + } +} \ No newline at end of file diff --git a/dynamic/src/main/java/xyz/fycz/dynamic/fix/AppFix.kt b/dynamic/src/main/java/xyz/fycz/dynamic/fix/AppFix.kt new file mode 100644 index 0000000..49b36c5 --- /dev/null +++ b/dynamic/src/main/java/xyz/fycz/dynamic/fix/AppFix.kt @@ -0,0 +1,29 @@ +/* + * 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 + +/** + * @author fengyue + * @date 2022/4/25 22:05 + */ +annotation class AppFix( + val version: IntArray = [], + val fixLog: Array = [], + val date: String = "" +) diff --git a/dynamic/src/main/java/xyz/fycz/dynamic/fix/AppFixHandle.kt b/dynamic/src/main/java/xyz/fycz/dynamic/fix/AppFixHandle.kt new file mode 100644 index 0000000..6b66044 --- /dev/null +++ b/dynamic/src/main/java/xyz/fycz/dynamic/fix/AppFixHandle.kt @@ -0,0 +1,49 @@ +/* + * 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.app.AlertDialog +import android.content.Context +import android.os.Bundle +import me.fycz.maple.MapleBridge +import me.fycz.maple.MapleUtils +import me.fycz.maple.MethodHook +import xyz.fycz.dynamic.AppLoadImpl.Companion.spu +import xyz.fycz.myreader.ui.activity.MainActivity +import xyz.fycz.myreader.util.utils.AdUtils + +/** + * @author fengyue + * @date 2022/4/25 21:49 + */ +interface AppFixHandle { + + fun onFix(key: String): BooleanArray + + fun fixResult(key: String, name: String, success: Boolean) { + val res = if (success) "Success" else "Failed" + if (!spu.getBoolean("$key-$name-$res", false)) { + AdUtils.adRecord(name, "fx$res") + spu.edit().run { + putBoolean("$key-$name-$res", true) + apply() + } + } + } +} \ No newline at end of file