mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Use unified storage location for automatic backups
This commit is contained in:
parent
695813ef7d
commit
1fbf8ca079
7 changed files with 14 additions and 40 deletions
|
@ -21,6 +21,7 @@ import eu.kanade.tachiyomi.util.system.workManager
|
||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
import tachiyomi.core.util.system.logcat
|
import tachiyomi.core.util.system.logcat
|
||||||
import tachiyomi.domain.backup.service.BackupPreferences
|
import tachiyomi.domain.backup.service.BackupPreferences
|
||||||
|
import tachiyomi.domain.storage.service.StoragePreferences
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
@ -39,8 +40,9 @@ class BackupCreateJob(private val context: Context, workerParams: WorkerParamete
|
||||||
if (isAutoBackup && BackupRestoreJob.isRunning(context)) return Result.retry()
|
if (isAutoBackup && BackupRestoreJob.isRunning(context)) return Result.retry()
|
||||||
|
|
||||||
val backupPreferences = Injekt.get<BackupPreferences>()
|
val backupPreferences = Injekt.get<BackupPreferences>()
|
||||||
|
|
||||||
val uri = inputData.getString(LOCATION_URI_KEY)?.toUri()
|
val uri = inputData.getString(LOCATION_URI_KEY)?.toUri()
|
||||||
?: backupPreferences.backupsDirectory().get().toUri()
|
?: getAutomaticBackupLocation()
|
||||||
val flags = inputData.getInt(BACKUP_FLAGS_KEY, BackupCreateFlags.AutomaticDefaults)
|
val flags = inputData.getInt(BACKUP_FLAGS_KEY, BackupCreateFlags.AutomaticDefaults)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -73,6 +75,15 @@ class BackupCreateJob(private val context: Context, workerParams: WorkerParamete
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getAutomaticBackupLocation(): Uri {
|
||||||
|
val storagePreferences = Injekt.get<StoragePreferences>()
|
||||||
|
return storagePreferences.baseStorageDirectory().get().let {
|
||||||
|
val dir = UniFile.fromUri(context, it.toUri())
|
||||||
|
.createDirectory(StoragePreferences.BACKUP_DIR)
|
||||||
|
dir.uri
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun isManualJobRunning(context: Context): Boolean {
|
fun isManualJobRunning(context: Context): Boolean {
|
||||||
return context.workManager.isRunning(TAG_MANUAL)
|
return context.workManager.isRunning(TAG_MANUAL)
|
||||||
|
|
|
@ -47,7 +47,6 @@ class DownloadProvider(
|
||||||
val dir = UniFile.fromUri(context, it.toUri())
|
val dir = UniFile.fromUri(context, it.toUri())
|
||||||
.createDirectory(StoragePreferences.DOWNLOADS_DIR)
|
.createDirectory(StoragePreferences.DOWNLOADS_DIR)
|
||||||
DiskUtil.createNoMediaFile(dir, context)
|
DiskUtil.createNoMediaFile(dir, context)
|
||||||
logcat { "downloadsDir: ${dir.filePath}" }
|
|
||||||
dir
|
dir
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
|
||||||
import eu.kanade.tachiyomi.util.system.isDevFlavor
|
import eu.kanade.tachiyomi.util.system.isDevFlavor
|
||||||
import tachiyomi.core.preference.AndroidPreferenceStore
|
import tachiyomi.core.preference.AndroidPreferenceStore
|
||||||
import tachiyomi.core.preference.PreferenceStore
|
import tachiyomi.core.preference.PreferenceStore
|
||||||
import tachiyomi.core.provider.AndroidBackupFolderProvider
|
|
||||||
import tachiyomi.core.provider.AndroidStorageFolderProvider
|
import tachiyomi.core.provider.AndroidStorageFolderProvider
|
||||||
import tachiyomi.domain.backup.service.BackupPreferences
|
import tachiyomi.domain.backup.service.BackupPreferences
|
||||||
import tachiyomi.domain.download.service.DownloadPreferences
|
import tachiyomi.domain.download.service.DownloadPreferences
|
||||||
|
@ -53,13 +52,7 @@ class PreferenceModule(val app: Application) : InjektModule {
|
||||||
DownloadPreferences(get())
|
DownloadPreferences(get())
|
||||||
}
|
}
|
||||||
addSingletonFactory {
|
addSingletonFactory {
|
||||||
AndroidBackupFolderProvider(app)
|
BackupPreferences(get())
|
||||||
}
|
|
||||||
addSingletonFactory {
|
|
||||||
BackupPreferences(
|
|
||||||
folderProvider = get<AndroidBackupFolderProvider>(),
|
|
||||||
preferenceStore = get(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
addSingletonFactory {
|
addSingletonFactory {
|
||||||
AndroidStorageFolderProvider(app)
|
AndroidStorageFolderProvider(app)
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
package tachiyomi.core.provider
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.os.Environment
|
|
||||||
import androidx.core.net.toUri
|
|
||||||
import tachiyomi.core.i18n.stringResource
|
|
||||||
import tachiyomi.i18n.MR
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
class AndroidBackupFolderProvider(
|
|
||||||
private val context: Context,
|
|
||||||
) : FolderProvider {
|
|
||||||
|
|
||||||
override fun directory(): File {
|
|
||||||
return File(
|
|
||||||
Environment.getExternalStorageDirectory().absolutePath + File.separator +
|
|
||||||
context.stringResource(MR.strings.app_name),
|
|
||||||
"backup",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun path(): String {
|
|
||||||
return directory().toUri().toString()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,15 +2,11 @@ package tachiyomi.domain.backup.service
|
||||||
|
|
||||||
import tachiyomi.core.preference.Preference
|
import tachiyomi.core.preference.Preference
|
||||||
import tachiyomi.core.preference.PreferenceStore
|
import tachiyomi.core.preference.PreferenceStore
|
||||||
import tachiyomi.core.provider.FolderProvider
|
|
||||||
|
|
||||||
class BackupPreferences(
|
class BackupPreferences(
|
||||||
private val folderProvider: FolderProvider,
|
|
||||||
private val preferenceStore: PreferenceStore,
|
private val preferenceStore: PreferenceStore,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun backupsDirectory() = preferenceStore.getString("backup_directory", folderProvider.path())
|
|
||||||
|
|
||||||
fun backupInterval() = preferenceStore.getInt("backup_interval", 12)
|
fun backupInterval() = preferenceStore.getInt("backup_interval", 12)
|
||||||
|
|
||||||
fun lastAutoBackupTimestamp() = preferenceStore.getLong(Preference.appStateKey("last_auto_backup_timestamp"), 0L)
|
fun lastAutoBackupTimestamp() = preferenceStore.getLong(Preference.appStateKey("last_auto_backup_timestamp"), 0L)
|
||||||
|
|
|
@ -11,6 +11,7 @@ class StoragePreferences(
|
||||||
fun baseStorageDirectory() = preferenceStore.getString("storage_dir", folderProvider.path())
|
fun baseStorageDirectory() = preferenceStore.getString("storage_dir", folderProvider.path())
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
const val BACKUP_DIR = "backup"
|
||||||
const val DOWNLOADS_DIR = "downloads"
|
const val DOWNLOADS_DIR = "downloads"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -469,7 +469,6 @@
|
||||||
<string name="pref_create_backup_summ">Can be used to restore current library</string>
|
<string name="pref_create_backup_summ">Can be used to restore current library</string>
|
||||||
<string name="pref_restore_backup">Restore backup</string>
|
<string name="pref_restore_backup">Restore backup</string>
|
||||||
<string name="pref_restore_backup_summ">Restore library from backup file</string>
|
<string name="pref_restore_backup_summ">Restore library from backup file</string>
|
||||||
<string name="pref_backup_directory">Backup location</string>
|
|
||||||
<string name="pref_backup_interval">Automatic backup frequency</string>
|
<string name="pref_backup_interval">Automatic backup frequency</string>
|
||||||
<string name="action_create">Create</string>
|
<string name="action_create">Create</string>
|
||||||
<string name="backup_created">Backup created</string>
|
<string name="backup_created">Backup created</string>
|
||||||
|
|
Loading…
Reference in a new issue