mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 14:27:57 +01:00 
			
		
		
		
	Read from streams for local source manga details and legacy backups
This commit is contained in:
		| @@ -13,13 +13,12 @@ import eu.kanade.tachiyomi.data.database.models.Chapter | ||||
| import eu.kanade.tachiyomi.data.database.models.Manga | ||||
| import eu.kanade.tachiyomi.data.database.models.Track | ||||
| import eu.kanade.tachiyomi.source.Source | ||||
| import kotlinx.serialization.decodeFromString | ||||
| import kotlinx.serialization.json.Json | ||||
| import kotlinx.serialization.json.JsonObject | ||||
| import kotlinx.serialization.json.decodeFromJsonElement | ||||
| import kotlinx.serialization.json.decodeFromStream | ||||
| import kotlinx.serialization.json.intOrNull | ||||
| import kotlinx.serialization.json.jsonPrimitive | ||||
| import okio.buffer | ||||
| import okio.source | ||||
| import java.util.Date | ||||
|  | ||||
| @@ -28,8 +27,8 @@ class LegacyBackupRestore(context: Context, notifier: BackupNotifier) : Abstract | ||||
|     override suspend fun performRestore(uri: Uri): Boolean { | ||||
|         // Read the json and create a Json Object, | ||||
|         // cannot use the backupManager json deserializer one because its not initialized yet | ||||
|         val backupObject = Json.decodeFromString<JsonObject>( | ||||
|             context.contentResolver.openInputStream(uri)!!.source().buffer().use { it.readUtf8() } | ||||
|         val backupObject = Json.decodeFromStream<JsonObject>( | ||||
|             context.contentResolver.openInputStream(uri)!! | ||||
|         ) | ||||
|  | ||||
|         // Get parser version | ||||
|   | ||||
| @@ -5,9 +5,7 @@ import android.net.Uri | ||||
| import eu.kanade.tachiyomi.R | ||||
| import eu.kanade.tachiyomi.data.backup.AbstractBackupRestoreValidator | ||||
| import eu.kanade.tachiyomi.data.backup.legacy.models.Backup | ||||
| import kotlinx.serialization.decodeFromString | ||||
| import okio.buffer | ||||
| import okio.source | ||||
| import kotlinx.serialization.json.decodeFromStream | ||||
|  | ||||
| class LegacyBackupRestoreValidator : AbstractBackupRestoreValidator() { | ||||
|     /** | ||||
| @@ -19,8 +17,8 @@ class LegacyBackupRestoreValidator : AbstractBackupRestoreValidator() { | ||||
|     override fun validate(context: Context, uri: Uri): Results { | ||||
|         val backupManager = LegacyBackupManager(context) | ||||
|  | ||||
|         val backup = backupManager.parser.decodeFromString<Backup>( | ||||
|             context.contentResolver.openInputStream(uri)!!.source().buffer().use { it.readUtf8() } | ||||
|         val backup = backupManager.parser.decodeFromStream<Backup>( | ||||
|             context.contentResolver.openInputStream(uri)!! | ||||
|         ) | ||||
|  | ||||
|         if (backup.version == null) { | ||||
|   | ||||
| @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.source | ||||
|  | ||||
| import android.content.Context | ||||
| import com.github.junrar.Archive | ||||
| import com.google.gson.JsonParser | ||||
| import eu.kanade.tachiyomi.R | ||||
| import eu.kanade.tachiyomi.source.model.Filter | ||||
| import eu.kanade.tachiyomi.source.model.FilterList | ||||
| @@ -15,8 +14,16 @@ import eu.kanade.tachiyomi.util.lang.compareToCaseInsensitiveNaturalOrder | ||||
| import eu.kanade.tachiyomi.util.storage.DiskUtil | ||||
| import eu.kanade.tachiyomi.util.storage.EpubFile | ||||
| import eu.kanade.tachiyomi.util.system.ImageUtil | ||||
| import kotlinx.serialization.json.Json | ||||
| import kotlinx.serialization.json.JsonObject | ||||
| import kotlinx.serialization.json.contentOrNull | ||||
| import kotlinx.serialization.json.decodeFromStream | ||||
| import kotlinx.serialization.json.intOrNull | ||||
| import kotlinx.serialization.json.jsonArray | ||||
| import kotlinx.serialization.json.jsonPrimitive | ||||
| import rx.Observable | ||||
| import timber.log.Timber | ||||
| import uy.kohesive.injekt.injectLazy | ||||
| import java.io.File | ||||
| import java.io.FileInputStream | ||||
| import java.io.InputStream | ||||
| @@ -68,6 +75,8 @@ class LocalSource(private val context: Context) : CatalogueSource { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private val json: Json by injectLazy() | ||||
|  | ||||
|     override val id = ID | ||||
|     override val name = context.getString(R.string.local_source) | ||||
|     override val lang = "" | ||||
| @@ -157,16 +166,15 @@ class LocalSource(private val context: Context) : CatalogueSource { | ||||
|             .flatten() | ||||
|             .firstOrNull { it.extension == "json" } | ||||
|             ?.apply { | ||||
|                 val reader = this.inputStream().bufferedReader() | ||||
|                 val json = JsonParser.parseReader(reader).asJsonObject | ||||
|                 val obj = json.decodeFromStream<JsonObject>(inputStream()) | ||||
|  | ||||
|                 manga.title = json["title"]?.asString ?: manga.title | ||||
|                 manga.author = json["author"]?.asString ?: manga.author | ||||
|                 manga.artist = json["artist"]?.asString ?: manga.artist | ||||
|                 manga.description = json["description"]?.asString ?: manga.description | ||||
|                 manga.genre = json["genre"]?.asJsonArray?.joinToString(", ") { it.asString } | ||||
|                 manga.title = obj["title"]?.jsonPrimitive?.contentOrNull ?: manga.title | ||||
|                 manga.author = obj["author"]?.jsonPrimitive?.contentOrNull ?: manga.author | ||||
|                 manga.artist = obj["artist"]?.jsonPrimitive?.contentOrNull ?: manga.artist | ||||
|                 manga.description = obj["description"]?.jsonPrimitive?.contentOrNull ?: manga.description | ||||
|                 manga.genre = obj["genre"]?.jsonArray?.joinToString(", ") { it.jsonPrimitive.content } | ||||
|                     ?: manga.genre | ||||
|                 manga.status = json["status"]?.asInt ?: manga.status | ||||
|                 manga.status = obj["status"]?.jsonPrimitive?.intOrNull ?: manga.status | ||||
|             } | ||||
|  | ||||
|         return Observable.just(manga) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user