mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07:57 +01:00 
			
		
		
		
	Show error toast if empty URI is passed when trying to create/restore a backup
This commit is contained in:
		| @@ -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) | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user