2017-05-21 13:42:06 +02:00
|
|
|
package eu.kanade.tachiyomi
|
|
|
|
|
2020-03-13 22:29:51 +01:00
|
|
|
import eu.kanade.tachiyomi.data.backup.BackupCreatorJob
|
2017-05-21 13:42:06 +02:00
|
|
|
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
|
|
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
2017-12-11 20:01:28 +01:00
|
|
|
import eu.kanade.tachiyomi.data.updater.UpdaterJob
|
2020-03-21 03:53:24 +01:00
|
|
|
import eu.kanade.tachiyomi.extension.ExtensionUpdateJob
|
2020-05-02 01:59:08 +02:00
|
|
|
import eu.kanade.tachiyomi.ui.library.LibrarySort
|
2017-05-21 13:42:06 +02:00
|
|
|
import java.io.File
|
|
|
|
|
|
|
|
object Migrations {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs a migration when the application is updated.
|
|
|
|
*
|
|
|
|
* @param preferences Preferences of the application.
|
|
|
|
* @return true if a migration is performed, false otherwise.
|
|
|
|
*/
|
|
|
|
fun upgrade(preferences: PreferencesHelper): Boolean {
|
|
|
|
val context = preferences.context
|
2020-04-18 02:12:43 +02:00
|
|
|
val oldVersion = preferences.lastVersionCode().get()
|
2020-04-24 16:39:55 +02:00
|
|
|
|
|
|
|
// Cancel app updater job for debug builds that don't include it
|
|
|
|
if (BuildConfig.DEBUG && !BuildConfig.INCLUDE_UPDATER) {
|
|
|
|
UpdaterJob.cancelTask(context)
|
|
|
|
}
|
|
|
|
|
2017-05-21 13:42:06 +02:00
|
|
|
if (oldVersion < BuildConfig.VERSION_CODE) {
|
|
|
|
preferences.lastVersionCode().set(BuildConfig.VERSION_CODE)
|
|
|
|
|
2020-03-07 19:11:02 +01:00
|
|
|
// Fresh install
|
|
|
|
if (oldVersion == 0) {
|
2020-05-01 02:27:02 +02:00
|
|
|
// Set up default background tasks
|
2020-04-24 16:39:55 +02:00
|
|
|
if (BuildConfig.INCLUDE_UPDATER) {
|
2020-03-07 19:11:02 +01:00
|
|
|
UpdaterJob.setupTask(context)
|
|
|
|
}
|
2020-04-29 15:42:56 +02:00
|
|
|
ExtensionUpdateJob.setupTask(context)
|
2020-05-01 02:27:02 +02:00
|
|
|
LibraryUpdateJob.setupTask(context)
|
2020-03-07 19:11:02 +01:00
|
|
|
return false
|
|
|
|
}
|
2017-05-21 13:42:06 +02:00
|
|
|
|
|
|
|
if (oldVersion < 14) {
|
2020-03-07 19:00:58 +01:00
|
|
|
// Restore jobs after upgrading to Evernote's job scheduler.
|
2020-04-24 16:39:55 +02:00
|
|
|
if (BuildConfig.INCLUDE_UPDATER) {
|
2020-03-07 19:00:58 +01:00
|
|
|
UpdaterJob.setupTask(context)
|
2017-05-21 13:42:06 +02:00
|
|
|
}
|
2020-03-07 19:00:58 +01:00
|
|
|
LibraryUpdateJob.setupTask(context)
|
2017-05-21 13:42:06 +02:00
|
|
|
}
|
|
|
|
if (oldVersion < 15) {
|
|
|
|
// Delete internal chapter cache dir.
|
|
|
|
File(context.cacheDir, "chapter_disk_cache").deleteRecursively()
|
|
|
|
}
|
|
|
|
if (oldVersion < 19) {
|
|
|
|
// Move covers to external files dir.
|
|
|
|
val oldDir = File(context.externalCacheDir, "cover_disk_cache")
|
|
|
|
if (oldDir.exists()) {
|
|
|
|
val destDir = context.getExternalFilesDir("covers")
|
|
|
|
if (destDir != null) {
|
2020-03-07 19:00:58 +01:00
|
|
|
oldDir.listFiles()?.forEach {
|
2017-05-21 13:42:06 +02:00
|
|
|
it.renameTo(File(destDir, it.name))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-10 12:29:04 +02:00
|
|
|
if (oldVersion < 26) {
|
|
|
|
// Delete external chapter cache dir.
|
|
|
|
val extCache = context.externalCacheDir
|
|
|
|
if (extCache != null) {
|
|
|
|
val chapterCache = File(extCache, "chapter_disk_cache")
|
|
|
|
if (chapterCache.exists()) {
|
|
|
|
chapterCache.deleteRecursively()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-13 22:29:51 +01:00
|
|
|
if (oldVersion < 43) {
|
|
|
|
// Restore jobs after migrating from Evernote's job scheduler to WorkManager.
|
2020-04-24 16:39:55 +02:00
|
|
|
if (BuildConfig.INCLUDE_UPDATER) {
|
2020-03-13 22:29:51 +01:00
|
|
|
UpdaterJob.setupTask(context)
|
|
|
|
}
|
|
|
|
LibraryUpdateJob.setupTask(context)
|
|
|
|
BackupCreatorJob.setupTask(context)
|
2020-04-29 15:09:18 +02:00
|
|
|
|
|
|
|
// New extension update check job
|
2020-04-29 15:42:56 +02:00
|
|
|
ExtensionUpdateJob.setupTask(context)
|
2020-03-13 22:29:51 +01:00
|
|
|
}
|
2020-05-02 01:59:08 +02:00
|
|
|
if (oldVersion < 44) {
|
|
|
|
// Reset sorting preference if using removed sort by source
|
|
|
|
if (preferences.librarySortingMode().get() == LibrarySort.SOURCE) {
|
|
|
|
preferences.librarySortingMode().set(LibrarySort.ALPHA)
|
|
|
|
}
|
|
|
|
}
|
2020-07-04 20:36:56 +02:00
|
|
|
return true
|
2017-05-21 13:42:06 +02:00
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2020-02-27 00:03:34 +01:00
|
|
|
}
|