fix: crash when downloaded filename too long

This commit is contained in:
Bnyro 2023-09-10 12:40:04 +02:00
parent 62ff36b77c
commit d4ba106aa7
2 changed files with 13 additions and 1 deletions

View File

@ -162,11 +162,17 @@ class DownloadDialog : DialogFragment() {
restorePreviousSelections(binding, videoStreams, audioStreams, subtitles)
onDownloadConfirm = onDownloadConfirm@{
if (binding.fileName.text.toString().isEmpty()) {
val fileName = binding.fileName.text.toString()
if (fileName.isBlank()) {
Toast.makeText(context, R.string.invalid_filename, Toast.LENGTH_SHORT).show()
return@onDownloadConfirm
}
if (fileName.length > MAX_FILE_NAME_LENGTH - 20) { // reserve 20 chars for quality and extension
Toast.makeText(context, R.string.filename_too_long, Toast.LENGTH_SHORT).show()
return@onDownloadConfirm
}
val videoPosition = binding.videoSpinner.selectedItemPosition - 1
val audioPosition = binding.audioSpinner.selectedItemPosition - 1
val subtitlePosition = binding.subtitleSpinner.selectedItemPosition - 1
@ -269,6 +275,11 @@ class DownloadDialog : DialogFragment() {
}
companion object {
/**
* Max file name length at Android systems
*/
private const val MAX_FILE_NAME_LENGTH = 255
private const val VIDEO_DOWNLOAD_QUALITY = "video_download_quality"
private const val VIDEO_DOWNLOAD_FORMAT = "video_download_format"
private const val AUDIO_DOWNLOAD_QUALITY = "audio_download_quality"

View File

@ -472,6 +472,7 @@
<string name="segment_type">Segment type</string>
<string name="sb_invalid_segment">Invalid segment start or end</string>
<string name="contribute_to_sponsorblock">Contribute to SponsorBlock</string>
<string name="filename_too_long">Filename too long!</string>
<!-- Notification channel strings -->
<string name="download_channel_name">Download Service</string>