mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
feat: Check if folder is accessible via IO
Signed-off-by: Myzel394 <50424412+Myzel394@users.noreply.github.com>
This commit is contained in:
parent
f77aeb78c6
commit
257e38632b
@ -25,6 +25,9 @@ import app.myzel394.alibi.ui.SUPPORTS_SCOPED_STORAGE
|
|||||||
import app.myzel394.alibi.ui.utils.PermissionHelper
|
import app.myzel394.alibi.ui.utils.PermissionHelper
|
||||||
import com.arthenica.ffmpegkit.FFmpegKitConfig
|
import com.arthenica.ffmpegkit.FFmpegKitConfig
|
||||||
import kotlinx.coroutines.CompletableDeferred
|
import kotlinx.coroutines.CompletableDeferred
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
@ -592,20 +595,29 @@ abstract class BatchesFolder(
|
|||||||
return 350 * 1024 * 1024
|
return 350 * 1024 * 1024
|
||||||
}
|
}
|
||||||
|
|
||||||
fun canAccessFolder(context: Context, uri: Uri): Boolean {
|
suspend fun canAccessFolder(context: Context, uri: Uri): Boolean {
|
||||||
return try {
|
var canAccess = false
|
||||||
|
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
try {
|
||||||
// Create temp file
|
// Create temp file
|
||||||
val tempFile = DocumentFile.fromSingleUri(context, uri)!!.createFile(
|
val documentFile = DocumentFile.fromTreeUri(context, uri)!!
|
||||||
|
val tempFile = documentFile.createFile(
|
||||||
"application/octet-stream",
|
"application/octet-stream",
|
||||||
"temp"
|
"temp"
|
||||||
)!!
|
)!!
|
||||||
|
if (!tempFile.exists() || !tempFile.canWrite() || !tempFile.canRead()) {
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
tempFile.delete()
|
tempFile.delete()
|
||||||
|
|
||||||
true
|
canAccess = true
|
||||||
} catch (error: RuntimeException) {
|
} catch (error: RuntimeException) {
|
||||||
error.printStackTrace()
|
error.printStackTrace()
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
}.join()
|
||||||
|
|
||||||
|
return canAccess
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,10 +96,12 @@ fun SaveFolderTile(
|
|||||||
|
|
||||||
val successMessage = stringResource(R.string.ui_settings_option_saveFolder_success)
|
val successMessage = stringResource(R.string.ui_settings_option_saveFolder_success)
|
||||||
fun updateValue(path: String?) {
|
fun updateValue(path: String?) {
|
||||||
|
scope.launch {
|
||||||
if (path != null && path != RECORDER_MEDIA_SELECTED_VALUE) {
|
if (path != null && path != RECORDER_MEDIA_SELECTED_VALUE) {
|
||||||
context.contentResolver.takePersistableUriPermission(
|
context.contentResolver.takePersistableUriPermission(
|
||||||
path.toUri(),
|
path.toUri(),
|
||||||
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||||
|
or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!BatchesFolder.canAccessFolder(context, path.toUri())) {
|
if (!BatchesFolder.canAccessFolder(context, path.toUri())) {
|
||||||
@ -111,7 +113,7 @@ fun SaveFolderTile(
|
|||||||
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return
|
return@launch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +134,6 @@ fun SaveFolderTile(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scope.launch {
|
|
||||||
dataStore.updateData {
|
dataStore.updateData {
|
||||||
it.setSaveFolder(path)
|
it.setSaveFolder(path)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user