From 07af3ea703f416aa1b45168bd9980d8e31e0307f Mon Sep 17 00:00:00 2001 From: Koitharu Date: Tue, 14 Oct 2025 14:38:54 +0300 Subject: [PATCH] Backup-restore fixes --- app/src/main/AndroidManifest.xml | 1 + .../kotatsu/backups/domain/AppBackupAgent.kt | 23 +++++++++++-------- .../kotatsu/backups/domain/BackupSection.kt | 2 +- app/src/main/res/xml/backup_content.xml | 12 ++++++++++ app/src/main/res/xml/backup_rules.xml | 12 +++++++++- 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9ed1691e5..d23fea7fd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -55,6 +55,7 @@ android:fullBackupContent="@xml/backup_content" android:fullBackupOnly="true" android:hasFragileUserData="true" + android:restoreAnyVersion="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:largeHeap="true" diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/backups/domain/AppBackupAgent.kt b/app/src/main/kotlin/org/koitharu/kotatsu/backups/domain/AppBackupAgent.kt index d63e22a66..110f3143f 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/backups/domain/AppBackupAgent.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/backups/domain/AppBackupAgent.kt @@ -36,15 +36,14 @@ class AppBackupAgent : BackupAgent() { override fun onFullBackup(data: FullBackupDataOutput) { super.onFullBackup(data) - val file = - createBackupFile( - this, - BackupRepository( - MangaDatabase(context = applicationContext), - AppSettings(applicationContext), - TapGridSettings(applicationContext), - ), - ) + val file = createBackupFile( + this, + BackupRepository( + MangaDatabase(context = applicationContext), + AppSettings(applicationContext), + TapGridSettings(applicationContext), + ), + ) try { fullBackupFile(file, data) } finally { @@ -90,8 +89,12 @@ class AppBackupAgent : BackupAgent() { @VisibleForTesting fun restoreBackupFile(fd: FileDescriptor, size: Long, repository: BackupRepository) { ZipInputStream(ByteStreams.limit(FileInputStream(fd), size)).use { input -> + val sections = EnumSet.allOf(BackupSection::class.java) + // managed externally + sections.remove(BackupSection.SETTINGS) + sections.remove(BackupSection.SETTINGS_READER_GRID) runBlocking { - repository.restoreBackup(input, EnumSet.allOf(BackupSection::class.java), null) + repository.restoreBackup(input, sections, null) } } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/backups/domain/BackupSection.kt b/app/src/main/kotlin/org/koitharu/kotatsu/backups/domain/BackupSection.kt index b418787da..05762cd68 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/backups/domain/BackupSection.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/backups/domain/BackupSection.kt @@ -21,7 +21,7 @@ enum class BackupSection( fun of(entry: ZipEntry): BackupSection? { val name = entry.name.lowercase(Locale.ROOT) - return entries.first { x -> x.entryName == name } + return entries.find { x -> x.entryName == name } } } } diff --git a/app/src/main/res/xml/backup_content.xml b/app/src/main/res/xml/backup_content.xml index f2c5989ed..b4c3946f2 100644 --- a/app/src/main/res/xml/backup_content.xml +++ b/app/src/main/res/xml/backup_content.xml @@ -3,4 +3,16 @@ + + + + diff --git a/app/src/main/res/xml/backup_rules.xml b/app/src/main/res/xml/backup_rules.xml index 5c0b063ba..2b2c835ec 100644 --- a/app/src/main/res/xml/backup_rules.xml +++ b/app/src/main/res/xml/backup_rules.xml @@ -2,5 +2,15 @@ + + + + - \ No newline at end of file + + + + + + +