From 49d8563658d5a8e6a3d40ddfcb7c668a65768fba Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 6 May 2020 22:28:16 -0400 Subject: [PATCH] Start storing extension ID/source name mapping in backup files --- .../tachiyomi/data/backup/BackupManager.kt | 19 +++++++++++++++++++ .../tachiyomi/data/backup/models/Backup.kt | 1 + 2 files changed, 20 insertions(+) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt index 0e86ccec6b..43aad96b4b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt @@ -136,20 +136,33 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) { root[Backup.VERSION] = CURRENT_VERSION root[Backup.MANGAS] = mangaEntries root[CATEGORIES] = categoryEntries + root[EXTENSIONS] = extensionEntries databaseHelper.inTransaction { // Get manga from database val mangas = getFavoriteManga() + val extensions: MutableSet = mutableSetOf() + // Backup library manga and its dependencies mangas.forEach { manga -> mangaEntries.add(backupMangaObject(manga, flags)) + + // Maintain set of extensions/sources used (excludes local source) + if (manga.source != 0L) { + sourceManager.get(manga.source)?.let { + extensions.add("${manga.source}:${it.name}") + } + } } // Backup categories if ((flags and BACKUP_CATEGORY_MASK) == BACKUP_CATEGORY) { backupCategories(categoryEntries) } + + // Backup extension ID/name mapping + backupExtensionInfo(extensionEntries, extensions) } try { @@ -192,6 +205,12 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) { } } + private fun backupExtensionInfo(root: JsonArray, extensions: Set) { + extensions.sorted().forEach { + root.add(it) + } + } + /** * Backup the categories of library * diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/models/Backup.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/models/Backup.kt index d0e46e1b3a..917f27754a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/models/Backup.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/models/Backup.kt @@ -14,6 +14,7 @@ object Backup { const val TRACK = "track" const val CHAPTERS = "chapters" const val CATEGORIES = "categories" + const val EXTENSIONS = "extensions" const val HISTORY = "history" const val VERSION = "version"