From 3be2d74f0a5523d10e3962ce7672820de5bbea6a Mon Sep 17 00:00:00 2001 From: Martijn Brekhof Date: Tue, 20 Jun 2017 20:12:16 +0200 Subject: [PATCH] Fixed issue with filenames that contain question marks (#409) --- .../org/xbmc/kore/utils/FileDownloadHelper.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/xbmc/kore/utils/FileDownloadHelper.java b/app/src/main/java/org/xbmc/kore/utils/FileDownloadHelper.java index 0b09729..edfc32b 100644 --- a/app/src/main/java/org/xbmc/kore/utils/FileDownloadHelper.java +++ b/app/src/main/java/org/xbmc/kore/utils/FileDownloadHelper.java @@ -42,6 +42,9 @@ import java.util.List; public class FileDownloadHelper { private static final String TAG = LogUtils.makeLogTag(FileDownloadHelper.class); + // These chars cause problems with DownloadManager + private static final String RESERVED_CHARS_REGEX = "[?]"; + public static final int OVERWRITE_FILES = 0, DOWNLOAD_WITH_NEW_NAME = 1; @@ -80,16 +83,18 @@ public class FileDownloadHelper { public String getAbsoluteDirectoryPath() { File externalFilesDir = Environment.getExternalStoragePublicDirectory(getExternalPublicDirType()); - return externalFilesDir.getPath() + "/" + getRelativeDirectoryPath(); - + String filePath = externalFilesDir.getPath() + "/" + getRelativeDirectoryPath(); + return filePath.replaceAll(RESERVED_CHARS_REGEX, "_"); } public String getAbsoluteFilePath() { - return getAbsoluteDirectoryPath() + "/" + getDownloadFileName(); + String filePath = getAbsoluteDirectoryPath() + "/" + getDownloadFileName(); + return filePath.replaceAll(RESERVED_CHARS_REGEX, "_"); } public String getRelativeFilePath() { - return getRelativeDirectoryPath() + "/" + getDownloadFileName(); + String filePath = getRelativeDirectoryPath() + "/" + getDownloadFileName(); + return filePath.replaceAll(RESERVED_CHARS_REGEX, "_"); } public abstract String getExternalPublicDirType();