Keep the names of uninstalled sources across backup restores
This commit is contained in:
@@ -27,12 +27,12 @@ class BackupFileValidator(
|
|||||||
val sources = backup.backupSources.associate { it.sourceId to it.name }
|
val sources = backup.backupSources.associate { it.sourceId to it.name }
|
||||||
val missingSources = sources
|
val missingSources = sources
|
||||||
.filterKeys { sourceManager.get(it) == null }
|
.filterKeys { sourceManager.get(it) == null }
|
||||||
.values.map {
|
.map { (id, name) ->
|
||||||
val id = it.toLongOrNull()
|
// Some backups store the id as the name, and sources without a stub were backed up with no name
|
||||||
if (id == null) {
|
if (name.isBlank() || name.toLongOrNull() != null) {
|
||||||
it
|
|
||||||
} else {
|
|
||||||
sourceManager.getOrStub(id).toString()
|
sourceManager.getOrStub(id).toString()
|
||||||
|
} else {
|
||||||
|
name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.distinct()
|
.distinct()
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.data.backup.models.BackupCategory
|
|||||||
import eu.kanade.tachiyomi.data.backup.models.BackupExtensionStore
|
import eu.kanade.tachiyomi.data.backup.models.BackupExtensionStore
|
||||||
import eu.kanade.tachiyomi.data.backup.models.BackupManga
|
import eu.kanade.tachiyomi.data.backup.models.BackupManga
|
||||||
import eu.kanade.tachiyomi.data.backup.models.BackupPreference
|
import eu.kanade.tachiyomi.data.backup.models.BackupPreference
|
||||||
|
import eu.kanade.tachiyomi.data.backup.models.BackupSource
|
||||||
import eu.kanade.tachiyomi.data.backup.models.BackupSourcePreferences
|
import eu.kanade.tachiyomi.data.backup.models.BackupSourcePreferences
|
||||||
import eu.kanade.tachiyomi.data.backup.restore.restorers.CategoriesRestorer
|
import eu.kanade.tachiyomi.data.backup.restore.restorers.CategoriesRestorer
|
||||||
import eu.kanade.tachiyomi.data.backup.restore.restorers.ExtensionStoreRestorer
|
import eu.kanade.tachiyomi.data.backup.restore.restorers.ExtensionStoreRestorer
|
||||||
@@ -26,6 +27,8 @@ import kotlinx.coroutines.launch
|
|||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
import tachiyomi.core.common.i18n.stringResource
|
import tachiyomi.core.common.i18n.stringResource
|
||||||
import tachiyomi.core.common.util.system.logcat
|
import tachiyomi.core.common.util.system.logcat
|
||||||
|
import tachiyomi.domain.source.repository.StubSourceRepository
|
||||||
|
import tachiyomi.domain.source.service.SourceManager
|
||||||
import tachiyomi.i18n.MR
|
import tachiyomi.i18n.MR
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
@@ -48,6 +51,8 @@ class BackupRestorer(
|
|||||||
private val extensionStoreRestorer: ExtensionStoreRestorer,
|
private val extensionStoreRestorer: ExtensionStoreRestorer,
|
||||||
private val mangaRestorer: MangaRestorer,
|
private val mangaRestorer: MangaRestorer,
|
||||||
private val backupDecoder: BackupDecoder,
|
private val backupDecoder: BackupDecoder,
|
||||||
|
private val sourceManager: SourceManager,
|
||||||
|
private val stubSourceRepository: StubSourceRepository,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@AssistedFactory
|
@AssistedFactory
|
||||||
@@ -99,6 +104,7 @@ class BackupRestorer(
|
|||||||
sourceMapping = backupMaps.associate { it.sourceId to it.name }
|
sourceMapping = backupMaps.associate { it.sourceId to it.name }
|
||||||
|
|
||||||
if (options.libraryEntries) {
|
if (options.libraryEntries) {
|
||||||
|
restoreSourceNames(backupMaps)
|
||||||
restoreAmount += backup.backupManga.size
|
restoreAmount += backup.backupManga.size
|
||||||
}
|
}
|
||||||
if (options.categories) {
|
if (options.categories) {
|
||||||
@@ -145,6 +151,16 @@ class BackupRestorer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Without a stub, a source that isn't installed has no name for the next backup to write
|
||||||
|
private suspend fun restoreSourceNames(backupSources: List<BackupSource>) {
|
||||||
|
backupSources
|
||||||
|
.filter { it.name.isNotBlank() }
|
||||||
|
.filter {
|
||||||
|
sourceManager.get(it.sourceId) == null && stubSourceRepository.getStubSource(it.sourceId) == null
|
||||||
|
}
|
||||||
|
.forEach { stubSourceRepository.upsertStubSource(it.sourceId, lang = "", name = it.name) }
|
||||||
|
}
|
||||||
|
|
||||||
private fun CoroutineScope.restoreCategories(backupCategories: List<BackupCategory>) = launch {
|
private fun CoroutineScope.restoreCategories(backupCategories: List<BackupCategory>) = launch {
|
||||||
ensureActive()
|
ensureActive()
|
||||||
categoriesRestorer(backupCategories)
|
categoriesRestorer(backupCategories)
|
||||||
|
|||||||
Reference in New Issue
Block a user