2017-05-21 07:42:06 -04:00
|
|
|
package eu.kanade.tachiyomi
|
|
|
|
|
|
|
|
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
|
|
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
|
|
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
2017-12-11 14:01:28 -05:00
|
|
|
import eu.kanade.tachiyomi.data.updater.UpdaterJob
|
2017-05-21 07:42:06 -04: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
|
|
|
|
val oldVersion = preferences.lastVersionCode().getOrDefault()
|
|
|
|
if (oldVersion < BuildConfig.VERSION_CODE) {
|
|
|
|
preferences.lastVersionCode().set(BuildConfig.VERSION_CODE)
|
|
|
|
|
2020-03-07 13:11:02 -05:00
|
|
|
// Fresh install
|
|
|
|
if (oldVersion == 0) {
|
|
|
|
// Set up default app updater task
|
|
|
|
if (BuildConfig.INCLUDE_UPDATER && preferences.automaticUpdates()) {
|
|
|
|
UpdaterJob.setupTask(context)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2017-05-21 07:42:06 -04:00
|
|
|
|
|
|
|
if (oldVersion < 14) {
|
2020-03-07 13:00:58 -05:00
|
|
|
// Restore jobs after upgrading to Evernote's job scheduler.
|
2017-05-21 07:42:06 -04:00
|
|
|
if (BuildConfig.INCLUDE_UPDATER && preferences.automaticUpdates()) {
|
2020-03-07 13:00:58 -05:00
|
|
|
UpdaterJob.setupTask(context)
|
2017-05-21 07:42:06 -04:00
|
|
|
}
|
2020-03-07 13:00:58 -05:00
|
|
|
LibraryUpdateJob.setupTask(context)
|
2017-05-21 07:42:06 -04: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 13:00:58 -05:00
|
|
|
oldDir.listFiles()?.forEach {
|
2017-05-21 07:42:06 -04:00
|
|
|
it.renameTo(File(destDir, it.name))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-10 06:29:04 -04: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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-21 07:42:06 -04:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2020-02-26 18:03:34 -05:00
|
|
|
}
|