fix unionChapterCathe

pull/21/head
fengyuecanzhu 3 years ago
parent 54cbc6d26c
commit 3e9a432a09
  1. 15
      app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseAdapter.java
  2. 2
      dynamic/build.gradle
  3. 15
      dynamic/src/androidTest/java/xyz/fycz/dynamic/ExampleInstrumentedTest.kt
  4. 71
      dynamic/src/main/java/xyz/fycz/dynamic/AppLoadImpl.kt
  5. 40
      dynamic/src/main/java/xyz/fycz/dynamic/fix/App243Fix.kt
  6. 105
      dynamic/src/main/java/xyz/fycz/dynamic/fix/App244Fix.kt
  7. 29
      dynamic/src/main/java/xyz/fycz/dynamic/fix/AppFix.kt
  8. 49
      dynamic/src/main/java/xyz/fycz/dynamic/fix/AppFixHandle.kt

@ -230,9 +230,6 @@ public abstract class BookcaseAdapter extends RecyclerView.Adapter<BookcaseAdapt
public boolean unionChapterCathe(Book book) throws IOException {
ArrayList<Chapter> chapters = (ArrayList<Chapter>) 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<BookcaseAdapt
if (!bookFile.exists()) {
return false;
}
BufferedReader br = null;
BufferedWriter bw = null;
String filePath = APPCONST.TXT_BOOK_DIR + book.getName() + (TextUtils.isEmpty(book.getAuthor())
? "" : " 作者:" + book.getAuthor()) + ".txt";
bw = new BufferedWriter(new FileWriter(FileUtils.getFile(filePath)));
bw.write("《" + book.getName() + "》\n");
if (!TextUtils.isEmpty(book.getAuthor())) bw.write("作者:" + book.getAuthor() + "\n");
if (!TextUtils.isEmpty(book.getDesc())) bw.write("简介:\n" + book.getDesc() + "\n");
bw.newLine();
for (Chapter chapter : chapters) {
if (ChapterService.isChapterCached(chapter)) {
bw.write("\t" + chapter.getTitle());
bw.newLine();
br = new BufferedReader(new FileReader(APPCONST.BOOK_CACHE_PATH + book.getId()
+ File.separator + chapter.getTitle() + FileUtils.SUFFIX_FY));
br = new BufferedReader(new FileReader(ChapterService.getChapterFile(chapter)));
String line = null;
while ((line = br.readLine()) != null) {
bw.write(line);

@ -48,7 +48,7 @@ android {
}
dependencies {
implementation "androidx.core:core-ktx:$kotlin_version"
compileOnly("androidx.core:core-ktx:$kotlin_version")
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

@ -18,14 +18,13 @@
package xyz.fycz.dynamic
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import me.fycz.maple.MapleUtils
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
import xyz.fycz.dynamic.fix.App243Fix
import xyz.fycz.myreader.application.App
/**
@ -38,17 +37,5 @@ class ExampleInstrumentedTest {
@Test
fun testFix() {
// Context of the app under test.
if (App.getVersionCode() == 243) {
try {
App243Fix.fixGetAllNoLocalSource()
} catch (e: Exception) {
MapleUtils.log(e)
}
try {
App243Fix.fixAdTimeout()
} catch (e: Exception) {
MapleUtils.log(e)
}
}
}
}

@ -20,10 +20,15 @@ package xyz.fycz.dynamic
import android.app.AlertDialog
import android.content.Context
import android.content.SharedPreferences
import android.os.Bundle
import me.fycz.maple.MapleBridge
import me.fycz.maple.MapleUtils
import me.fycz.maple.MethodHook
import xyz.fycz.dynamic.fix.App243Fix
import xyz.fycz.dynamic.fix.App244Fix
import xyz.fycz.dynamic.fix.AppFix
import xyz.fycz.dynamic.fix.AppFixHandle
import xyz.fycz.myreader.application.App
import xyz.fycz.myreader.ui.activity.MainActivity
import xyz.fycz.myreader.util.utils.AdUtils
@ -33,34 +38,41 @@ import xyz.fycz.myreader.util.utils.AdUtils
* @date 2022/3/29 11:59
*/
class AppLoadImpl : IAppLoader {
private val spuName = "FYReader_plugin"
private val spu = App.getmContext().getSharedPreferences(spuName, Context.MODE_PRIVATE)
companion object {
private const val spuName = "FYReader_plugin"
val spu: SharedPreferences =
App.getmContext().getSharedPreferences(spuName, Context.MODE_PRIVATE)
}
private val fixList = listOf(
App243Fix::class.java,
App244Fix::class.java
)
override fun onLoad(appParam: AppParam) {
if (App.getVersionCode() == 243) {
val key = "2022-03-31"
var fx1 = false
var fx2 = false
try {
App243Fix.fixGetAllNoLocalSource()
fx1 = true
fixResult(key, "getAllNoLocalSource", true)
} catch (e: Exception) {
MapleUtils.log(e)
fixResult(key, "getAllNoLocalSource", false)
}
try {
App243Fix.fixAdTimeout()
fx2 = true
fixResult(key, "adTimeout", true)
} catch (e: Exception) {
MapleUtils.log(e)
fixResult(key, "adTimeout", false)
val sb = StringBuilder()
var index = 1
fixList.forEach {
val annotation = it.getAnnotation(AppFix::class.java)!!
annotation.version.forEach { version ->
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()
}
}
}
}

@ -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<BookSource> {
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
}
}

@ -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 <https://www.gnu.org/licenses/>.
*
* 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<Chapter>
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
}
}

@ -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 <https://www.gnu.org/licenses/>.
*
* 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<String> = [],
val date: String = ""
)

@ -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 <https://www.gnu.org/licenses/>.
*
* 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()
}
}
}
}
Loading…
Cancel
Save