Added update logic for outdated readers

This commit is contained in:
tom5079
2019-12-12 20:14:55 +09:00
parent 865bf0ba83
commit d40b4f3748
2 changed files with 82 additions and 1 deletions

View File

@@ -25,6 +25,10 @@ import android.util.Log
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.ActivityTestRule
import kotlinx.serialization.ImplicitReflectionSerializer
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
import kotlinx.serialization.json.JsonObject
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@@ -34,6 +38,7 @@ import xyz.quaver.hiyobi.getReader
import xyz.quaver.hiyobi.user_agent
import xyz.quaver.pupil.ui.LockActivity
import xyz.quaver.pupil.util.getDownloadDirectory
import java.io.File
import java.net.URL
import javax.net.ssl.HttpsURLConnection
@@ -63,7 +68,7 @@ class ExampleInstrumentedTest {
@Test
fun test_doSearch() {
val reader = getReader(1426382)
val reader = getReader( 1426382)
val data: ByteArray
@@ -76,4 +81,31 @@ class ExampleInstrumentedTest {
Log.d("Pupil", data.size.toString())
}
@UseExperimental(ImplicitReflectionSerializer::class)
@Test
fun test_deleteCodeFromReader() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
val json = Json(JsonConfiguration.Stable)
listOf(
getDownloadDirectory(context),
File(context.cacheDir, "imageCache")
).forEach { root ->
root.listFiles()?.forEach gallery@{ gallery ->
val reader = json.parseJson(File(gallery, "reader.json").apply {
if (!exists())
return@gallery
}.readText())
.jsonObject.toMutableMap()
Log.d("PUPILD", gallery.name)
reader.remove("code")
File(gallery, "reader.json").writeText(JsonObject(reader).toString())
}
}
}
}