Start storing extension ID/source name mapping in backup files

This commit is contained in:
arkon 2020-05-01 21:25:23 -04:00
parent 37045c77cb
commit abf2d4b718
2 changed files with 22 additions and 0 deletions

View file

@ -24,6 +24,7 @@ import eu.kanade.tachiyomi.data.backup.models.Backup
import eu.kanade.tachiyomi.data.backup.models.Backup.CATEGORIES import eu.kanade.tachiyomi.data.backup.models.Backup.CATEGORIES
import eu.kanade.tachiyomi.data.backup.models.Backup.CHAPTERS import eu.kanade.tachiyomi.data.backup.models.Backup.CHAPTERS
import eu.kanade.tachiyomi.data.backup.models.Backup.CURRENT_VERSION import eu.kanade.tachiyomi.data.backup.models.Backup.CURRENT_VERSION
import eu.kanade.tachiyomi.data.backup.models.Backup.EXTENSIONS
import eu.kanade.tachiyomi.data.backup.models.Backup.HISTORY import eu.kanade.tachiyomi.data.backup.models.Backup.HISTORY
import eu.kanade.tachiyomi.data.backup.models.Backup.MANGA import eu.kanade.tachiyomi.data.backup.models.Backup.MANGA
import eu.kanade.tachiyomi.data.backup.models.Backup.TRACK import eu.kanade.tachiyomi.data.backup.models.Backup.TRACK
@ -110,24 +111,38 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
// Create category array // Create category array
val categoryEntries = JsonArray() val categoryEntries = JsonArray()
// Create extension ID/name mapping
val extensionEntries = JsonArray()
// Add value's to root // Add value's to root
root[Backup.VERSION] = CURRENT_VERSION root[Backup.VERSION] = CURRENT_VERSION
root[Backup.MANGAS] = mangaEntries root[Backup.MANGAS] = mangaEntries
root[CATEGORIES] = categoryEntries root[CATEGORIES] = categoryEntries
root[EXTENSIONS] = extensionEntries
databaseHelper.inTransaction { databaseHelper.inTransaction {
// Get manga from database // Get manga from database
val mangas = getFavoriteManga() val mangas = getFavoriteManga()
val extensions: MutableSet<String> = mutableSetOf()
// Backup library manga and its dependencies // Backup library manga and its dependencies
mangas.forEach { manga -> mangas.forEach { manga ->
mangaEntries.add(backupMangaObject(manga, flags)) mangaEntries.add(backupMangaObject(manga, flags))
// Maintain set of extensions/sources used (excludes local source)
if (manga.source != 0L) {
extensions.add("${manga.source}:${sourceManager.get(manga.source)!!.name}")
}
} }
// Backup categories // Backup categories
if ((flags and BACKUP_CATEGORY_MASK) == BACKUP_CATEGORY) { if ((flags and BACKUP_CATEGORY_MASK) == BACKUP_CATEGORY) {
backupCategories(categoryEntries) backupCategories(categoryEntries)
} }
// Backup extension ID/name mapping
backupExtensionInfo(extensionEntries, extensions)
} }
try { try {
@ -170,6 +185,12 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
} }
} }
private fun backupExtensionInfo(root: JsonArray, extensions: Set<String>) {
extensions.sorted().forEach {
root.add(it)
}
}
/** /**
* Backup the categories of library * Backup the categories of library
* *

View file

@ -14,6 +14,7 @@ object Backup {
const val TRACK = "track" const val TRACK = "track"
const val CHAPTERS = "chapters" const val CHAPTERS = "chapters"
const val CATEGORIES = "categories" const val CATEGORIES = "categories"
const val EXTENSIONS = "extensions"
const val HISTORY = "history" const val HISTORY = "history"
const val VERSION = "version" const val VERSION = "version"