Skip to content

Commit e6a7542

Browse files
author
Jan Guegel
committed
use sanitizeFilename for FileItem
remove hardcoded string
1 parent 49bae41 commit e6a7542

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

app/src/main/kotlin/org/fossify/filemanager/activities/SaveAsActivity.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,19 @@ class SaveAsActivity : SimpleActivity() {
154154
return try {
155155
val originalFilename = getFilenameFromContentUri(source)
156156
?: source.toString().getFilenameFromPath()
157-
?: "file_$index"
158-
val filename = originalFilename.replace("[/\\\\<>:\"|?*\u0000-\u001F]".toRegex(), "_")
159-
.takeIf { it.isNotBlank() } ?: "unnamed_file"
157+
val filename = sanitizeFilename(originalFilename)
160158

161159
val mimeType = contentResolver.getType(source)
162160
?: mimeTypes?.getOrNull(index)?.takeIf { it != "*/*" }
163161
?: intent.type?.takeIf { it != "*/*" }
164162
?: filename.getMimeType()
165163

166164
val inputStream = contentResolver.openInputStream(source)
167-
?: throw IOException("Cannot open input stream")
165+
?: throw IOException(getString(R.string.error, source))
168166

169167
val destinationPath = getAvailablePath("$destination/$filename")
170168
val outputStream = getFileOutputStreamSync(destinationPath, mimeType, null)
171-
?: throw IOException("Cannot create output stream")
169+
?: throw IOException(getString(R.string.error, source))
172170

173171
inputStream.use { input ->
174172
outputStream.use { output ->

0 commit comments

Comments
 (0)