From 9a7a03e32744a966f01ad184cad3775b9e715dd8 Mon Sep 17 00:00:00 2001 From: Jace <54625750+Jacekun@users.noreply.github.com> Date: Sun, 12 Sep 2021 06:10:10 +0800 Subject: [PATCH] Change ProtoNumber of Backup Models for History and Source to a non-zero digit (#5849) * Change ProtoNumber of Backup Models for History and Source to non-zero Changed BackupHistory url and BackupSource name properties * Provide backwards compatibility to current proto backups - Added data class for zero-based protoNumber - Restore both 'new' proto and old ones by mapping old to 'new' proto format - Thanks to @jobobby04 for providing the initial solution. * Fix on createBackup missing parameter for brokenSource * Fix issues on build * Fix missing import on FullBackupRestore --- .../tachiyomi/data/backup/full/FullBackupManager.kt | 1 + .../tachiyomi/data/backup/full/FullBackupRestore.kt | 6 ++++-- .../eu/kanade/tachiyomi/data/backup/full/models/Backup.kt | 3 ++- .../tachiyomi/data/backup/full/models/BackupHistory.kt | 8 +++++++- .../tachiyomi/data/backup/full/models/BackupManga.kt | 5 +++-- .../tachiyomi/data/backup/full/models/BackupSource.kt | 8 +++++++- 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt index 61a2448579..597cbbd10c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt @@ -53,6 +53,7 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) { backup = Backup( backupManga(databaseManga, flags), backupCategories(), + emptyList(), backupExtensionInfo(databaseManga) ) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestore.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestore.kt index 8e0dd54085..be5d73e523 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestore.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestore.kt @@ -9,6 +9,7 @@ import eu.kanade.tachiyomi.data.backup.full.models.BackupCategory import eu.kanade.tachiyomi.data.backup.full.models.BackupHistory import eu.kanade.tachiyomi.data.backup.full.models.BackupManga import eu.kanade.tachiyomi.data.backup.full.models.BackupSerializer +import eu.kanade.tachiyomi.data.backup.full.models.BackupSource import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Track @@ -33,7 +34,8 @@ class FullBackupRestore(context: Context, notifier: BackupNotifier) : AbstractBa } // Store source mapping for error messages - sourceMapping = backup.backupSources.map { it.sourceId to it.name }.toMap() + var backupMaps = backup.backupBrokenSources.map { BackupSource(it.name, it.sourceId) } + backup.backupSources + sourceMapping = backupMaps.map { it.sourceId to it.name }.toMap() // Restore individual manga backup.backupManga.forEach { @@ -62,7 +64,7 @@ class FullBackupRestore(context: Context, notifier: BackupNotifier) : AbstractBa val manga = backupManga.getMangaImpl() val chapters = backupManga.getChaptersImpl() val categories = backupManga.categories - val history = backupManga.history + val history = backupManga.brokenHistory.map { BackupHistory(it.url, it.lastRead) } + backupManga.history val tracks = backupManga.getTrackingImpl() try { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/Backup.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/Backup.kt index b938639e7d..ad0fb5b747 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/Backup.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/Backup.kt @@ -8,5 +8,6 @@ data class Backup( @ProtoNumber(1) val backupManga: List, @ProtoNumber(2) var backupCategories: List = emptyList(), // Bump by 100 to specify this is a 0.x value - @ProtoNumber(100) var backupSources: List = emptyList(), + @ProtoNumber(100) var backupBrokenSources: List = emptyList(), + @ProtoNumber(101) var backupSources: List = emptyList() ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupHistory.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupHistory.kt index 3cbfbc622b..98b415e60e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupHistory.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupHistory.kt @@ -4,7 +4,13 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.protobuf.ProtoNumber @Serializable -data class BackupHistory( +data class BrokenBackupHistory( @ProtoNumber(0) var url: String, @ProtoNumber(1) var lastRead: Long ) + +@Serializable +data class BackupHistory( + @ProtoNumber(1) var url: String, + @ProtoNumber(2) var lastRead: Long +) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupManga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupManga.kt index 77013480bc..e513b0aa2e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupManga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupManga.kt @@ -33,8 +33,9 @@ data class BackupManga( // Bump by 100 for values that are not saved/implemented in 1.x but are used in 0.x @ProtoNumber(100) var favorite: Boolean = true, @ProtoNumber(101) var chapterFlags: Int = 0, - @ProtoNumber(102) var history: List = emptyList(), - @ProtoNumber(103) var viewer_flags: Int? = null + @ProtoNumber(102) var brokenHistory: List = emptyList(), + @ProtoNumber(103) var viewer_flags: Int? = null, + @ProtoNumber(104) var history: List = emptyList() ) { fun getMangaImpl(): MangaImpl { return MangaImpl().apply { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupSource.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupSource.kt index 78b993373a..a8c12f5843 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupSource.kt @@ -5,9 +5,15 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.protobuf.ProtoNumber @Serializable -data class BackupSource( +data class BrokenBackupSource( @ProtoNumber(0) var name: String = "", @ProtoNumber(1) var sourceId: Long +) + +@Serializable +data class BackupSource( + @ProtoNumber(1) var name: String = "", + @ProtoNumber(2) var sourceId: Long ) { companion object { fun copyFrom(source: Source): BackupSource {