mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 11:01:52 +01:00
Show error toast if empty URI is passed when trying to create/restore a backup
This commit is contained in:
parent
1b71e4cee7
commit
d5015d37e1
@ -21,7 +21,7 @@ abstract class AbstractBackupManager(protected val context: Context) {
|
||||
internal val trackManager: TrackManager by injectLazy()
|
||||
protected val preferences: PreferencesHelper by injectLazy()
|
||||
|
||||
abstract fun createBackup(uri: Uri, flags: Int, isJob: Boolean): String?
|
||||
abstract fun createBackup(uri: Uri, flags: Int, isJob: Boolean): String
|
||||
|
||||
/**
|
||||
* Returns manga
|
||||
|
@ -44,7 +44,7 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) {
|
||||
* @param uri path of Uri
|
||||
* @param isJob backup called from job
|
||||
*/
|
||||
override fun createBackup(uri: Uri, flags: Int, isJob: Boolean): String? {
|
||||
override fun createBackup(uri: Uri, flags: Int, isJob: Boolean): String {
|
||||
// Create root object
|
||||
var backup: Backup? = null
|
||||
|
||||
@ -87,7 +87,7 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) {
|
||||
file.openOutputStream().sink().gzip().buffer().use { it.write(byteArray) }
|
||||
val fileUri = file.uri
|
||||
|
||||
// Validate it to make sure it works
|
||||
// Make sure it's a valid backup file
|
||||
FullBackupRestoreValidator().validate(context, fileUri)
|
||||
|
||||
return fileUri.toString()
|
||||
|
@ -162,39 +162,33 @@ class SettingsBackupController : SettingsController() {
|
||||
val activity = activity ?: return
|
||||
val uri = data.data
|
||||
|
||||
if (uri == null) {
|
||||
activity.toast(R.string.backup_restore_invalid_uri)
|
||||
return
|
||||
}
|
||||
|
||||
when (requestCode) {
|
||||
CODE_BACKUP_DIR -> {
|
||||
// Get UriPermission so it's possible to write files
|
||||
val flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or
|
||||
Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
|
||||
if (uri != null) {
|
||||
activity.contentResolver.takePersistableUriPermission(uri, flags)
|
||||
}
|
||||
|
||||
// Set backup Uri
|
||||
activity.contentResolver.takePersistableUriPermission(uri, flags)
|
||||
preferences.backupsDirectory().set(uri.toString())
|
||||
}
|
||||
CODE_BACKUP_CREATE -> {
|
||||
val flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or
|
||||
Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
|
||||
if (uri != null) {
|
||||
activity.contentResolver.takePersistableUriPermission(uri, flags)
|
||||
}
|
||||
|
||||
val file = UniFile.fromUri(activity, uri)
|
||||
|
||||
activity.toast(R.string.creating_backup)
|
||||
|
||||
activity.contentResolver.takePersistableUriPermission(uri, flags)
|
||||
BackupCreateService.start(
|
||||
activity,
|
||||
file.uri,
|
||||
uri,
|
||||
backupFlags,
|
||||
)
|
||||
}
|
||||
CODE_BACKUP_RESTORE -> {
|
||||
uri?.let { RestoreBackupDialog(it).showDialog(router) }
|
||||
RestoreBackupDialog(uri).showDialog(router)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -425,6 +425,7 @@
|
||||
<string name="pref_backup_slots">Maximum backups</string>
|
||||
<string name="source_not_found_name">Source not found: %1$s</string>
|
||||
<string name="tracker_not_logged_in">Not logged in: %1$s</string>
|
||||
<string name="backup_restore_invalid_uri">Error: empty URI</string>
|
||||
<string name="backup_created">Backup created</string>
|
||||
<string name="invalid_backup_file">Invalid backup file</string>
|
||||
<string name="invalid_backup_file_missing_data">File is missing data.</string>
|
||||
|
Loading…
Reference in New Issue
Block a user